예제 #1
0
        public static CashInVm GetCashReceiptForPartners(string receiptType, int receiptId = 0)
        {
            CashInVm cashVm;

            if (receiptId != 0)
            {
                cashVm = CashOutHelper.FillCashVmForReceiptView(receiptId);
                return(cashVm);
            }
            cashVm = new CashInVm();

            if (receiptType == "out")
            {
                cashVm.CashType = "cashout";
            }
            else
            {
                cashVm.CashType = "cashin";
            }

            cashVm.ReceiptCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.CashOut, false);
            //cashVm.PaymentTermId = 1;
            //cashVm.CurrencyId = 1;
            CashInCheckVm cashCheckVm = new CashInCheckVm();

            cashVm.CashInReceiptChecks.Add(cashCheckVm);

            return(cashVm);
        }
예제 #2
0
        internal static CashInVm FillCashVmForReceiptView(int receiptId)
        {
            CashInVm            cashVm = new CashInVm();
            AccountingEntities  db     = new AccountingEntities();
            EasyFreightEntities db1    = new EasyFreightEntities();
            var cashDb = db.CashOutReceipts
                         .Include("PaymentTerm")
                         .Include("Currency").Where(x => x.ReceiptId == receiptId).FirstOrDefault();

            Mapper.CreateMap <CashOutReceipt, CashInVm>()
            .ForMember(x => x.CashInReceiptChecks, y => y.Ignore())
            .ForMember(x => x.CashInReceiptInvs, y => y.Ignore())
            .ForMember(x => x.CashOutReceiptExpenses, y => y.Ignore())
            .IgnoreAllNonExisting();

            Mapper.Map(cashDb, cashVm);

            cashVm.CurrencySign    = cashDb.Currency.CurrencySign;
            cashVm.PaymentTermName = cashDb.PaymentTerm.PaymentTermEn;
            //Get customer Name
            int custId;

            if (cashVm.CarrierId != null)
            {
                custId = cashVm.CarrierId.Value;
                cashVm.CustomerName = db1.Carriers.Where(x => x.CarrierId == custId).FirstOrDefault().CarrierNameEn;
            }
            else if (cashVm.ContractorId != null)
            {
                custId = cashVm.ConsigneeId.Value;
                cashVm.CustomerName = db1.Contractors.Where(x => x.ContractorId == custId).FirstOrDefault().ContractorNameEn;
            }
            else if (cashVm.AgentId != null)
            {
                custId = cashVm.AgentId.Value;
                cashVm.CustomerName = db1.Agents.Where(x => x.AgentId == custId).FirstOrDefault().AgentNameEn;
            }

            //for bank
            if (cashVm.PaymentTermId == (byte)PaymentTermEnum.BankCashDeposit)
            {
                if (cashVm.BankAccId != null)
                {
                    int bankAccId = cashVm.BankAccId.Value;
                    var bankInfo  = db.BankAccounts.Include("Bank").Where(x => x.BankAccId == bankAccId).FirstOrDefault();
                    cashVm.BankDetailsVm = new BankDetailsVm()
                    {
                        AccountName   = bankInfo.AccountName,
                        AccountNumber = bankInfo.AccountNumber,
                        BankNameEn    = bankInfo.Bank.BankNameEn,
                        BankAddressEn = bankInfo.Bank.BankAddressEn
                    };
                }
            }

            else if (cashVm.PaymentTermId == (byte)PaymentTermEnum.Check)
            {
                CashInCheckVm cashCheckVm = new CashInCheckVm();
                var           cashCheckDb = db.CashOutReceiptChecks.Where(x => x.ReceiptId == receiptId).FirstOrDefault();
                Mapper.CreateMap <CashOutReceiptCheck, CashInCheckVm>().IgnoreAllNonExisting();
                Mapper.Map(cashCheckDb, cashCheckVm);
                cashVm.CashInReceiptChecks.Add(cashCheckVm);
            }

            //kamal
            else if (cashVm.PaymentTermId == (byte)PaymentTermEnum.CashToBank)
            {
                CashInCheckVm cashCheckVm = new CashInCheckVm();
                var           cashCheckDb = db.CashOutReceiptChecks.Where(x => x.ReceiptId == receiptId).FirstOrDefault();
                Mapper.CreateMap <CashOutReceiptCheck, CashInCheckVm>().IgnoreAllNonExisting();
                Mapper.Map(cashCheckDb, cashCheckVm);
                cashVm.CashInReceiptChecks.Add(cashCheckVm);
            }



            //Get Invoice or agent notes codes list
            if (cashVm.AgentId != null)
            {
            }
            else
            {
                var invlist = db.CashOutReceiptInvs.Include("InvoiceAP")
                              .Where(x => x.ReceiptId == receiptId).Select(x => x.InvoiceAP.InvoiceCode).ToArray();

                cashVm.InvCodeListString = string.Join(" - ", invlist);
            }

            //Check if for expenses
            var cashOutExp = db.CashOutReceiptExpenses.Include("ExpenseLib").Where(x => x.ReceiptId == receiptId).ToList();

            if (cashOutExp.Count() > 0)
            {
                List <CashOutExpense> cashOutExpenseList = new List <CashOutExpense>();
                CashOutExpense        cashOutExpense;
                foreach (var item in cashOutExp)
                {
                    cashOutExpense = new CashOutExpense();
                    cashOutExpense.CurrencySign = cashVm.CurrencySign;
                    cashOutExpense.ExpenseName  = item.ExpenseLib.ExpenseNameEn;
                    cashOutExpense.PaidAmount   = item.PaidAmount;

                    cashOutExpenseList.Add(cashOutExpense);
                }
                cashVm.CashOutReceiptExpenses = cashOutExpenseList;
            }

            cashVm.CashType = "cashout";
            //Get Created by user name


            return(cashVm);
        }
예제 #3
0
        public static CashInVm GetCashReceiptInfo(int invId, int agNoteId = 0, int cashReceiptId     = 0,
                                                  int operationId         = 0, decimal receiptAmount = 0)
        {
            CashInVm cashVm;

            if (cashReceiptId != 0)
            {
                cashVm = FillCashVmForReceiptView(cashReceiptId);
                return(cashVm);
            }

            AccountingEntities db = new AccountingEntities();

            if (invId != 0) //Invoice
            {
                cashVm = db.APInvoiceViews.Where(x => x.InvoiceId == invId)
                         .Select(x => new CashInVm
                {
                    CarrierId    = x.CarrierId,
                    ContractorId = x.ContractorId,
                    CustomerName = x.InvoiceType == 1 ? x.CarrierNameEn : x.ContractorNameEn,
                    OrderFrom    = x.OrderFrom,
                    InvoiceType  = x.InvoiceType
                }).FirstOrDefault();
            }
            else if (operationId != 0) //operationId != 0 .. so it will be cash deposit for CC
            {
                OperationsEntities db1 = new OperationsEntities();
                cashVm = db1.Operations.Where(x => x.OperationId == operationId).Select(x => new CashInVm
                {
                    OperationId   = x.OperationId,
                    OperationCode = x.OperationCode,
                    Notes         = "Custom Clerance Cash Deposit For Operation " + x.OperationCode
                }).FirstOrDefault();

                if (receiptAmount != 0)
                {
                    cashVm.ReceiptAmount = receiptAmount;
                    cashVm.PaymentTermId = 1;
                }


                cashVm.CCCashDepositVmList = GetCCCashDepositList(operationId);
            }
            else //invId == 0 .. so agNoteId will not be 0 .. collect agent note
            {
                cashVm = db.AgentNoteViews.Where(x => x.AgentNoteId == agNoteId)
                         .Select(x => new CashInVm
                {
                    AgentId      = x.AgentId,
                    CustomerName = x.AgentNameEn,
                    OrderFrom    = x.OrderFrom
                }).FirstOrDefault();
            }


            cashVm.ReceiptCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.CashOut, false);
            CashInCheckVm cashCheckVm = new CashInCheckVm();

            cashVm.CashInReceiptChecks.Add(cashCheckVm);

            if (agNoteId != 0) //Cash Receipt for Agent Note
            {
                FillCashVmForAgNote(agNoteId, ref cashVm);
                cashVm.CashType = "cashout";
                return(cashVm);
            }

            if (operationId != 0) //operationId != 0 .. so it will be cash deposit for CC
            {
                cashVm.CashType = "cashout";
                return(cashVm);
            }
            //Cash Receipt for Invoice

            //Get invoice list for this customer
            List <CashInInvoiceVm> cashInvList = new List <CashInInvoiceVm>();
            List <APInvoiceView>   invList     = new List <APInvoiceView>();

            if (cashVm.InvoiceType == 1)
            {
                invList = db.APInvoiceViews
                          .Where(x => x.CarrierId == cashVm.CarrierId && (x.InvStatusId != 4 && x.InvStatusId != 1)).ToList();
            }
            else if (cashVm.InvoiceType == 2)
            {
                invList = db.APInvoiceViews
                          .Where(x => x.ContractorId == cashVm.ContractorId && (x.InvStatusId != 4 && x.InvStatusId != 1)).ToList();
            }
            else if (cashVm.InvoiceType == 3) // Cutom clearance .. will get all not paid invoices
            //as there is only one grouped credit account for Cutom clearance suppliers .. 22/11/2016
            {
                invList = db.APInvoiceViews
                          .Where(x => x.InvoiceType == 3 && (x.InvStatusId != 4 && x.InvStatusId != 1)).ToList();
            }

            Mapper.CreateMap <APInvoiceView, CashInInvoiceVm>().IgnoreAllNonExisting();
            Mapper.Map(invList, cashInvList);


            cashVm.CashInReceiptInvs = cashInvList;
            List <int> invIds    = cashInvList.Select(x => x.InvoiceId).ToList();
            var        cashInvDb = db.CashOutReceiptInvs
                                   .Where(x => invIds.Contains(x.InvoiceId))
                                   .GroupBy(x => x.InvoiceId)
                                   .ToList();

            foreach (var item in cashVm.CashInReceiptInvs)
            {
                item.CollectedAmount = cashInvDb.Where(x => x.Key == item.InvoiceId)
                                       .Select(x => x.Sum(y => y.PaidAmount)).FirstOrDefault();
                item.AmountDue = item.TotalAmount - item.CollectedAmount;
            }


            cashVm.CashType = "cashout";

            return(cashVm);
        }