public ActionResult mergeAndSendToAcoount(int OrgId)
        {
            BalanceStatement BSObj = new BalanceStatement();

            Commission CommissionLastrecord = Commission.GetAllCommissions().Where(w => w.OrgId == OrgId).Last();

            Sale SaleLastrecord = Sale.GetAllSales().Where(w => w.OrgId == OrgId).Last();

            BSObj.Narration = "Online Payment received Entry No." + SaleLastrecord.EntryNo;
            BSObj.CRAmount  = SaleLastrecord.SaleAmount;

            BalanceStatement TotalBalance = BalanceStatement.GetAllForBalanceCalculation(OrgId).Last();

            BSObj.Balance = TotalBalance.Balance - BSObj.CRAmount;

            BSObj.Date    = DateTime.Now;
            BSObj.OrgId   = OrgId;
            BSObj.EntryNo = SaleLastrecord.EntryNo;
            BSObj.SaveOpeningValue();

            BalanceStatement Obj = new BalanceStatement();


            Obj.Narration = "Commission Invoice No." + CommissionLastrecord.EntryNo;
            Obj.Amount    = CommissionLastrecord.CommissionAmount;
            BalanceStatement TotalBalances = BalanceStatement.GetAllForBalanceCalculation(OrgId).Last();

            Obj.Balance = TotalBalances.Balance + Obj.Amount;
            Obj.Date    = DateTime.Now;
            Obj.OrgId   = OrgId;
            Obj.EntryNo = CommissionLastrecord.EntryNo;
            Obj.SaveOpeningValue();

            return(Json(new { data = BSObj }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EntryToAccount(int OrgId)
        {
            Accounts Obj = new Accounts();

            Accounts AObj = new Accounts();

            Accounts AObj1 = new Accounts();

            Accounts ADObj = new Accounts();

            List <Accounts> ADObjList = new List <Accounts>();

            Commission AllCommissions = Commission.GetAllCommissions().Where(w => w.OrgId == OrgId).Last();

            BalanceStatement LastRecords = BalanceStatement.GetAllForBalanceCalculation(OrgId).Last();

            BalanceStatement FirstRecords = BalanceStatement.GetAllForBalanceCalculation(OrgId).Where(w => w.Narration == "Opening Balance").Last();

            Sale AllSales = Sale.GetAllSales().Where(w => w.OrgId == OrgId).Last();

            Accounts FirstAccountRecords = Accounts.GetAll().Where(w => w.Narration == "Opening Balance").FirstOrDefault();

            if (FirstAccountRecords == null)
            {
                Obj.Date      = FirstRecords.Date;
                Obj.Narration = "Opening Balance";
                Obj.AOrgId    = OrgId;
                if (AllSales == null)
                {
                    Obj.DRAmount = 0.00;
                }
                else
                {
                    Obj.DRAmount = LastRecords.Balance;
                }
                Obj.SaveGeneral();
            }
            AObj.DRAmount  = AllSales.SaleAmount;
            AObj.Narration = "Online Payment received Entry No." + AllSales.EntryNo;
            AObj.Balance   = AllSales.SaleAmount;
            AObj.Date      = DateTime.Now;
            AObj.AOrgId    = OrgId;
            AObj.SaveGeneral();

            //===============================================
            HG_OrganizationDetails Objitem = new HG_OrganizationDetails();
            HG_OrganizationDetails State   = Objitem.GetAll(OrgId).FirstOrDefault();

            Ledger LedgerDetails = Ledger.GetAllList().Where(x => x.DebtorType == 1 &&
                                                             x.OrgId == OrgId).FirstOrDefault();

            AObj1.CRAmount  = AllCommissions.CommissionAmount;
            AObj1.Narration = "Commission Invoice No." + AllCommissions.EntryNo;
            AObj1.Balance   = AllSales.SaleAmount - AllCommissions.CommissionAmount;
            AObj1.Date      = DateTime.Now;
            AObj1.AOrgId    = OrgId;

            // entry to Account Details
            if (State.State == "17")
            {
                for (int i = 1; i <= 2; i++)
                {
                    ADObj = new Accounts();
                    if (i == 1)
                    {
                        ADObj.ADDate     = DateTime.Now;
                        ADObj.ADAmount   = AllCommissions.CommissionAmount * (LedgerDetails.TaxOnAboveMargin / 2) / 100;
                        ADObj.CRLedgerId = 13;
                        ADObj.ADGroupId  = 3;
                        ADObj.AOrgId     = OrgId;
                        ADObjList.Add(ADObj);
                    }
                    else if (i == 2)
                    {
                        ADObj.ADDate     = DateTime.Now;
                        ADObj.ADAmount   = AllCommissions.CommissionAmount * (LedgerDetails.TaxOnAboveMargin / 2) / 100;
                        ADObj.CRLedgerId = 17;
                        ADObj.ADGroupId  = 3;
                        ADObj.AOrgId     = OrgId;
                        ADObjList.Add(ADObj);
                    }
                }
            }
            else
            {
                ADObj.ADDate     = DateTime.Now;
                ADObj.ADAmount   = (AllCommissions.CommissionAmount * LedgerDetails.TaxOnAboveMargin) / 100;
                ADObj.CRLedgerId = 21;
                ADObj.ADGroupId  = 3;
                ADObj.AOrgId     = OrgId;
                ADObjList.Add(ADObj);
            }

            //=============================
            AObj1.Save(ADObjList);

            return(Json(new { data = AllCommissions }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetAllCommission(int OrgId)
        {
            // Sale table objects//
            Sale SObj  = new Sale();
            Sale S1Obj = new Sale();
            //======================//

            // Commission table objects//
            Commission CObj  = new Commission();
            Commission CMObj = new Commission();
            //==================================


            int LastEntry = 0;

            int LastSaleEntry = 0;

            double totalAmount = 0.00;

            double TotalSale = 0.00;

            double TotalTaxOnCommission = 0.00;

            List <BalanceStatement> GetRecords      = new List <BalanceStatement>();
            BalanceStatement        FindLastEntryNo = new BalanceStatement();


            try
            {
                FindLastEntryNo = BalanceStatement.GetAllForBalanceCalculation(OrgId)
                                  .Where(w => w.EntryNo > 0 && w.Narration.Contains("Commission Invoice No.")).Last();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }


            if (FindLastEntryNo.EntryNo == 0)
            {
                GetRecords = BalanceStatement.GetAllForBalanceCalculation(OrgId);
            }
            else
            {
                GetRecords = BalanceStatement.GetAllForBalanceCalculation(OrgId).Where(w => w.BID > FindLastEntryNo.BID).ToList();
            }

            if (GetRecords != null)
            {
                BalanceStatement LastRecords = BalanceStatement.GetAllForBalanceCalculation(OrgId).Last();

                Ledger LedgerDetails = Ledger.GetAllList().Where(x => x.DebtorType == 1 &&
                                                                 x.OrgId == OrgId).FirstOrDefault();

                foreach (var data in GetRecords)
                {
                    if (data.Narration != "Opening Balance")
                    {
                        CObj.CommissionAmount = data.CRAmount;
                        SObj.SaleAmount       = data.Amount;
                        if (data.TaxOnCash > 0)
                        {
                            CObj.TaxOnCommission = (data.CRAmount * data.TaxOnCash) / 100;
                        }
                        if (data.TaxOnOnline > 0)
                        {
                            CObj.TaxOnCommission = (data.CRAmount * data.TaxOnOnline) / 100;
                        }
                        // CObj.BalanceStatementId = data.BID;
                        CObj.OrgId = data.OrgId;
                        SObj.OrgId = data.OrgId;
                        //Save to commision table
                        CObj.Save();
                        //======================//
                        // Save to Sale Table
                        SObj.Save();
                        //====================//
                    }
                }

                //if (GetRecords.Count != 1) // used for eliminating Opening Balance entry when there is no data for next entry
                // {
                int GetLastCalculationRecord = Commission.GetAllCommissions().Where(w => w.OrgId == OrgId).Select(s => s.BalanceStatementId).Max();

                int CommissionId = Commission.GetAllCommissions()
                                   .Where(w => w.BalanceStatementId == GetLastCalculationRecord && w.OrgId == OrgId).Select(s => s.CommisionId).FirstOrDefault();
                if (GetLastCalculationRecord == 0)
                {
                    TotalTaxOnCommission = Commission.GetAllCommissions()
                                           .Where(w => w.CommisionId >= CommissionId && w.OrgId == OrgId).Select(s => s.TaxOnCommission).Sum();

                    totalAmount = Commission.GetAllCommissions()
                                  .Where(w => w.CommisionId >= CommissionId && w.OrgId == OrgId).Select(s => s.CommissionAmount).Sum();
                }
                else
                {
                    TotalTaxOnCommission = Commission.GetAllCommissions()
                                           .Where(w => w.CommisionId > CommissionId && w.OrgId == OrgId).Select(s => s.TaxOnCommission).Sum();

                    totalAmount = Commission.GetAllCommissions()
                                  .Where(w => w.CommisionId > CommissionId && w.OrgId == OrgId).Select(s => s.CommissionAmount).Sum();
                }


                int GetMaxBID = Sale.GetAllSales().Where(w => w.OrgId == OrgId).Select(s => s.BalanceStatementId).Max();

                int SaleId = Sale.GetAllSales()
                             .Where(w => w.BalanceStatementId == GetMaxBID && w.OrgId == OrgId).Select(s => s.SaleId).FirstOrDefault();
                if (GetMaxBID == 0)
                {
                    TotalSale = Sale.GetAllSales().Where(w => w.SaleId >= SaleId &&
                                                         w.OrgId == OrgId).Select(s => s.SaleAmount).Sum();
                }
                else
                {
                    TotalSale = Sale.GetAllSales().Where(w => w.SaleId > SaleId &&
                                                         w.OrgId == OrgId).Select(s => s.SaleAmount).Sum();
                }



                try
                {
                    LastEntry = Commission.GetAllCommissions()
                                .Where(w => w.EntryNo > 0 && w.OrgId == OrgId).Select(s => s.EntryNo).Max();

                    LastSaleEntry = Sale.GetAllSales()
                                    .Where(w => w.EntryNo > 0 && w.OrgId == OrgId).Select(s => s.EntryNo).Max();
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }

                CMObj.EntryNo            = LastEntry + 1;
                CMObj.CommissionAmount   = totalAmount;
                CMObj.TaxOnCommission    = TotalTaxOnCommission;
                CMObj.BalanceStatementId = LastRecords.BID;
                CMObj.OrgId = LastRecords.OrgId;
                CMObj.Save();


                S1Obj.EntryNo            = LastSaleEntry + 1;
                S1Obj.SaleAmount         = TotalSale;
                S1Obj.BalanceStatementId = LastRecords.BID;
                S1Obj.OrgId = LastRecords.OrgId;
                S1Obj.Save();

                mergeAndSendToAcoount(LastRecords.OrgId);
                EntryToAccount(LastRecords.OrgId);
                // }
            }
            return(Json(new { data = CObj }, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult Delete(int ID)
        {
            List <Ledger> LedgerList = Ledger.GetAll();

            LedgerList = LedgerList.FindAll(x => x.OrgId == ID);

            List <BalanceStatement> BList = BalanceStatement.GetByOrgId(ID);

            BList = BList.FindAll(x => x.OrgId == ID);

            List <Commission> CommissionList = Commission.GetAllCommissions();

            CommissionList = CommissionList.FindAll(x => x.OrgId == ID);

            List <Sale> SList = Sale.GetAllSales();

            SList = SList.FindAll(x => x.OrgId == ID);

            List <Accounts> AccountList = Accounts.GetAll();

            AccountList = AccountList.FindAll(x => x.AOrgId == ID);

            List <Accounts> AccountDetailsList = Accounts.GetAllDetails();

            AccountList = AccountList.FindAll(x => x.ADOrgId == ID);

            //   List<Receipt> ReceiptList = Receipt.GetAllList(ID,0);


            if (LedgerList != null)
            {
                int i = Ledger.Dell(ID);
            }

            if (BList != null)
            {
                int i = BalanceStatement.Dell(ID);
            }

            if (CommissionList != null)
            {
                int i = Commission.Dell(ID);
            }

            if (SList != null)
            {
                int i = Sale.Dell(ID);
            }

            if (AccountList != null)
            {
                int i = Accounts.Dell(ID);
            }
            if (AccountDetailsList != null)
            {
                int i = Accounts.DellAccountDetails(ID);
            }
            //if(ReceiptList!=null)
            //{
            //    int i = Receipt.Dell(ID);
            //}
            return(Json(new { data = "1" }, JsonRequestBehavior.AllowGet));
        }