Ejemplo n.º 1
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"));
        }