Beispiel #1
0
        public async Task <IActionResult> DeleteTaxRatesByCode([FromBody] TaxRatesByCodeView view)
        {
            TaxRatesByCodeModule invMod         = new TaxRatesByCodeModule();
            TaxRatesByCode       TaxRatesByCode = await invMod.TaxRatesByCode.Query().MapToEntity(view);

            invMod.TaxRatesByCode.DeleteTaxRatesByCode(TaxRatesByCode).Apply();

            return(Ok(view));
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateTaxRatesByCode([FromBody] TaxRatesByCodeView view)
        {
            TaxRatesByCodeModule invMod = new TaxRatesByCodeModule();

            TaxRatesByCode TaxRatesByCode = await invMod.TaxRatesByCode.Query().MapToEntity(view);


            invMod.TaxRatesByCode.UpdateTaxRatesByCode(TaxRatesByCode).Apply();

            TaxRatesByCodeView retView = await invMod.TaxRatesByCode.Query().GetViewById(TaxRatesByCode.TaxRatesByCodeId);


            return(Ok(retView));
        }
Beispiel #3
0
        public async Task <TaxRatesByCode> GetTaxRateByCode(string TaxCode)
        {
            try
            {
                Entities _dbEntities = (Entities)_dbContext;

                TaxRatesByCode tax = await(from e in _dbEntities.TaxRatesByCodes
                                           where e.TaxCode == TaxCode
                                           select e).FirstOrDefaultAsync <TaxRatesByCode>();

                return(tax);
            }
            catch (Exception ex)
            { throw new Exception(GetMyMethodName(), ex); }
        }
Beispiel #4
0
        public async Task <IActionResult> AddTaxRatesByCode([FromBody] TaxRatesByCodeView view)
        {
            TaxRatesByCodeModule invMod = new TaxRatesByCodeModule();

            NextNumber nnTaxRatesByCode = await invMod.TaxRatesByCode.Query().GetNextNumber();

            view.TaxRatesByCodeNumber = nnTaxRatesByCode.NextNumberValue;

            TaxRatesByCode TaxRatesByCode = await invMod.TaxRatesByCode.Query().MapToEntity(view);

            invMod.TaxRatesByCode.AddTaxRatesByCode(TaxRatesByCode).Apply();

            TaxRatesByCodeView newView = await invMod.TaxRatesByCode.Query().GetViewByNumber(view.TaxRatesByCodeNumber);

            return(Ok(newView));
        }
Beispiel #5
0
        public async Task TestAddUpdatDeleteComment()
        {
            TaxRatesByCodeModule TaxRatesByCodeMod = new TaxRatesByCodeModule();

            TaxRatesByCodeView view = new TaxRatesByCodeView()
            {
                TaxCode = "StateTaxUT",
                TaxRate = 4.85M,
                State   = "UT"
            };
            NextNumber nnNextNumber = await TaxRatesByCodeMod.TaxRatesByCode.Query().GetNextNumber();

            view.TaxRatesByCodeNumber = nnNextNumber.NextNumberValue;

            TaxRatesByCode taxRatesByCode = await TaxRatesByCodeMod.TaxRatesByCode.Query().MapToEntity(view);

            TaxRatesByCodeMod.TaxRatesByCode.AddTaxRatesByCode(taxRatesByCode).Apply();

            TaxRatesByCode newTaxRatesByCode = await TaxRatesByCodeMod.TaxRatesByCode.Query().GetEntityByNumber(view.TaxRatesByCodeNumber);

            Assert.NotNull(newTaxRatesByCode);

            newTaxRatesByCode.TaxRate = 4.86M;

            TaxRatesByCodeMod.TaxRatesByCode.UpdateTaxRatesByCode(newTaxRatesByCode).Apply();

            TaxRatesByCodeView updateView = await TaxRatesByCodeMod.TaxRatesByCode.Query().GetViewById(newTaxRatesByCode.TaxRatesByCodeId);

            string taxRatesByCodeString = updateView.TaxRate.ToString();

            Assert.NotSame(taxRatesByCodeString, "4.86");

            TaxRatesByCodeView lookupByCode = await TaxRatesByCodeMod.TaxRatesByCode.Query().GetViewByTaxCode(TypeofTaxRatesByCode.StateTaxUT.ToString());

            Assert.NotNull(lookupByCode);

            TaxRatesByCodeMod.TaxRatesByCode.DeleteTaxRatesByCode(newTaxRatesByCode).Apply();
            TaxRatesByCode lookupTaxRatesByCode = await TaxRatesByCodeMod.TaxRatesByCode.Query().GetEntityById(view.TaxRatesByCodeId);

            Assert.Null(lookupTaxRatesByCode);
        }
        public async Task <CreateProcessStatus> CreatePurchaseOrderByView(PurchaseOrderView purchaseOrderView)
        {
            decimal grossAmount = 0;

            try
            {
                //check if PO exists
                var queryPO = await(from e in _dbContext.PurchaseOrders
                                    where e.PONumber == purchaseOrderView.PONumber

                                    select e).FirstOrDefaultAsync <PurchaseOrder>();
                if (queryPO != null)
                {
                    return(CreateProcessStatus.AlreadyExists);
                }


                foreach (var detail in purchaseOrderView.PurchaseOrderDetailViews)
                {
                    grossAmount += detail.Amount ?? 0;
                }
                purchaseOrderView.GrossAmount = grossAmount;
                purchaseOrderView.AmountPaid  = 0;

                TaxRatesByCode tax = await base.GetTaxRateByCode(purchaseOrderView.TaxCode1);

                purchaseOrderView.Tax = grossAmount * tax.TaxRate;

                PurchaseOrder po = new PurchaseOrder();
                applicationViewFactory.MapPurchaseOrderEntity(ref po, purchaseOrderView);

                base.AddObject(po);

                return(CreateProcessStatus.Insert);
            }
            catch (Exception ex) { throw new Exception(GetMyMethodName(), ex); }
        }
Beispiel #7
0
        async Task TestCreateAccountReceivableFromPO()
        {
            AddressBook         addressBook      = null;
            AddressBook         buyerAddressBook = null;
            PurchaseOrderModule PurchaseOrderMod = new PurchaseOrderModule();
            ChartOfAccount      account          = await PurchaseOrderMod.ChartOfAccount.Query().GetEntityById(17);

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

            if (supplier != null)
            {
                addressBook = await PurchaseOrderMod.AddressBook.Query().GetEntityById(supplier.AddressId);
            }
            Contract contract = await PurchaseOrderMod.Contract.Query().GetEntityById(1);

            Poquote poquote = await PurchaseOrderMod.POQuote.Query().GetEntityById(2);

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

            if (buyer != null)
            {
                buyerAddressBook = await PurchaseOrderMod.AddressBook.Query().GetEntityById(buyer.AddressId);
            }
            TaxRatesByCode taxRatesByCode = await PurchaseOrderMod.TaxRatesByCode.Query().GetEntityById(1);

            PurchaseOrderView view = new PurchaseOrderView()
            {
                DocType               = "STD",
                PaymentTerms          = "Net 30",
                Amount                = 286.11M,
                AmountPaid            = 0,
                Remark                = "PO Remark",
                Gldate                = DateTime.Parse("11/29/2019"),
                AccountId             = account.AccountId,
                Location              = account.Location,
                BusUnit               = account.BusUnit,
                Subsidiary            = account.Subsidiary,
                SubSub                = account.SubSub,
                Account               = account.Account,
                AccountDescription    = account.Description,
                SupplierId            = supplier.SupplierId,
                CustomerId            = contract?.CustomerId,
                SupplierName          = addressBook.Name,
                ContractId            = contract?.ContractId,
                PoquoteId             = poquote?.PoquoteId,
                QuoteAmount           = poquote?.QuoteAmount,
                Description           = "PO Description",
                Ponumber              = "PO-123",
                TakenBy               = "David Nishimoto",
                ShippedToName         = " shipped name",
                ShippedToAddress1     = "shipped to address1",
                ShippedToAddress2     = "shipped to address2",
                ShippedToCity         = "shipped city",
                ShippedToState        = "ID",
                ShippedToZipcode      = "83709",
                BuyerId               = buyer.BuyerId,
                BuyerName             = buyerAddressBook?.Name,
                RequestedDate         = DateTime.Parse("11/29/2019"),
                PromisedDeliveredDate = DateTime.Parse("11/29/2019"),
                Tax                 = 0M,
                TransactionDate     = DateTime.Parse("11/29/2019"),
                TaxCode1            = taxRatesByCode.TaxCode,
                TaxCode2            = "",
                TaxRate             = taxRatesByCode.TaxRate ?? 0,
                PurchaseOrderNumber = (await PurchaseOrderMod.PurchaseOrder.Query().GetNextNumber()).NextNumberValue
            };

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

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

            Udc udcAccountReceivableType = await PurchaseOrderMod.Udc.Query().GetEntityById(66);

            ChartOfAccount coaAccountReceivable = await PurchaseOrderMod.ChartOfAccount.Query().GetEntityById(4);

            AccountReceivable accountReceivable = await PurchaseOrderMod.AccountReceivable.Query().MapEntityFromPurchaseOrder(purchaseOrder, udcAccountReceivableType, coaAccountReceivable);

            PurchaseOrderMod.AccountReceivable.AddAccountReceivable(accountReceivable).Apply();
        }
Beispiel #8
0
 public IFluentTaxRatesByCode DeleteTaxRatesByCode(TaxRatesByCode deleteObject)
 {
     unitOfWork.taxRateByCodeRepository.DeleteObject(deleteObject);
     this.processStatus = CreateProcessStatus.Delete;
     return(this as IFluentTaxRatesByCode);
 }
Beispiel #9
0
 public IFluentTaxRatesByCode AddTaxRatesByCode(TaxRatesByCode newObject)
 {
     unitOfWork.taxRateByCodeRepository.AddObject(newObject);
     this.processStatus = CreateProcessStatus.Insert;
     return(this as IFluentTaxRatesByCode);
 }
Beispiel #10
0
        public async Task TestObserver()
        {
            InvoiceModule         invMod             = new InvoiceModule();
            ContractInvoiceModule contractInvoiceMod = new ContractInvoiceModule();

            Customer customer = await invMod.Customer.Query().GetEntityById(9);

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

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

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

            InvoiceView invoiceView = new InvoiceView();

            invoiceView.InvoiceDocument  = "Inv-99";
            invoiceView.InvoiceDate      = DateTime.Parse("8/10/2018");
            invoiceView.Amount           = 1500.0M;
            invoiceView.CustomerId       = customer?.CustomerId;
            invoiceView.CustomerName     = addressBookCustomer?.Name;
            invoiceView.Description      = "VNW Fixed Asset project";
            invoiceView.PaymentTerms     = "Net 30";
            invoiceView.TaxAmount        = 0;
            invoiceView.CompanyId        = 1;
            invoiceView.TaxRatesByCodeId = taxRatesByCode.TaxRatesByCodeId;

            invoiceView.InvoiceNumber = nextNumber.NextNumberValue;

            Invoice newInvoice = await invMod.Invoice.Query().MapToEntity(invoiceView);

            Observer mediator = new Observer();

            mediator.SubscribeToObserver(invMod, invMod.MessageFromObserver);
            mediator.SubscribeToObserver(contractInvoiceMod, contractInvoiceMod.MessageFromObserver);


            IObservableAction observedAction = new ObservableAction();

            MessageAction action = new MessageAction {
                targetByName = nameof(Invoice), command_action = TypeOfObservableAction.InsertData, Invoice = newInvoice
            };

            observedAction.Actions.Add(action);

            NextNumber nextNumberContractInvoice = await invMod.ContractInvoice.Query().GetNextNumber();

            ContractInvoiceView contractInvoiceView = new ContractInvoiceView
            {
                InvoiceId             = 5,
                ContractId            = 1,
                ContractInvoiceNumber = nextNumberContractInvoice.NextNumberValue
            };

            ContractInvoice contractInvoice = await invMod.ContractInvoice.Query().MapToEntity(contractInvoiceView);

            MessageAction actionContractInvoice = new MessageAction {
                targetByName = nameof(ContractInvoice), command_action = TypeOfObservableAction.InsertData, ContractInvoice = contractInvoice
            };

            observedAction.Actions.Add(actionContractInvoice);

            mediator.TransmitMessage(observedAction);

            if (observedAction.Actions.Count() > 0)
            {
                Assert.True(false);
            }

            Invoice lookupInvoice = await invMod.Invoice.Query().GetEntityByNumber(invoiceView.InvoiceNumber);

            lookupInvoice.Amount = 9999;

            ContractInvoice lookupContractInvoice = await contractInvoiceMod.ContractInvoice.Query().GetEntityByNumber(contractInvoiceView.ContractInvoiceNumber);


            //*******Contract Invoice


            MessageAction actionInvoiceUpdate = new MessageAction
            {
                targetByName   = nameof(Invoice),
                command_action = TypeOfObservableAction.UpdateData,
                Invoice        = lookupInvoice
            };

            observedAction.Actions.Add(actionInvoiceUpdate);

            MessageAction actionInvoiceDelete = new MessageAction
            {
                targetByName   = nameof(Invoice),
                command_action = TypeOfObservableAction.DeleteData,
                Invoice        = lookupInvoice
            };

            observedAction.Actions.Add(actionInvoiceDelete);

            MessageAction actionContractInvoiceDelete = new MessageAction
            {
                targetByName    = nameof(ContractInvoice),
                command_action  = TypeOfObservableAction.DeleteData,
                ContractInvoice = lookupContractInvoice
            };

            observedAction.Actions.Add(actionContractInvoiceDelete);

            mediator.TransmitMessage(observedAction);

            if (observedAction.Actions.Count() > 0)
            {
                Assert.True(false);
            }

            await Task.Yield();

            Assert.True(true);
        }
Beispiel #11
0
        public async Task TestPostInvoiceAndDetailToAcctRec()
        {
            try
            {
                //NextNumber nextNumber = await unitOfWork.invoiceRepository.Get("InvoiceNumber");
                InvoiceModule           invoiceModule = new InvoiceModule();
                AccountReceivableModule acctRecMod    = new AccountReceivableModule();
                Customer customer = await acctRecMod.Customer.Query().GetEntityById(9);

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

                ChartOfAccount chartOfAccount = await acctRecMod.ChartOfAccount.Query().GetEntity("1000", "1200", "101", "");

                PurchaseOrder purchaseOrder = await acctRecMod.PurchaseOrder.Query().GetEntityById(20);

                Udc udcReceivable = await acctRecMod.Udc.Query().GetEntityById(66);

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

                AccountReceivableView newAccountReceivableView = new AccountReceivableView
                {
                    Amount                  = 1500M,
                    OpenAmount              = 1500M,
                    DiscountDueDate         = DateTime.Parse("1/21/2020"),
                    Gldate                  = DateTime.Parse("1/21/2020"),
                    CreateDate              = DateTime.Parse("1/21/2020"),
                    DocNumber               = (await acctRecMod.AccountReceivable.Query().GetDocNumber()).NextNumberValue,
                    Remark                  = " partial payment",
                    PaymentTerms            = "Net 30",
                    CustomerId              = customer.CustomerId,
                    CustomerName            = addressBookCustomer?.Name,
                    PurchaseOrderId         = purchaseOrder.PurchaseOrderId,
                    Description             = "Fixed Asset Project",
                    AcctRecDocTypeXrefId    = udcReceivable.XrefId,
                    DocType                 = udcReceivable.KeyCode,
                    AccountId               = chartOfAccount.AccountId,
                    AccountReceivableNumber = (await acctRecMod.AccountReceivable.Query().GetNextNumber()).NextNumberValue
                };

                AccountReceivable accountReceivable = await acctRecMod.AccountReceivable.Query().MapToEntity(newAccountReceivableView);

                acctRecMod.AccountReceivable.AddAccountReceivable(accountReceivable).Apply();

                InvoiceView invoiceView = new InvoiceView();

                invoiceView.InvoiceDocument  = accountReceivable.DocNumber.ToString();
                invoiceView.InvoiceDate      = DateTime.Parse("8/10/2018");
                invoiceView.PurchaseOrderId  = purchaseOrder.PurchaseOrderId;
                invoiceView.Amount           = 1500.0M;
                invoiceView.CustomerId       = customer.CustomerId;
                invoiceView.Description      = "VNW Fixed Asset project";
                invoiceView.PaymentTerms     = "Net 30";
                invoiceView.TaxAmount        = 0;
                invoiceView.CompanyId        = 1;
                invoiceView.TaxRatesByCodeId = taxRatesByCode.TaxRatesByCodeId;
                invoiceView.TaxCode          = taxRatesByCode.TaxCode;
                invoiceView.InvoiceNumber    = (await invoiceModule.Invoice.Query().GetNextNumber()).NextNumberValue;


                IList <PurchaseOrderDetail> listPurchaseOrderDetail = await acctRecMod.PurchaseOrderDetail.Query().GetEntitiesByPurchaseOrderId(purchaseOrder.PurchaseOrderId);

                IList <InvoiceDetailView> listInvoiceDetailView = new List <InvoiceDetailView>();
                //invoiceDetailView.InvoiceId = invoice.InvoiceId;

                foreach (var item in listPurchaseOrderDetail)
                {
                    listInvoiceDetailView.Add(
                        new InvoiceDetailView()
                    {
                        UnitOfMeasure         = item.UnitOfMeasure,
                        Quantity              = (int)item.OrderedQuantity,
                        PurchaseOrderId       = item.PurchaseOrderId,
                        PurchaseOrderDetailId = item.PurchaseOrderDetailId,
                        UnitPrice             = item.UnitPrice,
                        Amount              = item.Amount,
                        DiscountPercent     = 0,
                        DiscountAmount      = 0,
                        ItemId              = item.ItemId,
                        InvoiceDetailNumber = (await invoiceModule.InvoiceDetail.Query().GetNextNumber()).NextNumberValue
                    });
                }

                invoiceView.InvoiceDetailViews = listInvoiceDetailView;

                bool result = await invoiceModule.PostInvoiceAndDetailToAcctRec(invoiceView);



                Assert.True(result);
            }
            catch (Exception ex)
            {
                throw new Exception("TestPostInvoiceAndDetailToAcctRec", ex);
            }
        }
Beispiel #12
0
        public async Task TestAddInvoice()
        {
            InvoiceModule       invMod       = new InvoiceModule();
            InvoiceDetailModule invDetailMod = new InvoiceDetailModule();

            Customer customer = await invMod.Customer.Query().GetEntityById(9);

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

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

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

            InvoiceView invoiceView = new InvoiceView();

            invoiceView.InvoiceDocument  = "Inv-99";
            invoiceView.InvoiceDate      = DateTime.Parse("8/10/2018");
            invoiceView.Amount           = 1500.0M;
            invoiceView.CustomerId       = customer?.CustomerId;
            invoiceView.CustomerName     = addressBookCustomer?.Name;
            invoiceView.Description      = "VNW Fixed Asset project";
            invoiceView.PaymentTerms     = "Net 30";
            invoiceView.TaxAmount        = 0;
            invoiceView.CompanyId        = 1;
            invoiceView.TaxRatesByCodeId = taxRatesByCode.TaxRatesByCodeId;

            invoiceView.InvoiceNumber = nextNumber.NextNumberValue;

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

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

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

            InvoiceDetailView invoiceDetailView       = new InvoiceDetailView();
            NextNumber        nextNumberInvoiceDetail = await invDetailMod.InvoiceDetail.Query().GetNextNumber();

            invoiceDetailView.Amount = 1500M;

            invoiceDetailView.InvoiceId           = newInvoice.InvoiceId;
            invoiceDetailView.InvoiceDetailNumber = nextNumberInvoiceDetail.NextNumberValue;

            invoiceDetailView.UnitOfMeasure   = "Project";
            invoiceDetailView.Quantity        = 1;
            invoiceDetailView.UnitPrice       = 1500M;
            invoiceDetailView.Amount          = 1500M;
            invoiceDetailView.DiscountPercent = 0;
            invoiceDetailView.DiscountAmount  = 0;
            invoiceDetailView.ItemId          = 4;
            IList <InvoiceDetailView> listInvoiceDetails = new List <InvoiceDetailView>();

            listInvoiceDetails.Add(invoiceDetailView);
            invoiceView.InvoiceDetailViews = listInvoiceDetails;

            List <InvoiceDetail> list = (await invDetailMod.InvoiceDetail.Query().MapToEntity(invoiceView.InvoiceDetailViews)).ToList <InvoiceDetail>();

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

            invDetailMod.InvoiceDetail.DeleteInvoiceDetails(list).Apply();
            invMod.Invoice.DeleteInvoice(newInvoice).Apply();

            Invoice invoiceLookup = await invMod.Invoice.Query().GetEntityById(newInvoice.InvoiceId);

            Assert.Null(invoiceLookup);
        }
Beispiel #13
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);
        }