예제 #1
0
        public TblVoucherDetail AddVoucherDetails(ERPContext context, TblJournalVoucherMaster journalVoucherMaster, TblBranch _branch, TblVoucherMaster _voucherMaster, TblAccountLedger _accountLedger, decimal?productRate, decimal?ledgerId, string ledgerCode, bool isFromCashDetials = true)
        {
            try
            {
                var _voucherDetail = new TblVoucherDetail();
                var ledgerName     = GetAccountLedgerList().Where(al => al.LedgerCode == ledgerCode).FirstOrDefault();
                _voucherDetail.VoucherMasterId   = _voucherMaster.VoucherMasterId;
                _voucherDetail.VoucherDetailDate = _voucherMaster.VoucherDate;
                _voucherDetail.BranchId          = _branch.BranchId;
                _voucherDetail.BranchCode        = journalVoucherMaster.BranchCode;
                _voucherDetail.BranchName        = journalVoucherMaster.BranchName;
                if (isFromCashDetials == true)
                {
                    _voucherDetail.FromLedgerId    = journalVoucherMaster.FromLedgerId;
                    _voucherDetail.FromLedgerCode  = journalVoucherMaster.FromLedgerCode;
                    _voucherDetail.FromLedgerName  = journalVoucherMaster.FromLedgerName;
                    _voucherDetail.ToLedgerId      = ledgerName.LedgerId;
                    _voucherDetail.ToLedgerCode    = ledgerCode;
                    _voucherDetail.ToLedgerName    = ledgerName.LedgerName;
                    _voucherDetail.Amount          = productRate;
                    _voucherDetail.TransactionType = "Debit";
                    _voucherDetail.CostCenter      = journalVoucherMaster.BranchCode;
                    _voucherDetail.ServerDate      = DateTime.Now;
                    _voucherDetail.Narration       = "Journal Voucher";
                }
                //To ledger  clarifiaction on selecion of product
                else
                {
                    _voucherDetail.FromLedgerId    = ledgerName.LedgerId;
                    _voucherDetail.FromLedgerCode  = ledgerCode;
                    _voucherDetail.FromLedgerName  = ledgerName.LedgerName;
                    _voucherDetail.ToLedgerId      = journalVoucherMaster.FromLedgerId;
                    _voucherDetail.ToLedgerCode    = journalVoucherMaster.FromLedgerCode;
                    _voucherDetail.ToLedgerName    = journalVoucherMaster.FromLedgerName;
                    _voucherDetail.Amount          = productRate;
                    _voucherDetail.TransactionType = "Credit";
                    _voucherDetail.CostCenter      = journalVoucherMaster.BranchCode;
                    _voucherDetail.ServerDate      = DateTime.Now;
                    _voucherDetail.Narration       = "Journal Voucher";
                }

                context.TblVoucherDetail.Add(_voucherDetail);
                if (context.SaveChanges() > 0)
                {
                    return(_voucherDetail);
                }


                return(null);
                // }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public TblVoucherMaster AddVoucherMaster(ERPContext context, TblJournalVoucherMaster journalVoucherMaster, TblBranch branch, decimal?voucherTypeId, string paymentType)
        {
            try
            {
                decimal shifId = Convert.ToDecimal(new UserManagmentHelper().GetShiftId(journalVoucherMaster.UserId ?? 0, null));

                var _voucherMaster = new TblVoucherMaster
                {
                    BranchCode        = journalVoucherMaster.BranchCode,
                    BranchName        = branch.BranchName,
                    VoucherDate       = journalVoucherMaster.JournalVoucherDate,
                    VoucherTypeIdMain = voucherTypeId,
                    VoucherTypeIdSub  = 6,
                    VoucherNo         = journalVoucherMaster.VoucherNo,
                    Amount            = journalVoucherMaster.TotalAmount,
                    PaymentType       = "Journal Voucher",
                    Narration         = "Journal Voucher",
                    ServerDate        = DateTime.Now,
                    UserId            = journalVoucherMaster.UserId,
                    UserName          = journalVoucherMaster.UserName,
                    EmployeeId        = -1,
                    ShiftId           = shifId
                };

                context.TblVoucherMaster.Add(_voucherMaster);
                if (context.SaveChanges() > 0)
                {
                    return(_voucherMaster);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public bool RegisterJournalVoucher(TblJournalVoucherMaster journalVoucherMaster, List <TblJournalVoucherDetails> journalVoucherDetails)
        {
            try
            {
                decimal shifId = Convert.ToDecimal(new UserManagmentHelper().GetShiftId(journalVoucherMaster.UserId ?? 0, null));
                using ERPContext repo   = new ERPContext();
                using var dbTransaction = repo.Database.BeginTransaction();
                try
                {
                    //add voucher typedetails
                    var _branch = GetBranches(journalVoucherMaster.BranchCode).ToArray().FirstOrDefault();

                    var _accountLedger        = GetAccountLedgersCode(journalVoucherMaster.FromLedgerCode).ToArray().FirstOrDefault();
                    var _cashpayAccountLedger = GetAccountLedgerList().Where(x => x.LedgerCode == journalVoucherMaster.FromLedgerCode).FirstOrDefault();
                    var _vouchertType         = GetVoucherTypeList(32).ToArray().FirstOrDefault();

                    #region Add voucher master record
                    var _voucherMaster = AddVoucherMaster(repo, journalVoucherMaster, _branch, _vouchertType.VoucherTypeId, _accountLedger.CrOrDr);
                    #endregion


                    journalVoucherMaster.JournalVchNo   = _voucherMaster.VoucherMasterId.ToString();
                    journalVoucherMaster.ServerDate     = DateTime.Now;
                    journalVoucherMaster.BranchId       = _branch.BranchId;
                    journalVoucherMaster.BranchName     = _branch.BranchName;
                    journalVoucherMaster.FromLedgerId   = _cashpayAccountLedger.LedgerId;
                    journalVoucherMaster.FromLedgerName = _cashpayAccountLedger.LedgerName;
                    journalVoucherMaster.FromLedgerCode = _cashpayAccountLedger.LedgerCode;
                    journalVoucherMaster.EmployeeId     = _voucherMaster.EmployeeId;
                    journalVoucherMaster.ShiftId        = shifId;
                    repo.TblJournalVoucherMaster.Add(journalVoucherMaster);
                    repo.SaveChanges();

                    foreach (var bankDtl in journalVoucherDetails)
                    {
                        //   _accountLedger = GetAccountLedgersByLedgerId((decimal)_taxStructure.SalesAccount).FirstOrDefault();

                        #region Add voucher Details
                        var _voucherDetail = AddVoucherDetails(repo, journalVoucherMaster, _branch, _voucherMaster, _accountLedger, bankDtl.Amount, bankDtl.ToLedgerId, bankDtl.ToLedgerCode);
                        var _cashDtlLedger = GetAccountLedgerList().Where(x => x.LedgerCode == bankDtl.ToLedgerCode).FirstOrDefault();
                        #endregion

                        #region BankReceiptDetail
                        bankDtl.JournalVoucherMasterId    = journalVoucherMaster.JournalVoucherMasterId;
                        bankDtl.JournalVoucherDetailsDate = journalVoucherMaster.JournalVoucherDate;
                        bankDtl.ToLedgerId = _cashDtlLedger.LedgerId;
                        repo.TblJournalVoucherDetails.Add(bankDtl);
                        repo.SaveChanges();

                        #endregion

                        #region Add Account Ledger Transaction

                        AddAccountLedgerTransactions(repo, journalVoucherMaster, _voucherDetail, journalVoucherMaster.JournalVoucherDate);
                        #endregion
                        AddVoucherDetails(repo, journalVoucherMaster, _branch, _voucherMaster, _accountLedger, bankDtl.Amount, bankDtl.ToLedgerId, bankDtl.ToLedgerCode, false);
                        AddAccountLedgerTransactions(repo, journalVoucherMaster, _voucherDetail, journalVoucherMaster.JournalVoucherDate, false);
                    }

                    _accountLedger = GetAccountLedgers(journalVoucherMaster.FromLedgerCode).ToArray().FirstOrDefault();
                    //AddVoucherDetails(repo, bankReceiptMaster, _branch, _voucherMaster, _accountLedger, bankReceiptMaster.TotalAmount, false);


                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        public TblAccountLedgerTransactions AddAccountLedgerTransactions(ERPContext context, TblJournalVoucherMaster journalVoucherMaster, TblVoucherDetail _voucherDetail, DateTime?invoiceDate, bool isdebit = true)
        {
            try
            {
                var _accountLedgerTransactions = new TblAccountLedgerTransactions
                {
                    BranchId        = _voucherDetail.BranchId,
                    BranchCode      = _voucherDetail.BranchCode,
                    BranchName      = _voucherDetail.BranchName,
                    TransactionDate = invoiceDate,
                    // _accountLedgerTransactions.TransactionType = _voucherDetail.TransactionType;
                    VoucherAmount = _voucherDetail.Amount
                };
                if (isdebit == true)
                {
                    _accountLedgerTransactions.VoucherDetailId = _voucherDetail.VoucherDetailId;
                    _accountLedgerTransactions.LedgerId        = _voucherDetail.ToLedgerId;
                    _accountLedgerTransactions.LedgerCode      = _voucherDetail.ToLedgerCode;
                    _accountLedgerTransactions.LedgerName      = _voucherDetail.ToLedgerName;
                    _accountLedgerTransactions.TransactionType = _voucherDetail.TransactionType;
                    _accountLedgerTransactions.DebitAmount     = _accountLedgerTransactions.VoucherAmount;
                    _accountLedgerTransactions.CreditAmount    = Convert.ToDecimal("0.00");
                }
                else
                {
                    _accountLedgerTransactions.VoucherDetailId = _voucherDetail.VoucherDetailId;
                    _accountLedgerTransactions.LedgerId        = journalVoucherMaster.FromLedgerId;
                    _accountLedgerTransactions.LedgerCode      = journalVoucherMaster.FromLedgerCode;
                    _accountLedgerTransactions.LedgerName      = journalVoucherMaster.FromLedgerName;
                    _accountLedgerTransactions.TransactionType = "Credit";
                    _accountLedgerTransactions.CreditAmount    = _accountLedgerTransactions.VoucherAmount;
                    _accountLedgerTransactions.DebitAmount     = Convert.ToDecimal("0.00");
                }


                context.TblAccountLedgerTransactions.Add(_accountLedgerTransactions);
                if (context.SaveChanges() > 0)
                {
                    return(_accountLedgerTransactions);
                }


                return(null);
                //  }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }