Ejemplo n.º 1
0
        public override async Task <InvoiceView> MapToView(Invoice inputObject)
        {
            InvoiceView outObject = mapper.Map <InvoiceView>(inputObject);

            Task <Supplier>       supplierTask       = _unitOfWork.supplierRepository.GetEntityById(inputObject?.SupplierId);
            Task <Customer>       customerTask       = _unitOfWork.customerRepository.GetEntityById(inputObject?.CustomerId);
            Task <TaxRatesByCode> taxRatesByCodeTask = _unitOfWork.taxRateByCodeRepository.GetEntityById(inputObject.TaxRatesByCodeId);

            Task.WaitAll(supplierTask, customerTask, taxRatesByCodeTask);

            Task <AddressBook> addressBookSupplierTask = _unitOfWork.addressBookRepository.GetEntityById(supplierTask.Result?.AddressId);
            Task <AddressBook> addressBookCustomerTask = _unitOfWork.addressBookRepository.GetEntityById(customerTask.Result?.AddressId);

            Task.WaitAll(addressBookSupplierTask, addressBookCustomerTask);

            outObject.SupplierName = addressBookSupplierTask.Result?.Name;
            outObject.CustomerName = addressBookCustomerTask.Result?.Name;
            outObject.TaxCode      = taxRatesByCodeTask.Result.TaxCode;

            List <InvoiceDetailView> viewsList           = new List <InvoiceDetailView>();
            FluentInvoiceDetail      fluentInvoiceDetail = new FluentInvoiceDetail(_unitOfWork);
            IList <InvoiceDetail>    list = await fluentInvoiceDetail.Query().GetEntitiesByInvoiceId(inputObject?.InvoiceId);

            foreach (var item in list)
            {
                viewsList.Add(await fluentInvoiceDetail.Query().MapToView(item));
            }
            outObject.InvoiceDetailViews = viewsList;
            await Task.Yield();

            return(outObject);
        }
Ejemplo n.º 2
0
        public async Task <bool> PostInvoiceAndDetailToAcctRec(InvoiceView invoiceView)
        {
            try
            {
                Invoice invoiceNew = await Invoice.Query().MapToEntity(invoiceView);

                Invoice
                .AddInvoice(invoiceNew)
                .Apply();

                Invoice invoiceLookup = await Invoice.Query().GetEntityByInvoiceDocument(invoiceView.InvoiceDocument);

                invoiceView.InvoiceId = invoiceLookup.InvoiceId;

                //Assign the InvoiceId
                for (int i = 0; i < invoiceView.InvoiceDetailViews.Count; i++)
                {
                    invoiceView.InvoiceDetailViews[i].InvoiceId = invoiceLookup.InvoiceId;
                    InvoiceDetail invoiceDetail = await InvoiceDetail.Query().MapToEntity(invoiceView.InvoiceDetailViews[i]);

                    InvoiceDetail.AddInvoiceDetail(invoiceDetail);
                }

                InvoiceDetail.Apply();

                await AccountReceivable
                .UpdateAccountReceivableByInvoiceView(invoiceView);

                AccountReceivable.Apply();

                await GeneralLedger
                .CreateGeneralLedgerByInvoiceView(invoiceView);

                GeneralLedger.Apply();

                AccountReceivable acctRecLookup = await AccountReceivable.Query().GetEntityByPurchaseOrderId(invoiceView.PurchaseOrderId);

                GeneralLedger.UpdateLedgerBalances(acctRecLookup.DocNumber ?? 0, "OV");

                await CustomerLedger
                .CreateCustomerLedgerByInvoiceView(invoiceView);

                CustomerLedger.Apply();


                return(true);
            }
            catch (Exception ex) { throw new Exception("PostInvoiceAndDetailToAcctRec", ex); }
        }