Example #1
0
        public void InsertOrUpdateIssue(string productId, int quantity, string issueId)
        {
            try
            {
                Inventory inventory;
                if (CheckExits(productId))
                {
                    inventory = new Inventory
                    {
                        Date = DateTime.Now.Date.ToString("MM-yyyy"),
                        InventoryDate = DateTime.Now.Date,
                        ProductID = productId,
                        InventoryFirt = 0,
                        IssueID = issueId,
                        TotalOut = quantity,
                        Plan = 0,
                    };

                    if (string.IsNullOrEmpty(inventory.TotalIn.ToString()))
                    {
                        inventory.TotalIn = 0;
                    }

                    Add(inventory);
                }
                else
                {
                    inventory = GetInventoryByProductId(productId);
                    if (inventory != null)
                    {
                        if (inventory.TotalOut > 0)
                        {
                            inventory.TotalOut += quantity;
                        }
                        else
                        {
                            inventory.TotalOut = quantity;
                        }
                        
                    }
                    try
                    {
                        Update(inventory);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// Thêm mới hoặc cập nhật vào bảng
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="quantity"></param>
        /// <param name="receiptId"></param>
        public void InsertOrUpdateReceipt(string productId, int quantity, string receiptId, int plan)
        {
            try
            {
                Inventory inventory;
                if (CheckExits(productId))
                {
                    inventory = new Inventory
                    {
                        InventoryDate = DateTime.Now.Date,
                        ProductID = productId,
                        InventoryFirt = 0,
                        ReceiptID = receiptId,
                        TotalIn = quantity,
                        Plan = plan,
                    };

                    if (string.IsNullOrEmpty(inventory.TotalOut.ToString()))
                    {
                        inventory.TotalOut = 0;
                    }

                    Add(inventory);
                }
                else
                {
                    // Update Quantiry
                    inventory = GetInventoryByProductId(productId);
                    
                    if (inventory != null)
                    {
                        inventory.ReceiptID = receiptId;
                        if (inventory.TotalIn > 0)
                        {
                            inventory.TotalIn += quantity;
                        }
                        else
                        {
                            inventory.TotalIn = quantity;
                        }

                    }
                    try
                    {
                        Update(inventory);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="inventory"></param>
 public void Add(Inventory inventory)
 {
     _context.Inventories.Add(inventory);
     SaveChanges();
 }
Example #4
0
 /// <summary>
 /// Cập nhật thông tin
 /// </summary>
 /// <param name="inventory"></param>
 private void Update(Inventory inventory)
 {
     _context.Inventories.Attach(inventory);
     _context.Entry(inventory).State = EntityState.Modified;
     SaveChanges();
 }
Example #5
0
        public void InsertOrUpdateInventoryExport(string productId, int quantity, string orderExportId)
        {
            try
            {
                Inventory inventory;
                if (CheckExits(productId))
                {
                    inventory = new Inventory
                    {
                        InventoryDate = DateTime.Now.Date,
                        ProductID = productId,
                        QuantityFirst = 0,
                        OrderImportID = orderExportId,
                        QuantityExport = quantity,
                    };

                    if (string.IsNullOrEmpty(inventory.QuantityImport.ToString()))
                    {
                        inventory.QuantityImport = 0;
                    }

                    Add(inventory);
                }
                else
                {
                    inventory = GetInventoryByProductId(productId);
                    if (inventory != null)
                    {
                        if (inventory.QuantityExport > 0)
                        {
                            inventory.QuantityExport += quantity;
                        }
                        else
                        {
                            inventory.QuantityExport = quantity;
                        }
                        
                    }
                    try
                    {
                        Update(inventory);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }