Exemplo n.º 1
0
        public bool PostLedger(TaxPeriod taxPeriod, bool SaveImmediately = true)
        {
            if (taxPeriod.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            taxPeriod.ReCalculate();

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = taxPeriod.Id,
                TransactionDate = taxPeriod.TransactionDate,
                TransactionName = taxPeriod.Name,
                TransactionNo   = taxPeriod.No ?? 0,
                TransactionType = transactionType
            };

            taxPeriod.GetCommercialTaxGroups().ForEach(taxGroup =>
            {
                switch (taxGroup.TaxCode.TaxDirection)
                {
                case TaxDirection.Input:
                    Console.WriteLine($"INP =>{taxGroup.TaxCode.TaxAccount.Name}{taxGroup.TaxBalance}");
                    trLedger.AddCredit(taxGroup.TaxCode.TaxAccount, taxGroup.TaxBalance);
                    break;

                case TaxDirection.Output:
                    Console.WriteLine($"OUT =>{taxGroup.TaxCode.TaxAccount.Name}{taxGroup.TaxBalance}");
                    trLedger.AddDebit(taxGroup.TaxCode.TaxAccount, taxGroup.TaxBalance);
                    break;
                }
            });

            if (taxPeriod.CloseToAccount.Type == Models.ChartOfAccount.AccountTypes.Asset)
            {
                trLedger.AddDebit(taxPeriod.CloseToAccount, Math.Abs(taxPeriod.ClosingAmount));
            }
            else if (taxPeriod.CloseToAccount.Type == Models.ChartOfAccount.AccountTypes.Liability)
            {
                trLedger.AddCredit(taxPeriod.CloseToAccount, Math.Abs(taxPeriod.ClosingAmount));
            }

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                taxPeriod.PostStatus = LedgerPostStatus.Posted;
            }

            if (SaveImmediately && taxPeriod.PostStatus == LedgerPostStatus.Posted)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool PostLedger(ReceivePayment tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                throw new Exception("Posted Transaction");
            }
            if (tr.CommercialCount == 0 || tr.TotalCommercialAmount == 0)
            {
                throw new Exception("Zero commecial transaction");
            }

            tr.AssetAccount      = tr.AssetAccount ?? organization.SystemAccounts.Cash;
            tr.ReceivableAccount = organization.SystemAccounts.AccountReceivable;
            tr.UpdateBalance();

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType,
                ProfileName     = tr.Profile?.Name,
            };

            string memo = "";

            //Cr.
            trLedger.AddCredit(tr.ReceivableAccount, tr.TotalCommercialAmount, memo);

            //Dr.
            tr.PaymentRetentions.ToList().ForEach(pr =>
                                                  trLedger.AddDebit(pr.RetentionType.RetentionToAccount, pr.RetentionAmount, memo));
            trLedger.AddDebit(organization.SystemAccounts.DiscountGiven, tr.DiscountAmount, memo);
            trLedger.AddDebit(tr.AssetAccount, tr.AmountPaymentReceive, memo);


            if (tr.BankFeeAmount > 0)
            {
                trLedger.AddDebit(organization.SystemAccounts.BankFee, tr.BankFeeAmount);
                trLedger.AddCredit(tr.AssetAccount, tr.BankFeeAmount);
            }

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else if (tr.PostStatus != LedgerPostStatus.Posted)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool PostLedger(LiabilityPayment tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            if (tr.LiabilityAccount == null)
            {
                return(false);
            }


            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };

            //Dr.
            trLedger.AddDebit(tr.LiabilityAccount, tr.Amount);

            //Cr.
            tr.PaymentRetentions.ToList().ForEach(pr =>
                                                  trLedger.AddCredit(pr.RetentionType.RetentionToAccount, pr.RetentionAmount));
            tr.PaymentFromAccounts.ToList().ForEach(payFrom =>
                                                    trLedger.AddCredit(payFrom.AccountItem, payFrom.PayAmount));
            trLedger.AddCredit(tr.AssetAccount, tr.AmountLiabilityPayFromPrimaryAcc);

            if (tr.BankFeeAmount > 0)
            {
                trLedger.AddDebit(organization.SystemAccounts.BankFee, tr.BankFeeAmount);
                trLedger.AddCredit(tr.AssetAccount, tr.BankFeeAmount);
            }

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else
            {
                return(false);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool PostLedger(PeriodItemCOGS tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };

            erpNodeDBContext.LedgerGroups.Add(trLedger);

            trLedger.AddCredit(tr.Item.PurchaseAccount, tr.OutputCost);
            trLedger.AddDebit(tr.Item.COGSAccount, tr.OutputCost);

            tr.PostStatus = LedgerPostStatus.Posted;

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 5
0
        public bool PostLedger(Loan tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };


            trLedger.AddDebit(tr.AssetAccount, tr.Amount);
            trLedger.AddCredit(tr.LiabilityAccount, tr.Amount);

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 6
0
 private void PostLedger_Items(Models.Accounting.LedgerGroup trLedger, Sale sale)
 {
     foreach (var transactionItem in sale.CommercialItems)
     {
         string memo = transactionItem.Amount.ToString() + " x " + transactionItem.ItemPartNumber;
         trLedger.AddCredit(transactionItem.Item.IncomeAccount, transactionItem.LineTotal, memo);
     }
 }
Exemplo n.º 7
0
        private bool PostLedger_Tax(Models.Accounting.LedgerGroup trLedger, Sale sale)
        {
            sale.CommercialTaxes
            .ToList()
            .ForEach(commercialTax =>
            {
                trLedger.AddCredit(commercialTax.TaxCode.TaxAccount, commercialTax.TaxBalance);
            });

            return(true);
        }
Exemplo n.º 8
0
        private void PostDeductionToGL(Models.Accounting.LedgerGroup trLedger, EmployeePayment employeePayment)
        {
            var paymentDeductionItems = employeePayment.PaymentItems
                                        .Where(t => t.PaymentType.PayDirection == Models.Employees.PayDirection.Deduction)
                                        .ToList();

            foreach (var paymentItem in paymentDeductionItems)
            {
                trLedger.AddCredit(paymentItem.PaymentType.Account, paymentItem.Amount);
            }
        }
Exemplo n.º 9
0
        public void PostLedger(CapitalActivity tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return;
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No ?? 0,
                TransactionType = transactionType
            };

            erpNodeDBContext.LedgerGroups.Add(trLedger);


            if (tr.Type == Models.Equity.Enums.CapitalActivityType.Invest)
            {
                trLedger.AddDebit(tr.AssetAccount, tr.TotalStockParValue);
                trLedger.AddCredit(tr.EquityAccount, tr.TotalStockParValue);
            }
            else
            {
                trLedger.AddCredit(tr.AssetAccount, Math.Abs(tr.TotalStockParValue));
                trLedger.AddDebit(tr.EquityAccount, Math.Abs(tr.TotalStockParValue));
            }

            tr.PostStatus = LedgerPostStatus.Posted;

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public bool PostLedger(JournalEntry tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };

            foreach (var journalentryItem in tr.Items.ToList())
            {
                if (journalentryItem.Debit != null && journalentryItem.Debit > 0)
                {
                    trLedger.AddDebit(journalentryItem.Account, journalentryItem.Debit ?? 0);
                }
                else
                {
                    trLedger.AddCredit(journalentryItem.Account, journalentryItem.Credit ?? 0);
                }
            }


            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else
            {
                return(false);
            }


            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 11
0
        public bool PostLedger(Purchase tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                throw new Exception("Post fail, Transaaction aleardy posted");
            }
            if (tr.Total == 0)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType,
                Reference       = tr.Reference,
                ProfileName     = tr.Profile?.Name,
            };

            this.PostLedger_Items(trLedger, tr);
            this.PostLedger_Tax(trLedger, tr);
            trLedger.AddCredit(organization.SystemAccounts.AccountPayable, tr.Total);

            if (trLedger.FinalValidate())
            {
                tr.PostStatus = LedgerPostStatus.Posted;
                erpNodeDBContext.LedgerGroups.Add(trLedger);
            }
            else
            {
                trLedger.RemoveAllLedgerLines();
                organization.EventLogs.NewEventLog(EventLogLevel.Error,
                                                   "1011", "Error Posting", trLedger.TransactionName, "");
                return(false);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 12
0
        public bool PostLedger(FundTransfer tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };

            trLedger.AddCredit(tr.WithDrawAccount, tr.AmountwithDraw);
            if (tr.AmountFee > 0)
            {
                trLedger.AddDebit(tr.BankFeeAccount, tr.AmountFee);
            }
            trLedger.AddDebit(tr.DepositAccount, tr.AmountDeposit);



            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else
            {
                return(false);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 13
0
        public bool PostLedger(EmployeePayment tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No ?? 0,
                TransactionType = transactionType
            };

            if (tr.PayFromAccount == null)
            {
                tr.PayFromAccount = organization.SystemAccounts.Cash;
            }

            trLedger.AddCredit(tr.PayFromAccount, tr.TotalPayment);
            PostEanringToGL(trLedger, tr);
            PostDeductionToGL(trLedger, tr);

            if (trLedger.FinalValidate())
            {
                tr.PostStatus = LedgerPostStatus.Posted;
                erpNodeDBContext.LedgerGroups.Add(trLedger);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }

            return(true);
        }
Exemplo n.º 14
0
        public bool PostLedger(DeprecateSchedule tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }

            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType
            };


            trLedger.AddDebit(tr.FixedAsset.FixedAssetType.AmortizeExpenseAccount, tr.DepreciationValue);
            trLedger.AddCredit(tr.FixedAsset.FixedAssetType.AccumulateDeprecateAcc, tr.DepreciationValue);

            if (trLedger.FinalValidate())
            {
                erpNodeDBContext.LedgerGroups.Add(trLedger);
                tr.PostStatus = LedgerPostStatus.Posted;
            }
            else
            {
                return(false);
            }

            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 15
0
        public bool PostLedger(SupplierPayment tr, bool SaveImmediately = true)
        {
            if (tr.PostStatus == LedgerPostStatus.Posted)
            {
                return(false);
            }


            tr.AssetAccount     = tr.AssetAccount ?? organization.SystemAccounts.Cash;
            tr.LiabilityAccount = tr.LiabilityAccount ?? organization.SystemAccounts.AccountPayable;
            tr.UpdateBalance();


            var trLedger = new Models.Accounting.LedgerGroup()
            {
                Id = tr.Id,
                TransactionDate = tr.TransactionDate,
                TransactionName = tr.Name,
                TransactionNo   = tr.No,
                TransactionType = transactionType,
                ProfileName     = tr.Profile.DisplayName,
            };



            tr.LiabilityAccount = organization.SystemAccounts.AccountPayable;
            trLedger.AddDebit(tr.LiabilityAccount, tr.TotalCommercialAmount);
            tr.PaymentRetentions.ToList()
            .ForEach(pr => trLedger.AddCredit(pr.RetentionType.RetentionToAccount, pr.RetentionAmount));

            tr.PaymentFromAccounts.ToList()
            .ForEach(payFrom =>
                     trLedger.AddCredit(payFrom.AccountItem, payFrom.PayAmount));
            if (tr.DiscountAmount > 0)
            {
                trLedger.AddCredit(organization.SystemAccounts.DiscountTaken, tr.DiscountAmount);
            }

            trLedger.AddCredit(tr.AssetAccount, tr.AmountBillPayFromPrimaryAcc);



            if (tr.BankFeeAmount > 0)
            {
                trLedger.AddDebit(organization.SystemAccounts.BankFee, tr.BankFeeAmount);
                trLedger.AddCredit(tr.AssetAccount, tr.BankFeeAmount);
            }



            if (trLedger.FinalValidate())
            {
                tr.PostStatus = LedgerPostStatus.Posted;
                erpNodeDBContext.LedgerGroups.Add(trLedger);
            }
            if (SaveImmediately)
            {
                erpNodeDBContext.SaveChanges();
            }
            return(true);
        }