public async Task <ActionResult> CreateDebitMemo(CreateDebitMemoDto dto) { await _debitMemoService.CreateAsync(dto); if (dto.Warehouse == "Main") { foreach (var items in dto.DebitMemoDetails) { var check = await _stockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces -= items.TotalPieces; check.Amount -= items.Amount; await _stockService.UpdateAsync(check); } } } else { foreach (var items in dto.DebitMemoDetails) { var check = await _badStockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces -= items.TotalPieces; check.Amount -= items.Amount; await _badStockService.UpdateAsync(check); } } } return(Ok(dto)); }
public async Task <ActionResult> CreateCreditMemo(CreateCreditMemoDto dto) { await _creditMemoAppService.CreateAsync(dto); if (dto.CreditMemoMode == "Good") { foreach (var items in dto.CreditMemoDetails) { var check = await _stockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces += items.TotalPieces; check.Amount += items.Amount; await _stockService.UpdateAsync(check); } } } else { foreach (var items in dto.CreditMemoDetails) { var check = await _badStockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces += items.TotalPieces; check.Amount += items.Amount; await _badStockService.UpdateAsync(check); } else { var stocks = new BadStockDto { ProductId = items.ProductId, TotalPieces = items.TotalPieces, PricePerPiece = items.PricePerPiece, Amount = items.Amount }; await _badStockService.CreateAsync(stocks); } } } return(Ok(dto)); }