public async Task <IActionResult> FinishAddition(InvoiceOutEditModel input)
        {
            var invoiceId = await this.invoicesService.SaveInvoiceOut(input);

            await this.invoicesService.UpdateInvoiceOutStatusAsync(invoiceId, InvoiceStatusNames.AwaitingPayment.ToString());

            this.notyfService.Success(this.localizer["Invoice filed."]);

            return(this.Redirect(@$ "/Invoices/GenerateInvoice/{invoiceId}"));
        }
Example #2
0
        public async Task <string> SaveInvoiceOut(InvoiceOutEditModel input)
        {
            var invoice = this.invoiceOuts.All().FirstOrDefault(i => i.Id == input.Id);

            if (invoice is null)
            {
                throw new ArgumentException("Invoice do not exist.");
            }

            invoice.Number        = input.Number;
            invoice.CreateDate    = input.CreateDate;
            invoice.DueDays       = input.DueDays;
            invoice.BankDetailsId = input.BankDetailsId;
            invoice.VATReasonId   = input.VATReasonId;
            if (invoice.NoteInfo != null)
            {
                invoice.NoteInfo.Details    = input.NoteInfo.Details;
                invoice.NoteInfo.Amount     = input.NoteInfo.Amount;
                invoice.NoteInfo.CurrencyId = input.NoteInfo.CurrencyId;
            }
            else
            {
                foreach (var orderToInput in input.OrderTos)
                {
                    var orderTo = this.orderTos.All().FirstOrDefault(o => o.Id == orderToInput.Id);
                    if (orderTo.InvoiceOut is null)
                    {
                        orderTo.InvoiceOut = invoice;
                    }
                }

                await this.orderTos.SaveChangesAsync();

                foreach (var orderTo in invoice.OrderTos)
                {
                    if (!input.OrderTos.Any(o => o.Id == orderTo.Id))
                    {
                        orderTo.InvoiceInId = null;
                    }
                }
            }

            this.invoiceOuts.Update(invoice);
            await this.invoiceOuts.SaveChangesAsync();

            return(invoice.Id);
        }
        public async Task <IActionResult> SaveOut(InvoiceOutEditModel input)
        {
            await this.invoicesService.SaveInvoiceOut(input);

            return(this.RedirectToAction("Unfinished"));
        }