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