)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Inventory (Ia.Ftn.Cl.Models)

Public general use code classes and xml files that we've compiled and used over the years:

Inventory Entity Framework class for Fixed Telecommunications Network (FTN) entity model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.ComponentModel.DataAnnotations.Schema;
    5: using System.Threading;
    6: using System.Threading.Tasks;
    7:  
    8: namespace Ia.Ftn.Cl.Models
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Inventory Entity Framework class for Fixed Telecommunications Network (FTN) entity model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     /// </remarks> 
   19:     public class Inventory
   20:     {
   21:         /// <summary/>
   22:         public Inventory() { }
   23:  
   24:         /// <summary/>
   25:         public int Id { get; set; }
   26:  
   27:         /// <summary/>
   28:         public string Name { get; set; }
   29:  
   30:         /// <summary/>
   31:         public int Company { get; set; }
   32:  
   33:         /// <summary/>
   34:         public string Description { get; set; }
   35:  
   36:         /// <summary/>
   37:         public string BarCode { get; set; }
   38:  
   39:         /// <summary/>
   40:         public int Quantity { get; set; }
   41:  
   42:         /// <summary/>
   43:         public float Price { get; set; }
   44:  
   45:         /// <summary/>
   46:         public DateTime Created { get; set; }
   47:  
   48:         /// <summary/>
   49:         public DateTime Updated { get; set; }
   50:  
   51:         /// <summary/>
   52:         [ForeignKey("StaffIdentityUser_Id")]
   53:         public virtual StaffIdentityUser StaffIdentityUser { get; set; }
   54:  
   55:         ////////////////////////////////////////////////////////////////////////////
   56:  
   57:         /// <summary>
   58:         ///
   59:         /// </summary>
   60:         public static bool Create(Inventory newInventory, out string result)
   61:         {
   62:             bool b;
   63:  
   64:             b = false;
   65:             result = string.Empty;
   66:  
   67:             using (var db = new Ia.Ftn.Cl.Db())
   68:             {
   69:                 newInventory.Created = newInventory.Updated = DateTime.UtcNow.AddHours(3);
   70:  
   71:                 db.Inventories.Add(newInventory);
   72:                 db.SaveChanges();
   73:  
   74:                 b = true;
   75:             }
   76:  
   77:             return b;
   78:         }
   79:  
   80:         ////////////////////////////////////////////////////////////////////////////
   81:  
   82:         /// <summary>
   83:         ///
   84:         /// </summary>
   85:         public static Inventory Read(int id)
   86:         {
   87:             Inventory inventory;
   88:  
   89:             using (var db = new Ia.Ftn.Cl.Db())
   90:             {
   91:                 inventory = (from i in db.Inventories where i.Id == id select i).SingleOrDefault();
   92:             }
   93:  
   94:             return inventory;
   95:         }
   96:  
   97:         ////////////////////////////////////////////////////////////////////////////
   98:  
   99:         /// <summary>
  100:         ///
  101:         /// </summary>
  102:         public static List<Inventory> ReadList()
  103:         {
  104:             List<Inventory> inventoryList;
  105:  
  106:             using (var db = new Ia.Ftn.Cl.Db())
  107:             {
  108:                 inventoryList = (from i in db.Inventories select i).ToList();
  109:             }
  110:  
  111:             return inventoryList;
  112:         }
  113:  
  114:         ////////////////////////////////////////////////////////////////////////////
  115:  
  116:         /// <summary>
  117:         ///
  118:         /// </summary>
  119:         public static bool Update(Inventory updatedInventory, out string result)
  120:         {
  121:             bool b;
  122:  
  123:             b = false;
  124:             result = string.Empty;
  125:  
  126:             using (var db = new Ia.Ftn.Cl.Db())
  127:             {
  128:                 updatedInventory = (from i in db.Inventories where i.Id == updatedInventory.Id select i).SingleOrDefault();
  129:  
  130:                 updatedInventory.Updated = DateTime.UtcNow.AddHours(3);
  131:  
  132:                 db.Inventories.Attach(updatedInventory);
  133:  
  134:                 var v = db.Entry(updatedInventory);
  135:                 v.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  136:                 db.SaveChanges();
  137:  
  138:                 b = true;
  139:             }
  140:  
  141:             return b;
  142:         }
  143:  
  144:         ////////////////////////////////////////////////////////////////////////////
  145:  
  146:         /// <summary>
  147:         ///
  148:         /// </summary>
  149:         public bool Update(/*Ont updatedOnt*/ object updatedObject)
  150:         {
  151:             // below: this will not update Id, Created
  152:             bool updated;
  153:  
  154:             updated = false;
  155:  
  156:             //if (this.StateId != updatedOnt.StateId) { this.StateId = updatedOnt.StateId; updated = true; }
  157:  
  158:             //if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
  159:  
  160:             return updated;
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:  
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         public static bool QuantityChange(int inventoryId, int increment, out string result)
  169:         {
  170:             bool b;
  171:             Inventory updatedInventory;
  172:  
  173:             b = false;
  174:             result = string.Empty;
  175:  
  176:             using (var db = new Ia.Ftn.Cl.Db())
  177:             {
  178:                 updatedInventory = (from i in db.Inventories where i.Id == inventoryId select i).SingleOrDefault();
  179:  
  180:                 updatedInventory.Quantity += increment;
  181:  
  182:                 if (updatedInventory.Quantity >= 0)
  183:                 {
  184:                     // below: don't go below 0
  185:                     updatedInventory.Updated = DateTime.UtcNow.AddHours(3);
  186:  
  187:                     db.Inventories.Attach(updatedInventory);
  188:  
  189:                     var v = db.Entry(updatedInventory);
  190:                     v.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  191:                     db.SaveChanges();
  192:  
  193:                     b = true;
  194:                 }
  195:                 else
  196:                 {
  197:                     b = false;
  198:                 }
  199:             }
  200:  
  201:             return b;
  202:         }
  203:  
  204:         ////////////////////////////////////////////////////////////////////////////
  205:  
  206:         /// <summary>
  207:         ///
  208:         /// </summary>
  209:         public static bool Delete(int id, out string result)
  210:         {
  211:             bool b;
  212:  
  213:             b = false;
  214:             result = string.Empty;
  215:  
  216:             using (var db = new Ia.Ftn.Cl.Db())
  217:             {
  218:                 var v = (from i in db.Inventories where i.Id == id select i).FirstOrDefault();
  219:  
  220:                 if (v.Quantity == 0)
  221:                 {
  222:                     db.Inventories.Remove(v);
  223:                     db.SaveChanges();
  224:  
  225:                     b = true;
  226:                 }
  227:                 else
  228:                 {
  229:                     result = "Item can't be deleted because quantity is not zero. ";
  230:  
  231:                     b = false;
  232:                 }
  233:             }
  234:  
  235:             return b;
  236:         }
  237:  
  238:         /*
  239: <?xml version="1.0" encoding="utf-8"?>
  240: 
  241: <inventory>
  242: 
  243:   <!--
  244:   Inventory System Requirements
  245: 
  246:   demand and
  247:   replenishment lead time data
  248: 
  249:   forecasts
  250: 
  251:   reviewing the stock
  252:   position;
  253:   - preparing the purchase
  254:   request;
  255:   - selecting the supplier;
  256:   receiving, inspecting, and
  257:   placing the material in
  258:   storage; and
  259:   - paying the vendor.
  260: 
  261:   Does the system estimate and
  262:   routinely update the per unit
  263:   inventory holding cost, which
  264:   is an estimate of the cost to
  265:   hold each additional unit of
  266:   inventory? Its primary
  267:   elements are storage space,
  268:   obsolescence, interest on
  269:   inventory investment, and
  270:   inventory shrinkage (due to
  271:   deterioration, theft, damage,
  272:   etc.).
  273:   4.
  274: 
  275: 
  276:   Does the system recompute
  277:   the Economic Order Quantity
  278:   (EOQ) on a regular, frequent
  279:   schedule, using the demand
  280:   forecast, ordering cost,
  281:   inventory holding cost, and
  282:   unit cost of the material? In
  283:   lieu of the EOQ, any other
  284:   optimum order quantity
  285:   calculation may be used,
  286:   provided (a) it is based on
  287:   sound business principles and
  288:   (b) it minimizes total cost,
  289:   including the sum of ordering
  290:   and inventory holding costs
  291: 
  292: 
  293:   Does the system recompute
  294:   the safety stock, if any, on a
  295:   regular and frequent schedule
  296: 
  297: 
  298:   Does the system recompute
  299:   the reorder point level on a
  300:   regular and frequent schedule
  301: 
  302: 
  303:   Does the system determine if
  304:   replenishment is needed on a
  305:   regular and frequent schedule,
  306:   basing the determination on
  307:   net stock and reorder point? If
  308:   needed, immediately initiate a
  309:   replenishment action using the
  310:   EOQ or other order quantity,
  311: 
  312:   Does the system provide
  313:   information on current
  314:   inventories and historical
  315:   usage to be used in capacity
  316:   planning?
  317: 
  318:   Does the system provide to
  319:   agency inventory managers
  320:   and designated internal review
  321:   officials, on a periodic or
  322:   requested basis, at least the
  323:   following types of
  324:   management information:
  325:   - demand?
  326:   - procurement lead time?
  327:   - procurement cycle?
  328:   - requirements?
  329:   - assets?
  330:   - available funds?
  331:   - budget versus actual?
  332:   - rates of fund utilization?
  333: 
  334:   Does the system record
  335:   information on material
  336:   returned by customers?
  337: 
  338:   Does the system provide
  339:   support for physical
  340:   verification of inventory
  341:   balances by location and type?
  342: 
  343:   Does the system record
  344:   changes in physical condition
  345:   (e.g., excellent, good, fair, or
  346:   poor), quantities, etc., based
  347:   on the results of physical
  348:   inventory verifications?
  349: 
  350:   =====================================
  351: 
  352:   Inventory System supports updating inventory information for all items, monitoring inventory depletion, and importing and exporting
  353:   inventory information to and from external systems of record
  354: 
  355:   =====================================
  356: 
  357:   Flexible configuration that allows for backordering and display of out of stock stock-keeping units (SKUs).
  358: 
  359:   Order checking and update through pipeline components.
  360: 
  361:   Full text search and query integration with the Catalog System.
  362: 
  363:   Transactional updates.
  364: 
  365:   Import and export operations similar to the Catalog System.
  366: 
  367:   Runtime APIs with methods for searching, browsing, viewing details, inventory search options that include product filtering, assigning inventory conditions, and roll-up values.
  368:   
  369:   
  370:   
  371:   Inventory Disposition consists of the following processes: (a) loaning
  372: process, (b) issuing process, and (c) disposal process.
  373: 
  374: 
  375: inventory shrinkage (due to
  376: deterioration, theft, damage,
  377: etc.).
  378: 4.
  379: 
  380: Economic Order Quantity
  381: (EOQ) on
  382: 
  383: 
  384:   <inventory>
  385:     <transaction>
  386:       <type id="1" name="Purchased" name_ar=""/>
  387:       <type id="2" name="Sold" name_ar=""/>
  388:       <type id="3" name="On Hold" name_ar=""/>
  389:       <type id="4" name="Waste" name_ar=""/>
  390:       <type id="0" name="Unspecified" name_ar="غير معرف"/>
  391:     </transaction>
  392:   </inventory>
  393: 
  394:   -->
  395: 
  396:   <type id="1" name="ONT" description=""/>
  397:   <type id="2" name="Computer" description=""/>
  398:   <type id="3" name="Board" description=""/>
  399:   <type id="4" name="Card" description=""/>
  400:   <type id="5" name="Switch" description=""/>
  401:   <type id="6" name="Cable" description=""/>
  402:   <type id="7" name="RJ" description=""/>
  403:   <type id="8" name="Screen" description=""/>
  404:   <type id="9" name="Keyboard" description=""/>
  405:   <type id="10" name="Mouse" description=""/>
  406:   <type id="11" name="Phone" description=""/>
  407: 
  408:   <item id="1" type_id="1" name="SFU" code="" discontinued="" description=""/>
  409: 
  410: </inventory>
  411:          */
  412:  
  413:         ////////////////////////////////////////////////////////////////////////////
  414:         ////////////////////////////////////////////////////////////////////////////
  415:     }
  416:  
  417:     ////////////////////////////////////////////////////////////////////////////
  418:     ////////////////////////////////////////////////////////////////////////////
  419: }