コード例 #1
0
        public ActionResult ConfirmChallan(int id)
        {
            int confirmChallanFlag = 0;
            var date        = (DateTime)Session["SystemDate"];
            var tbltChallan = Db.tblt_Challan.Find(id);


            List <ChallanlineVm> challanlineVmList = new List <ChallanlineVm>();

            if (tbltChallan != null)
            {
                var skuList = from a in Db.tblt_Challan_line
                              join b in Db.tbld_SKU on a.sku_id equals b.SKU_id
                              where a.challan_id == id
                              select a;

                foreach (var skuListitem in skuList)
                {
                    int confirmQty  = 0;
                    int freeQty     = 0;
                    var orderQtysum = (from a in Db.tblt_Order
                                       join b in Db.tblt_Order_line on a.Orderid equals b.Orderid
                                       where b.sku_id == skuListitem.sku_id &&
                                       b.Betch_id == skuListitem.batch_id && b.sku_order_type_id == 1 && a.so_status != 9 && a.Challan_no == id
                                       select(int?) b.quantity_delivered).Sum();

                    var freeQtysum = (from a in Db.tblt_Order
                                      join b in Db.tblt_Order_line on a.Orderid equals b.Orderid
                                      where b.sku_id == skuListitem.sku_id &&
                                      b.Betch_id == skuListitem.batch_id && b.sku_order_type_id == 2 && a.so_status != 9 && a.Challan_no == id
                                      select(int?) b.quantity_delivered).Sum();

                    if (orderQtysum != null)
                    {
                        confirmQty = (int)orderQtysum;
                    }

                    if (freeQtysum != null)
                    {
                        freeQty = (int)freeQtysum;
                    }

                    int challanQtyGap = skuListitem.Total_qty - (confirmQty + freeQty);

                    confirmChallanFlag = challanQtyGap < 0 ? 0 : 1;

                    ChallanlineVm challanlineVm = new ChallanlineVm
                    {
                        ChallanId      = skuListitem.challan_id,
                        SkuId          = skuListitem.sku_id,
                        BatchId        = skuListitem.batch_id,
                        PackSize       = skuListitem.Pack_size,
                        Price          = skuListitem.price,
                        TotalQty       = skuListitem.Total_qty,
                        ConfirmQty     = confirmQty,
                        ConfirmFreeQty = freeQty,
                        ReturnQty      = skuListitem.Total_qty - (confirmQty + freeQty)
                    };

                    challanlineVmList.Add(challanlineVm);
                }

                Double deliveryGrandTotalCs = 0;
                Double deliveryGrandTotal   = 0;

                if (confirmChallanFlag == 1)
                {
                    foreach (var challanlineitem in challanlineVmList)
                    {
                        Db.tblt_Challan_line.Where(x => x.challan_id == challanlineitem.ChallanId && x.sku_id == challanlineitem.SkuId && x.batch_id == challanlineitem.BatchId).ToList()
                        .ForEach(x =>
                        {
                            x.Confirm_qty       = challanlineitem.ConfirmQty;
                            x.Confirm_Free_qty  = challanlineitem.ConfirmFreeQty;
                            x.Return_qty        = challanlineitem.ReturnQty;
                            x.Confirm_qty_price = challanlineitem.ConfirmQty * x.price;
                        });


                        //Update Inventory
                        Db.tblt_inventory.Where(x => x.dbId == tbltChallan.db_id && x.skuId == challanlineitem.SkuId &&
                                                x.batchNo == challanlineitem.BatchId).ToList().ForEach(x =>
                        {
                            x.qtyPs = x.qtyPs + challanlineitem.ReturnQty;
                        });
                        if (challanlineitem.ReturnQty != 0)
                        {
                            // Add inventory log
                            tbll_inventory_log tbllInventoryLog = new tbll_inventory_log
                            {
                                db_id          = tbltChallan.db_id,
                                sku_id         = challanlineitem.SkuId,
                                batch_id       = challanlineitem.BatchId,
                                price          = 0,
                                tx_qty_ps      = challanlineitem.ReturnQty,
                                tx_type        = 3,
                                tx_System_date = date,
                                tx_date        = DateTime.Now,
                                tx_challan     = challanlineitem.ChallanId
                            };

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



                        deliveryGrandTotalCs = deliveryGrandTotalCs + ((Double)challanlineitem.ConfirmQty / challanlineitem.PackSize);
                        deliveryGrandTotal   = deliveryGrandTotal + (challanlineitem.ConfirmQty * challanlineitem.Price);
                    }

                    //Update Order status and add challan number
                    Db.tblt_Challan.Where(a => a.id == tbltChallan.id && a.challan_status == 1).ToList()
                    .ForEach(x =>
                    {
                        x.delivery_grand_total_CS = deliveryGrandTotalCs;
                        x.delivery_grand_total    = deliveryGrandTotal;
                        x.challan_status          = 2;
                    });
                    Db.SaveChanges();
                    //Update Order status and add challan number
                    Db.tblt_Order.Where(a => a.Challan_no == tbltChallan.id && a.so_status != 9).ToList()
                    .ForEach(x =>
                    {
                        x.delivery_date         = tbltChallan.delivery_date;
                        x.so_status             = 3;
                        x.delivery_Process_Date = DateTime.Now;
                    });
                    Db.SaveChanges();



                    // return RedirectToAction("index", new { id });
                    return(RedirectToAction("Index"));
                }
                else if (confirmChallanFlag == 0)
                {
                    return(RedirectToAction("ShowConfirmChallan", new { id }));
                }
            }

            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 Addchallan(ChallaniVm challaniVm)
        {
            int dbid = (int)Session["DBId"];
            var date = (DateTime)Session["SystemDate"];

            var deliverydate = Db.tbld_Route_Plan_Detail.SingleOrDefault(x => x.route_id == challaniVm.RouteId && x.planned_visit_date == challaniVm.OrderDate);

            if (deliverydate == null)
            {
                challaniVm.DeliveryDate = date;
            }
            else
            {
                if (deliverydate.delivery_date != null)
                {
                    challaniVm.DeliveryDate = (DateTime)deliverydate.delivery_date;
                }
            }

            if (challaniVm != null)
            {
                int          count         = Db.tblt_Challan.Count(x => x.System_date == date && x.db_id == dbid) + 1;
                string       challanNumber = "C-" + challaniVm.OrderDate.ToString("yyyymmdd") + "-" + dbid + "-" + challaniVm.PsrId + "-" + count;
                tblt_Challan tbltChallan   = new tblt_Challan
                {
                    challan_number          = challanNumber,
                    db_id                   = dbid,
                    psr_id                  = challaniVm.PsrId,
                    psr_Name                = challaniVm.PsrName,
                    route_id                = challaniVm.RouteId,
                    route_Name              = challaniVm.RouteName,
                    challan_status          = 1,
                    No_of_memo              = challaniVm.NoOfMemo,
                    order_date              = challaniVm.OrderDate,
                    delivery_date           = challaniVm.DeliveryDate,
                    Create_date_time        = DateTime.Now,
                    System_date             = date,
                    grand_total_CS          = challaniVm.GrandTotalCs,
                    delivery_grand_total_CS = 0,
                    grand_total             = challaniVm.GrandTotal,
                    delivery_grand_total    = 0
                };


                Db.tblt_Challan.Add(tbltChallan);
                Db.SaveChanges();
                int challanid = tbltChallan.id;

                foreach (var challanlineitem in challaniVm.Challanline)
                {
                    tblt_Challan_line tbltChallanLine = new tblt_Challan_line
                    {
                        challan_id        = challanid,
                        sku_id            = challanlineitem.SkuId,
                        batch_id          = challanlineitem.BatchId,
                        price             = challanlineitem.Price,
                        Pack_size         = challanlineitem.PackSize,
                        Order_qty         = challanlineitem.OrderQty,
                        Extra_qty         = challanlineitem.ExtraQty,
                        Free_qty          = challanlineitem.FreeQty,
                        Total_qty         = challanlineitem.TotalQty,
                        Confirm_qty       = 0,
                        Confirm_Free_qty  = 0,
                        Order_qty_price   = challanlineitem.OrderQty * challanlineitem.Price,
                        Extra_qty_price   = challanlineitem.ExtraQty * challanlineitem.Price,
                        Total_qty_price   = (challanlineitem.OrderQty + challanlineitem.ExtraQty) * challanlineitem.Price,
                        Confirm_qty_price = 0
                    };
                    Db.tblt_Challan_line.Add(tbltChallanLine);



                    //Update Inventory
                    Db.tblt_inventory.Where(x => x.dbId == dbid && x.skuId == challanlineitem.SkuId &&
                                            x.batchNo == challanlineitem.BatchId).ToList().ForEach(x =>
                    {
                        x.qtyPs = x.qtyPs - challanlineitem.TotalQty;
                    });

                    // Add inventory log
                    tbll_inventory_log tbllInventoryLog = new tbll_inventory_log
                    {
                        db_id          = dbid,
                        sku_id         = challanlineitem.SkuId,
                        batch_id       = challanlineitem.BatchId,
                        price          = 0,
                        tx_qty_ps      = challanlineitem.TotalQty,
                        tx_type        = 2,
                        tx_System_date = date,
                        tx_date        = DateTime.Now,
                        tx_challan     = challanid
                    };

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

                //Update Order status and add challan number
                Db.tblt_Order.Where(a => a.db_id == dbid && a.psr_id == challaniVm.PsrId &&
                                    a.route_id == challaniVm.RouteId &&
                                    a.isProcess == 1 && a.so_status == 1 && a.so_status != 9 &&
                                    a.planned_order_date == challaniVm.OrderDate && a.Challan_no == 0).ToList()
                .ForEach(x =>
                {
                    x.Challan_no = challanid;
                    x.so_status  = 2;
                });
                Db.SaveChanges();



                return(Json("Success", JsonRequestBehavior.AllowGet));
            }

            return(Json("Error", JsonRequestBehavior.AllowGet));
        }
コード例 #4
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"));
        }