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