public void ValidateTrueProjectNotNullHeadNullShowAllAdvanceTrue()
 {
     var p = new Project();
     Head h = null;
     var actual = _ledgerManager.Validate(p, h, true);
     Assert.AreEqual(true, actual, "Shoild return true when head null but show advance is true");
 }
 public void ValidateReturnsFalseHeadNullShowlAllAdvavceFalse()
 {
     var p = new Project();
     Head h = null;
     var actual = _ledgerManager.Validate(p, h, false);
     Assert.AreEqual(false, actual, "Should return false when head is null and show all advance is false");
 }
 public void ValidateReturnsTrueProjectNotNullHeadNotNull()
 {
     var p = new Project();
     var h = new Head();
     var actual = _ledgerManager.Validate(p, h, false);
     Assert.AreEqual(true, actual, "Shoild return true when  project and head is not null");
 }
 public IList<Record> GetAllAdvance(Project project)
 {
     //return _ledgerRepository.GetLedger(projectId);
     //int[] projectHeadIds = db.ProjectHeads.Where(ph => ph.ProjectID == projectId).Select(ph => ph.ID).ToArray();
     //double balance = 0;
     return project.ProjectHeads.SelectMany(ph => ph.Records).Where(
             r => r.Tag == "Advance" && r.LedgerType == "LedgerBook").ToList();
     //TODO: add date filter
 }
Exemple #5
0
        public IList<Head> GetHeads(Project project, bool isCashOrBankIncluded = true, bool bringInactive = true)
        {
            IList<ProjectHead> headQuery = _projectHeadRepository.Get(ph => ph.Project.ID == project.ID).ToList();
            //TODO: Nazmul direct referencing is not working. ID is working...  ph => ph.Project.ID == project.ID
            IList<Head> heads = headQuery.Select(ph => ph.Head).ToList();
            heads = bringInactive ? heads.OrderBy(h => h.Name).ToList() : heads.Where(h => h.IsActive).OrderBy(h => h.Name).ToList();

            if (!isCashOrBankIncluded) return heads.Where(p => p.Name != "Cash Book" && p.Name != "Bank Book").ToList();
            return heads;
        }
 public int GetNewVoucherNo(string voucherType, Project project)
 {
     IList<ProjectHead> projectHeads = _projectHeadRepository.Get(ph => ph.Project.ID == project.ID).ToList();
     int[] ids = projectHeads.Select(ph => ph.ID).ToArray();
     IList<Record> records = _recordRepository.GetAll().ToList();
     if (records.Count == 0) return 1;
     records = records.Where(r => r.VoucherType == voucherType).ToList();
     if (records.Count == 0) return 1;
     int maxVoucherSerialNo = records.Where(r => ids.Contains(r.ProjectHead.ID)).
             ToList().Max(r => r.VoucherSerialNo);
     return maxVoucherSerialNo + 1;
 }
        public IList<Record> GetLedgerBook(Project project, Head head, bool isCashBankShown = false)
        {
            DateTime financialYearStartDate = _parameterManager.GetFinancialYearStartDate();

            return _recordRepository.Get(r => r.ProjectHead.Project.ID == project.ID && r.ProjectHead.Head.ID == head.ID).OrderBy(l => l.Date).ToList().Where(
                    l => GetDateAt12Am(l.Date) >= financialYearStartDate && GetDateAt12Am(l.Date) <= LedgerEndDate).
                    ToList();

            //return
            //    _ledgerRepository.GetLedger(projectId, headId) .OrderBy(l => l.Date).Where(
            //        l => GetDateAt12Am(l.Date) >= financialYearStartDate && GetDateAt12Am(l.Date) <= LedgerEndDate).
            //        ToList();
        }
        public bool Validate(Project project, Head head, bool showAllAdvance)
        {
            if (project == null)
            {
                InvokeManagerEvent(EventType.Error, "NoProjectSelected");
                return false;
            }

            if (!showAllAdvance && head == null)
            {
                InvokeManagerEvent(EventType.Error, "NoHeadSelected");
                return false;
            }
            return true;
        }
        //<<<<<<< HEAD
        //        public bool Set(Project project, Head head, string financialYear, double budgetAmount)
        //        {
        //            ProjectHead projectHead = _projectHeadRepository.GetSingle(ph => ph.Project.ID == project.ID && ph.Head.ID == head.ID );
        //            if (projectHead == null) return false;
        //            Budget budget = projectHead.Budgets.SingleOrDefault(b => b.FinancialYear == financialYear && b.IsActive);
        //            //TODO: depends on current accounting year.
        //            if (budget == null)
        //            {
        //                return InsertNewBudget(projectHead, budgetAmount);
        //=======
        public bool Set(Project project, Head head, double amount, int budgetYear)
        {
            if (project == null)
            {
                InvokeManagerEvent(EventType.Error, "NoProjectSelected");
                return false;
                //>>>>>>> githubJakaria42/master
            }
            if (head == null)
            {
                InvokeManagerEvent(EventType.Error, "NoHeadSelected");
                return false;
            }
            if (amount == 0)
            {
                // TODO: This will not work right now, think through. But not a big problem.
                InvokeManagerEvent(EventType.Warning, "ZeroBudgetProvidedForFixedAsset");
            }

            string projectName = project.Name;
            string headName = head.Name;

            ProjectHead projectHead = _projectHeadRepository.GetSingle(ph => ph.Project.ID == project.ID && ph.Head.ID == head.ID);

            bool update = false;
            if (projectHead != null && projectHead.Budgets != null)
            {
                //<<<<<<< HEAD
                //                budget.IsActive = false;
                //                return InsertNewBudget(projectHead, budgetAmount);
                //=======
                Budget budget = projectHead.Budgets.SingleOrDefault(b => b.FinancialYear == budgetYear.ToString());
                if (budget != null)
                {
                    budget.Amount = amount;
                    budget.FinancialYear = budgetYear.ToString();
                    budget.Date = DateTime.Today;
                    budget.IsActive = budgetYear < DateTime.Now.Year ? false : true;

                    update = true;
                }
                else
                {
                    budget = new Budget
                    {
                        Amount = amount,
                        FinancialYear = budgetYear.ToString(),
                        Date = DateTime.Today,
                        IsActive = budgetYear < DateTime.Now.Year ? false : true,
                        ProjectHead = projectHead
                    };
                }

                return InsertOrUpdateBudget(budget, update);
                //>>>>>>> githubJakaria42/master
            }
            else
                return false;

            //ProjectHead projectHead = _projectHeadRepository.GetSingle(ph => ph.Head.Name == headName && ph.Project.Name == projectName);
            //Budget budget = projectHead.Budgets.SingleOrDefault(b => b.IsActive);
            ////TODO: depends on current accounting year.
            //if (budget == null)
            //{
            //    return InsertNewBudget(projectHead, amount);
            //}
            //else
            //{
            //    budget.IsActive = false;
            //    return InsertNewBudget(projectHead, amount);
            //}
        }
 public IList<Budget> GetAllBudgets(Project project)
 {
     return _budgetRepository.Get(r => r.ProjectHead.Project.ID == project.ID).ToList();
     //return _budgetRepository.GetAll().ToList();
 }
        public SortedDictionary<string, double> GetAllClosingBalances(Project project)
        {
            string currentFinancialYear = GetCurrentFinancialYear();
            IList<Record> records = _recordRepository.Get(r => r.ProjectHead.Project.ID == project.ID && r.FinancialYear == currentFinancialYear).ToList();
            //records = records.Where(r => r.LedgerType.Equals("LedgerBook", StringComparison.OrdinalIgnoreCase)).ToList();

            SortedDictionary<string, double> closingBalances = new SortedDictionary<string, double>();
            foreach (Record record in records)
            {
                string headName;
                if (record.LedgerType.Equals("CashBook", StringComparison.OrdinalIgnoreCase))
                    headName = "Cash Book";
                else if (record.LedgerType.Equals("BankBook", StringComparison.OrdinalIgnoreCase))
                    headName = "Bank Book";
                else
                    headName = record.ProjectHead.Head.Name;

                double cumulativeBalance = record.Debit - record.Credit;
                double currentBalance;
                if (closingBalances.TryGetValue(headName, out currentBalance))
                {
                    closingBalances.Remove(headName);
                    cumulativeBalance += currentBalance;
                }
                else
                {
                    double openingBalance = GetOpeningBalance(project.Name, headName, currentFinancialYear);
                    cumulativeBalance = openingBalance + cumulativeBalance;
                }

                closingBalances.Add(headName, cumulativeBalance);
            }

            return closingBalances;
        }
        public bool Set(Project project, Head head, double amount)
        {
            if (project == null)
            {
                InvokeManagerEvent(EventType.Error, "NoProjectSelected");
                return false;
            }
            if (head == null)
            {
                InvokeManagerEvent(EventType.Error, "NoHeadSelected");
                return false;
            }
            if (amount == 0)
            {
                // TODO: This will not work right now, think through. But not a big problem.
                InvokeManagerEvent(EventType.Warning, "ZeroDepreciationProvidedForFixedAsset");
            }

            string projectName = project.Name;
            string headName = head.Name;

            ProjectHead projectHead = _projectHeadRepository.GetSingle(ph => ph.Head.Name == headName && ph.Project.Name == projectName);

            bool update = false;
            //if (projectHead != null && projectHead.Budgets != null)
            if (projectHead != null && projectHead.OpeningBalances != null)
            {
                string currentFinancialYear = GetCurrentFinancialYear();
                OpeningBalance openingBalance = projectHead.OpeningBalances.SingleOrDefault(b => b.FinancialYear == currentFinancialYear);
                if (openingBalance != null)
                {
                    openingBalance.Balance = amount;
                    openingBalance.FinancialYear = currentFinancialYear;
                    openingBalance.Date = DateTime.Today;
                    openingBalance.IsActive = Convert.ToInt32(currentFinancialYear) < DateTime.Now.Year ? false : true;
                    openingBalance.Description = "opening";

                    update = true;
                }
                else
                {
                    openingBalance = new OpeningBalance
                    {
                        Balance = amount,
                        FinancialYear = currentFinancialYear,
                        Date = DateTime.Today,
                        IsActive = Convert.ToInt32(currentFinancialYear) < DateTime.Now.Year ? false : true,
                        Description = "opening",
                        ProjectHead = projectHead
                    };
                }

                return InsertOrUpdateOpeningBalance(openingBalance, update);
            }
            else
                return false;

            //return true;
        }
 public IList<OpeningBalance> GetOpeningBalances(Project project)
 {
     string currentFinancialYear = GetCurrentFinancialYear();
     return _openingBalanceRepository.Get(r => r.ProjectHead.Project.ID == project.ID && r.FinancialYear == currentFinancialYear).ToList();
 }
        // TODO: Refactor -- Code cloning with the overload below.
        public double GetOpeningBalance(Project project, Head head)
        {
            if (!head.HeadType.Equals("Capital", StringComparison.OrdinalIgnoreCase))
                return 0.0;

            string currentFinancialYear = GetCurrentFinancialYear();
            OpeningBalance openingBalance = _openingBalanceRepository.GetSingle(r => r.ProjectHead.Project.ID == project.ID
                                                                                  && r.ProjectHead.Head.ID == head.ID
                                                                                  && r.FinancialYear == currentFinancialYear && r.Description.Equals("opening", StringComparison.OrdinalIgnoreCase));

            if (openingBalance == null)
                return 0.0;
            else
                return openingBalance.Balance;
        }