예제 #1
0
        public ActionResult GetInwardListFromInwardNo(string No)
        {
            MainApplication model     = new MainApplication();
            string          InwardNos = No;

            string[] SingleInwardNo = InwardNos.Split(',');
            List <InwardFromSupplier> InwardList = new List <InwardFromSupplier>();

            for (int i = 0; i < SingleInwardNo.Count(); i++)
            {
                //for inward main table
                model.InwardFromSupplierDetails = _InwardFromSupplierService.GetInwardByInwardNo(SingleInwardNo[i]);

                //access debit note amount
                double DebitNoteAmt  = 0;
                var    DebitNoteList = _DebitNoteService.GetDebitNoteListByInwardNo(SingleInwardNo[i]);
                if (DebitNoteList != null)
                {
                    foreach (var data in DebitNoteList)
                    {
                        DebitNoteAmt = DebitNoteAmt + Convert.ToDouble(data.Amount);
                    }
                }
                model.InwardFromSupplierDetails.ReadOnlyDebitNoteAmt = DebitNoteAmt;
                InwardList.Add(model.InwardFromSupplierDetails);
            }
            model.InwardFromSupplierList = InwardList;
            return(View(model));
        }
        public ActionResult PurchaseReturn(MainApplication model, FormCollection frmcol)
        {
            string shopcode = Session["LOGINSHOPGODOWNCODE"].ToString();
            string shopname = Session["SHOPGODOWNNAME"].ToString();

            string year = FinancialYear;

            string[] yr    = year.Split(' ', '-');
            string   FinYr = "/" + yr[2].Substring(2) + "-" + yr[6].Substring(2);
            var      LastPurchaseReturn   = _PurchaseReturnService.GetLastPurchaseByFinYr(FinYr, shopcode);
            string   PurchaseReturnCode   = string.Empty;
            int      PurchaseReturnLength = 0;
            int      PurchaseReturnNo     = 0;

            if (LastPurchaseReturn == null)
            {
                PurchaseReturnLength = 1;
                PurchaseReturnNo     = 1;
            }
            else
            {
                int PurchaseReturnIndex = LastPurchaseReturn.PurchaseReturnNo.LastIndexOf('P');
                PurchaseReturnCode   = LastPurchaseReturn.PurchaseReturnNo.Substring(PurchaseReturnIndex + 2, 6);
                PurchaseReturnLength = (Convert.ToInt32(PurchaseReturnCode) + 1).ToString().Length;
                PurchaseReturnNo     = Convert.ToInt32(PurchaseReturnCode) + 1;
            }

            string ShortCode = string.Empty;

            if (shopcode.Contains("SH"))
            {
                var detail = _ShopService.GetShopDetailsByName(shopname);
                ShortCode = detail.ShortCode;
            }
            else
            {
                var detail = _GodownService.GetGodownDetailsByName(shopname);
                ShortCode = detail.ShortCode;
            }
            PurchaseReturnCode = _UtilityService.getName(ShortCode + "/PR", PurchaseReturnLength, PurchaseReturnNo);
            PurchaseReturnCode = PurchaseReturnCode + FinYr;
            string DebitNoteNo = _UtilityService.getName(ShortCode + "/DBN", PurchaseReturnLength, PurchaseReturnNo);

            DebitNoteNo = DebitNoteNo + FinYr;
            model.PurchaseReturnDetails.Code               = Session["LOGINSHOPGODOWNCODE"].ToString();
            model.PurchaseReturnDetails.PurchaseReturnNo   = PurchaseReturnCode;
            model.PurchaseReturnDetails.PurchaseReturnDate = DateTime.Now;
            model.PurchaseReturnDetails.DebitNoteNo        = DebitNoteNo;
            model.PurchaseReturnDetails.DebitNoteDate      = DateTime.Now;
            if (model.PurchaseReturnDetails.PackAndForwd == null)
            {
                model.PurchaseReturnDetails.PackAndForwd = 0;
            }
            model.PurchaseReturnDetails.DebitNoteAmount = Convert.ToDouble(frmcol["SupplierAmount"]);
            model.PurchaseReturnDetails.TotalAmount     = Convert.ToDouble(frmcol["TotalAmountValue"]);
            model.PurchaseReturnDetails.TotalTaxAmount  = Convert.ToDouble(frmcol["TotalTaxAmountValue"]);
            model.PurchaseReturnDetails.GrandTotal      = Convert.ToDouble(frmcol["GrandTotalValue"]);
            model.PurchaseReturnDetails.Status          = "Active";
            model.PurchaseReturnDetails.ModifiedOn      = DateTime.Now;
            _PurchaseReturnService.Create(model.PurchaseReturnDetails);

            DebitNote DebitNote = new DebitNote();

            DebitNote.DebitNoteNo      = DebitNoteNo;
            DebitNote.DebitNoteDate    = DateTime.Now;
            DebitNote.SupplierName     = model.PurchaseReturnDetails.SupplierName;
            DebitNote.BillNo           = model.PurchaseReturnDetails.SupplierBillNo;
            DebitNote.ChallanNo        = model.PurchaseReturnDetails.SupplierChallanNo;
            DebitNote.InwardNo         = model.PurchaseReturnDetails.InwardNo;
            DebitNote.PurchaseReturnNo = PurchaseReturnCode;
            DebitNote.Amount           = Convert.ToDouble(frmcol["SupplierAmount"]);
            DebitNote.Status           = "Active";
            DebitNote.ModifiedOn       = DateTime.Now;
            _DebitNoteService.Create(DebitNote);

            var Inwardreturnlist = TempData["InwardItemList"] as IEnumerable <InwardItemsFromSupplier>;
            int count            = 1;

            foreach (var item in Inwardreturnlist)
            {
                string checkbox = "CheckBox" + count;
                string quantity = "quantity" + count;
                string amount   = "amountvalue" + count;
                string prevqty  = "prevquantityvalue" + count;
                if (frmcol[checkbox] == "Yes")
                {
                    PurchaseReturnItem PurchaseReturnItem = new PurchaseReturnItem();
                    PurchaseReturnItem.PurchaseReturnNo = PurchaseReturnCode;
                    PurchaseReturnItem.Barcode          = item.Barcode;
                    PurchaseReturnItem.ItemCode         = item.itemCode;
                    PurchaseReturnItem.ItemName         = item.Item;
                    PurchaseReturnItem.ItemType         = item.ItemType;
                    PurchaseReturnItem.Description      = item.Description;
                    PurchaseReturnItem.DesignCode       = item.Design;
                    PurchaseReturnItem.DesignName       = item.DesignName;
                    PurchaseReturnItem.Color            = item.Color;
                    PurchaseReturnItem.Material         = item.Material;
                    PurchaseReturnItem.Brand            = item.Brand;
                    PurchaseReturnItem.Size             = item.Size;
                    PurchaseReturnItem.Unit             = item.Unit;
                    PurchaseReturnItem.NumberType       = item.NumberType;
                    PurchaseReturnItem.Quantity         = Convert.ToDouble(frmcol[quantity]);
                    PurchaseReturnItem.Balance          = Convert.ToDouble(frmcol[prevqty]) - Convert.ToDouble(frmcol[quantity]);
                    PurchaseReturnItem.CostPrice        = item.CostPrice;
                    PurchaseReturnItem.DisPer           = item.Discount.ToString();
                    PurchaseReturnItem.SellingPrice     = item.SellingPrice;
                    PurchaseReturnItem.MRP        = item.MRP;
                    PurchaseReturnItem.ItemTax    = item.ItemTax;
                    PurchaseReturnItem.Amount     = Convert.ToDouble(frmcol[amount]);
                    PurchaseReturnItem.Status     = "Active";
                    PurchaseReturnItem.ModifiedOn = DateTime.Now;
                    _PurchaseReturnItemService.Create(PurchaseReturnItem);

                    var inwarditem = _InwardItemFromSupplierService.GetItemByInwardNoAndItemCode(model.PurchaseReturnDetails.InwardNo, PurchaseReturnItem.ItemCode);
                    inwarditem.PurchaseReturn = "Yes";
                    _InwardItemFromSupplierService.Update(inwarditem);

                    DebitNoteItem DebitNoteItem = new DebitNoteItem();
                    DebitNoteItem.DebitNoteNo  = DebitNoteNo;
                    DebitNoteItem.ItemCode     = item.itemCode;
                    DebitNoteItem.ItemName     = item.Item;
                    DebitNoteItem.Description  = item.Description;
                    DebitNoteItem.ItemType     = item.ItemType;
                    DebitNoteItem.Color        = item.Color;
                    DebitNoteItem.Material     = item.Material;
                    DebitNoteItem.DesignName   = item.DesignName;
                    DebitNoteItem.Brand        = item.Brand;
                    DebitNoteItem.Size         = item.Size;
                    DebitNoteItem.Quantity     = Convert.ToDouble(frmcol[quantity]);
                    DebitNoteItem.Unit         = item.Unit;
                    DebitNoteItem.CostPrice    = item.CostPrice;
                    DebitNoteItem.NumberType   = item.NumberType;
                    DebitNoteItem.SellingPrice = item.SellingPrice;
                    DebitNoteItem.MRP          = item.MRP;
                    DebitNoteItem.ItemTax      = item.ItemTax;
                    DebitNoteItem.Amount       = Convert.ToDouble(frmcol[amount]);
                    DebitNoteItem.Status       = "Active";
                    DebitNoteItem.ModifiedOn   = DateTime.Now;
                    _DebitNoteItemService.Create(DebitNoteItem);

                    var iteminward = _InwardItemFromSupplierService.GetItemByInwardNoAndItemCode(model.PurchaseReturnDetails.InwardNo, item.itemCode);
                    iteminward.PurchaseReturn = "Yes";
                    _InwardItemFromSupplierService.Update(iteminward);

                    string code = Session["LOGINSHOPGODOWNCODE"].ToString();
                    if (item.ItemType == "Inventory")
                    {
                        if (code.Contains("SH"))
                        {
                            var shopdetails = _ShopStockService.GetDetailsByItemCodeAndShopCode(item.itemCode, code);
                            shopdetails.Quantity = shopdetails.Quantity - PurchaseReturnItem.Quantity;
                            _ShopStockService.Update(shopdetails);

                            var stockitemdetails = _StockItemDistributionService.GetDetailsByItemCodeAndShopCode(item.itemCode, code);
                            stockitemdetails.ItemQuantity = stockitemdetails.ItemQuantity - PurchaseReturnItem.Quantity;
                            _StockItemDistributionService.Update(stockitemdetails);
                        }
                        else
                        {
                            var godowndetails = _GodownStockService.GetDetailsByItemCodeAndGodownCode(item.itemCode, code);
                            godowndetails.Quantity = godowndetails.Quantity - PurchaseReturnItem.Quantity;
                            _GodownStockService.Update(godowndetails);

                            var stockitemdetails = _StockItemDistributionService.GetDetailsByItemCodeAndGodownCode(item.itemCode, code);
                            stockitemdetails.ItemQuantity = stockitemdetails.ItemQuantity - PurchaseReturnItem.Quantity;
                            _StockItemDistributionService.Update(stockitemdetails);
                        }

                        var entrystockitems = _EntryStockItemService.getDetailsByItemCode(item.itemCode);
                        if (entrystockitems != null)
                        {
                            entrystockitems.TotalQuantity = entrystockitems.TotalQuantity - PurchaseReturnItem.Quantity;
                            _EntryStockItemService.Update(entrystockitems);
                        }
                        else
                        {
                            var openingstockitems = _OpeningStockService.GetDetailsByItemCode(item.itemCode);
                            openingstockitems.TotalQuantity = openingstockitems.TotalQuantity - PurchaseReturnItem.Quantity;
                            _OpeningStockService.UpdateStock(openingstockitems);
                        }
                    }
                }
                count++;
            }
            count = Inwardreturnlist.Count() + 1;
            var purchasereturnlist = TempData["PurchaseReturnList"] as IEnumerable <PurchaseReturnItem>;

            foreach (var item in purchasereturnlist)
            {
                string checkbox = "CheckBox" + count;
                string quantity = "quantity" + count;
                string amount   = "amountvalue" + count;
                string prevqty  = "prevquantityvalue" + count;
                if (frmcol[checkbox] == "Yes")
                {
                    item.PurchaseReturnNo = PurchaseReturnCode;
                    item.Quantity         = Convert.ToDouble(frmcol[quantity]);
                    item.Balance          = Convert.ToDouble(frmcol[prevqty]) - Convert.ToDouble(frmcol[quantity]);
                    item.Amount           = Convert.ToDouble(frmcol[amount]);
                    item.Status           = "Active";
                    item.ModifiedOn       = DateTime.Now;
                    _PurchaseReturnItemService.Create(item);

                    DebitNoteItem DebitNoteItem = new DebitNoteItem();
                    DebitNoteItem.DebitNoteNo  = DebitNoteNo;
                    DebitNoteItem.ItemCode     = item.ItemCode;
                    DebitNoteItem.ItemName     = item.ItemName;
                    DebitNoteItem.Description  = item.Description;
                    DebitNoteItem.ItemType     = item.ItemType;
                    DebitNoteItem.Color        = item.Color;
                    DebitNoteItem.Material     = item.Material;
                    DebitNoteItem.DesignName   = item.DesignName;
                    DebitNoteItem.Brand        = item.Brand;
                    DebitNoteItem.Size         = item.Size;
                    DebitNoteItem.Quantity     = Convert.ToDouble(frmcol[quantity]);
                    DebitNoteItem.Unit         = item.Unit;
                    DebitNoteItem.NumberType   = item.NumberType;
                    DebitNoteItem.CostPrice    = item.CostPrice;
                    DebitNoteItem.SellingPrice = item.SellingPrice;
                    DebitNoteItem.MRP          = item.MRP;
                    DebitNoteItem.ItemTax      = item.ItemTax;
                    DebitNoteItem.Amount       = Convert.ToDouble(frmcol[amount]);
                    DebitNoteItem.Status       = "Active";
                    DebitNoteItem.ModifiedOn   = DateTime.Now;
                    _DebitNoteItemService.Create(DebitNoteItem);

                    string code = Session["LOGINSHOPGODOWNCODE"].ToString();
                    if (item.ItemType == "Inventory")
                    {
                        if (code.Contains("SH"))
                        {
                            var shopdetails = _ShopStockService.GetDetailsByItemCodeAndShopCode(item.ItemCode, code);
                            shopdetails.Quantity = shopdetails.Quantity - item.Quantity;
                            _ShopStockService.Update(shopdetails);

                            var stockitemdetails = _StockItemDistributionService.GetDetailsByItemCodeAndShopCode(item.ItemCode, code);
                            stockitemdetails.ItemQuantity = stockitemdetails.ItemQuantity - item.Quantity;
                            _StockItemDistributionService.Update(stockitemdetails);
                        }
                        else
                        {
                            var godowndetails = _GodownStockService.GetDetailsByItemCodeAndGodownCode(item.ItemCode, code);
                            godowndetails.Quantity = godowndetails.Quantity - item.Quantity;
                            _GodownStockService.Update(godowndetails);

                            var stockitemdetails = _StockItemDistributionService.GetDetailsByItemCodeAndGodownCode(item.ItemCode, code);
                            stockitemdetails.ItemQuantity = stockitemdetails.ItemQuantity - item.Quantity;
                            _StockItemDistributionService.Update(stockitemdetails);
                        }

                        var entrystockitems = _EntryStockItemService.getDetailsByItemCode(item.ItemCode);
                        if (entrystockitems != null)
                        {
                            entrystockitems.TotalQuantity = entrystockitems.TotalQuantity - item.Quantity;
                            _EntryStockItemService.Update(entrystockitems);
                        }
                        else
                        {
                            var openingstockitems = _OpeningStockService.GetDetailsByItemCode(item.ItemCode);
                            openingstockitems.TotalQuantity = openingstockitems.TotalQuantity - item.Quantity;
                            _OpeningStockService.UpdateStock(openingstockitems);
                        }
                    }
                }
                else
                {
                    item.PurchaseReturnNo = PurchaseReturnCode;
                    item.Quantity         = 0;
                    _PurchaseReturnItemService.Create(item);
                }
                count++;
            }
            var data = _InwardFromSupplierService.GetInwardByInwardNo(model.PurchaseReturnDetails.InwardNo);

            data.PurchaseReturn = "Yes";
            if (data.PurchaseReturnNo == null)
            {
                data.PurchaseReturnNo = PurchaseReturnCode;
            }
            else
            {
                data.PurchaseReturnNo = data.PurchaseReturnNo + "," + PurchaseReturnCode;
            }
            _InwardFromSupplierService.UpdateInward(data);

            //Store total tax and total amount of tax of PO
            int itemtaxcount = Convert.ToInt32(frmcol["ReturnItemTaxCount"]);

            model.PurchaseInventoryTaxDetails = new PurchaseInventoryTax();
            for (int i = 1; i <= itemtaxcount; i++)
            {
                string taxnumber   = "ReturnItemTaxNumber" + i;
                string taxamount   = "ReturnAddedTaxAmounthdn" + i;
                string amountontax = "ReturnAddedAmounthdn" + i;
                if (Convert.ToDouble(frmcol[taxamount]) != 0)
                {
                    model.PurchaseInventoryTaxDetails.Code      = PurchaseReturnCode;
                    model.PurchaseInventoryTaxDetails.Amount    = frmcol[amountontax];
                    model.PurchaseInventoryTaxDetails.Tax       = frmcol[taxnumber];
                    model.PurchaseInventoryTaxDetails.TaxAmount = frmcol[taxamount];
                    _PurchaseInventoryTaxService.Create(model.PurchaseInventoryTaxDetails);
                }
            }

            var    details = _PurchaseReturnService.GetPurchaseByReturnNo(PurchaseReturnCode);
            string PRId    = Encode(details.Id.ToString());

            return(RedirectToAction("PurchaseReturnDetails/" + PRId));
        }