public int AccountGroup_Save(BLL.AccountGroup agp)
        {
            try
            {
                agp.CompanyId = Caller.CompanyId;
                DAL.AccountGroup d = DB.AccountGroups.Where(x => x.Id == agp.Id).FirstOrDefault();

                if (d == null)
                {
                    d = new DAL.AccountGroup();
                    DB.AccountGroups.Add(d);

                    agp.toCopy <DAL.AccountGroup>(d);
                    DB.SaveChanges();

                    agp.Id = d.Id;
                    LogDetailStore(agp, LogDetailType.INSERT);
                }
                else
                {
                    agp.toCopy <DAL.AccountGroup>(d);
                    DB.SaveChanges();
                    LogDetailStore(agp, LogDetailType.UPDATE);
                }

                Clients.Clients(OtherLoginClientsOnGroup).AccountGroup_Save(agp);

                return(agp.Id);
            }
            catch (Exception ex) { }
            return(0);
        }
 public void GetLedgerTotal_NoOP(DAL.AccountGroup ag, ref decimal total)
 {
     foreach (var l in ag.Ledgers)
     {
         total += GetLedgerBalance_NoOP(l, DateTime.Now);
     }
     foreach (var ag1 in ag.AccountGroup1)
     {
         GetLedgerTotal_NoOP(ag1, ref total);
     }
 }
 BLL.AccountGroup AccountGroupDAL_BLL(DAL.AccountGroup d)
 {
     BLL.AccountGroup b = d.toCopy <BLL.AccountGroup>(new BLL.AccountGroup());
     b.Company = d.CompanyDetail == null ? new BLL.CompanyDetail() : d.CompanyDetail.toCopy <BLL.CompanyDetail>(new BLL.CompanyDetail());
     //b.UnderAccountGroup = d.AccountGroup2 == null ? new BLL.AccountGroup() : AccountGroupDAL_BLL(d.AccountGroup2);
     b.UnderAccountGroup = d.AccountGroup2 == null ? new BLL.AccountGroup() : new BLL.AccountGroup()
     {
         GroupName = d.AccountGroup2.GroupName, GroupCode = d.AccountGroup2.GroupCode
     };
     return(b);
 }
 BLL.AccountGroup AccountGroupDAL_BLL(DAL.AccountGroup d)
 {
     BLL.AccountGroup b = d.toCopy <BLL.AccountGroup>(new BLL.AccountGroup());
     b.Fund = d.FundMaster == null ? new BLL.FundMaster() : d.FundMaster.toCopy <BLL.FundMaster>(new BLL.FundMaster());
     //b.UnderAccountGroup = d.AccountGroup2 == null ? new BLL.AccountGroup() : AccountGroupDAL_BLL(d.AccountGroup2);
     b.UnderAccountGroup = d.AccountGroup2 == null ? new BLL.AccountGroup() : new BLL.AccountGroup()
     {
         GroupName = d.AccountGroup2.GroupName, GroupCode = d.AccountGroup2.GroupCode
     };
     return(b);
 }
Example #5
0
 public void GetLedgerTotal(DAL.AccountGroup ag, ref decimal total)
 {
     foreach (var l in ag.Ledgers)
     {
         total += GetLedgerBalance(l);
     }
     foreach (var ag1 in ag.AccountGroup1)
     {
         GetLedgerTotal(ag1, ref total);
     }
 }
Example #6
0
        void AccountSetup(BLL.FundMaster cmp)
        {
            DAL.AccountGroup pr = new DAL.AccountGroup();
            pr.GroupName    = BLL.DataKeyValue.Primary_Key;
            pr.GroupCode    = string.Empty;
            pr.FundMasterId = cmp.Id;
            DB.AccountGroups.Add(pr);
            DB.SaveChanges();
            SetDataKeyValue(cmp.Id, pr.GroupName, pr.Id);


            AccountSetup_Asset(pr);
            AccountSetup_Liabilities(pr);
            AccountSetup_Income(pr);
            AccountSetup_Expense(pr);

            DAL.Ledger PL = new DAL.Ledger();
            PL.LedgerName     = BLL.DataKeyValue.Profit_Loss_Ledger_Key;
            PL.AccountGroupId = pr.Id;
            DB.Ledgers.Add(PL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, PL.LedgerName, PL.Id);
        }
        void AccountSetup(BLL.CompanyDetail cmp)
        {
            DAL.AccountGroup pr = new DAL.AccountGroup();
            pr.GroupName = BLL.DataKeyValue.Primary_Key;
            pr.GroupCode = "";
            pr.CompanyId = cmp.Id;
            DB.AccountGroups.Add(pr);
            DB.SaveChanges();
            insertDataKeyValue(cmp.Id, pr.GroupName, pr.Id);


            AccountSetup_Asset(pr);
            AccountSetup_Liabilities(pr);
            AccountSetup_Income(pr);
            AccountSetup_Expense(pr);

            DAL.Ledger PL = new DAL.Ledger();
            PL.LedgerName     = BLL.DataKeyValue.Profit_Loss_Ledger_Key;
            PL.AccountGroupId = pr.Id;
            DB.Ledgers.Add(PL);
            DB.SaveChanges();
            insertDataKeyValue(pr.CompanyId, PL.LedgerName, PL.Id);
        }
Example #8
0
        List <BLL.SubsidaryAccounts> SubsidaryAccountsByGroupName(DAL.AccountGroup ag, DateTime dtFrom, DateTime dtTo, string Prefix, ref decimal TotalDr, ref decimal TotalCr, ref decimal TotalDrOP, ref decimal TotalCrOP)
        {
            decimal GTotalDr = 0, GTotalCr = 0, GTotalDrOP = 0, GTotalCrOP = 0;
            List <BLL.SubsidaryAccounts> lstSubsidaryAccounts = new List <BLL.SubsidaryAccounts>();
            decimal total = 0;

            GetLedgerTotal(ag, ref total);
            if (total == 0)
            {
                return(lstSubsidaryAccounts);
            }

            BLL.SubsidaryAccounts tb = new BLL.SubsidaryAccounts();

            //tb = new BLL.SubsidaryAccounts();
            //tb.LedgerList = new BLL.Ledger();
            //tb.LedgerList.AccountName = Prefix + ag.GroupName;
            //tb.CrAmt = null;
            //tb.DrAmt = null;
            //tb.CrAmtOP = null;
            //tb.DrAmtOP = null;

            // lstSubsidaryAccounts.Add(tb);


            //foreach (var uag in ag.AccountGroup1)
            //{
            //    lstSubsidaryAccounts.AddRange(SubsidaryAccountsByGroupName(uag, dtFrom, dtTo, Prefix + "", ref GTotalDr, ref GTotalCr, ref GTotalDrOP, ref GTotalCrOP));
            //}

            decimal OPDr = 0, OPCr = 0, Dr = 0, Cr = 0;

            foreach (var l in ag.Ledgers)
            {
                tb            = new BLL.SubsidaryAccounts();
                tb.LedgerList = LedgerDAL_BLL(l);

                LedgerBalance(l, dtFrom, dtTo, ref OPDr, ref OPCr, ref Dr, ref Cr);

                tb.DrAmt   = Dr;
                tb.CrAmt   = Cr;
                tb.DrAmtOP = OPDr;
                tb.CrAmtOP = OPCr;
                lstSubsidaryAccounts.Add(tb);
                if (tb.DrAmt != 0 || tb.CrAmt != 0)
                {
                    tb.LedgerList.AccountGroup.GroupCode = Prefix + "" + tb.LedgerList.AccountGroup.GroupCode;
                    //lstSubsidaryAccounts.Add(tb);
                    GTotalDr += tb.DrAmt ?? 0;
                    GTotalCr += tb.CrAmt ?? 0;

                    GTotalDrOP += tb.DrAmtOP ?? 0;
                    GTotalCrOP += tb.CrAmtOP ?? 0;
                }
            }

            if (GTotalDr > GTotalCr)
            {
                GTotalDr = Math.Abs(GTotalDr - GTotalCr);
                GTotalCr = 0;
            }
            else
            {
                GTotalCr = Math.Abs(GTotalDr - GTotalCr);
                GTotalDr = 0;
            }

            if (GTotalDrOP > GTotalCrOP)
            {
                GTotalDrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalCrOP = 0;
            }
            else
            {
                GTotalCrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalDrOP = 0;
            }



            //tb = new BLL.SubsidaryAccounts();
            //tb.LedgerList = new BLL.Ledger();
            //// tb.LedgerList.AccountName = Prefix + "Total " + ag.GroupName;
            //tb.LedgerList.AccountName = "Total ";
            //tb.CrAmt = GTotalCr;
            //tb.DrAmt = GTotalDr;
            //tb.CrAmtOP = GTotalCrOP;
            //tb.DrAmtOP = GTotalDrOP;


            //lstSubsidaryAccounts.Add(tb);

            TotalDr   += GTotalDr;
            TotalCr   += GTotalCr;
            TotalDrOP += GTotalDrOP;
            TotalCrOP += GTotalCrOP;

            return(lstSubsidaryAccounts);
        }
 public bool AccountGroup_CanDelete(DAL.AccountGroup l)
 {
     return(l.Ledgers.Count() == 0);
 }
Example #10
0
        void AccountSetup_Expense(DAL.AccountGroup pr)
        {
            DAL.AccountGroup Exp = new DAL.AccountGroup();
            Exp.GroupName    = BLL.DataKeyValue.Expenses_Key;
            Exp.GroupCode    = "400";
            Exp.FundMasterId = pr.FundMasterId;
            Exp.UnderGroupId = pr.Id;
            DB.AccountGroups.Add(Exp);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Exp.GroupName, Exp.Id);

            #region Direct Expense

            DAL.AccountGroup DExp = new DAL.AccountGroup();
            DExp.GroupName    = BLL.DataKeyValue.DirectExpenses_Key;
            DExp.GroupCode    = "410";
            DExp.FundMasterId = pr.FundMasterId;
            DExp.UnderGroupId = Exp.Id;
            DB.AccountGroups.Add(DExp);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, DExp.GroupName, DExp.Id);

            #endregion

            #region Indirect Expense

            DAL.AccountGroup IndExp = new DAL.AccountGroup();
            IndExp.GroupName    = BLL.DataKeyValue.IndirectExpense_Key;
            IndExp.GroupCode    = "320";
            IndExp.FundMasterId = pr.FundMasterId;
            IndExp.UnderGroupId = Exp.Id;
            DB.AccountGroups.Add(IndExp);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, IndExp.GroupName, IndExp.Id);
            #endregion

            DAL.AccountGroup Pur = new DAL.AccountGroup();
            Pur.GroupName    = BLL.DataKeyValue.PurchaseAccount_Key;
            Pur.GroupCode    = "330";
            Pur.FundMasterId = pr.FundMasterId;
            Pur.UnderGroupId = Exp.Id;
            DB.AccountGroups.Add(Pur);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Pur.GroupName, Pur.Id);



            DAL.Ledger PurL = new DAL.Ledger();
            PurL.LedgerName     = BLL.DataKeyValue.PurchaseAccount_Ledger_Key;
            PurL.AccountGroupId = Pur.Id;
            DB.Ledgers.Add(PurL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, PurL.LedgerName, PurL.Id);

            DAL.Ledger PRL = new DAL.Ledger();
            PRL.LedgerName     = BLL.DataKeyValue.Purchase_Return_Ledger_Key;
            PRL.AccountGroupId = Pur.Id;
            DB.Ledgers.Add(PRL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, PRL.LedgerName, PRL.Id);

            DAL.Ledger JO = new DAL.Ledger();
            JO.LedgerName     = BLL.DataKeyValue.JobOrderIssued_Ledger_Key;
            JO.AccountGroupId = Exp.Id;
            DB.Ledgers.Add(JO);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, JO.LedgerName, JO.Id);

            DAL.AccountGroup salary = new DAL.AccountGroup();
            salary.GroupName    = BLL.DataKeyValue.Salary_Key;
            salary.GroupCode    = "340";
            salary.FundMasterId = pr.FundMasterId;
            salary.UnderGroupId = IndExp.Id;
            DB.AccountGroups.Add(salary);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, salary.GroupName, salary.Id);
        }
Example #11
0
        void AccountSetup_Income(DAL.AccountGroup pr)
        {
            DAL.AccountGroup Inc = new DAL.AccountGroup();
            Inc.GroupName    = BLL.DataKeyValue.Income_Key;
            Inc.GroupCode    = "300";
            Inc.FundMasterId = pr.FundMasterId;
            Inc.UnderGroupId = pr.Id;
            DB.AccountGroups.Add(Inc);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Inc.GroupName, Inc.Id);



            #region Direct Income

            DAL.AccountGroup DInc = new DAL.AccountGroup();
            DInc.GroupName    = BLL.DataKeyValue.DirectIncome_Key;
            DInc.GroupCode    = "310";
            DInc.FundMasterId = pr.FundMasterId;
            DInc.UnderGroupId = Inc.Id;
            DB.AccountGroups.Add(DInc);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, DInc.GroupName, DInc.Id);

            #endregion

            #region Indirect Income

            DAL.AccountGroup IndInc = new DAL.AccountGroup();
            IndInc.GroupName    = BLL.DataKeyValue.IndirectIncome_Key;
            IndInc.GroupCode    = "320";
            IndInc.FundMasterId = pr.FundMasterId;
            IndInc.UnderGroupId = Inc.Id;
            DB.AccountGroups.Add(IndInc);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, IndInc.GroupName, IndInc.Id);

            #endregion

            DAL.AccountGroup Sa = new DAL.AccountGroup();
            Sa.GroupName    = BLL.DataKeyValue.SalesAccount_Key;
            Sa.GroupCode    = "330";
            Sa.FundMasterId = pr.FundMasterId;
            Sa.UnderGroupId = Inc.Id;
            DB.AccountGroups.Add(Sa);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Sa.GroupName, Sa.Id);

            DAL.Ledger salL = new DAL.Ledger();
            salL.LedgerName     = BLL.DataKeyValue.SalesAccount_Ledger_Key;
            salL.AccountGroupId = Sa.Id;
            DB.Ledgers.Add(salL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, salL.LedgerName, salL.Id);

            DAL.Ledger SRL = new DAL.Ledger();
            SRL.LedgerName     = BLL.DataKeyValue.Sales_Return_Ledger_Key;
            SRL.AccountGroupId = Sa.Id;
            DB.Ledgers.Add(SRL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SRL.LedgerName, SRL.Id);

            DAL.Ledger JR = new DAL.Ledger();
            JR.LedgerName     = BLL.DataKeyValue.JobOrderReceived_Ledger_Key;
            JR.AccountGroupId = Inc.Id;
            DB.Ledgers.Add(JR);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, JR.LedgerName, JR.Id);
        }
Example #12
0
        void AccountSetup_Liabilities(DAL.AccountGroup pr)
        {
            DAL.AccountGroup liab = new DAL.AccountGroup();
            liab.GroupName    = BLL.DataKeyValue.Liabilities_Key;
            liab.GroupCode    = "200";
            liab.FundMasterId = pr.FundMasterId;
            liab.UnderGroupId = pr.Id;
            DB.AccountGroups.Add(liab);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, liab.GroupName, liab.Id);

            #region Current Liabilities
            DAL.AccountGroup cl = new DAL.AccountGroup();
            cl.GroupName    = BLL.DataKeyValue.CurrentLiabilities_Key;
            cl.GroupCode    = "210";
            cl.UnderGroupId = liab.Id;
            cl.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(cl);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, cl.GroupName, cl.Id);

            DAL.AccountGroup DT = new DAL.AccountGroup();
            DT.GroupName    = BLL.DataKeyValue.DutiesTaxes_Key;
            DT.GroupCode    = "211";
            DT.UnderGroupId = cl.Id;
            DT.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(DT);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, DT.GroupName, DT.Id);

            DAL.Ledger IT = new DAL.Ledger();
            IT.LedgerName     = BLL.DataKeyValue.Input_Tax_Ledger_Key;
            IT.AccountGroupId = DT.Id;
            DB.Ledgers.Add(IT);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, IT.LedgerName, IT.Id);


            DAL.Ledger OT = new DAL.Ledger();
            OT.LedgerName     = BLL.DataKeyValue.Output_Tax_Ledger_Key;
            OT.AccountGroupId = DT.Id;
            DB.Ledgers.Add(OT);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, OT.LedgerName, OT.Id);

            DAL.AccountGroup prov = new DAL.AccountGroup();
            prov.GroupName    = BLL.DataKeyValue.Provisions_Key;
            prov.GroupCode    = "212";
            prov.UnderGroupId = cl.Id;
            prov.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(prov);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, prov.GroupName, prov.Id);

            DAL.AccountGroup sc = new DAL.AccountGroup();
            sc.GroupName    = BLL.DataKeyValue.SundryCreditors_Key;
            sc.GroupCode    = "212";
            sc.UnderGroupId = cl.Id;
            sc.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(sc);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, sc.GroupName, sc.Id);


            #region Loans
            DAL.AccountGroup l = new DAL.AccountGroup();
            l.GroupName    = BLL.DataKeyValue.Loans_Key;
            l.GroupCode    = "220";
            l.UnderGroupId = liab.Id;
            l.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(l);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, l.GroupName, l.Id);


            DAL.AccountGroup BOAc = new DAL.AccountGroup();
            BOAc.GroupName    = BLL.DataKeyValue.BankODAc_Key;
            BOAc.GroupCode    = "221";
            BOAc.UnderGroupId = l.Id;
            BOAc.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(BOAc);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, BOAc.GroupName, BOAc.Id);

            DAL.AccountGroup SL = new DAL.AccountGroup();
            SL.GroupName    = BLL.DataKeyValue.SecuredLoans_Key;
            SL.GroupCode    = "221";
            SL.UnderGroupId = l.Id;
            SL.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(SL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SL.GroupName, SL.Id);

            DAL.AccountGroup USL = new DAL.AccountGroup();
            USL.GroupName    = BLL.DataKeyValue.UnSecuredLoans_Key;
            USL.GroupCode    = "222";
            USL.UnderGroupId = l.Id;
            USL.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(USL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, USL.GroupName, USL.Id);

            #endregion


            DAL.AccountGroup BD = new DAL.AccountGroup();
            BD.GroupName    = BLL.DataKeyValue.BranchDivisions_Key;
            BD.GroupCode    = "230";
            BD.UnderGroupId = liab.Id;
            BD.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(BD);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, BD.GroupName, BD.Id);



            DAL.AccountGroup Cap = new DAL.AccountGroup();
            Cap.GroupName    = BLL.DataKeyValue.CapitalAccount_Key;
            Cap.GroupCode    = "240";
            Cap.UnderGroupId = liab.Id;
            Cap.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(Cap);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Cap.GroupName, Cap.Id);

            DAL.AccountGroup RS = new DAL.AccountGroup();
            RS.GroupName    = BLL.DataKeyValue.ReservesSurplus_Key;
            RS.GroupCode    = "250";
            RS.UnderGroupId = liab.Id;
            RS.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(RS);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, RS.GroupName, RS.Id);

            DAL.AccountGroup SAC = new DAL.AccountGroup();
            SAC.GroupName    = BLL.DataKeyValue.SuspenseAc_Key;
            SAC.GroupCode    = "260";
            SAC.UnderGroupId = liab.Id;
            SAC.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(SAC);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SAC.GroupName, SAC.Id);

            #endregion
        }
Example #13
0
        void AccountSetup_Asset(DAL.AccountGroup pr)
        {
            DAL.AccountGroup ast = new DAL.AccountGroup();
            ast.GroupName    = BLL.DataKeyValue.Assets_Key;
            ast.GroupCode    = "100";
            ast.FundMasterId = pr.FundMasterId;
            ast.UnderGroupId = pr.Id;
            DB.AccountGroups.Add(ast);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, ast.GroupName, ast.Id);


            #region Current Assets
            DAL.AccountGroup ca = new DAL.AccountGroup();
            ca.GroupName    = BLL.DataKeyValue.CurrentAssets_Key;
            ca.GroupCode    = "110";
            ca.UnderGroupId = ast.Id;
            ca.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(ca);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, ca.GroupName, ca.Id);


            DAL.AccountGroup ch = new DAL.AccountGroup();
            ch.GroupName    = BLL.DataKeyValue.CashInHand_Key;
            ch.GroupCode    = "111";
            ch.UnderGroupId = ca.Id;
            ch.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(ch);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, ch.GroupName, ch.Id);

            DAL.Ledger cL = new DAL.Ledger();
            cL.LedgerName     = BLL.DataKeyValue.CashLedger_Key;
            cL.AccountGroupId = ch.Id;
            DB.Ledgers.Add(cL);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, cL.LedgerName, cL.Id);

            DAL.AccountGroup dp = new DAL.AccountGroup();
            dp.GroupName    = BLL.DataKeyValue.Deposits_Key;
            dp.GroupCode    = "112";
            dp.UnderGroupId = ca.Id;
            dp.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(dp);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, dp.GroupName, dp.Id);


            DAL.AccountGroup la = new DAL.AccountGroup();
            la.GroupName    = BLL.DataKeyValue.LoansandAdvances_Key;
            la.GroupCode    = "113";
            la.UnderGroupId = ca.Id;
            la.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(la);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, la.GroupName, la.Id);


            DAL.AccountGroup ba = new DAL.AccountGroup();
            ba.GroupName    = BLL.DataKeyValue.BankAccounts_Key;
            ba.GroupCode    = "114";
            ba.UnderGroupId = ca.Id;
            ba.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(ba);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, ba.GroupName, ba.Id);


            DAL.AccountGroup SIH = new DAL.AccountGroup();
            SIH.GroupName    = BLL.DataKeyValue.StockInHand_Key;
            SIH.GroupCode    = "115";
            SIH.UnderGroupId = ca.Id;
            SIH.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(SIH);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SIH.GroupName, SIH.Id);

            DAL.Ledger st = new DAL.Ledger();
            st.LedgerName     = BLL.DataKeyValue.Stock_In_Hand_Ledger_Key;
            st.AccountGroupId = SIH.Id;
            DB.Ledgers.Add(st);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, st.LedgerName, st.Id);

            DAL.Ledger sti = new DAL.Ledger();
            sti.LedgerName     = BLL.DataKeyValue.Stock_Inward_Ledger_Key;
            sti.AccountGroupId = SIH.Id;
            DB.Ledgers.Add(sti);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, sti.LedgerName, sti.Id);

            DAL.Ledger sto = new DAL.Ledger();
            sto.LedgerName     = BLL.DataKeyValue.Stock_Outward_Ledger_Key;
            sto.AccountGroupId = SIH.Id;
            DB.Ledgers.Add(sto);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, sto.LedgerName, sto.Id);

            DAL.AccountGroup sd = new DAL.AccountGroup();
            sd.GroupName    = BLL.DataKeyValue.SundryDebtors_Key;
            sd.GroupCode    = "116";
            sd.UnderGroupId = ca.Id;
            sd.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(sd);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, sd.GroupName, sd.Id);


            DAL.Ledger SP = new DAL.Ledger();
            SP.LedgerName     = BLL.DataKeyValue.StockInProcess_Ledger_Key;
            SP.AccountGroupId = SIH.Id;
            DB.Ledgers.Add(SP);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SP.LedgerName, SP.Id);

            DAL.Ledger SS = new DAL.Ledger();
            SS.LedgerName     = BLL.DataKeyValue.StockSeperated_Ledger_Key;
            SS.AccountGroupId = SIH.Id;
            DB.Ledgers.Add(SS);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, SS.LedgerName, SS.Id);



            #endregion

            #region Fixed Assets

            DAL.AccountGroup fa = new DAL.AccountGroup();
            fa.GroupName    = BLL.DataKeyValue.FixedAssets_Key;
            fa.GroupCode    = "120";
            fa.UnderGroupId = ast.Id;
            fa.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(fa);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, fa.GroupName, fa.Id);

            #endregion


            #region Misc. Expenses

            DAL.AccountGroup me = new DAL.AccountGroup();
            me.GroupName    = BLL.DataKeyValue.MiscExpenses_Key;
            me.GroupCode    = "130";
            me.UnderGroupId = ast.Id;
            me.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(me);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, me.GroupName, me.Id);

            #endregion

            DAL.AccountGroup Inv = new DAL.AccountGroup();
            Inv.GroupName    = BLL.DataKeyValue.Investments_Key;
            Inv.GroupCode    = "140";
            Inv.UnderGroupId = ast.Id;
            Inv.FundMasterId = pr.FundMasterId;
            DB.AccountGroups.Add(Inv);
            DB.SaveChanges();
            SetDataKeyValue(pr.FundMasterId, Inv.GroupName, Inv.Id);
        }
        List <BLL.MonthlyReport> IncomeExpenditureByGroupName(DAL.AccountGroup ag, DateTime dtFrom, DateTime dtTo, string Prefix, bool isMonthly)
        {
            int n = Math.Abs((dtTo.Year * 12 + (dtTo.Month - 1)) - (dtFrom.Year * 12 + (dtFrom.Month - 1)));

            if (isMonthly == false)
            {
                n = n / 2;
            }
            if (n > 12)
            {
                n = 12;
            }


            List <BLL.MonthlyReport> rv = new List <BLL.MonthlyReport>();

            BLL.MonthlyReport sr   = new BLL.MonthlyReport();
            decimal[]         tamt = new decimal[12];


            #region CustomeWise

            decimal[] gtamt = new decimal[12];

            foreach (var l in ag.Ledgers)
            {
                decimal[] amt = new decimal[12];

                for (int i = 0; i <= n; i++)
                {
                    decimal dr = 0, cr = 0;

                    amt[i] = isMonthly == true ? 0 : 1;
                    if (isMonthly == true)
                    {
                        DateTime dt = dtFrom.AddMonths(i);

                        dr = l.PaymentDetails.Where(x => x.Payment.PaymentDate.Year == dt.Year && x.Payment.PaymentDate.Month == dt.Month).Sum(x => x.Amount);
                        cr = l.Payments.Where(x => x.PaymentDate.Year == dt.Year && x.PaymentDate.Month == dt.Month).Sum(x => x.Amount);

                        dr += l.Receipts.Where(x => x.ReceiptDate.Year == dt.Year && x.ReceiptDate.Month == dt.Month).Sum(x => x.Amount);
                        cr += l.ReceiptDetails.Where(x => x.Receipt.ReceiptDate.Year == dt.Year && x.Receipt.ReceiptDate.Month == dt.Month).Sum(x => x.Amount);

                        cr    += l.JournalDetails.Where(x => x.Journal.JournalDate.Year == dt.Year && x.Journal.JournalDate.Month == dt.Month).Sum(x => x.CrAmt);
                        dr    += l.JournalDetails.Where(x => x.Journal.JournalDate.Year == dt.Year && x.Journal.JournalDate.Month == dt.Month).Sum(x => x.DrAmt);
                        amt[i] = Math.Abs(dr - cr);
                    }
                    else
                    {
                        DateTime dt = dtFrom.AddYears(i);
                        dr = l.PaymentDetails.Where(x => x.Payment.PaymentDate.Year == dt.Year).Sum(x => x.Amount);
                        cr = l.Payments.Where(x => x.PaymentDate.Year == dt.Year).Sum(x => x.Amount);

                        dr += l.Receipts.Where(x => x.ReceiptDate.Year == dt.Year).Sum(x => x.Amount);
                        cr += l.ReceiptDetails.Where(x => x.Receipt.ReceiptDate.Year == dt.Year).Sum(x => x.Amount);

                        dr    += l.JournalDetails.Where(x => x.Journal.JournalDate.Year == dt.Year).Sum(x => x.DrAmt);
                        cr    += l.JournalDetails.Where(x => x.Journal.JournalDate.Year == dt.Year).Sum(x => x.CrAmt);
                        amt[i] = Math.Abs(dr - cr);
                    }
                }
                sr        = new BLL.MonthlyReport();
                sr.Amount = amt.Sum();

                if (sr.Amount > 0)
                {
                    sr.Description = string.Format("   {0}-{1}", l.LedgerCode, l.LedgerName);
                    sr.LId         = l.Id;
                    sr.M1          = amt[0];
                    sr.M2          = amt[1];
                    sr.M3          = amt[2];
                    sr.M4          = amt[3];
                    sr.M5          = amt[4];
                    sr.M6          = amt[5];
                    sr.M7          = amt[6];
                    sr.M8          = amt[7];
                    sr.M9          = amt[8];
                    sr.M10         = amt[9];
                    sr.M11         = amt[10];
                    sr.M12         = amt[11];
                    rv.Add(sr);
                }

                for (int i = 0; i < 12; i++)
                {
                    tamt[i] += amt[i];
                }
            }
            sr        = new BLL.MonthlyReport();
            sr.Amount = tamt.Sum();



            for (int i = 0; i < 12; i++)
            {
                gtamt[i] += tamt[i];
            }

            sr        = new BLL.MonthlyReport();
            sr.Amount = gtamt.Sum();

            if (sr.Amount != 0)
            {
                sr.Description = string.Format("Grand Total");
                sr.M1          = gtamt[0];
                sr.M2          = gtamt[1];
                sr.M3          = gtamt[2];
                sr.M4          = gtamt[3];
                sr.M5          = gtamt[4];
                sr.M6          = gtamt[5];
                sr.M7          = gtamt[6];
                sr.M8          = gtamt[7];
                sr.M9          = gtamt[8];
                sr.M10         = gtamt[9];
                sr.M11         = gtamt[10];
                sr.M12         = gtamt[11];
                rv.Add(sr);

                // rv.Add(new BLL.MonthlyReport());
            }
            #endregion

            return(rv);
        }
        List <BLL.IncomeExpenditure> IncomeExpenditureByGroupName(DAL.AccountGroup ag, DateTime dtFrom, DateTime dtTo, string Prefix, ref decimal TotalDr, ref decimal TotalCr, ref decimal TotalDrOP, ref decimal TotalCrOP)
        {
            decimal GTotalDr = 0, GTotalCr = 0, GTotalDrOP = 0, GTotalCrOP = 0;

            List <BLL.IncomeExpenditure> lstIncomeExpenditure = new List <BLL.IncomeExpenditure>();
            decimal total = 0;

            GetLedgerTotal(ag, ref total);
            if (total == 0)
            {
                return(lstIncomeExpenditure);
            }

            BLL.IncomeExpenditure tb = new BLL.IncomeExpenditure();

            tb                    = new BLL.IncomeExpenditure();
            tb.Ledger             = new BLL.Ledger();
            tb.Ledger.AccountName = Prefix + ag.GroupName;
            tb.CrAmt              = null;
            tb.DrAmt              = null;
            tb.CrAmtOP            = null;
            tb.DrAmtOP            = null;

            lstIncomeExpenditure.Add(tb);


            foreach (var uag in ag.AccountGroup1)
            {
                lstIncomeExpenditure.AddRange(IncomeExpenditureByGroupName(uag, dtFrom, dtTo, Prefix + "     ", ref GTotalDr, ref GTotalCr, ref GTotalDrOP, ref GTotalCrOP));
            }

            decimal OPDr = 0, OPCr = 0, Dr = 0, Cr = 0;

            foreach (var l in ag.Ledgers)
            {
                tb        = new BLL.IncomeExpenditure();
                tb.Ledger = LedgerDAL_BLL(l);

                LedgerBalance(l, dtFrom, dtTo, ref OPDr, ref OPCr, ref Dr, ref Cr);

                tb.DrAmt   = Dr;
                tb.CrAmt   = Cr;
                tb.DrAmtOP = OPDr;
                tb.CrAmtOP = OPCr;

                if (tb.DrAmt != 0 || tb.CrAmt != 0)
                {
                    tb.Ledger.AccountGroup.GroupCode = Prefix + "     " + tb.Ledger.AccountGroup.GroupCode;
                    lstIncomeExpenditure.Add(tb);
                    GTotalDr += tb.DrAmt ?? 0;
                    GTotalCr += tb.CrAmt ?? 0;

                    GTotalDrOP += tb.DrAmtOP ?? 0;
                    GTotalCrOP += tb.CrAmtOP ?? 0;
                }
            }

            if (GTotalDr > GTotalCr)
            {
                GTotalDr = Math.Abs(GTotalDr - GTotalCr);
                GTotalCr = 0;
            }
            else
            {
                GTotalCr = Math.Abs(GTotalDr - GTotalCr);
                GTotalDr = 0;
            }

            if (GTotalDrOP > GTotalCrOP)
            {
                GTotalDrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalCrOP = 0;
            }
            else
            {
                GTotalCrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalDrOP = 0;
            }
            tb                    = new BLL.IncomeExpenditure();
            tb.Ledger             = new BLL.Ledger();
            tb.Ledger.AccountName = Prefix + "Total " + ag.GroupName;
            tb.CrAmt              = GTotalCr;
            tb.DrAmt              = GTotalDr;
            tb.CrAmtOP            = GTotalCrOP;
            tb.DrAmtOP            = GTotalDrOP;


            lstIncomeExpenditure.Add(tb);

            TotalDr   += GTotalDr;
            TotalCr   += GTotalCr;
            TotalDrOP += GTotalDrOP;
            TotalCrOP += GTotalCrOP;

            return(lstIncomeExpenditure);
        }
Example #16
0
        List <BLL.BalanceSheet> BalanceSheetByGroupName(DAL.AccountGroup ag, DateTime dtFrom, DateTime dtTo, string Prefix, ref decimal TotalDr, ref decimal TotalCr, ref decimal TotalDrOP, ref decimal TotalCrOP)
        {
            decimal GTotalDr = 0, GTotalCr = 0, GTotalDrOP = 0, GTotalCrOP = 0;
            List <BLL.BalanceSheet> lstBalanceSheet = new List <BLL.BalanceSheet>();
            decimal total = 0;

            GetLedgerTotal(ag, ref total);
            if (total == 0)
            {
                return(lstBalanceSheet);
            }

            BLL.BalanceSheet tb = new BLL.BalanceSheet();

            tb                        = new BLL.BalanceSheet();
            tb.LedgerList             = new BLL.Ledger();
            tb.LedgerList.AccountName = Prefix + ag.GroupName;
            tb.CrAmt                  = null;
            tb.DrAmt                  = null;
            tb.CrAmtOP                = null;
            tb.DrAmtOP                = null;

            lstBalanceSheet.Add(tb);


            foreach (var uag in ag.AccountGroup1)
            {
                lstBalanceSheet.AddRange(BalanceSheetByGroupName(uag, dtFrom, dtTo, Prefix + "     ", ref GTotalDr, ref GTotalCr, ref GTotalDrOP, ref GTotalCrOP));
            }

            decimal OPDr = 0, OPCr = 0, Dr = 0, Cr = 0;

            foreach (var l in ag.Ledgers)
            {
                tb            = new BLL.BalanceSheet();
                tb.LedgerList = LedgerDAL_BLL(l);

                LedgerBalance(l, dtFrom, dtTo, ref OPDr, ref OPCr, ref Dr, ref Cr);

                tb.DrAmt   = Dr;
                tb.CrAmt   = Cr;
                tb.DrAmtOP = OPDr;
                tb.CrAmtOP = OPCr;

                if (tb.DrAmt != 0 || tb.CrAmt != 0 || tb.DrAmtOP != 0 || tb.CrAmtOP != 0)
                {
                    tb.LedgerList.AccountGroup.GroupCode = Prefix + "     " + tb.LedgerList.AccountGroup.GroupCode;
                    lstBalanceSheet.Add(tb);
                    GTotalDr += tb.DrAmt ?? 0;
                    GTotalCr += tb.CrAmt ?? 0;

                    GTotalDrOP += tb.DrAmtOP ?? 0;
                    GTotalCrOP += tb.CrAmtOP ?? 0;
                }
            }
            if (ag.GroupName == "Equity")
            {
                var l1 = IncomeExpenditure_List(dtFrom, dtTo);
                var ie = l1.Where(x => x.Ledger.AccountName == "Surplus/Deficit ").FirstOrDefault();
                if (ie != null)
                {
                    tb                        = new BLL.BalanceSheet();
                    tb.LedgerList             = new BLL.Ledger();
                    tb.LedgerList.AccountName = Prefix + "Net Income";
                    tb.CrAmt                  = ie.CrAmt;
                    tb.DrAmt                  = ie.DrAmt;
                    tb.CrAmtOP                = ie.CrAmtOP;
                    tb.DrAmtOP                = ie.DrAmtOP;
                    GTotalDr                 += tb.DrAmt ?? 0;
                    GTotalCr                 += tb.CrAmt ?? 0;

                    GTotalDrOP += tb.DrAmtOP ?? 0;
                    GTotalCrOP += tb.CrAmtOP ?? 0;

                    lstBalanceSheet.Add(tb);
                }
            }
            if (GTotalDr > GTotalCr)
            {
                GTotalDr = Math.Abs(GTotalDr - GTotalCr);
                GTotalCr = 0;
            }
            else
            {
                GTotalCr = Math.Abs(GTotalDr - GTotalCr);
                GTotalDr = 0;
            }

            if (GTotalDrOP > GTotalCrOP)
            {
                GTotalDrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalCrOP = 0;
            }
            else
            {
                GTotalCrOP = Math.Abs(GTotalDrOP - GTotalCrOP);
                GTotalDrOP = 0;
            }



            tb                        = new BLL.BalanceSheet();
            tb.LedgerList             = new BLL.Ledger();
            tb.LedgerList.AccountName = Prefix + "Total " + ag.GroupName;
            tb.CrAmt                  = GTotalCr;
            tb.DrAmt                  = GTotalDr;
            tb.CrAmtOP                = GTotalCrOP;
            tb.DrAmtOP                = GTotalDrOP;


            lstBalanceSheet.Add(tb);

            TotalDr   += GTotalDr;
            TotalCr   += GTotalCr;
            TotalDrOP += GTotalDrOP;
            TotalCrOP += GTotalCrOP;

            return(lstBalanceSheet);
        }