コード例 #1
0
        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"));
        }