public IActionResult PutBankExpenditureNote([FromRoute] int deliveryOrderId, [FromBody] BankExpenditureNoteFormDto form) { try { VerifyUser(); var id = _service.UpdateFromBankExpenditureNote(deliveryOrderId, form); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(NoContent()); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }
public async Task <int> BankExpenditureUpdateIsPaidInternalNoteAndInvoiceNote(bool dppVATIsPaid, int bankExpenditureNoteId, string bankExpenditureNoteNo, string internalNoteIds = "[]", string invoiceNoteIds = "[]") { var parsedInternalNoteIds = JsonConvert.DeserializeObject <List <long> >(internalNoteIds); var parsedInvoiceNoteIds = JsonConvert.DeserializeObject <List <long> >(invoiceNoteIds); var internalNotes = dbContext .GarmentInternNotes .Where(entity => parsedInternalNoteIds.Contains(entity.Id)) .ToList() .Select(element => { element.DPPVATIsPaid = dppVATIsPaid; EntityExtension.FlagForUpdate(element, element.CreatedBy, USER_AGENT); return(element); }) .ToList(); dbContext.GarmentInternNotes.UpdateRange(internalNotes); var invoiceNotes = dbContext .GarmentInvoices .Where(entity => parsedInvoiceNoteIds.Contains(entity.Id)) .ToList() .Select(element => { element.DPPVATIsPaid = dppVATIsPaid; EntityExtension.FlagForUpdate(element, element.CreatedBy, USER_AGENT); return(element); }) .ToList(); dbContext.GarmentInvoices.UpdateRange(invoiceNotes); var existingInvoiceNoteIds = invoiceNotes.Select(element => element.Id).ToList(); var invoiceNoteItems = dbContext .GarmentInvoiceItems .Where(entity => existingInvoiceNoteIds.Contains(entity.InvoiceId)) .ToList(); foreach (var invoiceNoteItem in invoiceNoteItems) { var deliveryOrder = dbContext.GarmentDeliveryOrders.FirstOrDefault(entity => entity.Id == invoiceNoteItem.DeliveryOrderId); var invoiceNote = invoiceNotes.FirstOrDefault(element => element.Id == invoiceNoteItem.InvoiceId); if (deliveryOrder != null) { if (dppVATIsPaid) { var amount = 0.0; var currencyAmount = 0.0; var vatAmount = 0.0; var currencyVATAmount = 0.0; var incomeTaxAmount = 0.0; var currencyIncomeTaxAmount = 0.0; if (invoiceNote.CurrencyCode == "IDR") { amount = invoiceNoteItem.TotalAmount; if (invoiceNote.IsPayVat) { vatAmount = invoiceNoteItem.TotalAmount * 0.1; } if (invoiceNote.IsPayTax) { incomeTaxAmount = invoiceNoteItem.TotalAmount * invoiceNote.IncomeTaxRate / 100; } } else { amount = invoiceNoteItem.TotalAmount * deliveryOrder.DOCurrencyRate.GetValueOrDefault(); currencyAmount = invoiceNoteItem.TotalAmount; if (invoiceNote.IsPayVat) { vatAmount = amount * 0.1; currencyVATAmount = invoiceNoteItem.TotalAmount * 0.1; } if (invoiceNote.IsPayTax) { incomeTaxAmount = amount * invoiceNote.IncomeTaxRate / 100; currencyIncomeTaxAmount = invoiceNoteItem.TotalAmount * invoiceNote.IncomeTaxRate / 100; } } amount = amount + vatAmount - incomeTaxAmount; currencyAmount = currencyAmount + currencyVATAmount - currencyIncomeTaxAmount; await _garmentDebtBalanceService.UpdateFromBankExpenditureNote((int)invoiceNoteItem.DeliveryOrderId, new BankExpenditureNoteFormDto(bankExpenditureNoteId, bankExpenditureNoteNo, amount, currencyAmount)); } else { await _garmentDebtBalanceService.EmptyBankExpenditureNote((int)deliveryOrder.Id); } } } return(dbContext.SaveChanges()); }