Exemple #1
0
        public async Task TestAddUpdatDelete()
        {
            AccountReceivableDetailModule AccountReceivableDetailMod = new AccountReceivableDetailModule();
            Invoice invoice = await AccountReceivableDetailMod.Invoice.Query().GetEntityById(18);

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

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

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

            Udc udc = await AccountReceivableDetailMod.Udc.Query().GetEntityById(66);

            ChartOfAccount chartOfAccount = await AccountReceivableDetailMod.ChartOfAccount.Query().GetEntityById(3);

            AccountReceivableView acctRecView = new AccountReceivableView()
            {
                DiscountDueDate         = DateTime.Parse("2/8/2020"),
                Gldate                  = DateTime.Parse("7/16/2018"),
                InvoiceId               = invoice.InvoiceId,
                CreateDate              = DateTime.Parse("7/16/2018"),
                DocNumber               = (await AccountReceivableDetailMod.AccountReceivable.Query().GetDocNumber()).NextNumberValue,
                Remark                  = "VNW Fixed Asset project",
                PaymentTerms            = "Net 30",
                CustomerId              = customer?.CustomerId ?? 0,
                PurchaseOrderId         = purchaseOrder?.PurchaseOrderId ?? 0,
                Description             = "Fixed Asset Project",
                AcctRecDocTypeXrefId    = udc.XrefId,
                AccountId               = chartOfAccount.AccountId,
                Amount                  = 1500M,
                DebitAmount             = 189.6300M,
                CreditAmount            = 1500,
                OpenAmount              = 1335.37M,
                DiscountPercent         = 0,
                DiscountAmount          = 0,
                AcctRecDocType          = "INV",
                InterestPaid            = 0,
                LateFee                 = 25.0000M,
                AccountReceivableNumber = (await AccountReceivableDetailMod.AccountReceivable.Query().GetNextNumber()).NextNumberValue,
                CustomerPurchaseOrder   = "PO-321",
                Tax             = 0,
                InvoiceDocument = invoice.InvoiceDocument,
                CustomerName    = addressBookCustomer?.Name,
                DocType         = udc.KeyCode
            };

            AccountReceivable newAccountReceivable = await AccountReceivableDetailMod.AccountReceivable.Query().MapToEntity(acctRecView);

            AccountReceivableDetailMod.AccountReceivable.AddAccountReceivable(newAccountReceivable).Apply();
            AccountReceivable lookupAccountReceivable = await AccountReceivableDetailMod.AccountReceivable.Query().GetEntityByNumber(newAccountReceivable.AccountReceivableNumber);

            InvoiceDetail invoiceDetail = await AccountReceivableDetailMod.InvoiceDetail.Query().GetEntityById(6);

            PurchaseOrderDetail purchaseOrderDetail = await AccountReceivableDetailMod.PurchaseOrderDetail.Query().GetEntityById(33);

            ItemMaster itemMaster = await AccountReceivableDetailMod.ItemMaster.Query().GetEntityById(4);

            AccountReceivableDetailView acctRecDetailView = new AccountReceivableDetailView()
            {
                InvoiceId           = invoice.InvoiceId,
                InvoiceDetailId     = invoiceDetail.InvoiceDetailId,
                AccountReceivableId = lookupAccountReceivable.AccountReceivableId,
                UnitPrice           = invoiceDetail.UnitPrice,
                Quantity            = invoiceDetail.Quantity,
                UnitOfMeasure       = invoiceDetail.UnitOfMeasure,
                Amount                        = invoiceDetail.Amount,
                AmountReceived                = 189.6300M,
                PurchaseOrderDetailId         = purchaseOrderDetail.PurchaseOrderDetailId,
                ItemId                        = itemMaster.ItemId,
                AccountReceivableDetailNumber = (await AccountReceivableDetailMod.AccountReceivableDetail.Query().GetNextNumber()).NextNumberValue,
                PurchaseOrderId               = purchaseOrder.PurchaseOrderId,
                CustomerId                    = customer.CustomerId,
                QuantityDelivered             = invoiceDetail.Quantity,
                Comment                       = "possible write off",
                TypeOfPayment                 = "Partial"
            };

            AccountReceivableDetail accountReceivableDetail = await AccountReceivableDetailMod.AccountReceivableDetail.Query().MapToEntity(acctRecDetailView);

            AccountReceivableDetailMod.AccountReceivableDetail.AddAccountReceivableDetail(accountReceivableDetail).Apply();

            AccountReceivableDetail newAccountReceivableDetail = await AccountReceivableDetailMod.AccountReceivableDetail.Query().GetEntityByNumber(acctRecDetailView.AccountReceivableDetailNumber);

            Assert.NotNull(newAccountReceivableDetail);

            newAccountReceivableDetail.Comment = "AccountReceivableDetail Test Update";

            AccountReceivableDetailMod.AccountReceivableDetail.UpdateAccountReceivableDetail(newAccountReceivableDetail).Apply();

            AccountReceivableDetailView updateView = await AccountReceivableDetailMod.AccountReceivableDetail.Query().GetViewById(newAccountReceivableDetail.AccountReceivableDetailId);

            Assert.Same(updateView.Comment, "AccountReceivableDetail Test Update");
            AccountReceivableDetailMod.AccountReceivableDetail.DeleteAccountReceivableDetail(newAccountReceivableDetail).Apply();
            AccountReceivableDetail lookupAccountReceivableDetail = await AccountReceivableDetailMod.AccountReceivableDetail.Query().GetEntityById(acctRecDetailView.AccountReceivableDetailId);

            Assert.Null(lookupAccountReceivableDetail);

            AccountReceivableDetailMod.AccountReceivable.DeleteAccountReceivable(lookupAccountReceivable).Apply();
            AccountReceivable lookupAccountReceivable2 = await AccountReceivableDetailMod.AccountReceivable.Query().GetEntityByNumber(newAccountReceivable.AccountReceivableNumber);

            Assert.Null(lookupAccountReceivable2);
        }
Exemple #2
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);
            }
        }