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