Ejemplo n.º 1
0
        public bool SaleRegister(GST_TRN_INVOICE invoice)
        {
            foreach (GST_TRN_INVOICE_DATA item in invoice.GST_TRN_INVOICE_DATA)
            {
                var itemType = unitOfWork.ItemRepository.Find(f => f.Item_ID == item.Item_ID).ItemType;
                // var purchaseItems = unitOfWork.PurchaseDataRepositry.Filter(f => f.Status == true && item.Item_ID == f.Item_ID).Select(s => s.GST_MST_PURCHASE_REGISTER.UserID).ToList();
                if (itemType == (byte)EnumConstants.ItemType.HSN)
                {
                    //string uId = seller.SellerUserID;
                    //int iTem = Convert.ToInt32(item.Item_ID);
                    //decimal LeftQty = purchaseRegister.GetLeftItemQty(iTem, uId);

                    //if (LeftQty > item.Qty)
                    //{
                    GST_MST_SALE_REGISTER salRegister = new GST_MST_SALE_REGISTER();
                    salRegister.InvoiceID   = invoice.InvoiceID;
                    salRegister.PerUnitRate = item.Rate;
                    salRegister.Item_ID     = item.Item_ID;
                    salRegister.Qty         = item.Qty;
                    salRegister.CreatedBy   = invoice.CreatedBy;
                    salRegister.CreatedDate = DateTime.Now;
                    salRegister.Status      = true;
                    salRegister.Id          = invoice.SellerUserID;
                    salRegister.SaleStatus  = (byte)EnumConstants.SaleStatus.Fresh;
                    unitOfWork.SaleRegisterDataRepositry.Create(salRegister);

                    //q }
                }
            }
            unitOfWork.Save();
            return(true);
        }
Ejemplo n.º 2
0
        public override int SaveInvoiceData(Seller seller)
        {
            cls_Invoice invoiceObject = new cls_Invoice();
            int         result        = 0;

            GST_TRN_INVOICE inv = new GST_TRN_INVOICE();

            inv.InvoiceNo    = seller.SellerInvoice;
            inv.InvoiceDate  = DateTime.Now;//Convert.ToDateTime(seller.DateOfInvoice);
            inv.InvoiceMonth = Convert.ToByte(DateTime.Now.Month);
            //  inv.InvoiceMonth = Convert.ToByte(DateTime.Now.Month);
            inv.SellerUserID               = seller.SellerUserID;
            inv.ReceiverUserID             = seller.Reciever.RecieveruserID;
            inv.ConsigneeUserID            = seller.Consignee.ConsigneeUserID;
            inv.VendorID                   = seller.Invoice.VendorID;
            inv.TransShipment_ID           = seller.Invoice.TransShipment_ID;
            inv.Freight                    = seller.Invoice.Freight;
            inv.Insurance                  = seller.Invoice.Insurance;
            inv.PackingAndForwadingCharges = seller.Invoice.PackingAndForwadingCharges;
            inv.FinYear_ID                 = invoiceObject.GetCurrentFinYear(); // Convert.ToInt32(DateTime.UtcNow.Year + "-" + DateTime.UtcNow.AddYears(1));//Convert.ToInt32(seller.SerialNoInvoice.FinancialYear);
            // inv.IsInter = seller.Reciever.StateCode == seller.Consignee.StateCode ? true : false;
            inv.ReceiverFinYear_ID = invoiceObject.GetCurrentFinYear();         // Convert.ToInt32(DateTime.UtcNow.Year + "-" + DateTime.UtcNow.AddYears(1));// Convert.ToInt32(seller.SerialNoInvoice.FinancialYear);
            inv.Status             = true;
            inv.CreatedDate        = DateTime.Now;
            inv.InvoiceStatus      = (byte)EnumConstants.InvoiceStatus.Fresh;
            // inv.InvoiceStatus = (byte)EnumConstants.InvoiceStatus.Fresh;
            bool isInter = GetConsumptionDestinationOfGoodsOrServices(seller.SellerStateCode, seller.Reciever.StateCode, seller.Consignee.StateCode);

            inv.IsInter            = isInter;
            inv.TaxBenefitingState = seller.Consignee.StateCode;
            inv.CreatedBy          = seller.CreatedBy;
            //condition for tax con.
            //if ((EnumConstants.InvoiceSpecialCondition.Regular).ToString || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.Export) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.Advance) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.JobWork) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.SEZUnit) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.SEZDeveloper) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.DeemedExport) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.B2CS) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.B2CL) || Convert.ToBoolean(EnumConstants.InvoiceSpecialCondition.ECommerce))
            if (seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Regular.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Export.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Advance.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.JobWork.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.SEZDeveloper.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.SEZUnit.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.DeemedExport.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.B2CS.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.B2CL.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.ECommerce.ToString())
            // if (seller.Invoice.InvoiceSpecialCondition == (EnumConstants.InvoiceSpecialCondition.Regular) || (EnumConstants.InvoiceSpecialCondition.Export) || (EnumConstants.InvoiceSpecialCondition.Advance).ToString() || (EnumConstants.InvoiceSpecialCondition.JobWork).ToString() || (EnumConstants.InvoiceSpecialCondition.SEZUnit).ToString() || (EnumConstants.InvoiceSpecialCondition.SEZDeveloper).ToString() || (EnumConstants.InvoiceSpecialCondition.DeemedExport).ToString() || (EnumConstants.InvoiceSpecialCondition.B2CS).ToString() || (EnumConstants.InvoiceSpecialCondition.B2CL).ToString() || (EnumConstants.InvoiceSpecialCondition.ECommerce).ToString())
            {
                //inv.InvoiceUserID = seller.Reciever.RecieveruserID;
                inv.InvoiceUserID = seller.SellerUserID;
            }
            else
            {
                inv.InvoiceUserID = seller.Reciever.RecieveruserID;
            }
            inv.InvoiceType = (byte)(EnumConstants.InvoiceType)Enum.Parse(typeof(EnumConstants.InvoiceType), seller.Invoice.InvoiceType);

            if (inv.InvoiceType == (byte)EnumConstants.InvoiceType.B2C)
            {
                var totalBillamount = seller.Invoice.LineEntry.Sum(amt => amt.AmountWithTax);
                if (totalBillamount > 250000)
                {
                    inv.InvoiceSpecialCondition = (byte)(EnumConstants.InvoiceSpecialCondition.B2CL);
                }
                else
                {
                    inv.InvoiceSpecialCondition = (byte)(EnumConstants.InvoiceSpecialCondition)Enum.Parse(typeof(EnumConstants.InvoiceSpecialCondition), seller.Invoice.InvoiceSpecialCondition);
                }
            }
            else
            {
                inv.InvoiceSpecialCondition = (byte)(EnumConstants.InvoiceSpecialCondition)Enum.Parse(typeof(EnumConstants.InvoiceSpecialCondition), seller.Invoice.InvoiceSpecialCondition);
            }

            if (inv.InvoiceSpecialCondition == (byte)EnumConstants.InvoiceSpecialCondition.ECommerce)
            {
                inv.OrderDate = seller.OrderDate;
            }

            var invoiceCreate = unitOfWork.InvoiceRepository.Create(inv);

            unitOfWork.Save();

            if (seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Export.ToString())
            {
                bool isStateExampted = false;
            }
            else
            {
                bool isStateExampted = unitOfWork.StateRepository.Find(f => f.StateCode == seller.Consignee.StateCode).IsExempted.Value;
            }
            bool isExported = false;

            if (seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Export.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.SEZDeveloper.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.SEZUnit.ToString() || seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.DeemedExport.ToString())
            {
                isExported = true;
            }

            bool isJobwork   = (seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.JobWork.ToString());
            bool isImport    = (seller.Invoice.InvoiceSpecialCondition == EnumConstants.InvoiceSpecialCondition.Import.ToString());
            var  stateData   = unitOfWork.StateRepository.Find(c => c.StateCode == seller.SellerStateCode);
            var  isUTState   = stateData.UT.Value;
            var  isExempted  = stateData.IsExempted.Value;
            var  isEcom      = false;
            var  isUn        = false;
            var  invLineItem = from invo in seller.Invoice.LineEntry
                               select new GST_TRN_INVOICE_DATA
            {
                InvoiceID = invoiceCreate.InvoiceID,
                LineID    = invo.LineID,
                // GST_MST_ITEM = invo.Item,
                Item_ID       = invo.Item.Item_ID,
                Qty           = invo.Qty,
                Rate          = invo.PerUnitRate,
                TotalAmount   = invo.TotalLineIDWise,
                Discount      = invo.Discount,
                TaxableAmount = invo.TaxableValueLineIDWise,
                // TotalAmountWithTax = invo.TaxValue,
                IGSTRate = Calculate.TaxRate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.IGST, invo.TaxableValueLineIDWise, invo.Item.IGST.Value),                   //isJobwork ? 0 : (isUTState ? 0 : (isInter ? invo.Item.IGST : (isExport ? invo.Item.IGST : (isImport ? invo.Item.IGST : 0)))),
                IGSTAmt  = Calculate.TaxCalculate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.IGST, invo.TaxableValueLineIDWise, invo.Item.IGST.Value),              // isJobwork ? 0 : (isUTState ? 0 : (isInter ? Calculate.CalculateIGSTLineIDWise(invo.TaxableValueLineIDWise, invo.Item.IGST.Value) : (isExport ? Calculate.CalculateIGSTLineIDWise(invo.TaxableValueLineIDWise, invo.Item.IGST.Value) : (isImport ? Calculate.CalculateIGSTLineIDWise(invo.TaxableValueLineIDWise, invo.Item.IGST.Value) : 0)))),
                CGSTRate = Calculate.TaxRate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.CGST, invo.TaxableValueLineIDWise, invo.Item.CGST.Value),
                CGSTAmt  = Calculate.TaxCalculate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.CGST, invo.TaxableValueLineIDWise, invo.Item.CGST.Value),
                SGSTRate = Calculate.TaxRate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.SGST, invo.TaxableValueLineIDWise, invo.Item.SGST.Value),
                SGSTAmt  = Calculate.TaxCalculate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.SGST, invo.TaxableValueLineIDWise, invo.Item.SGST.Value),
                UGSTRate = Calculate.TaxRate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.UTGST, invo.TaxableValueLineIDWise, invo.Item.UGST.Value),
                UGSTAmt  = Calculate.TaxCalculate(invo.Item, isInter, isExported, isImport, isUTState, isJobwork, isEcom, isUn, EnumConstants.TaxType.UTGST, invo.TaxableValueLineIDWise, invo.Item.UGST.Value),
                CessRate = isJobwork ? 0 : invo.Item.CESS,
                CessAmt  = isJobwork ? 0 : Calculate.CalculateCESSLineIDWise(invo.TaxableValueLineIDWise, invo.Item.CESS.Value)
            };


            foreach (GST_TRN_INVOICE_DATA item in invLineItem)
            {
                item.TotalAmountWithTax = item.TaxableAmount + item.IGSTAmt + item.CGSTAmt + item.SGSTAmt + item.UGSTAmt + item.CessAmt;
                item.CreatedDate        = DateTime.Now;
                unitOfWork.InvoiceDataRepository.Create(item);
            }

            unitOfWork.Save();

            //start- Mapp Regular and Jobwork Challan no.
            foreach (Int64 itm in seller.ChallanInvoiceIds)
            {
                GST_TRN_INVOICE_MAP map = new GST_TRN_INVOICE_MAP();
                map.MapfromInvoiceID = itm;
                map.MaptoInvoiceID   = invoiceCreate.InvoiceID;
                map.Status           = true;
                map.CreatedBy        = seller.CreatedBy;
                map.CreatedDate      = DateTime.Now;
                unitOfWork.InvoiceMapRepository.Create(map);
            }

            unitOfWork.Save();
            //end
            foreach (Int64 itm in seller.AdvanceInvoiceIds)
            {
                GST_TRN_INVOICE_MAP map = new GST_TRN_INVOICE_MAP();
                map.MapfromInvoiceID = itm;
                map.MaptoInvoiceID   = invoiceCreate.InvoiceID;
                map.Status           = true;
                map.CreatedBy        = seller.CreatedBy;
                map.CreatedDate      = DateTime.Now;
                unitOfWork.InvoiceMapRepository.Create(map);
            }
            unitOfWork.Save();

            cls_ITC itc = new cls_ITC();

            itc.ITCVoucherType = (byte)EnumConstants.ITCVoucherType.TaxInvoice;
            itc.SaveItc(invoiceCreate);

            cls_PurchaseRegister purchaseRegister = new cls_PurchaseRegister();

            //var allitems = invLineItem.Select(s => s.Item_ID).Distinct();
            if (inv.InvoiceSpecialCondition == (byte)(EnumConstants.InvoiceSpecialCondition.Advance))
            {
                //No data will be save in sale and purchase.
            }
            else if (inv.InvoiceSpecialCondition != (byte)(EnumConstants.InvoiceSpecialCondition.Import))  //enumm
            {
                foreach (GST_TRN_INVOICE_DATA item in invLineItem)
                {
                    var itemType = unitOfWork.ItemRepository.Find(f => f.Item_ID == item.Item_ID).ItemType;
                    // var purchaseItems = unitOfWork.PurchaseDataRepositry.Filter(f => f.Status == true && item.Item_ID == f.Item_ID).Select(s => s.GST_MST_PURCHASE_REGISTER.UserID).ToList();
                    if (itemType == (byte)EnumConstants.ItemType.HSN)
                    {
                        string  uId     = seller.SellerUserID;
                        int     iTem    = Convert.ToInt32(item.Item_ID);
                        decimal LeftQty = purchaseRegister.GetLeftItemQty(iTem, uId);

                        if (LeftQty > item.Qty)
                        {
                            GST_MST_SALE_REGISTER salRegister = new GST_MST_SALE_REGISTER();
                            salRegister.InvoiceID   = invoiceCreate.InvoiceID;
                            salRegister.PerUnitRate = item.Rate;
                            salRegister.Item_ID     = item.Item_ID;
                            salRegister.Qty         = item.Qty;
                            salRegister.CreatedBy   = seller.CreatedBy;
                            salRegister.CreatedDate = DateTime.Now;
                            salRegister.Status      = true;
                            salRegister.Id          = uId;
                            salRegister.SaleStatus  = (byte)EnumConstants.SaleStatus.Fresh;
                            unitOfWork.SaleRegisterDataRepositry.Create(salRegister);
                            unitOfWork.Save();
                        }
                    }
                }
            }

            else
            {
                //Add stock in PURCHSE Reagister When item is import from seller..
                purchaseRegister.LoggedinUserID   = invoiceCreate.SellerUserID;
                purchaseRegister.SellerName       = seller.NameAsOnGST;
                purchaseRegister.SellerAddress    = seller.Address;
                purchaseRegister.SellerGSTN       = seller.GSTIN;
                purchaseRegister.ReceiverName     = seller.Reciever.NameAsOnGST;
                purchaseRegister.ReceiverAddress  = seller.Reciever.Address;
                purchaseRegister.ConsigneeName    = seller.Consignee.NameAsOnGST;
                purchaseRegister.ConsigneeAddress = seller.Consignee.Address;
                purchaseRegister.StateCode        = seller.SellerStateCode;

                purchaseRegister.SaveInvoiveDataInPurchaseRegister(inv);
            }

            if (inv.InvoiceSpecialCondition == (byte)(EnumConstants.InvoiceSpecialCondition.SupplierMissingInvoice))
            {
                GST_TRN_INVOICE_AUDIT_TRAIL IAT = new GST_TRN_INVOICE_AUDIT_TRAIL();

                IAT.InvoiceID        = invoiceCreate.InvoiceID;
                IAT.AuditTrailStatus = (byte)EnumConstants.InvoiceAuditTrailSatus.Import2A;
                IAT.InvoiceAction    = (byte)EnumConstants.InvoiceActionAuditTrail.Add;
                IAT.UserIP           = HelperUtility.IP;
                //IAT.SellerInvoiceAction = "" ;
                IAT.ReceiverInvoiceAction = (byte)EnumConstants.InvoiceActionAuditTrail.Add;
                // IAT.SellerInvoiceActionDate = DateTime.Now;
                IAT.ReceiverInvoiceActionDate = DateTime.Now;
                IAT.CreatedBy   = invoiceCreate.CreatedBy;
                IAT.CreatedDate = DateTime.Now;
                unitOfWork.InvoiceAuditTrailRepositry.Create(IAT);
                unitOfWork.Save();
            }
            //foreach (GST_TRN_INVOICE_DATA item in invLineItem)
            //{
            // itc.UserID = seller.Reciever.RecieveruserID;
            // itc.Amount = item.IGSTAmt + item.CGSTAmt + item.SGSTAmt + item.UGSTAmt + item.CessAmt;
            //itc.InvoiceID = invoiceCreate.InvoiceID;
            // itc.ITCStatus = (byte)(EnumConstants.ITCStatus.Active);
            // itc.ITCVoucherType = (byte)EnumConstants.ITCMovement.Credit;
            // itc.ITCDate = DateTime.Now;
            // itc.ITCMovement = (byte)(EnumConstants.InvoiceSpecialCondition.Import);
            //// itc.TaxType = item.UGSTAmt;
            // itc.IGST = item.IGSTAmt;
            // itc.CGST = item.CGSTAmt;
            // if (item.SGSTAmt != 0)
            // {
            // itc.SGST = item.SGSTAmt;
            // }
            // else
            // {
            //     itc.SGST = item.UGSTAmt;
            // }
            // itc.CreatedBy = seller.CreatedBy;
            // itc.CreatedDate = DateTime.Now;
            // unitOfWork.ITCRepository.Create(itc);
            // unitOfWork.Save();
            //}


            //User Current TurnOver
            GST_MST_USER_CURRENT_TURNOVER turnOver = new GST_MST_USER_CURRENT_TURNOVER();

            turnOver.User_ID                 = inv.SellerUserID;
            turnOver.Month                   = inv.InvoiceMonth;
            turnOver.InvoiceID               = invoiceCreate.InvoiceID;
            turnOver.InvoiceAmountWithTax    = invLineItem.Sum(s => s.TotalAmount);
            turnOver.InvoiceAmountWithoutTax = invLineItem.Sum(s => s.TaxableAmount);
            turnOver.TurnOverStatus          = 0;//TODO:Need to change
            turnOver.CreatedBy               = inv.CreatedBy;
            turnOver.CreatedDate             = DateTime.Now;
            turnOver.Status                  = true;
            unitOfWork.CurrentTurnoverRepositry.Create(turnOver);
            unitOfWork.Save();
            //// ExcelDB exceldb = new ExcelDB();
            ////result = exceldb.SaveInvoiceData(seller);

            //  }
            return(result);
        }