示例#1
0
 public vmSettlement()
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
         {
             //SELECT ID, TRNDATE, AMOUNT, TERMINAL, TRNUSER, TRNTIME, CUSER, POST FROM CashSettlement
             TerminalList = conn.Query <Terminal>("SELECT TERMINAL_CODE, TERMINAL_NAME FROM TERMINALS WHERE [STATUS] = 0").ToList();
             UserList     = conn.Query <User>("SELECT [UID], UserName, FullName FROM USERS WHERE [STATUS] = 0").ToList();
         }
         Settlement = new CashSettlement()
         {
             TRNDATE = DateTime.Today, TERMINAL_CODE = GlobalClass.Terminal, SETTLER_UID = GlobalClass.User.UID, SETTLED_UID = GlobalClass.User.UID
         };
         Settlement.PropertyChanged += Settlement_PropertyChanged;
         Settlement.OnPropertyChanged("SETTLED_UID");
         OpenDenomination = new RelayCommand(openDenomination, canOpenDenomination);
         PrintCommand     = new RelayCommand(ExecutePrint, CanExecutePrint);
         NewCommand       = new RelayCommand(ExecuteNew);
         SetAction(ButtonAction.Init);
     }
     catch (Exception ex)
     {
         MessageBox.Show(GlobalClass.GetRootException(ex).Message, "Settlemennt", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
示例#2
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 }
            });
        }
示例#3
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 });
        }
示例#4
0
        private void ExecuteNew(object obj)
        {
            if (_action == ButtonAction.Init)
            {
                SetAction(ButtonAction.New);
                Settlement.SETTLER_UID = GlobalClass.User.UID;
                Deno = new Denomination();// { TRNDATE = Settlement.TRNDATE, COUNTER = Settlement.TERMINAL, USERID = Settlement.TRNUSER };
            }
            else if (_action == ButtonAction.New)
            {
                if (Settlement.AMOUNT <= 0)
                {
                    MessageBox.Show("Settlement amount cannot be Zero of less.", "Cash Settlement", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (Deno.RTOTAL != Settlement.AMOUNT)
                {
                    MessageBox.Show("Denomination and settlement amount does not match. Enter denomination correctly and try again.", "Cash Settlement", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                try
                {
                    SqlTransaction tran;
                    using (SqlConnection conn = new SqlConnection(GlobalClass.TConnectionString))
                    {
                        conn.Open();
                        tran = conn.BeginTransaction();
                        try
                        {
                            Settlement.FYID          = GlobalClass.FYID;
                            Settlement.SETTLEMENT_ID = conn.ExecuteScalar <int>("SELECT CurNo FROM tblSequence WHERE VNAME = 'SID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                            Settlement._TRNDATE      = conn.ExecuteScalar <DateTime>("SELECT GETDATE()", transaction: tran);
                            Settlement.TRNTIME       = Settlement.TRNDATE.ToString("hh:mm tt");
                            Settlement._TRNDATE      = Settlement.TRNDATE.Date;
                            Deno.FYID          = GlobalClass.FYID;
                            Deno.SETTLEMENT_ID = Settlement.SETTLEMENT_ID;
                            Settlement.OnPropertyChanged("SETTLED_UID");
                            Settlement.Save(tran);
                            Deno.Save(tran);

                            CloseSession(tran);

                            conn.Execute("UPDATE tblSequence SET CurNo = CurNo + 1 WHERE VNAME = 'SID' AND FYID = " + GlobalClass.FYID, transaction: tran);
                            PrintCashSettlement(Settlement.SETTLEMENT_ID, conn, tran);

                            tran.Commit();
                            GlobalClass.StartSession();
                            MessageBox.Show("Transaction successfully saved", "Cash Settlement", MessageBoxButton.OK, MessageBoxImage.Information);
                            Settlement = new CashSettlement {
                                TRNDATE = DateTime.Today, SETTLED_UID = GlobalClass.User.UID, TERMINAL_CODE = GlobalClass.Terminal
                            };
                            Settlement.PropertyChanged += Settlement_PropertyChanged;
                            Settlement.SETTLED_UID      = 0;
                            SetAction(ButtonAction.Init);
                        }
                        catch (SqlException ex)
                        {
                            if (tran.Connection != null)
                            {
                                tran.Rollback();
                            }
                            MessageBox.Show(GlobalClass.GetRootException(ex).Message, "Settlemennt", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(GlobalClass.GetRootException(ex).Message, "Settlemennt", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }