public async Task <IActionResult> FinishOut(InvoiceOutInputModel input) { var invoiceId = await this.invoicesService.CreateInvoiceOut(input); await this.invoicesService.UpdateInvoiceOutStatusAsync(invoiceId, InvoiceStatusNames.AwaitingPayment.ToString()); this.notyfService.Success(this.localizer["Invoice filed."]); return(this.Redirect(@$ "/Invoices/GenerateInvoice/{invoiceId}")); }
public async Task <IActionResult> SaveForAddition(InvoiceOutInputModel input) { var invoiceId = await this.invoicesService.CreateInvoiceOut(input); await this.invoicesService.UpdateInvoiceOutStatusAsync(invoiceId, InvoiceStatusNames.AwaitingApproval.ToString()); this.notyfService.Success(this.localizer["Invoice filed."]); return(this.RedirectToAction("ForInvoicing")); }
public async Task <string> CreateInvoiceOut(InvoiceOutInputModel input) { var invoice = this.invoiceOuts.All().FirstOrDefault(i => i.Id == input.InvoiceOut.Id); if (invoice is null) { invoice = new InvoiceOut(); await this.invoiceOuts.AddAsync(invoice); } invoice.Number = input.InvoiceOut.Number; invoice.CreateDate = input.InvoiceOut.CreateDate; invoice.DueDays = input.InvoiceOut.DueDays; invoice.BankDetailsId = input.InvoiceOut.BankDetailsId; invoice.VATReasonId = input.InvoiceOut.VATReasonId; 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); }