Exemplo n.º 1
0
 public void UpdateInventoryInfo(InventorySaveModel inventory)
 {
     dataGridView1.DataSource = _inventory.GetInventoryDetail(inventory.InventoryDetail.Id, true);
     dataGridView2.DataSource = _inventory.GetInventory(inventory.Inventory.Id);
 }
Exemplo n.º 2
0
        public InventorySaveModel UpdateInventory(InventorySaveModel inventory)
        {
            try
            {
                using (FacturandoEntities context = new FacturandoEntities())
                {
                    bool isNewDetail = false;
                    InventoryDetail inventoryDetail = context.InventoryDetail
                        .Where(x => x.Id == inventory.InventoryDetail.Id)
                        .ToList()
                        .FirstOrDefault();

                    int inventoryQuantityTemp = 0;
                    int actualQuantity = inventoryDetail.Quantity;
                    int newQuantity = inventory.InventoryDetail.Quantity;

                    string actualSign = inventoryDetail.InventoryType.Sign;
                    string newSign = context.InventoryType
                        .Where(x => x.Id == inventory.InventoryDetail.IdInventoryType)
                        .ToList()
                        .FirstOrDefault().Sign;

                    Inventory inventoryTemp = context.Inventory
                           .Where(x => x.Id == inventory.Inventory.Id)
                           .ToList()
                           .FirstOrDefault();

                    inventoryTemp.LastSalePrice = inventory.InventoryDetail.SalePrice;

                    if (actualSign.Equals("+") && newSign.Equals("+"))
                    {
                        inventoryQuantityTemp = newQuantity - actualQuantity;
                        inventoryTemp.Quantity += inventoryQuantityTemp;
                    }

                    if (actualSign.Equals("-") && newSign.Equals("-"))
                    {
                        inventoryQuantityTemp = newQuantity - actualQuantity;
                        inventoryTemp.Quantity -= inventoryQuantityTemp;
                    }

                    if (actualSign.Equals("-") && newSign.Equals("+"))
                    {
                        inventoryQuantityTemp = newQuantity;
                        inventoryTemp.Quantity += inventoryQuantityTemp;
                        isNewDetail = true;
                    }

                    if (actualSign.Equals("+") && newSign.Equals("-"))
                    {
                        inventoryQuantityTemp = newQuantity;
                        inventoryTemp.Quantity -= inventoryQuantityTemp;
                        isNewDetail = true;
                    }

                    if (isNewDetail)
                    {
                        SaveInventory(inventory);
                    }
                    else
                    {
                        inventoryDetail.BarCodeData = inventory.InventoryDetail.BarCodeData;
                        inventoryDetail.ConstructionDate = inventory.InventoryDetail.ConstructDate;
                        inventoryDetail.DueDate = inventory.InventoryDetail.ConstructDate;
                        inventoryDetail.EventDate = inventory.InventoryDetail.EventDate;
                        inventoryDetail.IdInventoryClassification = inventory.InventoryDetail.IdInventoryClassification;
                        inventoryDetail.IdInventoryLocalization = inventory.InventoryDetail.IdInventoryLocalization;
                        inventoryDetail.PurchasePrice = inventory.InventoryDetail.PurchasePrice;
                        inventoryDetail.SalePrice = inventory.InventoryDetail.SalePrice;
                        inventoryDetail.IdInventoryType = inventory.InventoryDetail.IdInventoryType;
                        inventoryDetail.Quantity = inventory.InventoryDetail.Quantity;
                    }
                    
                    context.SaveChanges();
                    return inventory;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }        
Exemplo n.º 3
0
        public List<BillModel> CancelBill(List<BillModel> billList)
        {
            try
            {
                DateTime cancelDate = DateTime.Now;
                using (FacturandoEntities context = new FacturandoEntities())
                {
                    InventoryInterface inventoryData = new InventoryData();
                    var inventoryTypeList = inventoryData.GetInventoryType();
                    InventoryTypeModel inventoryTypeIn = inventoryTypeList.Where(x => x.Description.Equals("Devolución Cliente")).FirstOrDefault();
                    InventoryTypeModel inventoryTypeOut = inventoryTypeList.Where(x => x.Description.Equals("Venta")).FirstOrDefault();

                    foreach (var item in billList)
                    {
                        var billTemp = context.Bill.Where(x => x.Id == item.Id).FirstOrDefault();

                        // Simon Ariza - 10-03-2016 - inventory affect
                        if (billTemp.IsCanceled != item.IsCanceled)
                        {   
                            var billDetailTemp = context.BillDetail.Where(x => x.IdBill == item.Id).ToList();
                            foreach (var billProduct in billDetailTemp)
                            {
                                InventoryModel inventoryTemp = inventoryData.GetInventoryByProductId(billProduct.IdProduct.Value);
                                InventoryDetailModel inventoryDetailTemp = inventoryData.GetLastInventoryDetailInByProductId(billProduct.IdProduct.Value);
                                InventorySaveModel inventorySaveTemp = new InventorySaveModel {  Inventory = inventoryTemp, InventoryDetail = inventoryDetailTemp };
                                if (item.IsCanceled) // inventory in
                                {
                                    inventorySaveTemp.InventoryDetail.IdInventoryType = inventoryTypeIn.Id;                                    
                                }
                                else // inventory out
                                {
                                    inventorySaveTemp.InventoryDetail.IdInventoryType = inventoryTypeOut.Id;                                   
                                }
                                inventorySaveTemp.InventoryDetail.Quantity = billProduct.Quantity;
                                inventoryData.SaveInventory(inventorySaveTemp);
                            } 
                        }
                        //fin cambio

                        if (item.IsCanceled)
                        {
                            billTemp.IsCanceled = item.IsCanceled;
                            billTemp.CancelDate = cancelDate;
                            item.CancelDate = cancelDate;                            
                        }
                        else
                        {
                            billTemp.IsCanceled = item.IsCanceled;
                            billTemp.CancelDate = null;
                            item.CancelDate = null;
                        }
                    }
                    context.SaveChanges();
                    return billList;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public InventorySaveModel SaveInventory(InventorySaveModel inventory)
        {
            try
            {
                using (FacturandoEntities context = new FacturandoEntities())
                {
                    Inventory inventoryExists = context.Inventory
                        .Where(x => x.IdProduct == inventory.Inventory.IdProduct).ToList().FirstOrDefault();

                    int newQuantity = inventory.InventoryDetail.Quantity;

                    string newSign = context.InventoryType
                            .Where(x => x.Id == inventory.InventoryDetail.IdInventoryType)
                            .ToList().FirstOrDefault().Sign;
                    if (newSign.Equals("-"))
                    {
                        newQuantity = newQuantity * -1;
                    }

                    if (inventoryExists != null)
                    {
                        inventory.Inventory.Id = inventoryExists.Id;
                        inventoryExists.Quantity += newQuantity;
                        inventoryExists.LastSalePrice = inventory.InventoryDetail.SalePrice;
                        inventory.Inventory.IdProduct = inventoryExists.IdProduct.Value;
                        inventory.Inventory.Quantity = inventoryExists.Quantity;
                    }
                    else
                    {
                        inventory.Inventory.Id = Guid.NewGuid();
                        context.Inventory.Add(new Inventory
                        {
                            Id = inventory.Inventory.Id,
                            IdProduct = inventory.Inventory.IdProduct,
                            Quantity = newQuantity,
                            LastSalePrice = inventory.InventoryDetail.SalePrice
                        });
                    }
                    inventory.InventoryDetail.Id = Guid.NewGuid();
                    context.InventoryDetail.Add(new InventoryDetail
                    {
                        Id = inventory.InventoryDetail.Id,
                        BarCodeData = inventory.InventoryDetail.BarCodeData,
                        ConstructionDate = inventory.InventoryDetail.ConstructDate,
                        DueDate = inventory.InventoryDetail.ConstructDate,
                        EventDate = inventory.InventoryDetail.EventDate,
                        IdInventory = inventory.Inventory.Id,
                        IdInventoryClassification = inventory.InventoryDetail.IdInventoryClassification,
                        IdInventoryLocalization = inventory.InventoryDetail.IdInventoryLocalization,
                        IdInventoryType = inventory.InventoryDetail.IdInventoryType,
                        PurchasePrice = inventory.InventoryDetail.PurchasePrice,
                        SalePrice = inventory.InventoryDetail.SalePrice,
                        Quantity = inventory.InventoryDetail.Quantity
                    });
                    context.SaveChanges();
                    return inventory;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }