예제 #1
0
        public ActionResult SaveReturn(ReturnmentVM R)
        {
            var w = (from y in db.UserLogins
                     where y.UserID.ToString() == User.Identity.Name
                     select new { y.WorkStationID }).FirstOrDefault();
            var    wn        = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault();
            string s1        = w.WorkStationID.ToString();
            string s2        = string.Concat(s1 + "3000000");
            string s3        = string.Concat(s1 + "5000000");
            int    vRID      = Convert.ToInt32(s2);
            int    MaxCashID = Convert.ToInt32(s3);
            bool   status    = false;
            string mes       = "";
            //int  = db.Returnments.Max(p=>p.ReturnmentID)+1;
            var V = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault();

            var MvrID         = (from n in db.Returnments where n.WarehouseID == w.WorkStationID select n.ReturnmentID).DefaultIfEmpty(vRID).Max();
            int vrID          = MvrID + 1;
            int v             = vrID;
            var PTID          = (from x in db.ProductTransactions where x.WarehouseID == w.WorkStationID select x.TransactionNo).Max();
            int TrID          = (PTID + 1);
            var maxCasettleId = (from n in db.CashSettlements where n.WarehouseID == w.WorkStationID select n.CashSettlementID).DefaultIfEmpty(MaxCashID).Max();

            csID = Convert.ToInt32(maxCasettleId + 1);
            decimal securityAmt        = 0;
            decimal securitywithRebate = 0;
            decimal diffamt            = 0;
            decimal negload            = 0;

            if (ModelState.IsValid)
            {
                using (PEPSIEntities dc = new PEPSIEntities())
                {
                    CommonChk cm = new CommonChk();

                    Returnment dbr = new Returnment
                    {
                        WarehouseID    = R.WarehouseID,
                        ReturnmentID   = vrID,
                        CustomerID     = R.CustomerID,
                        Reasons        = R.Reasons,
                        RefNumber      = R.RefNumber,
                        ReturnDate     = DateTime.Today,//R.ReturnDate,
                        ReturnTypeID   = R.ReturnTypeID,
                        ReturnGoodsQty = R.ReturnGoodsQty,
                        InAmount       = R.InAmount,
                        AdjustedAmt    = R.AdjustedAmt,
                        CreateDate     = DateTime.Now,
                        CreateBy       = User.Identity.Name
                    };
                    dc.Returnments.Add(dbr);
                    if (R.FareAmt > 0)
                    {
                        var CustName = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault();
                        TransportAgencyandFareSetup tf = new TransportAgencyandFareSetup();
                        {
                            tf.WarehouseID   = R.WarehouseID;
                            tf.CustomerName  = CustName.CustomerName.ToString();
                            tf.Address       = CustName.CustomerAddress1;
                            tf.TAID          = (int)R.TAID;
                            tf.ChallanNumber = vrID;
                            tf.FareAmnt      = (decimal)R.FareAmt;
                            tf.VechileNo     = R.VechileNo;
                            tf.EnteredBy     = User.Identity.Name;
                            tf.EnteredDate   = DateTime.Now;
                            tf.ChallanDate   = DateTime.Today;
                            tf.TotalCases    = R.ReturnGoodsQty;
                            tf.Status        = "No";
                            tf.Remarks       = "Returned Hired Truck";
                            tf.EmptyReturn   = "Yes";
                        }
                        dc.TransportAgencyandFareSetups.Add(tf);
                    }
                    if (R.ReturnTypeID == 14)
                    {
                        foreach (var i in R.listreturndetail)

                        {
                            decimal countQtywithRebate        = 0;
                            int     countQtywithRebatePlastic = 0;
                            countQtywithRebate        = (decimal)i.ReturnQty + (decimal)i.RebateQty;
                            countQtywithRebatePlastic = (int)i.Packsize + (int)i.RebatePlastic;
                            decimal xxx = cm.GetSecurityAmount((int)i.ProductID, (decimal)i.ReturnQty, (int)i.Packsize);
                            decimal xx  = cm.GetSecurityAmount((int)i.ProductID, countQtywithRebate, countQtywithRebatePlastic);
                            securityAmt        = securityAmt + xxx;
                            securitywithRebate = securitywithRebate + xx;
                            diffamt            = securitywithRebate - securityAmt;
                        }
                    }

                    decimal cramt             = 0;
                    decimal drinksamount      = (decimal)R.InAmount - securityAmt;
                    decimal cramtsub          = (decimal)R.InAmount - (decimal)R.AdjustedAmt; // Unloadcharge is negetive
                    decimal cramtadd          = (decimal)R.InAmount + (decimal)R.AdjustedAmt;
                    decimal totsecurityamount = securityAmt + diffamt;
                    if (R.ReturnTypeID == 13)
                    {
                        cramt       = cramtadd;
                        securityAmt = (decimal)R.InAmount;
                    }
                    else
                    {
                        cramt = cramtsub;
                    }
                    if (R.ReturnTypeID != 13) // Not Empty Return
                    {
                        ProductTransaction dm = new ProductTransaction();
                        {
                            dm.TransactionTypeID = R.ReturnTypeID;
                            dm.TransactionNo     = TrID;//
                            dm.WarehouseID       = R.WarehouseID;
                            dm.FromWarehouse     = R.WarehouseID;
                            //dm.ToWarehouse = S.ToWarehouse;
                            dm.TransactionDate = DateTime.Today;
                            dm.ReferenceNo     = vrID.ToString();
                            if (R.ReturnTypeID != 13)
                            {
                                dm.Status = "R";
                            }
                            //else
                            //{
                            //    dm.Status = "A";
                            //}
                            //cuser = User.Identity.Name
                            dm.CreatedBy   = User.Identity.Name;
                            dm.CreatedDate = DateTime.Now;
                        }
                        dc.ProductTransactions.Add(dm);
                    }
                    // Customer Ledger
                    if (R.ReturnTypeID != 12)
                    {
                        CustomerLedgerDetail cld = new CustomerLedgerDetail();
                        {
                            cld.WarehouseID       = R.WarehouseID;
                            cld.CustomerID        = (int)R.CustomerID;
                            cld.TransactionNo     = "RTN" + vrID.ToString();
                            cld.TransactionTypeID = R.ReturnTypeID;
                            cld.RefNumber1        = R.RefNumber.ToString();
                            cld.TransactionDate   = DateTime.Today;
                            cld.CrAmount          = cramt;//R.InAmount;
                            cld.DrAmount          = 0;
                            cld.DebitCredit       = "C";
                            cld.Narration         = "Returnment Amount#" + cramt /*R.InAmount*/ + " to Customer" + cld.CustomerID;
                            cld.CreateBy          = User.Identity.Name;
                            cld.CreateDate        = System.DateTime.Now;
                        }
                        dc.CustomerLedgerDetails.Add(cld);
                        var            m  = (from x in db.Customers where x.CustomerID == R.CustomerID select x).FirstOrDefault();
                        CashSettlement cs = new CashSettlement();
                        cs.WarehouseID            = R.WarehouseID;
                        cs.CustomerID             = (int)R.CustomerID;
                        cs.CashSettlementID       = csID;
                        cs.CashSettlementDate     = DateTime.Today;
                        cs.DeliveryChallanDate    = DateTime.Today;
                        cs.OrderID                = vrID;// R.ReturnmentID;
                        cs.DeliveryChallanNumbers = 0;
                        cs.TransactionNo          = vrID;
                        cs.TotalAmount            = cramt;
                        cs.ReceivedAmount         = cramt;
                        cs.CustomerExecutiveID    = m.CustomerExecutiveID;
                        if (R.ReturnTypeID == 13)
                        {
                            cs.EmptyReturnLoadCharge = R.AdjustedAmt;
                            cs.SecurityAmount        = -R.InAmount;
                        }
                        else
                        {
                            // cs.FinishGoodsUnloadCharge = R.AdjustedAmt;
                            cs.ReturnFGCharge = R.AdjustedAmt;
                            cs.SecurityAmount = -totsecurityamount;
                        }

                        cs.CreateBy   = User.Identity.Name;
                        cs.CraeteDate = DateTime.Now;
                        dc.CashSettlements.Add(cs);

                        // var cb = db.spCustomerBalanceUpdate(R.CustomerID, "R", cramt/*R.InAmount*/);

                        decimal vInvAmt  = cramt - securityAmt;
                        decimal vBookAmt = 0;
                        decimal vCurBal  = cramt + diffamt;
                        if (R.ReturnTypeID == 14)
                        {
                            negload = -(decimal)R.AdjustedAmt;
                        }
                        else
                        {
                            negload = (decimal)R.AdjustedAmt;
                        }
                        decimal vChargeAmount   = negload;
                        decimal vSecurityAmt    = securityAmt + diffamt;// securitywithRebate;
                        decimal vRebate         = 0;
                        decimal vFare           = (decimal)R.FareAmt;
                        decimal VactuaInvAmount = vInvAmt - negload;// (decimal)R.AdjustedAmt; // without loaduloadcharge


                        db.spUpdateDBsInvoiceValue(
                            R.CustomerID,
                            "S",
                            vCurBal,
                            vCurBal,
                            VactuaInvAmount,
                            vBookAmt,
                            vSecurityAmt,
                            vChargeAmount,
                            vFare,
                            vRebate,
                            vrID
                            );
                    }
                    foreach (var i in R.listreturndetail)
                    {
                        var     q           = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault();
                        int     conf        = q.ConversionFactor;
                        decimal totpcqty    = (decimal)i.ReturnQty * conf;
                        int     csqty       = (Convert.ToInt32(Math.Round(totpcqty)) / conf);
                        int     pcqty       = (Convert.ToInt32(Math.Round(totpcqty)) % conf);
                        decimal totrebpcqty = (decimal)i.RebateQty * conf;
                        int     rebcsqty    = (Convert.ToInt32(Math.Round(totrebpcqty)) / conf);
                        int     rebpcqty    = (Convert.ToInt32(Math.Round(totrebpcqty)) % conf);

                        if (R.ReturnTypeID != 13)
                        {
                            ProductTransactionDetail ptd = new ProductTransactionDetail();
                            decimal qty = (decimal)i.ReturnQty + (decimal)i.RebateQty;
                            int     s   = q.ConversionFactor;
                            // decimal qt = Math.Round((decimal)(i.ReturnQty) * s, 2);
                            decimal qt         = Math.Round((decimal)(qty) * s, 2);
                            int     pcquantity = (Convert.ToInt32(Math.Round(qt)) % s);
                            int     casesqty   = (Convert.ToInt32(Math.Round(qt)) / s);
                            ptd.WarehouseID        = R.WarehouseID;
                            ptd.TransactionNo      = TrID;
                            ptd.ProductID          = (int)i.ProductID;
                            ptd.Quantity           = (int)qt;// (int)i.ReturnQty;
                            ptd.PlasticBoxQuantity = (int)i.Packsize;
                            ptd.BatchNo            = i.BatchNo;
                            dc.ProductTransactionDetails.Add(ptd);

                            StockBatchDetail sbd = new StockBatchDetail();
                            sbd.WarehouseID        = R.WarehouseID;
                            sbd.TransactionNo      = vrID;
                            sbd.TransactionDate    = System.DateTime.Today;
                            sbd.ProductID          = (int)i.ProductID;
                            sbd.Quantity           = (int)qt;// (int)i.ReturnQty;
                            sbd.PlasticBoxQuantity = i.Packsize;
                            sbd.TransactionType    = "Return Product";
                            sbd.BatchNo            = (int)i.BatchNo;
                            sbd.CreateBy           = User.Identity.Name;
                            sbd.CreateDate         = System.DateTime.Now;
                            dc.StockBatchDetails.Add(sbd);
                            if (R.ReturnTypeID == 14)
                            {
                                var peb = db.spProductBalanceUpdate(i.ProductID, R.WarehouseID, (int)qt, 0, 0, 0, 0);// (int)i.ReturnQty);
                            }
                            ;
                        }
                        ;
                        ReturnmentDetail rd = new ReturnmentDetail();
                        rd.WarehouseID   = R.WarehouseID;
                        rd.ReturnmentID  = vrID;// R.ReturnmentID;
                        rd.ProductID     = i.ProductID;
                        rd.ReturnQty     = i.ReturnQty;
                        rd.Amount        = i.Amount;
                        rd.Packsize      = i.Packsize;
                        rd.BatchNo       = i.BatchNo;
                        rd.RebateQty     = i.RebateQty;
                        rd.RebatePlastic = i.RebatePlastic;
                        rd.SchemeID      = i.SchemeID;
                        dc.ReturnmentDetails.Add(rd);

                        if (R.ReturnTypeID != 12)
                        {
                            CashSettlementDetail cd = new CashSettlementDetail();
                            var ratedata            = db.ProductRateDetails.Where(x => x.ProductRateID == V.ProductRateID && x.ProductID == i.ProductID).FirstOrDefault();
                            // double xva = .2;
                            cd.WarehouseID      = R.WarehouseID;
                            cd.CashSettlementID = csID;
                            cd.AlternateReturnedFilledQuantity = (int)i.RebateQty;
                            cd.ProductID = (int)i.ProductID;
                            cd.UnitPrice = ratedata.UnitPrice;
                            cd.AlternateAgencyCommission = ratedata.AlternateAgencyCommission;
                            cd.AlternateUnitPrice        = ratedata.AlternateUnitPrice;
                            cd.MRPRate = ratedata.MRPRate;
                            cd.AlternateRebateAmount     = 0;
                            cd.AlternateGrossSalesAmount = 0;
                            cd.VATAmount = 0;
                            cd.SchemeID  = (int)i.SchemeID;
                            cd.ReturnedPlasticBoxSecurity = 0;// (decimal)i.Amount* (decimal)xva;
                            //cd.UnitPrice =
                            if (R.ReturnTypeID == 13)
                            {
                                //cd.ReturnedAlternateSecurityDeposit = (decimal)i.Amount;
                                cd.ReturnedQuantity                 = pcqty;
                                cd.AlternateReturnedQuantity        = csqty;
                                cd.ReturnedPlasticBoxQuantity       = (int)i.Packsize;
                                cd.ReturnedSecurityDeposit          = q.SecurityDeposit;
                                cd.ReturnedAlternateSecurityDeposit = q.AlternateSecurityDeposit;
                                cd.ReturnedPlasticBoxSecurity       = q.PlasticBoxSecurity;
                            }
                            else
                            {
                                cd.AlternateReturnedFilledQuantity  = csqty;    // (int)i.ReturnQty;
                                cd.ReturnedFilledQuantity           = pcqty;
                                cd.AlternateReturnedRebateQuantity  = rebcsqty; // (int)i.RebateQty;
                                cd.ReturnedRebateQuantity           = rebpcqty;
                                cd.ReturnedPlasticBoxQuantity       = (int)i.Packsize + (int)i.RebatePlastic;
                                cd.ReturnedSecurityDeposit          = q.SecurityDeposit;
                                cd.ReturnedAlternateSecurityDeposit = q.AlternateSecurityDeposit;
                                cd.ReturnedPlasticBoxSecurity       = q.PlasticBoxSecurity;
                            }

                            dc.CashSettlementDetails.Add(cd);
                        }


                        //if (R.ReturnTypeID == 14)
                        //{
                        //    var pb = db.spProductBalanceUpdate(i.ProductID, R.WarehouseID, (int)i.ReturnQty, 0, 0, 0, 0);

                        //}
                    }
                    ;
                    dc.SaveChanges();
                    status = true;
                    dc.Dispose();
                }
                ModelState.Clear();
            }
            else

            {
                status = false;
            }
            return(new JsonResult {
                Data = new { status = status, mes = mes, v = v }
            });
        }
예제 #2
0
        public JsonResult AddInvoiceData(InvoiceVM Inv)
        {
            var w = (from yt in db.UserLogins
                     where yt.UserID.ToString() == User.Identity.Name
                     select new { yt.WorkStationID }).FirstOrDefault();
            var    wn            = db.Warehouses.Where(t => t.WarehouseID == w.WorkStationID).FirstOrDefault();
            bool   status        = false;
            string mes           = "";
            string s1            = w.WorkStationID.ToString();
            string s2            = string.Concat(s1 + "6000000");
            string s3            = string.Concat(s1 + "5000000");
            int    MaxChallanNo  = Convert.ToInt32(s2);
            int    MaxCashID     = Convert.ToInt32(s3);
            var    maxchno       = (from n in db.Orders where n.WarehouseID == w.WorkStationID select n.ChallanNumber).DefaultIfEmpty(MaxChallanNo).Max();
            var    maxCasettleId = (from n in db.CashSettlements where n.WarehouseID == w.WorkStationID select n.CashSettlementID).DefaultIfEmpty(MaxCashID).Max();
            var    maxprodtr     = (from j in db.ProductTransactions where j.WarehouseID == w.WorkStationID select j.TransactionNo).Max() + 1;

            chNumber = Convert.ToInt32(maxchno + 1);
            csID     = Convert.ToInt32(maxCasettleId + 1);
            int v = chNumber;

            if (ModelState.IsValid)
            {
                try
                {
                    using (PEPSIEntities dc = new PEPSIEntities())
                    {
                        //  var V = db.Orders.Max(p => p.ChallanNumber);
                        CommonChk cm = new CommonChk();
                        {
                            if (cm.chkDuplicateChallan(Inv.OrderID) == true)
                            {
                                //status = false;


                                var            vr = db.Orders.SingleOrDefault(x => x.OrderID == Inv.OrderID);
                                CashSettlement cs = new CashSettlement();
                                {
                                    // var vr = db.Orders.SingleOrDefault(x => x.OrderID == Inv.OrderID);
                                    cs.CashSettlementID       = csID;
                                    cs.SalesPersonID          = vr.SalesPersonID;
                                    cs.DeliveryChallanDate    = DateTime.Today; //vr.DeliveryChallanDate;
                                    cs.CustomerID             = vr.CustomerID;
                                    cs.DeliveryChallanNumbers = chNumber;       // Convert.ToInt32(vr.ChallanNumber)+1;
                                    cs.WarehouseID            = vr.WarehouseID;
                                    cs.VehicleID                  = vr.VehicleID;
                                    cs.CashSettlementDate         = DateTime.Today;
                                    cs.RebateWillBeGivenWithOrder = vr.RebateWillBeGivenWithOrder;
                                    cs.SpecialNoteFromOrder       = vr.SpecialNote;
                                    cs.SpecialInstruction         = Inv.SpecialNote;
                                    cs.OrderID                 = vr.OrderID;
                                    cs.ProductRateID           = vr.ProductRateID;
                                    cs.DayendFinished          = "N";
                                    cs.DayendDay               = DateTime.Now;
                                    cs.OrderTypeID             = vr.OrderTypeID;
                                    cs.CustomerExecutiveID     = vr.CustomerExecutiveID;
                                    cs.DriverID                = vr.DriverID;
                                    cs.Promotional             = vr.Promotional;
                                    cs.CheckedByShipping       = "Y";
                                    cs.AgencyCommission        = Inv.AgencyCommission;                     // vr.AgencyCommission;
                                    cs.TotalSpecialCharges     = vr.SpecialCharge1Amount;
                                    cs.SecurityAmount          = Inv.SecurityAmount;                       //vr
                                    cs.DrinksAmount            = (Inv.SalesAmount - Inv.AgencyCommission); //(vr.SalesAmount - vr.AgencyCommission);
                                    cs.FinishGoodsUnloadCharge = Inv.FinishGoodsUnloadCharge;              //vr
                                    cs.CreateBy                = User.Identity.Name;
                                    cs.CraeteDate              = DateTime.Now;

                                    // dc.CashSettlements.Add(cs);
                                }
                                dc.CashSettlements.Add(cs);
                                // Product Transaction
                                ProductTransaction pt = new ProductTransaction();
                                {
                                    pt.WarehouseID       = Inv.WarehouseID;
                                    pt.TransactionNo     = maxprodtr;
                                    pt.TransactionDate   = DateTime.Today;
                                    pt.TransactionTypeID = 7;
                                    pt.FromWarehouse     = Inv.WarehouseID;
                                    pt.ReferenceNo       = csID.ToString();
                                    pt.Remarks           = Inv.SpecialNote;
                                    pt.Status            = "I";
                                    pt.CreatedBy         = User.Identity.Name;
                                    pt.CreatedDate       = DateTime.Now;
                                }
                                dc.ProductTransactions.Add(pt);

                                // Helper
                                InvoiceHelper pm = new InvoiceHelper();
                                {
                                    pm.OrderID   = Inv.OrderID;
                                    pm.HelperID1 = Inv.Helper1;
                                    pm.HelperID2 = Inv.Helper2;
                                    pm.HelperID3 = Inv.Helper2;
                                    dc.InvoiceHelpers.Add(pm);
                                }
                                // Customer Ledger
                                CustomerLedgerDetail cld = new CustomerLedgerDetail();
                                {
                                    cld.WarehouseID       = vr.WarehouseID;
                                    cld.CustomerID        = vr.CustomerID;
                                    cld.TransactionNo     = "INV" + csID.ToString();
                                    cld.CrAmount          = 0;
                                    cld.TransactionTypeID = 15;
                                    cld.TransactionDate   = DateTime.Today;
                                    cld.RefNumber1        = csID.ToString();
                                    cld.DrAmount          = (Inv.SalesAmount + Inv.SecurityAmount) - (Inv.AgencyCommission + (decimal)Inv.FinishGoodsUnloadCharge);// (Inv.SalesAmount - Inv.AgencyCommission); //(vr.SalesAmount - vr.AgencyCommission);
                                    cld.DebitCredit       = "D";
                                    cld.Narration         = "Invoice Value#" + cld.DrAmount + " for Customer" + cld.CustomerID;
                                    cld.CreateBy          = User.Identity.Name;
                                    cld.CreateDate        = System.DateTime.Now;
                                }
                                dc.CustomerLedgerDetails.Add(cld);
                                // update Customer Ledgermaster
                                // Farid Correction 03dec2018
                                //decimal amountofdr = (Inv.SalesAmount - Inv.AgencyCommission);
                                //decimal bokamt = amountofdr + Inv.SecurityAmount;
                                //var clmbf = db.spCustomerBalanceUpdate(vr.CustomerID, "F", bokamt);
                                //var clm = db.spCustomerBalanceUpdate(vr.CustomerID, "I", amountofdr);
                                //var security = db.spCustomerBalanceUpdate(vr.CustomerID, "S", Inv.SecurityAmount);
                                //decimal vInvAmt = (Inv.SalesAmount - Inv.AgencyCommission)- (decimal)Inv.FinishGoodsUnloadCharge;
                                decimal vInvAmt       = Inv.SalesAmount - (Inv.AgencyCommission); //(decimal)Inv.FinishGoodsUnloadCharge
                                decimal vBookAmt      = Inv.SalesAmount + Inv.SecurityAmount - Inv.AgencyCommission;
                                decimal vCurBal       = (Inv.SalesAmount + Inv.SecurityAmount) - (Inv.AgencyCommission + (decimal)Inv.FinishGoodsUnloadCharge);
                                decimal vChargeAmount = (decimal)Inv.FinishGoodsUnloadCharge;
                                decimal vSecurityAmt  = Inv.SecurityAmount;
                                decimal vRebateAmt    = 0;
                                if (Inv.RebateAmount > 0)
                                {
                                    decimal vRebate = (Inv.RebateAmount);
                                    vRebateAmt = vRebate;
                                }
                                else
                                {
                                    decimal vRebate = Inv.RebateAmount;
                                    vRebateAmt = vRebate;
                                }

                                decimal vFare = Inv.FareAmnt;


                                db.spUpdateDBsInvoiceValue(
                                    vr.CustomerID,
                                    "I",
                                    vCurBal,
                                    vCurBal,
                                    vInvAmt,
                                    vBookAmt,
                                    vSecurityAmt,
                                    vChargeAmount,
                                    vFare,
                                    vRebateAmt,
                                    chNumber
                                    );
                                // Farid Correction
                                //  var clm = db.spCustomerBalanceUpdate(vr.CustomerID, "I", bokamt);// with sequirity amount
                                // Add Fare Amount
                                if (Inv.VehicleID == 1)
                                {
                                    //need to adjust without
                                    var cus    = cm.GetCustomerName(vr.CustomerID, "C");
                                    var cusAdd = db.Customers.Where(x => x.CustomerID == vr.CustomerID).FirstOrDefault();
                                    var c      = db.spInsertHireTruckFare(Inv.WarehouseID, chNumber, Inv.TAID, DateTime.Today, cus, cusAdd.CustomerAddress1, Inv.VechileNo, Inv.FareAmnt, 0, Inv.TotalCases, "No", User.Identity.Name, DateTime.Now, "Hired Truck");
                                }

                                var ODetails = db.OrderDetails.Where(x => x.WarehouseID == Inv.WarehouseID && x.OrderID == Inv.OrderID);
                                foreach (var z in ODetails.ToList())
                                {
                                    CashSettlementDetail csd = new CashSettlementDetail()
                                    {
                                        WarehouseID               = Inv.WarehouseID,
                                        CashSettlementID          = csID,
                                        ProductID                 = z.ProductID,
                                        SchemeID                  = (int)z.SchemeID,
                                        UnitPrice                 = (decimal)z.UnitPrice,
                                        AlternateUnitPrice        = (decimal)z.AlternateUnitPrice,
                                        Quantity                  = (int)z.Quantity,
                                        AlternateQuantity         = (int)z.AlternateQuantity,
                                        PlasticBoxQuantity        = (int)z.PlasticBoxQuantity,
                                        RebateQuantity            = (int)z.RebateQuantity,
                                        AlternateRebateQuantity   = (int)z.AlternateRebateQuantity,
                                        AgencyCommission          = (decimal)z.AgencyCommission,
                                        AlternateAgencyCommission = (decimal)z.AlternateAgencyCommission,
                                        SecurityDeposit           = (decimal)z.SecurityDeposit,
                                        AlternateSecurityDeposit  = (decimal)z.AlternateSecurityDeposit,
                                        PlasticBoxSecurity        = (decimal)z.PlasticBoxSecurity,
                                        MRPRate = z.MRPRate
                                    };
                                    dc.CashSettlementDetails.Add(csd);
                                    var totpc  = (from x in db.Products where x.ProductID == z.ProductID select x).FirstOrDefault();
                                    int TotQty = (int)(z.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * totpc.ConversionFactor) + z.RebateQuantity);

                                    StockBatchDetail sbd = new StockBatchDetail()
                                    {
                                        WarehouseID        = Inv.WarehouseID,
                                        TransactionNo      = csID,
                                        TransactionDate    = System.DateTime.Today,
                                        ProductID          = z.ProductID,
                                        Quantity           = TotQty,//(int)z.AlternateQuantity for rebate and case to pcs,
                                        PlasticBoxQuantity = z.PlasticBoxQuantity,
                                        TransactionType    = "Invoice Creation",
                                        BatchNo            = (int)z.BatchNo,
                                        CreateBy           = User.Identity.Name,
                                        CreateDate         = System.DateTime.Now,
                                    };
                                    dc.StockBatchDetails.Add(sbd);
                                    //var cc = (int)z.Quantity;
                                    //var xxx = (int)z.PlasticBoxQuantity;
                                    //var cc = CommonChk
                                    // CommonChk cm = new CommonChk();

                                    //int qty = cm.CasetoPcs(z.ProductID, (int)z.AlternateQuantity); // off for rebate
                                    int qty = TotQty;
                                    //int qty = cm.CasetoPcs(z.ProductID, TotQty); Farid Correction
                                    ProductTransactionDetail ptd = new ProductTransactionDetail();
                                    {
                                        ptd.TransactionNo      = maxprodtr;
                                        ptd.WarehouseID        = Inv.WarehouseID;
                                        ptd.ProductID          = z.ProductID;
                                        ptd.Quantity           = qty;// (int)z.AlternateQuantity;
                                        ptd.PlasticBoxQuantity = (int)z.PlasticBoxQuantity;
                                        //BatchNo = z.BatchNo,
                                        //ExpiryDate = z.ExpDate,
                                        //ManufactureDate = z.MfgDate,
                                        ptd.EmptyBottleQuantity    = 0;
                                        ptd.BurstBottleQuantity    = 0;
                                        ptd.BreakageBottleQuantity = 0;
                                        dc.ProductTransactionDetails.Add(ptd);
                                    };


                                    // Product Stock Maintaince

                                    // int allProductsQty;

                                    //var Pr = (from x in db.Products where x.ProductID == z.ProductID select x).FirstOrDefault();
                                    // allProductsQty = (int)(z.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * Pr.ConversionFactor) + z.RebateQuantity);
                                    // SqlCommand com = new SqlCommand("spProductBalanceDecrease", con);
                                    // off for holding stock against loadsheet
                                    //var decreaseprodbal = db.spProductBalanceDecrease(z.ProductID,
                                    //    vr.WarehouseID,
                                    //    qty,
                                    //    0,
                                    //    0,
                                    //    0,
                                    //    0);
                                    var decreaseprodbal = db.spStockBookedandBookedFree(z.ProductID, vr.WarehouseID, qty, "D");
                                }
                                // Update Order
                                var upby      = User.Identity.Name;
                                var orderdata = db.spOrderUpdateAfterInvoice(
                                    Inv.WarehouseID,
                                    Inv.OrderID,
                                    "Y",
                                    DateTime.Today,
                                    Inv.SalesAmount,
                                    Inv.SecurityAmount,
                                    Inv.RebateAmount,
                                    Inv.AgencyCommission,
                                    chNumber,
                                    upby,
                                    csID,
                                    "Y",
                                    Inv.FinishGoodsUnloadCharge,
                                    upby,
                                    DateTime.Now,
                                    Inv.AdvanceOrder
                                    );
                                // con.Close();
                                //Transport QR Data Tauhid
                                //salesOrderNo will be OrderDate
                                try
                                {
                                    var getSONo = (from x in db.Orders where x.OrderID == Inv.OrderID select x).FirstOrDefault();

                                    SalesOrdNo = Convert.ToInt32(getSONo.OrderID);
                                    TransportQRData qd = db.TransportQRDatas.SingleOrDefault(x => x.SalesOrderNo == SalesOrdNo);
                                    qd.InvoiceDateTime       = System.DateTime.Now;
                                    qd.DeliveryChallanNumber = chNumber;
                                    dc.Entry(qd).State       = EntityState.Modified;
                                }
                                catch (Exception ex)
                                {
                                }
                                dc.SaveChanges();
                                //Invoice Print
                                var getSNo = (from x in db.Orders where x.ChallanNumber == chNumber select x).FirstOrDefault();
                                SalesOrdNo = Convert.ToInt32(getSNo.SalesOrderNo);
                                // SalesOrdNo = (int)Inv.SalesOrderNo;
                                //if (SalesOrdNo!=null)
                                //{

                                //    return RedirectToAction("Invoce", "OrderReport");
                                //}
                                status = true;
                                //int v = chNumber;
                                Dispose();
                                // status = true;
                                //return new JsonResult { Data = new { status = status, mes = mes } };
                            }
                            else
                            {
                                status = false;
                                v      = 0;
                            }
                        }
                    }
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                status = false;
            }
            return(new JsonResult {
                Data = new { status = status, mes = mes, v = v, SNo = SalesOrdNo }
            });
            //return RedirectToAction("Invoice", "ReprintController", new { @InvNo = v });
        }
예제 #3
0
        public ActionResult SaveData(StockVM S)
        {
            var w = (from y in db.UserLogins
                     where y.UserID.ToString() == User.Identity.Name
                     select new { y.WorkStationID }).FirstOrDefault();
            var wn = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault();

            //  var PTID = (from x in db.OrderBankSummaries select x.SalesOrderNO).DefaultIfEmpty(610000000).Max();
            //  PIDMax = (PTID + 1);
            string s1      = w.WorkStationID.ToString();
            string s2      = string.Concat(s1 + "0000000");
            string s3      = string.Concat(s1 + Convert.ToString(DateTime.Now.Year) + "000");
            string plantfl = wn.PlantFlag;
            int    batchno = Convert.ToInt32(s3);
            int    Trno    = Convert.ToInt32(s2);
            bool   status  = true;
            string mes     = "";
            int    PIDMax;
            var    PTID = (from x in db.ProductTransactions where x.WarehouseID == wn.WarehouseID select x.TransactionNo).DefaultIfEmpty(Trno).Max();

            PIDMax = (PTID + 1);
            int v = PIDMax;

            if (ModelState.IsValid)
            {
                try
                {
                    using (PEPSIEntities dc = new PEPSIEntities())
                    {
                        CommonChk          ck = new CommonChk();
                        ProductTransaction dm = new ProductTransaction();
                        {
                            // Here Id   Primary Key of DB table auto increase
                            //var PTID = db.ProductTransactions.DefaultIfEmpty(100).Max(p => p.TransactionNo);
                            dm.TransactionTypeID = S.TransactionTypeID;
                            dm.TransactionNo     = PIDMax;//
                            dm.WarehouseID       = S.WarehouseID;
                            dm.FromWarehouse     = S.WarehouseID;
                            dm.ToWarehouse       = S.ToWarehouse;
                            dm.TransactionDate   = DateTime.Today;
                            dm.ReferenceNo       = S.ReferenceNo;
                            dm.Remarks           = S.Remarks;
                            if (S.TransactionTypeID != 1)
                            {
                                if (S.TransactionTypeID == 1)
                                {
                                    dm.Status = "T";
                                }
                                if (S.TransactionTypeID == 6)
                                {
                                    dm.Status = "D";
                                }
                                if (S.TransactionTypeID == 10)
                                {
                                    dm.Status = "B";
                                }
                                if (S.TransactionTypeID == 11)
                                {
                                    dm.Status = "W";
                                }
                            }
                            else
                            {
                                dm.Status = "A";
                            }
                            //cuser = User.Identity.Name
                            dm.CreatedBy     = User.Identity.Name;
                            dm.CreatedDate   = DateTime.Now;
                            dm.StoreLocation = S.StoreLocation;
                        }
                        dc.ProductTransactions.Add(dm);
                        // Transfer Note
                        if (S.TransactionTypeID == 2)
                        {
                            ProductTransferNote ptn = new ProductTransferNote();
                            {
                                var PTNoteID = (from x in db.ProductTransferNotes where x.WarehouseID == w.WorkStationID select x.SLNo).DefaultIfEmpty(1).Max();
                                int TrNoteId = Convert.ToInt32((PTNoteID)) + 1;
                                ptn.WarehouseID   = S.WarehouseID;
                                ptn.TransactionNo = PIDMax;
                                ptn.VehicleID     = S.VehicleID;
                                if (S.VehicleID == 1)
                                {
                                    ptn.DriverID = 0;
                                }
                                else
                                {
                                    ptn.DriverID = S.DriverID;
                                }
                                ptn.Remarks    = S.Remarks;
                                ptn.SLNo       = TrNoteId;
                                ptn.CreateBy   = User.Identity.Name;
                                ptn.CreateDate = DateTime.Now;
                            }
                            dc.ProductTransferNotes.Add(ptn);
                        }
                        // Agency Fare Amount
                        if (S.VehicleID == 1 && S.TransactionTypeID == 2)
                        {
                            TransportAgencyandFareSetup tf = new TransportAgencyandFareSetup();


                            {
                                tf.WarehouseID   = S.WarehouseID;
                                tf.TAID          = (int)S.TAID;
                                tf.ChallanNumber = PIDMax;
                                tf.ChallanDate   = DateTime.Today;
                                tf.CustomerName  = ck.GetCustomerName((int)S.ToWarehouse, "N");
                                tf.Address       = ck.GetCustomerName((int)S.ToWarehouse, "N");
                                tf.VechileNo     = S.VehicleID.ToString();
                                tf.FareAmnt      = (decimal)S.FareAmnt;
                                tf.Remarks       = "Hired Truck";
                                tf.TotalCases    = S.TotCase;
                                tf.Status        = "No";
                                tf.EnteredBy     = User.Identity.Name;
                                tf.EnteredDate   = System.DateTime.Now;
                            }
                            dc.TransportAgencyandFareSetups.Add(tf);
                        }

                        if (S.TransactionTypeID == 2)
                        {
                            foreach (var j in S.ProdTrDtl)
                            {
                                //checking  stock balace
                                if (ck.stockchkcs(j.ProductID, S.WarehouseID, (int)j.Quantity) == true)
                                {
                                    //status = false;
                                }
                                else
                                {
                                    status = false;
                                };
                            }
                            ;
                        }
                        if (status == true)
                        {
                            foreach (var i in S.ProdTrDtl)
                            {
                                var CF    = (from x in dc.Products where x.ProductID == i.ProductID select x).FirstOrDefault();
                                var batch = (from x in dc.StockBatches where x.ProductID == i.ProductID && x.WarehouseID == S.WarehouseID select x.BatchNo).DefaultIfEmpty(batchno).Max() + 1;
                                ProductTransactionDetail dmd = new ProductTransactionDetail();
                                dmd.ProductID     = i.ProductID; // Not Null
                                dmd.WarehouseID   = S.WarehouseID;
                                dmd.TransactionNo = PIDMax;
                                dmd.LineNoPlant   = i.LineNoPlant;
                                if (S.TransactionTypeID != 1)
                                {
                                    dmd.BatchNo = i.BatchNo;
                                }
                                else
                                {
                                    dmd.BatchNo = batch;
                                }

                                if (plantfl == "Y")
                                {
                                    int plant = (int)wn.PlantNo;
                                    dmd.PlantNo = plant;
                                }
                                dmd.ManufactureDate = i.ManufactureDate;
                                //DateTime d = Convert.ToDateTime(i.ManufactureDate);
                                if (CF.Expirydays == null)
                                {
                                    dmd.ExpiryDate = i.ManufactureDate;
                                }
                                else
                                {
                                    dmd.ExpiryDate = Convert.ToDateTime(i.ManufactureDate).AddDays((int)CF.Expirydays);// + 10;//  (int)CF.Expirydays;  //i.ExpiryDate;
                                }
                                dmd.Quantity               = (i.Quantity);
                                dmd.EmptyBottleQuantity    = (i.EmptyBottleQuantity);
                                dmd.PlasticBoxQuantity     = i.PlasticBoxQuantity;
                                dmd.BurstBottleQuantity    = (i.BurstBottleQuantity);
                                dmd.BreakageBottleQuantity = (i.BreakageBottleQuantity);
                                //TCases = TCases + i.Quantity;
                                dc.ProductTransactionDetails.Add(dmd);
                                // For Batch
                                StockBatch sb = new StockBatch();
                                sb.ProductID   = i.ProductID;
                                sb.WarehouseID = S.WarehouseID;
                                //sb.BatchNo = batch;

                                if (S.TransactionTypeID != 1)
                                {
                                    var t = db.StockBatches.Where(x => x.WarehouseID == S.WarehouseID && x.ProductID == i.ProductID && x.BatchNo == i.BatchNo).FirstOrDefault();
                                    sb.BatchRefNo     = t.BatchRefNo;
                                    sb.ManufacturDate = t.ManufacturDate;
                                    sb.ExpiryDate     = t.ExpiryDate;
                                    sb.PlantLineNo    = t.PlantLineNo;
                                    sb.BatchNo        = (int)i.BatchNo; // Add
                                    sb.PlantNo        = t.PlantNo;
                                    if (S.TransactionTypeID == 2)
                                    {
                                        sb.Status = "T";
                                    }
                                    if (S.TransactionTypeID == 6)
                                    {
                                        sb.Status = "D";
                                    }
                                    if (S.TransactionTypeID == 10)
                                    {
                                        sb.Status = "B";
                                    }
                                    if (S.TransactionTypeID == 11)
                                    {
                                        sb.Status = "W";
                                    }
                                }
                                else
                                {
                                    sb.ManufacturDate        = (DateTime)i.ManufactureDate;
                                    sb.ExpiryDate            = Convert.ToDateTime(i.ManufactureDate).AddDays((int)CF.Expirydays); //(DateTime)i.ExpiryDate;
                                    sb.PlantLineNo           = (int)i.LineNoPlant;
                                    sb.PlantNo               = i.PlantNo;
                                    sb.BatchRefNo            = i.BatchNo;
                                    sb.BatchNo               = batch; // Add
                                    sb.WarehouseLocationCode = S.StoreLocation;
                                    sb.Status = "A";
                                }
                                sb.IssueQuantity = (decimal)i.Quantity;
                                sb.ReceivedQty   = i.Quantity;
                                dc.StockBatches.Add(sb);
                                // Add stock batch detail for transaction history
                                StockBatchDetail sbd = new StockBatchDetail();
                                sbd.WarehouseID            = S.WarehouseID;
                                sbd.ProductID              = i.ProductID;
                                sbd.TransactionNo          = PIDMax;
                                sbd.Quantity               = i.Quantity;
                                sbd.BurstBottleQuantity    = i.BurstBottleQuantity;
                                sbd.BreakageBottleQuantity = i.BreakageBottleQuantity;
                                sbd.PlasticBoxQuantity     = (int)i.PlasticBoxQuantity;
                                sbd.TransactionDate        = DateTime.Today;
                                sbd.CreateBy               = User.Identity.Name;
                                sbd.CreateDate             = DateTime.Now;
                                if (S.TransactionTypeID == 2)
                                {
                                    sbd.BatchNo         = i.BatchNo;
                                    sbd.TransactionType = "Product Transfer";
                                }
                                else if (S.TransactionTypeID == 10)
                                {
                                    sbd.BatchNo         = i.BatchNo;
                                    sbd.TransactionType = "Warehouse Burst";
                                }
                                else if (S.TransactionTypeID == 11)
                                {
                                    sbd.BatchNo         = i.BatchNo;
                                    sbd.TransactionType = "Write Off";
                                }
                                else if (S.TransactionTypeID == 6)
                                {
                                    sbd.BatchNo         = i.BatchNo;
                                    sbd.TransactionType = "Adjustment";
                                }
                                else
                                {
                                    sbd.TransactionType = "Product Received";
                                    sbd.BatchNo         = batch;
                                }
                                dc.StockBatchDetails.Add(sbd);
                            }
                        }

                        //db.SaveChanges();
                        // dc.SaveChanges();
                        foreach (var i in S.ProdTrDtl)
                        {
                            var CF = (from x in dc.Products where x.ProductID == i.ProductID select x).FirstOrDefault();
                            try
                            {
                                if (S.TransactionTypeID == 1)
                                {
                                    var productupdate = dc.spProductBalanceUpdate(i.ProductID,
                                                                                  S.WarehouseID,
                                                                                  (int)i.Quantity, // change
                                                                                  i.BurstBottleQuantity,
                                                                                  i.BreakageBottleQuantity,
                                                                                  (int)i.PlasticBoxQuantity, //change
                                                                                  i.EmptyBottleQuantity);
                                }

                                if (S.TransactionTypeID != 1 && status == true)
                                {
                                    //Deduct Stock
                                    var productupdate = dc.spProductBalanceDecrease(i.ProductID,
                                                                                    S.WarehouseID,
                                                                                    (int)i.Quantity, //change
                                                                                    i.BurstBottleQuantity,
                                                                                    i.BreakageBottleQuantity,
                                                                                    (int)i.PlasticBoxQuantity,
                                                                                    i.EmptyBottleQuantity);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                        if (status == true)
                        {
                            dc.SaveChanges();
                            status = true;
                            dc.Dispose();
                        }
                    }
                    // return new JsonResult { Data = new { status = status, mes = mes } };
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                status = false;
            }
            return(new JsonResult {
                Data = new { status = status, mes = mes, v = v }
            });                                                                        //, v = v } };
        }
예제 #4
0
        public ActionResult DisburseSave(ReplaceDisburseVM D)
        {
            bool   status = false;
            string mes    = "";
            var    w      = (from y in db.UserLogins
                             where y.UserID.ToString() == User.Identity.Name
                             select new { y.WorkStationID }).FirstOrDefault();
            var    wn           = db.Warehouses.Where(x => x.WarehouseID == w.WorkStationID).FirstOrDefault();
            string s1           = w.WorkStationID.ToString();
            string s2           = string.Concat(s1 + "4000000");
            int    replaceDisNo = Convert.ToInt32(s2);
            var    maxreplaceNO = (from n in db.ReplaceDisburseMasters where n.WarehouseID == w.WorkStationID select n.ReplaceDisburseID).DefaultIfEmpty(replaceDisNo).Max();
            var    maxrNo       = maxreplaceNO + 1;
            int    v            = maxrNo;
            var    maxprodtr    = (from j in db.ProductTransactions where j.WarehouseID == w.WorkStationID select j.TransactionNo).Max() + 1;

            var customerData = (from i in db.Customers where (i.CustomerID == D.CustomerID) select i).FirstOrDefault();

            if (ModelState.IsValid)
            {
                using (PEPSIEntities dc = new PEPSIEntities())
                {
                    CommonChk             cm  = new CommonChk();
                    ReplaceDisburseMaster dbo = new ReplaceDisburseMaster();
                    {
                        dbo.ReplaceDisburseID = maxrNo;
                        dbo.WarehouseID       = D.WarehouseID;
                        dbo.CustomerID        = D.CustomerID;
                        dbo.TransactionDate   = DateTime.Today;
                        dbo.DriverID          = D.DriverID;
                        dbo.VehicleID         = D.VehicleID;
                        dbo.ReplaceRefNo      = D.ReplaceRefNo;
                        dbo.TotDisburseAmt    = D.TotDisburseAmt;
                        dbo.RemainingAmt      = D.RemainingAmt;
                        dbo.LoadSheetNo       = D.LoadSheetNo;
                        dbo.TotCase           = D.TotCase;
                        dbo.TotBox            = D.TotBox;
                        dbo.VehicleID         = D.VehicleID;
                        dbo.Remarks           = D.Remarks + "," + D.VehicleID;
                        dbo.CreateDate        = DateTime.Now;
                        dbo.CreateBy          = User.Identity.Name;
                    };
                    dc.ReplaceDisburseMasters.Add(dbo);
                    CustomerLedgerDetail cld = new CustomerLedgerDetail();
                    {
                        cld.WarehouseID       = D.WarehouseID;
                        cld.CustomerID        = D.CustomerID;
                        cld.TransactionNo     = "DIS" + maxrNo.ToString();
                        cld.TransactionTypeID = 19;
                        cld.RefNumber1        = D.ReplaceDisburseID.ToString();
                        cld.TransactionDate   = DateTime.Today;
                        cld.CrAmount          = 0;
                        cld.DrAmount          = D.TotDisburseAmt;
                        cld.DebitCredit       = "D";
                        cld.Narration         = "ReplaceDisburse Amount#" + D.TotDisburseAmt + " to Customer" + cld.CustomerID;
                        cld.CreateBy          = User.Identity.Name;
                        cld.CreateDate        = System.DateTime.Now;
                    }
                    dc.CustomerLedgerDetails.Add(cld);
                    ProductTransaction pt = new ProductTransaction();
                    {
                        pt.WarehouseID       = D.WarehouseID;
                        pt.TransactionNo     = maxprodtr;
                        pt.TransactionDate   = DateTime.Today;
                        pt.TransactionTypeID = 4;
                        pt.FromWarehouse     = D.WarehouseID;
                        pt.ReferenceNo       = maxrNo.ToString();
                        //pt.Remarks =
                        pt.Status      = "D";
                        pt.CreatedBy   = User.Identity.Name;
                        pt.CreatedDate = DateTime.Now;
                    }
                    dc.ProductTransactions.Add(pt);
                    foreach (var i in D.disbursedetail)
                    {
                        var iBatch = (from s in db.StockBatches
                                      where s.WarehouseID == D.WarehouseID &&
                                      s.ProductID == i.ProductID &&
                                      s.Status == "A"
                                      select s).FirstOrDefault();
                        int qty = cm.CasetoPcs(i.ProductID, (decimal)i.CaseQty);
                        ReplaceDisburseDetail obd = new ReplaceDisburseDetail();
                        {
                            var vr = db.ProductRateDetails.Where(x => x.ProductID == i.ProductID && x.ProductRateID == customerData.ProductRateID).FirstOrDefault();
                            obd.WarehouseID        = D.WarehouseID;
                            obd.ReplaceDisburseID  = maxrNo;
                            obd.CustomerID         = D.CustomerID;
                            obd.ProductID          = i.ProductID;
                            obd.CaseQty            = i.CaseQty;
                            obd.BoxQty             = i.BoxQty;
                            obd.BatchNo            = i.BatchNo;
                            obd.ManufactureDate    = iBatch.ManufacturDate;
                            obd.UnitPrice          = vr.UnitPrice;
                            obd.AlternateUnitPrice = vr.AlternateUnitPrice;
                            obd.TotAmount          = i.TotAmount;

                            dc.ReplaceDisburseDetails.Add(obd);
                        }
                        StockBatchDetail sbd = new StockBatchDetail()
                        {
                            WarehouseID        = D.WarehouseID,
                            TransactionNo      = maxprodtr,
                            TransactionDate    = System.DateTime.Today,
                            ProductID          = i.ProductID,
                            Quantity           = (int)i.CaseQty,
                            PlasticBoxQuantity = (int)i.BoxQty,
                            TransactionType    = "Replace Disburse",
                            BatchNo            = i.BatchNo,
                            CreateBy           = User.Identity.Name,
                            CreateDate         = System.DateTime.Now,
                        };
                        dc.StockBatchDetails.Add(sbd);

                        ProductTransactionDetail ptd = new ProductTransactionDetail();
                        {
                            ptd.TransactionNo          = maxprodtr;
                            ptd.WarehouseID            = D.WarehouseID;
                            ptd.ProductID              = i.ProductID;
                            ptd.Quantity               = qty;
                            ptd.PlasticBoxQuantity     = (int)i.BoxQty;
                            ptd.EmptyBottleQuantity    = 0;
                            ptd.BurstBottleQuantity    = 0;
                            ptd.BreakageBottleQuantity = 0;
                            dc.ProductTransactionDetails.Add(ptd);
                        };
                        //int allProductsQty;

                        // var Pr = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault();
                        //  allProductsQty = (int)(i.Quantity + ((z.AlternateQuantity + z.AlternateRebateQuantity) * Pr.ConversionFactor) + z.RebateQuantity);

                        var decreaseprodbal = db.spProductBalanceDecrease(i.ProductID,
                                                                          D.WarehouseID,
                                                                          qty,
                                                                          0,
                                                                          0,
                                                                          (int)i.BoxQty,
                                                                          0);
                    }

                    //{
                    //var replace = (from r in db.ReplaceMasters where r.WarehouseID == D.WarehouseID && r.ReplaceNo == D.ReplaceRefNo select r).FirstOrDefault();
                    //replace.Status = "R";
                    //}
                    var custReplacePayable = db.spCustomerBalanceUpdate(D.CustomerID, "A", D.TotDisburseAmt);
                    var updatereplace      = db.spRelaceDataUpdate(D.ReplaceRefNo, D.WarehouseID, "C", D.CustomerID, "M", User.Identity.Name, DateTime.Now);
                    dc.SaveChanges();
                    status = true;
                    dc.Dispose();
                }
                ModelState.Clear();
            }
            else

            {
                status = false;
            }
            return(new JsonResult {
                Data = new { status = status, mes = mes, v = v }
            });
        }
예제 #5
0
        public ActionResult CreateLoadSheet(LoadSheetVM A)
        {
            var w = (from yt in db.UserLogins
                     where yt.UserID.ToString() == User.Identity.Name
                     select new { yt.WorkStationID }).FirstOrDefault();
            var wn = db.Warehouses.Where(t => t.WarehouseID == w.WorkStationID).FirstOrDefault();

            bool   status = true;
            string mes    = "";
            // int maxsl = 0;

            decimal unitprice = 0;
            string  pstatus   = "";
            string  s1        = w.WorkStationID.ToString();
            string  s2        = string.Concat(s1 + "8000000");
            int     OrderNo   = Convert.ToInt32(s2);

            var orderID = (from n in db.Orders where n.WarehouseID == w.WorkStationID select n.OrderID).DefaultIfEmpty(OrderNo).Max();

            //var maxorderid = (from n in db.Orders
            //                  where n.OrderID == (db.Orders.Max(xo => xo.OrderID))
            //                  select new { n.OrderID }).FirstOrDefault();
            var customerData = (from i in db.Customers where (i.CustomerID == A.CustomerID) select i).FirstOrDefault();

            var mindeliverychallan = db.Orders
                                     .Where(p => p.WarehouseID == A.WarehouseID) // not consider salesorderno p.SalesOrderNo == A.SalesOrderNo &&
                                     .Min(p => p.ChallanNumber);
            //var maxsl = db.Orders
            //                    .Where(p => p.WarehouseID == A.WarehouseID)
            //                    .Max(p => p.OrderID);
            int orderno = orderID + 1;
            int v       = orderno;

            // Checking challan negetive
            if (mindeliverychallan >= 0)
            {
                mindeliverychallan = -1;
            }
            else
            {
                mindeliverychallan = mindeliverychallan - 1;
            }
            if (A.VehicleID == 1)
            {
                A.DriverID = 0;
            }
            if (ModelState.IsValid)
            {
                //  try
                //  {
                using (PEPSIEntities dc = new PEPSIEntities())
                {
                    var   getorderdate = dc.OrderBankSummaries.Where(x => x.WarehouseID == A.WarehouseID && x.SalesOrderNO == A.SalesOrderNo).FirstOrDefault();
                    Order dbo          = new Order
                    {
                        //Add orders table
                        //Here Id   Primary Key of DB table auto increase
                        // SLNo = maxsl,
                        SalesOrderNo = A.SalesOrderNo,
                        //CustomerExecutive = (A.CustomerExecutiveID),
                        OrderID = orderno,//A.OrderID,
                        //OrderDate = A.OrderDate,//DateTime.Today,
                        OrderDate     = getorderdate.SalesOrderDate,
                        WarehouseID   = A.WarehouseID,
                        DriverID      = (int)A.DriverID,
                        CustomerID    = A.CustomerID,
                        VehicleID     = A.VehicleID,
                        SalesPersonID = customerData.SalesPersonID,
                        //Trip = 0,
                        //SalesAmount = 0,
                        //SecurityAmount = 0,
                        //RebateAmount = 0,
                        //AgencyCommission = 0,
                        Trip                        = 1,
                        OrderTypeID                 = A.OrderTypeID,
                        ProductRateID               = customerData.ProductRateID,
                        CustomerExecutiveID         = customerData.CustomerExecutiveID,// A.CustomerExecutiveID,
                        LoadSheetRemarks            = A.LoadSheetRemarks,
                        Delivered                   = "N",
                        Cash                        = "N",
                        IsCashSettlementPrepared    = "N",
                        Transit                     = "N",
                        Promotional                 = "N",
                        InvoiceFromVATInvoiceNumber = "N",
                        VATChallanRequired          = "Y",
                        ReadyForDelivery            = "Y",
                        AdvanceOrder                = "N",
                        //RebateWillBeGivenWithOrder = A.RebateWillBeGivenWithOrder,
                        //SSMA_TimeStamp =Convert.ToByte(DateTime.Now),
                        //  SSMA_TimeStamp = null,
                        CreateBy   = User.Identity.Name,
                        CreateDate = System.DateTime.Now
                    };

                    dc.Orders.Add(dbo);
                    //  status = true;

                    CommonChk c = new CommonChk();
                    foreach (var j in A.orderdetail)
                    {
                        //checking  stock balace
                        if (c.stockchk(j.ProductID, A.WarehouseID, (int)j.AlternateQuantity) == true)
                        {
                            //status = false;
                        }
                        else
                        {
                            status = false;
                        };
                    }
                    ;
                    if (status == true)
                    {
                        foreach (var i in A.orderdetail)
                        {
                            // Add order detail
                            OrderDetail dod = new OrderDetail();
                            // var d = (from x in db.spGetSalesOrder(A.SalesOrderNo) where x.ProductID == i.ProductID select x).FirstOrDefault();

                            var d     = (from n in db.spGetSalesOrderNewProduct(A.SalesOrderNo, i.ProductID) where n.CustomerID == A.CustomerID select n).FirstOrDefault();
                            var batch = (from x in db.StockBatches where x.ProductID == i.ProductID && x.WarehouseID == A.WarehouseID && x.Status == "A" select x).FirstOrDefault();
                            // Id Primary key Auto generate
                            var q = (from x in db.Products where x.ProductID == i.ProductID select x).FirstOrDefault();
                            // unitprice = q.UnitPrice;

                            int     s            = q.ConversionFactor;
                            decimal qt           = Math.Round((decimal)(i.AlternateQuantity) * s, 2);
                            decimal rqty         = Math.Round((decimal)(i.AlternateRebateQuantity) * s, 2);
                            int     quantity     = (Convert.ToInt32(Math.Round(qt)) % s);
                            int     casesqty     = (Convert.ToInt32(Math.Round(qt)) / s);
                            int     rebateqty    = (Convert.ToInt32(Math.Round(rqty)) % s);
                            int     rebatecase   = (Convert.ToInt32(Math.Round(rqty)) / s);
                            int     totbookedqty = (int)qt + (int)rqty;
                            dod.WarehouseID = A.WarehouseID;
                            dod.OrderID     = orderno;// A.OrderID;
                            dod.ProductID   = i.ProductID;
                            //dod.Quantity = i.Quantity;
                            dod.SchemeID                  = (int)i.SchemeID;
                            dod.Quantity                  = quantity;
                            dod.AlternateQuantity         = casesqty;
                            dod.RebateQuantity            = rebateqty;
                            dod.AlternateRebateQuantity   = rebatecase;
                            dod.AgencyCommission          = d.AgencyCommission;
                            dod.AlternateAgencyCommission = d.AlternateAgencyCommission;
                            dod.UnitPrice                 = d.UnitPrice;
                            dod.AlternateUnitPrice        = d.AlternateUnitPrice;
                            dod.SecurityDeposit           = d.SecurityDeposit;
                            dod.AlternateSecurityDeposit  = d.AlternateSecurityDeposit;
                            dod.PlasticBoxQuantity        = (int)i.PlasticBoxQuantity;
                            dod.PlasticBoxSecurity        = d.PlasticBoxSecurity;
                            dod.BatchNo = batch.BatchNo;
                            dod.MfgDate = batch.ManufacturDate;
                            dod.ExpDate = batch.ExpiryDate;
                            dod.MRPRate = d.MRPRate;
                            dc.OrderDetails.Add(dod);

                            //Add scheme infomation
                            OrderSchemeDetail os = new OrderSchemeDetail();
                            os.OrderID     = orderno;// A.OrderID;
                            os.ProductID   = i.ProductID;
                            os.SchemeID    = (int)i.SchemeID;
                            os.WarehouseID = A.WarehouseID;
                            dc.OrderSchemeDetails.Add(os);
                            // Booked Product
                            var bookedproduct = db.spStockBookedandBookedFree(
                                i.ProductID,
                                A.WarehouseID,
                                totbookedqty,
                                "B");
                        }
                    }

                    //db.SaveChanges();
                    //  status = true;
                    if (status == true)
                    {
                        //update

                        if (A.OrderTypeID == 1)
                        {
                            pstatus = "C";
                        }
                        else
                        {
                            pstatus = "P";
                        }
                        var ob            = db.spOrderBankSumUpdate(A.SalesOrderNo, A.WarehouseID, pstatus); //Where(x => x.SalesOrderNO == A.SalesOrderNo && x.WarehouseID == A.WarehouseID && x.CustomerID == A.CustomerID).FirstOrDefault();
                        var bookamtupdate = db.spCustomerBalanceUpdate(A.CustomerID, "B", A.SalesAmount);    // db.Entry(ob).State = EntityState.Modified;
                                                                                                             //Transport QR Data                                                                         //Ad QR LoadSheet Timing                                                                       //Add scheme infomation
                        try
                        {
                            TransportQRData qd = db.TransportQRDatas.SingleOrDefault(x => x.SLNO == A.QRSL);
                            qd.LoadingDateTime = System.DateTime.Now;
                            qd.SalesOrderNo    = orderno;
                            dc.Entry(qd).State = EntityState.Modified;
                        }
                        catch (Exception ex)
                        {
                        }
                        dc.SaveChanges();
                        status = true;
                        dc.Dispose();
                    }
                    else
                    {
                        status = false;
                        v      = 0000;
                    }
                }
            }
            // catch (Exception ex)
            // {

            //   return new JsonResult { Data = new { status = false, mes = "NO Save", v = v } };
            //  return JsonResult { Data = new { status = "error", message = "Not Found" }};
            //}
            return(new JsonResult {
                Data = new { status = status, mes = mes, v = v }
            });
        }