Пример #1
0
        public ActionResult SavePrimaryChallan(List <PrimaryReceiveLineVm> primaryReceiveLineVm)
        {
            tblt_PurchaseOrder purchaseOrder = new tblt_PurchaseOrder();

            int dbid = (int)Session["DBId"];

            DateTime systemDate      = (DateTime)Session["SystemDate"];
            var      singleOrDefault = primaryReceiveLineVm.FirstOrDefault();

            var primaryChallanExist = Db.tblt_PurchaseOrder.FirstOrDefault(x => x.ChallanNo == singleOrDefault.PrimaryChallanno);

            if (primaryChallanExist == null)
            {
                if (singleOrDefault != null)
                {
                    purchaseOrder.ChallanNo   = singleOrDefault.PrimaryChallanno;
                    purchaseOrder.ChallanDate = singleOrDefault.PrimaryChallanDate;
                }
                purchaseOrder.ReceivedDate = systemDate;
                purchaseOrder.Timestamp    = DateTime.Now;
                purchaseOrder.DbId         = dbid;

                Db.tblt_PurchaseOrder.Add(purchaseOrder);
                Db.SaveChanges();

                int id = purchaseOrder.Id;


                foreach (var item in primaryReceiveLineVm)
                {
                    var latestBatch = (from a in Db.tbld_distribution_house
                                       join b in Db.tbld_bundle_price_details on a.PriceBuandle_id equals b.bundle_price_id
                                       where a.DB_Id == dbid && b.sku_id == item.SkuId && b.status == 1
                                       orderby b.batch_id descending
                                       select new { b.batch_id, b.db_lifting_price }).FirstOrDefault();

                    var tbltInventory = Db.tblt_inventory
                                        .Where(x => x.dbId == dbid && x.skuId == item.SkuId && x.batchNo == latestBatch.batch_id)
                                        .Select(x => new { x.id, x.dbId, x.skuId, x.BundleItemid, x.packSize, x.batchNo, x.qtyPs })
                                        .SingleOrDefault();

                    if (latestBatch != null)
                    {
                        tblt_inventory tbltinventory;
                        if (tbltInventory != null)
                        {
                            //Have Inventory

                            tbltinventory = new tblt_inventory
                            {
                                id           = tbltInventory.id,
                                dbId         = tbltInventory.dbId,
                                skuId        = tbltInventory.skuId,
                                BundleItemid = tbltInventory.BundleItemid,
                                packSize     = tbltInventory.packSize,
                                batchNo      = latestBatch.batch_id,
                                qtyPs        = tbltInventory.qtyPs + item.ReceiveQuantity,
                            };
                            Db.Entry(tbltinventory).State = EntityState.Modified;
                        }
                        else
                        {
                            //add new line
                            tbltinventory = new tblt_inventory
                            {
                                dbId         = dbid,
                                skuId        = item.SkuId,
                                BundleItemid = 0,
                                packSize     = item.PackSize,
                                batchNo      = latestBatch.batch_id,
                                qtyPs        = item.ReceiveQuantity,
                            };
                            Db.tblt_inventory.Add(tbltinventory);
                        }

                        tblt_PurchaseOrderLine tbltPurchaseOrderLine = new tblt_PurchaseOrderLine()
                        {
                            POId       = id,
                            sku_id     = item.SkuId,
                            BundelItem = 0,
                            BatchId    = latestBatch.batch_id,
                            Price      = latestBatch.db_lifting_price,
                            PackSize   = item.PackSize,
                            ChallanQty = item.ChallanQuantity,
                            ReciveQty  = item.ReceiveQuantity
                        };
                        Db.tblt_PurchaseOrderLine.Add(tbltPurchaseOrderLine);
                        // Add inventory log
                        tbll_inventory_log tbllInventoryLog = new tbll_inventory_log
                        {
                            db_id          = dbid,
                            sku_id         = item.SkuId,
                            batch_id       = latestBatch.batch_id,
                            price          = 0,
                            tx_qty_ps      = item.ReceiveQuantity,
                            tx_type        = 1,
                            tx_System_date = systemDate,
                            tx_date        = DateTime.Now,
                            tx_challan     = purchaseOrder.ChallanNo
                        };

                        Db.tbll_inventory_log.Add(tbllInventoryLog);
                    }
                    Db.SaveChanges();
                }
                TempData["alertbox"]    = "success";
                TempData["alertboxMsg"] = "Challan Receive successfully";
                return(RedirectToAction("Index"));
            }
            TempData["alertbox"]    = "error";
            TempData["alertboxMsg"] = "Challan Already Received";
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult PurchaseSave(PurchaseInsertVM purchaseInsertVm)
        {
            DateTime           systemDate    = (DateTime)Session["SystemDate"];
            int                dbid          = (int)Session["DBId"];
            tblt_PurchaseOrder purchaseOrder = new tblt_PurchaseOrder
            {
                ChallanNo    = purchaseInsertVm.ChallanNo,
                ChallanDate  = purchaseInsertVm.ChallanDate,
                ReceivedDate = systemDate,
                Timestamp    = DateTime.Now,
                DbId         = dbid
            };


            Db.tblt_PurchaseOrder.Add(purchaseOrder);
            int id = purchaseOrder.Id;

            foreach (var item in purchaseInsertVm.PurchaseLine)
            {
                var tbltInventory = Db.tblt_inventory
                                    .Where(x => x.dbId == dbid && x.skuId == item.SkuId && x.batchNo == item.BetchId)
                                    .Select(x => new { x.id, x.dbId, x.skuId, x.BundleItemid, x.packSize, x.batchNo, x.qtyPs })
                                    .SingleOrDefault();

                tblt_inventory tbltinventory;
                if (tbltInventory != null)
                {
                    //Have Inventory



                    tbltinventory = new tblt_inventory
                    {
                        id           = tbltInventory.id,
                        dbId         = tbltInventory.dbId,
                        skuId        = tbltInventory.skuId,
                        BundleItemid = tbltInventory.BundleItemid,
                        packSize     = tbltInventory.packSize,
                        batchNo      = tbltInventory.batchNo,
                        qtyPs        = tbltInventory.qtyPs + item.ChallanQuantity,
                    };
                    Db.Entry(tbltinventory).State = EntityState.Modified;
                }
                else
                {
                    //add new line
                    tbltinventory = new tblt_inventory
                    {
                        dbId         = dbid,
                        skuId        = item.SkuId,
                        BundleItemid = item.Bundelitemid,
                        packSize     = item.PackSize,
                        batchNo      = item.BetchId,
                        qtyPs        = item.ChallanQuantity,
                    };
                    Db.tblt_inventory.Add(tbltinventory);
                }



                tblt_PurchaseOrderLine tbltPurchaseOrderLine = new tblt_PurchaseOrderLine()
                {
                    POId       = id,
                    sku_id     = item.SkuId,
                    BundelItem = item.Bundelitemid,
                    BatchId    = item.BetchId,
                    Price      = item.UnitSalePrice,
                    PackSize   = item.PackSize,
                    ChallanQty = item.ChallanQuantity,
                    ReciveQty  = item.ChallanQuantity
                };
                Db.tblt_PurchaseOrderLine.Add(tbltPurchaseOrderLine);

                // Add inventory log
                tbll_inventory_log tbllInventoryLog = new tbll_inventory_log
                {
                    db_id          = dbid,
                    sku_id         = item.SkuId,
                    batch_id       = item.BetchId,
                    price          = 0,
                    tx_qty_ps      = item.ChallanQuantity,
                    tx_type        = 1,
                    tx_System_date = systemDate,
                    tx_date        = DateTime.Now,
                    tx_challan     = purchaseOrder.ChallanNo
                };

                Db.tbll_inventory_log.Add(tbllInventoryLog);
            }
            Db.SaveChanges();


            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public ActionResult UpdateStock(List <InventoryAdjustmentVm> inventoryAdjustmentVm)
        {
            int userId = (int)Session["User_Id"];

            var      item       = inventoryAdjustmentVm.FirstOrDefault();
            DateTime syatemdate = db.tblt_System.Where(x => x.DBid == item.DbId).Select(x => x.CurrentDate).SingleOrDefault();

            if (item != null)
            {
                tbld_AdjustmentStock tbldAdjustmentStock = new tbld_AdjustmentStock
                {
                    date       = DateTime.Now,
                    Syatemdate = syatemdate,
                    dbid       = item.DbId,
                    userid     = userId
                };

                db.tbld_AdjustmentStock.Add(tbldAdjustmentStock);
                db.SaveChanges();


                db.tblt_inventory.RemoveRange(db.tblt_inventory.Where(x => x.dbId == item.DbId).ToList());
                db.SaveChanges();

                foreach (var inventoryitem in inventoryAdjustmentVm)
                {
                    int previousQty = ((inventoryitem.CurrentCSqty * inventoryitem.PackSize) +
                                       inventoryitem.CurrentPSqty) ?? 0;
                    int currentQty = ((inventoryitem.AdjustmentCSqty * inventoryitem.PackSize) +
                                      inventoryitem.AdjustmentPSqty) ?? 0;

                    int adjustedQty = currentQty - previousQty;


                    tbld_AdjustmentStockItem tbldAdjustmentStockItem = new tbld_AdjustmentStockItem
                    {
                        AdjustmentStockID = tbldAdjustmentStock.id,
                        SKUID             = inventoryitem.SkuId,
                        BatchNo           = inventoryitem.BatchNo,
                        PreviousQty       = previousQty,
                        CurrentQty        = currentQty,
                        AdjustedQty       = adjustedQty
                    };
                    db.tbld_AdjustmentStockItem.Add(tbldAdjustmentStockItem);
                    if (inventoryitem.PackSize != null)
                    {
                        tblt_inventory tbltInventory = new tblt_inventory
                        {
                            dbId         = item.DbId,
                            skuId        = inventoryitem.SkuId,
                            packSize     = (int)inventoryitem.PackSize,
                            BundleItemid = inventoryitem.BundleItemid,
                            batchNo      = inventoryitem.BatchNo,
                            qtyPs        = currentQty
                        };
                        db.tblt_inventory.Add(tbltInventory);
                        db.SaveChanges();
                    }
                }
                //add  routeplan datils
                TempData["alertbox"]    = "success";
                TempData["alertboxMsg"] = " Adjustment Stock Successfully";

                return(RedirectToAction("Index", "Home"));
            }
            return(null);
        }