public AccountPayable Get(
            string name,
            DateTime?dueDate)
        {
            AccountPayable accountToSearch
                = new AccountPayable(name, dueDate);

            AccountPayable account = null;

            if (accountToSearch.IsValid())
            {
                account = this._accountPayableRepository.Get(
                    new object[] { name, dueDate });
            }

            if (account == null)
            {
                accountToSearch.EventNotification.Add(new EventNotificationDescription(
                                                          "Nenhuma conta {0}, com vencimento em {1}.",
                                                          new EventNotificationWarning(), name, dueDate.HasValue ? dueDate.Value.ToShortDateString() : string.Empty));
            }

            NotificationEntity = accountToSearch;

            return(account);
        }
        public ActionResult View(
            string name,
            string dueDate)
        {
            AccountPayableNewPage view = new AccountPayableNewPage();

            try
            {
                AccountPayable account = this._accountPayableApp.Get(
                    name,
                    dueDate.ToNullableDate());

                if (account != null)
                {
                    view.Item = new AccountPayableItem(
                        account.Name,
                        account.DueDate.Value,
                        account.Amount);
                }

                this.AddMessage(new MessageView(this._accountPayableApp));
            }
            catch (Exception exception)
            {
                this.CreateErroMessageView();
            }

            return(View(view));
        }
        public void Add(
            string name,
            DateTime?dueDate,
            decimal amount)
        {
            bool created = false;

            AccountPayable account = new AccountPayable(
                name,
                dueDate,
                amount);

            if (account.IsValid())
            {
                this._accountPayableRepository.Create(account);
                created = this._accountPayableRepository.SaveChanges();
            }

            if (created)
            {
                account.EventNotification.Add(NewAccountPayableAdd);
            }

            NotificationEntity = account;
        }
        public async Task <IActionResult> DeleteAccountPayable([FromBody] AccountPayableView view)
        {
            AccountPayableModule invMod         = new AccountPayableModule();
            AccountPayable       accountPayable = await invMod.AccountPayable.Query().MapToEntity(view);

            invMod.AccountPayable.DeleteAccountPayable(accountPayable).Apply();

            return(Ok(view));
        }
Exemple #5
0
        public async Task TestAddUpdatDelete()
        {
            SupplierLedgerModule SupplierLedgerMod = new SupplierLedgerModule();
            Supplier             supplier          = await SupplierLedgerMod.Supplier.Query().GetEntityById(3);

            Invoice invoice = await SupplierLedgerMod.Invoice.Query().GetEntityById(2);

            AccountPayable accountPayable = await SupplierLedgerMod.AccountPayable.Query().GetEntityById(2);

            GeneralLedger generalLedger = await SupplierLedgerMod.GeneralLedger.Query().GetEntityById(17);

            AddressBook addressBook = await SupplierLedgerMod.AddressBook.Query().GetEntityById(17);


            SupplierLedgerView view = new SupplierLedgerView()
            {
                SupplierId      = supplier.SupplierId,
                InvoiceId       = invoice.InvoiceId,
                AcctPayId       = accountPayable.AccountPayableId,
                Amount          = 300M,
                Gldate          = DateTime.Parse("11/11/2019"),
                AccountId       = generalLedger.AccountId,
                GeneralLedgerId = generalLedger.GeneralLedgerId,
                DocNumber       = 17,
                Comment         = "back to school",
                AddressId       = addressBook.AddressId,
                CreatedDate     = DateTime.Parse("11/11/2019"),
                DocType         = "PV",
                DebitAmount     = null,
                CreditAmount    = null,
                FiscalYear      = 2019,
                FiscalPeriod    = 11
            };
            NextNumber nnNextNumber = await SupplierLedgerMod.SupplierLedger.Query().GetNextNumber();

            view.SupplierLedgerNumber = nnNextNumber.NextNumberValue;

            SupplierLedger supplierLedger = await SupplierLedgerMod.SupplierLedger.Query().MapToEntity(view);

            SupplierLedgerMod.SupplierLedger.AddSupplierLedger(supplierLedger).Apply();

            SupplierLedger newSupplierLedger = await SupplierLedgerMod.SupplierLedger.Query().GetEntityByNumber(view.SupplierLedgerNumber);

            Assert.NotNull(newSupplierLedger);

            newSupplierLedger.Comment = "back to school update";

            SupplierLedgerMod.SupplierLedger.UpdateSupplierLedger(newSupplierLedger).Apply();

            SupplierLedgerView updateView = await SupplierLedgerMod.SupplierLedger.Query().GetViewById(newSupplierLedger.SupplierLedgerId);

            Assert.Same(updateView.Comment, "back to school update");
            SupplierLedgerMod.SupplierLedger.DeleteSupplierLedger(newSupplierLedger).Apply();
            SupplierLedger lookupSupplierLedger = await SupplierLedgerMod.SupplierLedger.Query().GetEntityById(view.SupplierLedgerId);

            Assert.Null(lookupSupplierLedger);
        }
        public async Task TestAddUpdatDelete()
        {
            AccountPayableDetailModule AccountPayableDetailMod = new AccountPayableDetailModule();

            Invoice invoice = await AccountPayableDetailMod.Invoice.Query().GetEntityById(20);

            InvoiceDetail invoiceDetail = await AccountPayableDetailMod.InvoiceDetail.Query().GetEntityById(21);

            PurchaseOrderDetail purchaseOrderDetail = await AccountPayableDetailMod.PurchaseOrderDetail.Query().GetEntityById(invoiceDetail.PurchaseOrderDetailId);

            AccountPayable accountPayable = await AccountPayableDetailMod.AccountPayable.Query().GetEntityById(2);

            AccountPayableDetailView view = new AccountPayableDetailView()
            {
                InvoiceId       = invoice.InvoiceId,
                InvoiceDetailId = invoiceDetail.InvoiceDetailId,
                UnitPrice       = invoiceDetail.UnitPrice,
                Quantity        = invoiceDetail.Quantity,
                //QuantityReceived =invoiceDetail.
                Amount                     = purchaseOrderDetail.Amount,
                AmountPaid                 = invoiceDetail.Amount,
                PurchaseOrderDetailId      = invoiceDetail.PurchaseOrderDetailId,
                SalesOrderDetailId         = invoiceDetail.SalesOrderDetailId,
                ItemId                     = invoiceDetail.ItemId,
                ExtendedDescription        = invoiceDetail.ExtendedDescription,
                PurchaseOrderId            = invoiceDetail.PurchaseOrderId,
                CustomerId                 = invoiceDetail.CustomerId,
                SupplierId                 = invoiceDetail.SupplierId,
                AccountPayableId           = accountPayable.AccountPayableId,
                AccountPayableDetailNumber = (await AccountPayableDetailMod.AccountPayableDetail.Query().GetNextNumber()).NextNumberValue
            };

            AccountPayableDetail accountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().MapToEntity(view);

            AccountPayableDetailMod.AccountPayableDetail.AddAccountPayableDetail(accountPayableDetail).Apply();

            AccountPayableDetail newAccountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().GetEntityByNumber(view.AccountPayableDetailNumber);

            Assert.NotNull(newAccountPayableDetail);

            newAccountPayableDetail.ExtendedDescription = "AccountPayableDetail Test Update";

            AccountPayableDetailMod.AccountPayableDetail.UpdateAccountPayableDetail(newAccountPayableDetail).Apply();

            AccountPayableDetailView updateView = await AccountPayableDetailMod.AccountPayableDetail.Query().GetViewById(newAccountPayableDetail.AccountPayableDetailId);

            Assert.Same(updateView.ExtendedDescription, "AccountPayableDetail Test Update");
            AccountPayableDetailMod.AccountPayableDetail.DeleteAccountPayableDetail(newAccountPayableDetail).Apply();
            AccountPayableDetail lookupAccountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().GetEntityById(view.AccountPayableDetailId);

            Assert.Null(lookupAccountPayableDetail);
        }
        public async Task <IActionResult> UpdateAccountPayable([FromBody] AccountPayableView view)
        {
            AccountPayableModule invMod = new AccountPayableModule();

            AccountPayable accountPayable = await invMod.AccountPayable.Query().MapToEntity(view);


            invMod.AccountPayable.UpdateAccountPayable(accountPayable).Apply();

            AccountPayableView retView = await invMod.AccountPayable.Query().GetViewById(accountPayable.AccountPayableId);


            return(Ok(retView));
        }
        public async Task <IActionResult> AddAccountPayable([FromBody] AccountPayableView view)
        {
            AccountPayableModule invMod = new AccountPayableModule();

            NextNumber nnAccountPayable = await invMod.AccountPayable.Query().GetNextNumber();

            view.AccountPayableNumber = nnAccountPayable.NextNumberValue;

            AccountPayable accountPayable = await invMod.AccountPayable.Query().MapToEntity(view);

            invMod.AccountPayable.AddAccountPayable(accountPayable).Apply();

            AccountPayableView newView = await invMod.AccountPayable.Query().GetViewByNumber(view.AccountPayableNumber);


            return(Ok(newView));
        }
Exemple #9
0
        public async Task TestPayAccountsPayable()
        {
            long   customerId = 2;
            string poNumber   = "PO-2";

            AccountPayableModule acctPayablesMod = new AccountPayableModule();
            GeneralLedgerView    ledgerView      = new GeneralLedgerView();

            long?addressId = await acctPayablesMod.AddressBook.Query().GetAddressIdByCustomerId(customerId);

            ChartOfAccount coa = await acctPayablesMod.ChartOfAccount.Query().GetEntity("1000", "1200", "210", "");

            AccountPayable acctPay = await acctPayablesMod.AccountPayable.Query().GetAcctPayByPONumber(poNumber);

            SupplierInvoice supplierInvoice = await acctPayablesMod.SupplierInvoice.Query().GetEntityByPONumber(poNumber);

            if (coa == null || acctPay == null || supplierInvoice == null)
            {
                Assert.True(false);
            }


            ledgerView.GeneralLedgerId = -1;
            ledgerView.SupplierId      = 3;
            ledgerView.DocNumber       = acctPay.DocNumber ?? 0; //doc number of the account payable
            ledgerView.AcctPayId       = acctPay.AccountPayableId;
            ledgerView.InvoiceId       = supplierInvoice.SupplierInvoiceId;
            ledgerView.DocType         = "PV";
            ledgerView.Amount          = 268M;
            ledgerView.LedgerType      = "AA";
            ledgerView.GLDate          = DateTime.Parse("8/28/2018");
            ledgerView.AccountId       = coa.AccountId;
            ledgerView.CreatedDate     = DateTime.Parse("8/28/2018");
            ledgerView.AddressId       = addressId ?? 0;
            ledgerView.Comment         = "Payment for back to school";
            ledgerView.DebitAmount     = 0;
            ledgerView.CreditAmount    = 268M;
            ledgerView.FiscalPeriod    = 8;
            ledgerView.FiscalYear      = 2018;
            ledgerView.CheckNumber     = "113";

            acctPayablesMod.CreateAccountPayable(ledgerView);
            acctPayablesMod.AccountPayable.Apply();

            Assert.True(true);
        }
Exemple #10
0
 public IFluentAccountPayable CreateAcctPayByPurchaseOrderView(PurchaseOrderView poView)
 {
     try
     {
         //Check if exists
         Task <AccountPayable> acctPayTask             = unitOfWork.accountPayableRepository.GetEntityByPurchaseOrderView(poView);
         Task <NextNumber>     nextNumberDocNumberTask = unitOfWork.nextNumberRepository.GetNextNumber(TypeOfPurchaseOrder.DocNumber.ToString());
         Task.WaitAll(acctPayTask, nextNumberDocNumberTask);
         if (acctPayTask.Result != null)
         {
             AccountPayable acctPay = acctPayTask.Result;
             acctPay.DocNumber = nextNumberDocNumberTask.Result?.NextNumberValue;
             AddAccountPayable(acctPayTask.Result);
             processStatus = CreateProcessStatus.Insert;
             return(this as IFluentAccountPayable);
         }
         processStatus = CreateProcessStatus.AlreadyExists;
         return(this as IFluentAccountPayable);
     }
     catch (Exception ex) { throw new Exception("CreateAcctPayByPurchaseOrderView", ex); }
 }
Exemple #11
0
        public async Task TestAddUpdatDelete()
        {
            AccountPayableModule AccountPayableMod = new AccountPayableModule();
            Supplier             supplier          = await AccountPayableMod.Supplier.Query().GetEntityById(3);

            ChartOfAccount chartOfAccount = await AccountPayableMod.ChartOfAccount.Query().GetEntityById(17);


            AccountPayableView view = new AccountPayableView()
            {
                DocNumber       = 17,
                GrossAmount     = 299.99M,
                DiscountAmount  = null,
                Remark          = null,
                Gldate          = DateTime.Now,
                SupplierId      = supplier.SupplierId,
                ContractId      = null,
                PoquoteId       = null,
                Description     = "back to school",
                PurchaseOrderId = null,
                Tax             = 16.08M,
                AccountId       = chartOfAccount.AccountId,
                DocType         = "STD",
                PaymentTerms    = "Net 30",
                DiscountPercent = 0,
                AmountOpen      = 0M,
                OrderNumber     = "PO-2",
                AmountPaid      = 299.99M,
            };
            NextNumber nnNextNumber = await AccountPayableMod.AccountPayable.Query().GetNextNumber();

            view.AccountPayableNumber = nnNextNumber.NextNumberValue;

            AccountPayable accountPayable = await AccountPayableMod.AccountPayable.Query().MapToEntity(view);

            AccountPayableMod.AccountPayable.AddAccountPayable(accountPayable).Apply();

            AccountPayable newAccountPayable = await AccountPayableMod.AccountPayable.Query().GetEntityByNumber(view.AccountPayableNumber);

            Assert.NotNull(newAccountPayable);

            //Add Account Payable Detail for an invoice detail payment
            AccountPayableDetailModule AccountPayableDetailMod = new AccountPayableDetailModule();

            Invoice invoice = await AccountPayableDetailMod.Invoice.Query().GetEntityById(20);

            InvoiceDetail invoiceDetail = await AccountPayableDetailMod.InvoiceDetail.Query().GetEntityById(21);

            PurchaseOrderDetail purchaseOrderDetail = await AccountPayableDetailMod.PurchaseOrderDetail.Query().GetEntityById(invoiceDetail.PurchaseOrderDetailId);

            AccountPayableDetailView accountPayableDetailView = new AccountPayableDetailView()
            {
                InvoiceId                  = invoice.InvoiceId,
                InvoiceDetailId            = invoiceDetail.InvoiceDetailId,
                UnitPrice                  = invoiceDetail.UnitPrice,
                Quantity                   = invoiceDetail.Quantity,
                QuantityReceived           = purchaseOrderDetail.ReceivedQuantity,
                Amount                     = purchaseOrderDetail.Amount,
                AmountPaid                 = invoiceDetail.Amount,
                PurchaseOrderDetailId      = invoiceDetail.PurchaseOrderDetailId,
                SalesOrderDetailId         = invoiceDetail.SalesOrderDetailId,
                ItemId                     = invoiceDetail.ItemId,
                ExtendedDescription        = invoiceDetail.ExtendedDescription,
                PurchaseOrderId            = invoiceDetail.PurchaseOrderId,
                CustomerId                 = invoiceDetail.CustomerId,
                SupplierId                 = invoiceDetail.SupplierId,
                AccountPayableId           = newAccountPayable.AccountPayableId,
                AccountPayableDetailNumber = (await AccountPayableDetailMod.AccountPayableDetail.Query().GetNextNumber()).NextNumberValue
            };

            AccountPayableDetail accountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().MapToEntity(accountPayableDetailView);

            AccountPayableDetailMod.AccountPayableDetail.AddAccountPayableDetail(accountPayableDetail).Apply();

            AccountPayableDetail newAccountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().GetEntityByNumber(accountPayableDetailView.AccountPayableDetailNumber);

            Assert.NotNull(newAccountPayableDetail);


            newAccountPayable.PaymentTerms = "Net 30 Update";

            AccountPayableMod.AccountPayable.UpdateAccountPayable(newAccountPayable).Apply();

            AccountPayableView updateView = await AccountPayableMod.AccountPayable.Query().GetViewById(newAccountPayable.AccountPayableId);

            Assert.Same(updateView.PaymentTerms, "Net 30 Update");

            AccountPayableDetailMod.AccountPayableDetail.DeleteAccountPayableDetail(newAccountPayableDetail).Apply();
            AccountPayableDetail lookupAccountPayableDetail = await AccountPayableDetailMod.AccountPayableDetail.Query().GetEntityById(accountPayableDetailView.AccountPayableDetailId);

            Assert.Null(lookupAccountPayableDetail);

            AccountPayableMod.AccountPayable.DeleteAccountPayable(newAccountPayable).Apply();
            AccountPayable lookupAccountPayable = await AccountPayableMod.AccountPayable.Query().GetEntityById(view.AccountPayableId);

            Assert.Null(lookupAccountPayable);
        }
Exemple #12
0
 public IFluentAccountPayable AddAccountPayable(AccountPayable newObject)
 {
     unitOfWork.accountPayableRepository.AddObject(newObject);
     this.processStatus = CreateProcessStatus.Insert;
     return(this as IFluentAccountPayable);
 }
Exemple #13
0
 public IFluentAccountPayable DeleteAccountPayable(AccountPayable deleteObject)
 {
     unitOfWork.accountPayableRepository.DeleteObject(deleteObject);
     this.processStatus = CreateProcessStatus.Delete;
     return(this as IFluentAccountPayable);
 }
Exemple #14
0
        public async Task TestAddUpdatDelete()
        {
            JobMasterModule JobMasterMod = new JobMasterModule();
            Customer        customer     = await JobMasterMod.Customer.Query().GetEntityById(12);

            AddressBook addressBookCustomer = await JobMasterMod.AddressBook.Query().GetEntityById(customer?.AddressId);

            Contract contract = await JobMasterMod.Contract.Query().GetEntityById(5);

            //public long? ProjectManagerId { get; set; }
            JobMasterView view = new JobMasterView()
            {
                CustomerId               = customer.CustomerId,
                CustomerName             = addressBookCustomer?.Name,
                ContractId               = contract.ContractId,
                ContractTitle            = contract?.Title,
                JobDescription           = "Kuna 4 plex project",
                Address1                 = " 123 ABC",
                City                     = "Kuna",
                State                    = "Id",
                Zipcode                  = "83709",
                TotalCommittedAmount     = 600000,
                RemainingCommittedAmount = 400000,
                RetainageAmount          = 200000,
                JobMasterNumber          = (await JobMasterMod.JobMaster.Query().GetNextNumber()).NextNumberValue
            };

            JobMaster jobMaster = await JobMasterMod.JobMaster.Query().MapToEntity(view);

            JobMasterMod.JobMaster.AddJobMaster(jobMaster).Apply();

            JobMaster newJobMaster = await JobMasterMod.JobMaster.Query().GetEntityByNumber(view.JobMasterNumber);

            JobCostType jobPhaseCostTypeMisc = await JobMasterMod.JobCostType.Query().GetEntityById(4);

            Assert.NotNull(newJobMaster);

            IList <JobPhaseView> listJobPhaseViews = new List <JobPhaseView> {
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Work Site Preparation - Safety",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                },
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Foundations",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                },
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Building Structure",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                }
                ,
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Facade",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                }
                ,
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Interior Construction",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                }
                ,
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Commissioning",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                }
                ,
                new JobPhaseView {
                    ContractId     = contract.ContractId,
                    ContractTitle  = contract.Title,
                    JobMasterId    = newJobMaster.JobMasterId,
                    JobDescription = newJobMaster.JobDescription,
                    PhaseGroup     = 1,
                    Phase          = "Grading and Landscaping",
                    JobPhaseNumber = (await JobMasterMod.JobPhase.Query().GetNextNumber()).NextNumberValue,
                    JobCostTypeId  = jobPhaseCostTypeMisc.JobCostTypeId,
                    CostCode       = jobPhaseCostTypeMisc.CostCode
                }
            };

            IList <JobPhase> listJobPhases = await JobMasterMod.JobPhase.Query().MapToEntity(listJobPhaseViews);

            JobMasterMod.JobPhase.AddJobPhases(listJobPhases.ToList <JobPhase>()).Apply();

            //Add Purchase Order
            PurchaseOrderModule PurchaseOrderMod = new PurchaseOrderModule();
            ChartOfAccount      chartOfAccount   = await PurchaseOrderMod.ChartOfAccount.Query().GetEntityById(16);

            Supplier supplier = await PurchaseOrderMod.Supplier.Query().GetEntityById(3);

            AddressBook addressBook = await PurchaseOrderMod.AddressBook.Query().GetEntityById(supplier?.AddressId);

            Contract pocontract = await PurchaseOrderMod.Contract.Query().GetEntityById(5);

            Buyer buyer = await PurchaseOrderMod.Buyer.Query().GetEntityById(1);

            AddressBook buyerAddressBook = await PurchaseOrderMod.AddressBook.Query().GetEntityById(buyer?.AddressId);

            TaxRatesByCode taxRatesByCode = await PurchaseOrderMod.TaxRatesByCode.Query().GetEntityById(1);

            //create purchase order and detail
            PurchaseOrderView viewPurchaseOrder = new PurchaseOrderView()
            {
                DocType               = "STD",
                PaymentTerms          = "Net 30",
                Amount                = (24 * 75) + 25,
                AmountPaid            = 0,
                Remark                = " installation not included ",
                Gldate                = DateTime.Parse("1/14/2020"),
                AccountId             = chartOfAccount.AccountId,
                Location              = chartOfAccount.Location,
                BusUnit               = chartOfAccount.BusUnit,
                Subsidiary            = chartOfAccount.Subsidiary,
                SubSub                = chartOfAccount.SubSub,
                Account               = chartOfAccount.Account,
                AccountDescription    = chartOfAccount.Description,
                SupplierId            = supplier.SupplierId,
                CustomerId            = contract?.CustomerId,
                SupplierName          = addressBook.Name,
                ContractId            = contract?.ContractId,
                Description           = " Standard doors - white",
                Ponumber              = "PO-123",
                TakenBy               = "David Nishimoto",
                ShippedToName         = " abc corp",
                ShippedToAddress1     = " 123 abc",
                ShippedToAddress2     = " zone 1",
                ShippedToCity         = "Kuna",
                ShippedToState        = "ID",
                ShippedToZipcode      = "83709",
                BuyerId               = buyer.BuyerId,
                BuyerName             = buyerAddressBook?.Name,
                RequestedDate         = DateTime.Parse("1/20/2014"),
                PromisedDeliveredDate = DateTime.Parse("1/20/2014"),
                Tax                 = 24 * 75 * taxRatesByCode.TaxRate,
                TransactionDate     = DateTime.Parse("1/14/2020"),
                TaxCode1            = taxRatesByCode.TaxCode,
                TaxCode2            = "",
                TaxRate             = taxRatesByCode.TaxRate ?? 0,
                PurchaseOrderNumber = (await PurchaseOrderMod.PurchaseOrder.Query().GetNextNumber()).NextNumberValue
            };

            PurchaseOrder purchaseOrder = await PurchaseOrderMod.PurchaseOrder.Query().MapToEntity(viewPurchaseOrder);

            PurchaseOrderMod.PurchaseOrder.AddPurchaseOrder(purchaseOrder).Apply();

            PurchaseOrder newPurchaseOrder = await PurchaseOrderMod.PurchaseOrder.Query().GetEntityByNumber(viewPurchaseOrder.PurchaseOrderNumber);

            Supplier supplierPODetail = await PurchaseOrderMod.Supplier.Query().GetEntityById(newPurchaseOrder?.SupplierId);

            AddressBook addressBookSupplier = await PurchaseOrderMod.AddressBook.Query().GetEntityById(supplierPODetail?.AddressId);

            IList <PurchaseOrderDetailView> listPurchaseOrderDetailViews = new List <PurchaseOrderDetailView> {
                new PurchaseOrderDetailView()
                {
                    PurchaseOrderId           = newPurchaseOrder.PurchaseOrderId,
                    Amount                    = 75 * 24,
                    OrderedQuantity           = 24,
                    LineDescription           = "Standard Door",
                    LineNumber                = 1,
                    UnitPrice                 = 75,
                    UnitOfMeasure             = "Each",
                    ExpectedDeliveryDate      = DateTime.Parse("1/30/2020"),
                    OrderDate                 = DateTime.Parse("1/16/2020"),
                    ReceivedQuantity          = 0,
                    RemainingQuantity         = 24,
                    SupplierId                = newPurchaseOrder.SupplierId,
                    SupplierName              = addressBookSupplier?.Name,
                    PurchaseOrderDetailNumber = (await PurchaseOrderMod.PurchaseOrderDetail.Query().GetNextNumber()).NextNumberValue
                },
                new PurchaseOrderDetailView()
                {
                    PurchaseOrderId           = newPurchaseOrder.PurchaseOrderId,
                    Amount                    = 25 * 1,
                    OrderedQuantity           = 25,
                    LineDescription           = "Door Hinges",
                    LineNumber                = 2,
                    UnitPrice                 = 25,
                    UnitOfMeasure             = "Box",
                    ExpectedDeliveryDate      = DateTime.Parse("1/30/2020"),
                    OrderDate                 = DateTime.Parse("1/16/2020"),
                    ReceivedQuantity          = 0,
                    RemainingQuantity         = 24,
                    SupplierId                = newPurchaseOrder.SupplierId,
                    SupplierName              = addressBookSupplier?.Name,
                    PurchaseOrderDetailNumber = (await PurchaseOrderMod.PurchaseOrderDetail.Query().GetNextNumber()).NextNumberValue
                }
            };
            IList <PurchaseOrderDetail> listPurchaseOrderDetail = await PurchaseOrderMod.PurchaseOrderDetail.Query().MapToEntity(listPurchaseOrderDetailViews);

            PurchaseOrderMod.PurchaseOrderDetail.AddPurchaseOrderDetails(listPurchaseOrderDetail.ToList <PurchaseOrderDetail>()).Apply();

            IList <PurchaseOrderDetail> listNewPurchaseOrderDetail = await PurchaseOrderMod.PurchaseOrderDetail.Query().GetEntitiesByPurchaseOrderId(newPurchaseOrder.PurchaseOrderId);


            //*****************Create Accounts Payable

            AccountPayableModule AccountPayableMod = new AccountPayableModule();
            ChartOfAccount       chartOfAccount2   = await AccountPayableMod.ChartOfAccount.Query().GetEntityById(17);

            AccountPayableView accountPayableView = new AccountPayableView()
            {
                DocNumber            = (await AccountPayableMod.AccountPayable.Query().GetNextDocNumber()),
                GrossAmount          = newPurchaseOrder.Amount,
                Tax                  = newPurchaseOrder.Tax,
                DiscountAmount       = null,
                Remark               = null,
                Gldate               = DateTime.Now,
                SupplierId           = newPurchaseOrder.SupplierId,
                ContractId           = newPurchaseOrder.ContractId,
                PoquoteId            = null,
                Description          = newPurchaseOrder.Description,
                PurchaseOrderId      = newPurchaseOrder.PurchaseOrderId,
                AccountId            = chartOfAccount.AccountId,
                DocType              = "STD",
                PaymentTerms         = newPurchaseOrder.PaymentTerms,
                DiscountPercent      = 0,
                AmountOpen           = newPurchaseOrder.Amount,
                OrderNumber          = newPurchaseOrder.Ponumber,
                AmountPaid           = 0,
                AccountPayableNumber = (await AccountPayableMod.AccountPayable.Query().GetNextNumber()).NextNumberValue
            };

            AccountPayable accountPayable = await AccountPayableMod.AccountPayable.Query().MapToEntity(accountPayableView);

            AccountPayableMod.AccountPayable.AddAccountPayable(accountPayable).Apply();
            AccountPayable lookupAccountPayable = await AccountPayableMod.AccountPayable.Query().GetEntityByNumber(accountPayableView.AccountPayableNumber);

            //****************Create the invoice payment
            InvoiceModule invoiceMod = new InvoiceModule();
            Supplier      supplier2  = await invoiceMod.Supplier.Query().GetEntityById(purchaseOrder.SupplierId);

            AddressBook addressBookSupplinvModier2 = await invoiceMod.AddressBook.Query().GetEntityById(supplier?.AddressId);

            TaxRatesByCode taxRatesByCode2 = await invoiceMod.TaxRatesByCode.Query().GetEntityByTaxCode(purchaseOrder.TaxCode1);

            NextNumber nextNumber = await invoiceMod.Invoice.Query().GetNextNumber();

            InvoiceView invoiceView = new InvoiceView
            {
                InvoiceDocument  = "Inv-" + nextNumber.NextNumberValue.ToString(),
                InvoiceDate      = DateTime.Parse("1/17/2020"),
                Amount           = purchaseOrder.Amount,
                SupplierId       = supplier2?.SupplierId,
                SupplierName     = addressBookCustomer?.Name,
                Description      = purchaseOrder.Description,
                PaymentTerms     = purchaseOrder.PaymentTerms,
                TaxAmount        = taxRatesByCode2.TaxRate * purchaseOrder.Amount,
                CompanyId        = 1,
                TaxRatesByCodeId = taxRatesByCode2.TaxRatesByCodeId,
                InvoiceNumber    = nextNumber.NextNumberValue
            };

            Invoice invoice = await invoiceMod.Invoice.Query().MapToEntity(invoiceView);

            invoiceMod.Invoice.AddInvoice(invoice).Apply();

            Invoice newInvoice = await invoiceMod.Invoice.Query().GetEntityByNumber(invoiceView.InvoiceNumber);

            InvoiceDetailModule       invDetailMod           = new InvoiceDetailModule();
            IList <InvoiceDetailView> listInvoiceDetailViews = new List <InvoiceDetailView>();

            foreach (var item in listNewPurchaseOrderDetail)
            {
                InvoiceDetailView invoiceDetailView = new InvoiceDetailView()
                {
                    Amount                = item.Amount,
                    InvoiceId             = newInvoice.InvoiceId,
                    InvoiceDetailNumber   = (await invDetailMod.InvoiceDetail.Query().GetNextNumber()).NextNumberValue,
                    UnitOfMeasure         = item.UnitOfMeasure,
                    Quantity              = (int)item.OrderedQuantity,
                    UnitPrice             = item.UnitPrice,
                    DiscountPercent       = 0,
                    DiscountAmount        = 0,
                    SupplierId            = item.SupplierId,
                    SupplierName          = (await(invDetailMod.AddressBook.Query().GetEntityById((await invDetailMod.Supplier.Query().GetEntityById(item.SupplierId)).AddressId))).Name,
                    PurchaseOrderId       = item.PurchaseOrderId,
                    PurchaseOrderDetailId = item.PurchaseOrderDetailId,
                    ExtendedDescription   = item.LineDescription
                };
                listInvoiceDetailViews.Add(invoiceDetailView);
            }

            List <InvoiceDetail> listInvoiceDetails = (await invDetailMod.InvoiceDetail.Query().MapToEntity(listInvoiceDetailViews)).ToList <InvoiceDetail>();

            invDetailMod.InvoiceDetail.AddInvoiceDetails(listInvoiceDetails).Apply();


            IList <InvoiceDetail> listLookupInvoiceDetails = await invDetailMod.InvoiceDetail.Query().GetEntitiesByInvoiceId(newInvoice.InvoiceId);

            //Update Accounts Payable - by invoices associated to a po

            IList <Invoice> listInvoiceByPurchaseOrder = await invoiceMod.Invoice.Query().GetEntitiesByPurchaseOrderId(newPurchaseOrder.PurchaseOrderId);

            lookupAccountPayable.AmountOpen = lookupAccountPayable.GrossAmount - listInvoiceByPurchaseOrder.Sum(e => e.Amount);
            AccountPayableMod.AccountPayable.UpdateAccountPayable(lookupAccountPayable).Apply();

            //add to job costing PO
            JobCostLedgerModule JobCostLedgerMod = new JobCostLedgerModule();
            JobPhase            jobPhase2        = await JobMasterMod.JobPhase.Query().GetEntityByJobIdAndPhase(newJobMaster.JobMasterId, "Work Site Preparation - Safety");

            JobCostType jobCostTypeMisc = await JobMasterMod.JobCostType.Query().GetEntityById(2);

            JobCostType jobCostTypeMaterial = await JobMasterMod.JobCostType.Query().GetEntityById(1);

            IList <JobCostLedgerView> listJobCostLedgerView = new List <JobCostLedgerView>
            {
                new JobCostLedgerView()
                {
                    JobMasterId         = jobMaster.JobMasterId,
                    ContractId          = jobMaster.ContractId,
                    EstimatedHours      = 0,
                    EstimatedAmount     = 0,
                    JobPhaseId          = jobPhase2.JobPhaseId,
                    ActualHours         = 0,
                    ActualCost          = 0,
                    ProjectedHours      = 0,
                    CommittedHours      = 0,
                    PurchaseOrderId     = newPurchaseOrder.PurchaseOrderId,
                    SupplierId          = newPurchaseOrder.SupplierId,
                    CommittedAmount     = newPurchaseOrder.Amount,
                    Description         = newPurchaseOrder.Description,
                    TransactionType     = "PO",
                    Source              = "Job Costing",
                    JobCostTypeId       = jobCostTypeMisc.JobCostTypeId,
                    JobCostLedgerNumber = (await JobCostLedgerMod.JobCostLedger.Query().GetNextNumber()).NextNumberValue
                },
                new JobCostLedgerView()
                {
                    JobMasterId         = jobMaster.JobMasterId,
                    ContractId          = jobMaster.ContractId,
                    EstimatedHours      = 0,
                    EstimatedAmount     = 0,
                    JobPhaseId          = jobPhase2.JobPhaseId,
                    ActualHours         = 0,
                    ActualCost          = lookupAccountPayable.AmountPaid,
                    ProjectedHours      = 0,
                    CommittedHours      = 0,
                    PurchaseOrderId     = lookupAccountPayable.PurchaseOrderId,
                    SupplierId          = lookupAccountPayable.SupplierId,
                    CommittedAmount     = 0,
                    Description         = lookupAccountPayable.Description,
                    TransactionType     = "AP",
                    Source              = "Job Costing",
                    TaxAmount           = lookupAccountPayable.Tax,
                    JobCostTypeId       = jobCostTypeMaterial.JobCostTypeId,
                    JobCostLedgerNumber = (await JobCostLedgerMod.JobCostLedger.Query().GetNextNumber()).NextNumberValue
                }
            };

            IList <JobCostLedger> listJobCostLedger = await JobCostLedgerMod.JobCostLedger.Query().MapToEntity(listJobCostLedgerView);

            JobCostLedgerMod.JobCostLedger.AddJobCostLedgers(listJobCostLedger.ToList <JobCostLedger>()).Apply();


            //Create the general ledger entry
            //Create the supplier ledger entry
            //Create Pay Roll
            //Add Pay Roll to job costing


            invDetailMod.InvoiceDetail.DeleteInvoiceDetails((listLookupInvoiceDetails).ToList <InvoiceDetail>()).Apply();
            invoiceMod.Invoice.DeleteInvoice(newInvoice).Apply();
            AccountPayableMod.AccountPayable.DeleteAccountPayable(lookupAccountPayable).Apply();
            PurchaseOrderMod.PurchaseOrderDetail.DeletePurchaseOrderDetails(listPurchaseOrderDetail.ToList <PurchaseOrderDetail>()).Apply();
            JobMasterMod.JobPhase.DeleteJobPhases(listJobPhases.ToList <JobPhase>()).Apply();
            IList <JobPhase> lookupListJobPhases = await JobMasterMod.JobPhase.Query().GetEntitiesByJobMasterId(newJobMaster.JobMasterId);

            if (lookupListJobPhases.Count > 0)
            {
                Assert.True(false);
            }
            newJobMaster.JobDescription = "JobMaster Test Update";
            JobMasterMod.JobMaster.UpdateJobMaster(newJobMaster).Apply();
            JobMasterView updateView = await JobMasterMod.JobMaster.Query().GetViewById(newJobMaster.JobMasterId);

            Assert.Same(updateView.JobDescription, "JobMaster Test Update");
            JobMasterMod.JobMaster.DeleteJobMaster(newJobMaster).Apply();
            JobMaster lookupJobMaster = await JobMasterMod.JobMaster.Query().GetEntityById(view.JobMasterId);

            Assert.Null(lookupJobMaster);
        }