public ActionResult JobWorkPayment(MainApplication mainapp, FormCollection frmcol)
        {
            MainApplication model = new MainApplication()
            {
                JobWorkOutwardToClientDetails = new JobWorkOutwardToClient(),
            };

            //CREATE JOB WORK PAYMENT CODE
            string year = FinancialYear;

            string[] yr          = year.Split(' ', '-');
            string   FinYr       = "/" + yr[2].Substring(2) + "-" + yr[6].Substring(2);
            string   paymentcode = string.Empty;

            var jobworkpaymentdata = _JobWorkPaymentService.GetLastPaymentByFinYr(FinYr);
            int PaymentVal         = 0;
            int length             = 0;

            if (jobworkpaymentdata != null)
            {
                paymentcode = jobworkpaymentdata.PaymentCode.Substring(3, 6);
                length      = (Convert.ToInt32(paymentcode) + 1).ToString().Length;
                PaymentVal  = Convert.ToInt32(paymentcode) + 1;
            }
            else
            {
                PaymentVal = 1;
                length     = 1;
            }

            paymentcode = _utilityService.getName("JWP", length, PaymentVal);
            paymentcode = paymentcode + FinYr;
            mainapp.JobWorkPaymentDetails.PaymentCode = paymentcode;

            //update previous job work payment status inactive..
            var jobworkpaymentlist = _JobWorkPaymentService.GetRowsByOutwardNo(mainapp.JobWorkPaymentDetails.OutwardToTailorNo);

            foreach (var row in jobworkpaymentlist)
            {
                row.Status = "InActive";
                _JobWorkPaymentService.Update(row);
            }

            //SAVE CASHIER RECEIVABLES PAYMENT DETAILS
            mainapp.JobWorkPaymentDetails.Cash_1000 = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_1000"]);
            mainapp.JobWorkPaymentDetails.Cash_500  = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_500"]);
            mainapp.JobWorkPaymentDetails.Cash_100  = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_100"]);
            mainapp.JobWorkPaymentDetails.Cash_50   = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_50"]);
            mainapp.JobWorkPaymentDetails.Cash_20   = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_20"]);
            mainapp.JobWorkPaymentDetails.Cash_10   = Convert.ToInt32(frmcol["JobWorkPaymentDetails.Cash_10"]);
            mainapp.JobWorkPaymentDetails.Cash_1    = Convert.ToDouble(frmcol["JobWorkPaymentDetails.Cash_1"]);

            mainapp.JobWorkPaymentDetails.Cash_1000_Amt = Convert.ToDouble(frmcol["Amt1"]);
            mainapp.JobWorkPaymentDetails.Cash_500_Amt  = Convert.ToDouble(frmcol["Amt2"]);
            mainapp.JobWorkPaymentDetails.Cash_100_Amt  = Convert.ToDouble(frmcol["Amt3"]);
            mainapp.JobWorkPaymentDetails.Cash_50_Amt   = Convert.ToDouble(frmcol["Amt4"]);
            mainapp.JobWorkPaymentDetails.Cash_20_Amt   = Convert.ToDouble(frmcol["Amt5"]);
            mainapp.JobWorkPaymentDetails.Cash_10_Amt   = Convert.ToDouble(frmcol["Amt6"]);
            mainapp.JobWorkPaymentDetails.Cash_1_Amt    = Convert.ToDouble(frmcol["Amt7"]);

            mainapp.JobWorkPaymentDetails.TotalCash = Convert.ToDouble(frmcol["JobWorkPaymentDetails.TotalCash"]);

            mainapp.JobWorkPaymentDetails.SelectedCard = frmcol["Card"];

            mainapp.JobWorkPaymentDetails.CreditCardNo = frmcol["JobWorkPaymentDetails.CreditCardNo"];
            if (frmcol["JobWorkPaymentDetails.CreditCardAmount"] == "")
            {
                mainapp.JobWorkPaymentDetails.CreditCardAmount  = 0;
                mainapp.JobWorkPaymentDetails.HandoverCreditAmt = 0;
            }
            else
            {
                mainapp.JobWorkPaymentDetails.CreditCardAmount  = Convert.ToDouble(frmcol["JobWorkPaymentDetails.CreditCardAmount"]);
                mainapp.JobWorkPaymentDetails.HandoverCreditAmt = Convert.ToDouble(frmcol["JobWorkPaymentDetails.CreditCardAmount"]);
            }
            mainapp.JobWorkPaymentDetails.CreditCardType = frmcol["JobWorkPaymentDetails.CreditCardType"];
            mainapp.JobWorkPaymentDetails.CreditCardBank = frmcol["JobWorkPaymentDetails.CreditCardBank"];
            mainapp.JobWorkPaymentDetails.DebitCardNo    = frmcol["JobWorkPaymentDetails.DebitCardNo"];
            mainapp.JobWorkPaymentDetails.DebitCardName  = frmcol["JobWorkPaymentDetails.DebitCardName"];
            mainapp.JobWorkPaymentDetails.DebitCardType  = frmcol["JobWorkPaymentDetails.DebitCardType"];
            mainapp.JobWorkPaymentDetails.DebitCardBank  = frmcol["JobWorkPaymentDetails.DebitCardBank"];
            if (frmcol["JobWorkPaymentDetails.DebitCardAmount"] == "")
            {
                mainapp.JobWorkPaymentDetails.DebitCardAmount  = 0;
                mainapp.JobWorkPaymentDetails.HandoverDebitAmt = 0;
            }
            else
            {
                mainapp.JobWorkPaymentDetails.DebitCardAmount  = Convert.ToDouble(frmcol["JobWorkPaymentDetails.DebitCardAmount"]);
                mainapp.JobWorkPaymentDetails.HandoverDebitAmt = Convert.ToDouble(frmcol["JobWorkPaymentDetails.DebitCardAmount"]);
            }
            mainapp.JobWorkPaymentDetails.ChequeNo    = frmcol["JobWorkPaymentDetails.ChequeNo"];
            mainapp.JobWorkPaymentDetails.ChequeAccNo = frmcol["JobWorkPaymentDetails.ChequeAccNo"];
            if (frmcol["JobWorkPaymentDetails.ChequeAmount"] == "")
            {
                mainapp.JobWorkPaymentDetails.ChequeAmount      = 0;
                mainapp.JobWorkPaymentDetails.HandoverChequeAmt = 0;
            }
            else
            {
                mainapp.JobWorkPaymentDetails.ChequeAmount      = Convert.ToDouble(frmcol["JobWorkPaymentDetails.ChequeAmount"]);
                mainapp.JobWorkPaymentDetails.HandoverChequeAmt = Convert.ToDouble(frmcol["JobWorkPaymentDetails.ChequeAmount"]);
            }
            if (mainapp.JobWorkPaymentDetails.ChequeNo != null && mainapp.JobWorkPaymentDetails.ChequeNo != "")
            {
                mainapp.JobWorkPaymentDetails.ChequeDate = Convert.ToDateTime(frmcol["JobWorkPaymentDetails.ChequeDate"]);
            }
            else
            {
                mainapp.JobWorkPaymentDetails.ChequeDate = null;
            }
            mainapp.JobWorkPaymentDetails.ChequeBank   = frmcol["JobWorkPaymentDetails.ChequeBank"];
            mainapp.JobWorkPaymentDetails.ChequeBranch = frmcol["JobWorkPaymentDetails.ChequeBranch"];


            var outwarddetails = _OutwardToTailorService.GetDetailsByCode(mainapp.JobWorkPaymentDetails.OutwardToTailorNo);

            mainapp.JobWorkPaymentDetails.OutwardToTailorDate  = outwarddetails.Date;
            mainapp.JobWorkPaymentDetails.ClientName           = outwarddetails.ClientName;
            mainapp.JobWorkPaymentDetails.ClientAddress        = outwarddetails.ClientAddress;
            mainapp.JobWorkPaymentDetails.ClientContact        = outwarddetails.ClientContact;
            mainapp.JobWorkPaymentDetails.ClientEmail          = outwarddetails.ClientEmail;
            mainapp.JobWorkPaymentDetails.TailorName           = outwarddetails.TailorName;
            mainapp.JobWorkPaymentDetails.TailorAddress        = outwarddetails.TailorAddress;
            mainapp.JobWorkPaymentDetails.TailorContact        = outwarddetails.TailorContact;
            mainapp.JobWorkPaymentDetails.TailorEmail          = outwarddetails.TailorEmail;
            mainapp.JobWorkPaymentDetails.GrandTotal           = outwarddetails.GrandTotal;
            mainapp.JobWorkPaymentDetails.AdvancePayment       = outwarddetails.AdvancePayment;
            mainapp.JobWorkPaymentDetails.Balance              = Convert.ToDouble(frmcol["BalanceVal"]);
            mainapp.JobWorkPaymentDetails.ItemsDeliveredStatus = frmcol["Delivered"];

            var username = HttpContext.Session["UserName"].ToString();

            //IF EXCEPT SUPERADMIN LOGIN THEN SHOW SHOP OR GODOWN
            if (username != "SuperAdmin")
            {
                mainapp.JobWorkPaymentDetails.ShopCode = Session["LOGINSHOPGODOWNCODE"].ToString();
                mainapp.JobWorkPaymentDetails.ShopName = Session["SHOPGODOWNNAME"].ToString();
            }
            else
            {
                mainapp.JobWorkPaymentDetails.ShopCode = "SuperAdmin";
                mainapp.JobWorkPaymentDetails.ShopName = "SuperAdmin";
            }

            mainapp.JobWorkPaymentDetails.Date       = DateTime.Now;
            mainapp.JobWorkPaymentDetails.Status     = "Active";
            mainapp.JobWorkPaymentDetails.ModifiedOn = DateTime.Now;

            //SAVE HANDOVER STATUS
            if (mainapp.JobWorkPaymentDetails.CreditCardAmount == 0 && mainapp.JobWorkPaymentDetails.DebitCardAmount == 0 && mainapp.JobWorkPaymentDetails.ChequeAmount == 0)
            {
                mainapp.JobWorkPaymentDetails.HandoverStatus = "InActive";
            }
            else
            {
                mainapp.JobWorkPaymentDetails.HandoverStatus = "Active";
            }
            _JobWorkPaymentService.Create(mainapp.JobWorkPaymentDetails);

            //UPDATE OUTWARD TO TAILOR PAYMENT AND BALANCE AFTER CASHIER PAYMENT
            var OutwardToTailorData = _OutwardToTailorService.GetDetailsByCode(mainapp.JobWorkPaymentDetails.OutwardToTailorNo);

            OutwardToTailorData.AdvancePayment = OutwardToTailorData.AdvancePayment + mainapp.JobWorkPaymentDetails.Payment;
            OutwardToTailorData.Balance        = mainapp.JobWorkPaymentDetails.Balance;

            if (OutwardToTailorData.Balance <= 0)
            {
                OutwardToTailorData.Status = "InActive";
            }
            _OutwardToTailorService.Update(OutwardToTailorData);

            //UPDATE OUTWARD TO TAILOR ITEM INACTIVE AFTER CASHIER PAYMENT
            if (OutwardToTailorData.Balance <= 0)
            {
                var OutwardToTailorItemData = _OutwardToTailorItemService.GetRowsByCode(mainapp.JobWorkPaymentDetails.OutwardToTailorNo);
                foreach (var data in OutwardToTailorItemData)
                {
                    data.Status = "InActive";
                    _OutwardToTailorItemService.Update(data);
                }
            }

            if (frmcol["Delivered"] == "Yes")
            {
                //IF DELIVERED STATUS IS YES THEN UPDATE JOB WORK STOCK
                var jobworkstockitems = _JobWorkStockService.GetRowsByOutwardNo(mainapp.JobWorkPaymentDetails.OutwardToTailorNo);
                foreach (var item in jobworkstockitems)
                {
                    item.Status = "InActive";
                    _JobWorkStockService.Update(item);

                    //IF DELIVERED STATUS IS YES THEN ADD THIS STOCK IN JUOB WORK OUTWARD TO CLIENT
                    model.JobWorkOutwardToClientDetails.OutwardToTailorNo = mainapp.JobWorkPaymentDetails.OutwardToTailorNo;
                    model.JobWorkOutwardToClientDetails.PaymentCode       = mainapp.JobWorkPaymentDetails.PaymentCode;
                    model.JobWorkOutwardToClientDetails.ClientName        = mainapp.JobWorkPaymentDetails.ClientName;
                    model.JobWorkOutwardToClientDetails.TailorName        = mainapp.JobWorkPaymentDetails.TailorName;
                    model.JobWorkOutwardToClientDetails.ItemName          = item.ItemName;
                    model.JobWorkOutwardToClientDetails.Quantity          = item.Quantity;
                    model.JobWorkOutwardToClientDetails.Narration         = item.Narration;
                    model.JobWorkOutwardToClientDetails.ShopCode          = mainapp.JobWorkPaymentDetails.ShopCode;
                    model.JobWorkOutwardToClientDetails.ShopName          = mainapp.JobWorkPaymentDetails.ShopName;
                    model.JobWorkOutwardToClientDetails.Status            = "Active";
                    model.JobWorkOutwardToClientDetails.ModifiedOn        = DateTime.Now;
                    _JobWorkOutwardToClientService.Create(model.JobWorkOutwardToClientDetails);
                }
            }

            return(RedirectToAction("JobWorkPayment"));
        }
Esempio n. 2
0
        public ActionResult InwardFromTailor(MainApplication mainapp, FormCollection frmcol)
        {
            MainApplication model = new MainApplication();

            string year = FinancialYear;

            string[] yr    = year.Split(' ', '-');
            string   FinYr = "/" + yr[2].Substring(2) + "-" + yr[6].Substring(2);

            string InwardCode = string.Empty;

            var details = _InwardFromTailorService.GetLastRowrByFinYr(FinYr);
            int val     = 0;
            int length  = 0;

            if (details != null)
            {
                InwardCode = details.InwardCode.Substring(4, 6);
                length     = (Convert.ToInt32(InwardCode) + 1).ToString().Length;
                val        = Convert.ToInt32(InwardCode) + 1;

                val    = details.Id;
                val    = val + 1;
                length = val.ToString().Length;
            }
            else
            {
                val    = 1;
                length = 1;
            }
            InwardCode = _UtilityService.getName("IWFT", length, val);
            InwardCode = InwardCode + FinYr;
            mainapp.InwardFromTailorDetails.InwardCode = InwardCode;

            var data = _OutwardToTailorService.GetDetailsByCode(mainapp.InwardFromTailorDetails.OutwardToTailorCode);

            if (data != null)
            {
                mainapp.InwardFromTailorDetails.OutwardToTailorCode = data.OutwardCode;
                mainapp.InwardFromTailorDetails.Date          = DateTime.Now;
                mainapp.InwardFromTailorDetails.TailorName    = data.TailorName;
                mainapp.InwardFromTailorDetails.TailorAddress = data.TailorAddress;
                mainapp.InwardFromTailorDetails.TailorContact = data.TailorContact;
                mainapp.InwardFromTailorDetails.TailorEmail   = data.TailorEmail;
                mainapp.InwardFromTailorDetails.ClientName    = data.ClientName;
                mainapp.InwardFromTailorDetails.ClientAddress = data.ClientAddress;
                mainapp.InwardFromTailorDetails.ClientContact = data.ClientContact;
                mainapp.InwardFromTailorDetails.ClientEmail   = data.ClientEmail;
                mainapp.InwardFromTailorDetails.RetailBills   = data.RetailBills;
                mainapp.InwardFromTailorDetails.SalesBills    = data.SalesBills;
                mainapp.InwardFromTailorDetails.GrandTotal    = data.GrandTotal;
                mainapp.InwardFromTailorDetails.Payment       = data.AdvancePayment;
                mainapp.InwardFromTailorDetails.JobWorkStatus = frmcol["InwardType"];
                //save balance after tailor paid amount
                if (frmcol["InwardType"] == "SentToClient")
                {
                    mainapp.InwardFromTailorDetails.Balance = Convert.ToDouble(frmcol["BalanceValAfterTailorAmt"]);
                }
                else
                {
                    mainapp.InwardFromTailorDetails.Balance = data.Balance;
                }
                mainapp.InwardFromTailorDetails.Status     = "Active";
                mainapp.InwardFromTailorDetails.ModifiedOn = DateTime.Now;

                var username = HttpContext.Session["UserName"].ToString();
                //IF EXCEPT SUPERADMIN LOGIN THEN SHOW SHOP OR GODOWN
                if (username != "SuperAdmin")
                {
                    mainapp.InwardFromTailorDetails.ShopCode = Session["LOGINSHOPGODOWNCODE"].ToString();
                    mainapp.InwardFromTailorDetails.ShopName = Session["SHOPGODOWNNAME"].ToString();
                }
                else
                {
                    mainapp.InwardFromTailorDetails.ShopCode = "SuperAdmin";
                    mainapp.InwardFromTailorDetails.ShopName = "SuperAdmin";
                }
                _InwardFromTailorService.Create(mainapp.InwardFromTailorDetails);
            }

            if (frmcol["InwardType"] == "InwardToShop")
            {
                int count = Convert.ToInt32(frmcol["hdnRowCount"]);
                for (int i = 1; i <= count; i++)
                {
                    string item      = "Item" + i;
                    string narration = "Narration" + i;
                    string quantity  = "Quantity" + i;

                    if (frmcol[quantity] != null)
                    {
                        //save inward from tailor items..
                        mainapp.InwardFromTailorItemDetails            = new InwardFromTailorItem();
                        mainapp.InwardFromTailorItemDetails.InwardCode = mainapp.InwardFromTailorDetails.InwardCode;
                        mainapp.InwardFromTailorItemDetails.Item       = frmcol[item];
                        mainapp.InwardFromTailorItemDetails.Narration  = frmcol[narration];
                        mainapp.InwardFromTailorItemDetails.Quantity   = Convert.ToDouble(frmcol[quantity]);
                        mainapp.InwardFromTailorItemDetails.Status     = "Active";
                        mainapp.InwardFromTailorItemDetails.ModifiedOn = DateTime.Now;
                        _InwardFromTailorItemService.Create(mainapp.InwardFromTailorItemDetails);

                        //save job work stock items..
                        mainapp.JobWorkStockDetails             = new JobWorkStock();
                        mainapp.JobWorkStockDetails.StockDate   = DateTime.Now;
                        mainapp.JobWorkStockDetails.InwardCode  = mainapp.InwardFromTailorDetails.InwardCode;
                        mainapp.JobWorkStockDetails.OutwardCode = mainapp.InwardFromTailorDetails.OutwardToTailorCode;
                        mainapp.JobWorkStockDetails.ItemName    = frmcol[item];
                        mainapp.JobWorkStockDetails.Quantity    = Convert.ToDouble(frmcol[quantity]);
                        mainapp.JobWorkStockDetails.Narration   = frmcol[narration];
                        mainapp.JobWorkStockDetails.Status      = "Active";
                        mainapp.JobWorkStockDetails.ModifiedOn  = DateTime.Now;

                        var username = HttpContext.Session["UserName"].ToString();
                        //IF EXCEPT SUPERADMIN LOGIN THEN SHOW SHOP OR GODOWN
                        if (username != "SuperAdmin")
                        {
                            mainapp.JobWorkStockDetails.ShopCode = Session["LOGINSHOPGODOWNCODE"].ToString();
                            mainapp.JobWorkStockDetails.ShopName = Session["SHOPGODOWNNAME"].ToString();
                        }
                        else
                        {
                            mainapp.JobWorkStockDetails.ShopCode = "SuperAdmin";
                            mainapp.JobWorkStockDetails.ShopName = "SuperAdmin";
                        }
                        _JobWorkStockService.Create(mainapp.JobWorkStockDetails);
                    }
                }
            }

            //UPDATE OUTWARD TO TAILOR AFTER INWARD
            var outwardtotailordetails = _OutwardToTailorService.GetDetailsByCode(mainapp.InwardFromTailorDetails.OutwardToTailorCode);

            outwardtotailordetails.InwardStatus = "InActive";
            if (frmcol["InwardType"] == "SentToClient")
            {
                //outwardtotailordetails.AdvancePayment = outwardtotailordetails.AdvancePayment + mainapp.InwardFromTailorDetails.PaidAmountToTailor;
                outwardtotailordetails.PaidAmountToTailor = mainapp.InwardFromTailorDetails.PaidAmountToTailor;
                outwardtotailordetails.Balance            = mainapp.InwardFromTailorDetails.Balance;
                if (outwardtotailordetails.Balance == 0)
                {
                    outwardtotailordetails.Status = "InActive";
                }
            }
            _OutwardToTailorService.Update(outwardtotailordetails);

            var outwardtotailoritems = _OutwardToTailorItemService.GetRowsByCode(mainapp.InwardFromTailorDetails.OutwardToTailorCode);

            foreach (var item in outwardtotailoritems)
            {
                item.InwardStatus = "InActive";
                _OutwardToTailorItemService.Update(item);
            }

            return(RedirectToAction("InwardFromTailor"));
        }