Example #1
0
        private void InsertIntoAccounting(CreditNoteReceivingAC creditNoteRecevingAC, CreditNoteDetail creditNoteDetail)
        {
            try
            {
                List <DoubleEntry> listOfDoubleEntry = new List <DoubleEntry>();
                var ledgersForSupplier = _iAccountingRepository.GetAccountLedgerBySupplier(creditNoteRecevingAC.ListOfCreditNotes[0].SupplierId);
                var ledgersForCash     = _iAccountingRepository.GetAccountLedgerByName(StringConstants.CashInHand, Convert.ToInt32(creditNoteDetail.BranchId));
                var ledgersForBank     = _iAccountingRepository.GetAccountLedgerByName(StringConstants.Bank, Convert.ToInt32(creditNoteDetail.BranchId));
                if (ledgersForSupplier != null && ledgersForCash != null && ledgersForBank != null)
                {
                    decimal totalAmount = 0;
                    totalAmount = (creditNoteRecevingAC.Cheque + creditNoteRecevingAC.Cash);
                    listOfDoubleEntry.Add(new DoubleEntry {
                        LedgerId = ledgersForSupplier.Id, TransactionDate = DateTime.UtcNow, Credit = totalAmount, Debit = 0, CreatedDateTime = DateTime.UtcNow, ActivityName = StringConstants.ReceivingCreditNote, Description = "Credit Note Number :" + creditNoteDetail.CreditNoteNo
                    });
                    if (creditNoteRecevingAC.Cash != 0)
                    {
                        listOfDoubleEntry.Add(new DoubleEntry {
                            LedgerId = ledgersForCash.Id, TransactionDate = DateTime.UtcNow, Credit = 0, Debit = creditNoteRecevingAC.Cash, CreatedDateTime = DateTime.UtcNow, ActivityName = StringConstants.ReceivingCreditNote, Description = "Credit Note Number :" + creditNoteDetail.CreditNoteNo
                        });
                    }
                    if (creditNoteRecevingAC.Cheque != 0)
                    {
                        listOfDoubleEntry.Add(new DoubleEntry {
                            LedgerId = ledgersForBank.Id, TransactionDate = DateTime.UtcNow, Credit = 0, Debit = creditNoteRecevingAC.Cheque, CreatedDateTime = DateTime.UtcNow, ActivityName = StringConstants.ReceivingCreditNote, Description = "Credit Note Number :" + creditNoteDetail.CreditNoteNo
                        });
                    }
                }

                if (listOfDoubleEntry.Any())
                {
                    _iAccountingRepository.AddAccountingEntries(listOfDoubleEntry);
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
Example #2
0
        public IHttpActionResult SubmitRecevingCreditNote(CreditNoteReceivingAC creditNoteRecevingAC)
        {
            try
            {
                RecevingCreditNotePaymentDetail recevingCreditNotePaymentDetail = new RecevingCreditNotePaymentDetail();
                recevingCreditNotePaymentDetail.CashAmount      = creditNoteRecevingAC.Cash;
                recevingCreditNotePaymentDetail.ChequeAmount    = creditNoteRecevingAC.Cheque;
                recevingCreditNotePaymentDetail.VoucherNo       = creditNoteRecevingAC.VoucharNo;
                recevingCreditNotePaymentDetail.ChequeNo        = creditNoteRecevingAC.ChequeNo;
                recevingCreditNotePaymentDetail.CreatedDateTime = DateTime.UtcNow;
                int     recevingCreditNotePaymantId = _iCreditNoteRepository.AddRecevingCreditNotePaymantDetal(recevingCreditNotePaymentDetail);
                decimal remainingAmount             = 0;
                decimal totalAmount = creditNoteRecevingAC.Cash + creditNoteRecevingAC.Cheque;
                foreach (var creditNote in creditNoteRecevingAC.ListOfCreditNotes.OrderBy(x => x.Amount))
                {
                    var creditNoteDetail = _iCreditNoteRepository.GetCreditNoteDetailById(creditNote.Id);
                    if (creditNoteDetail != null && totalAmount > 0)
                    {
                        if (creditNoteDetail.IsCollected)
                        {
                            remainingAmount = totalAmount - creditNoteDetail.RemainigAmount;
                            if (remainingAmount < 0)
                            {
                                creditNoteDetail.RemainigAmount = creditNoteDetail.RemainigAmount - totalAmount;
                                totalAmount = remainingAmount;
                            }
                            else
                            {
                                totalAmount = remainingAmount;
                                creditNoteDetail.RemainigAmount = 0;
                            }
                        }
                        else
                        {
                            creditNoteDetail.IsCollected = true;
                            remainingAmount = totalAmount - creditNoteDetail.Amount;
                            if (remainingAmount < 0)
                            {
                                creditNoteDetail.RemainigAmount = creditNoteDetail.Amount - totalAmount;
                                totalAmount = remainingAmount;
                            }
                            else
                            {
                                totalAmount = remainingAmount;
                                creditNoteDetail.RemainigAmount = 0;
                            }
                        }
                        creditNoteDetail.RecevingCreditNotePaymentId = recevingCreditNotePaymantId;
                        _iCreditNoteRepository.UpdateCreditNoteDetail(creditNoteDetail);
                    }


                    #region Insert Into Accounting
                    InsertIntoAccounting(creditNoteRecevingAC, creditNoteDetail);
                    #endregion
                }
                return(Ok(new { _isResult = true }));
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }