public CustomPurchaseInvoiceDetail SoftDeleteObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService) { if (_validator.ValidDeleteObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService)) { CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); _repository.SoftDeleteObject(customPurchaseInvoiceDetail); customPurchaseInvoice.Total = CalculateTotal(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); customPurchaseInvoice.CoGS = CalculateCoGS(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); _customPurchaseInvoiceService.GetRepository().Update(customPurchaseInvoice); } return(customPurchaseInvoiceDetail); }
public CustomPurchaseInvoiceDetail UpdateObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService, IItemService _itemService, IWarehouseItemService _warehouseItemService) { if (_validator.ValidUpdateObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService, this, _itemService, _warehouseItemService)) { Item item = _itemService.GetObjectById(customPurchaseInvoiceDetail.ItemId); CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); customPurchaseInvoiceDetail.Price = customPurchaseInvoiceDetail.ListedUnitPrice * (100 - customPurchaseInvoiceDetail.Discount) / 100; customPurchaseInvoiceDetail.Amount = customPurchaseInvoiceDetail.Price * customPurchaseInvoiceDetail.Quantity; customPurchaseInvoiceDetail.CoGS = customPurchaseInvoiceDetail.Quantity * _itemService.CalculateAvgPrice(item, customPurchaseInvoiceDetail.Quantity, customPurchaseInvoiceDetail.Price); customPurchaseInvoiceDetail = _repository.UpdateObject(customPurchaseInvoiceDetail); customPurchaseInvoice.Total = CalculateTotal(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); customPurchaseInvoice.CoGS = CalculateCoGS(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId); _customPurchaseInvoiceService.GetRepository().Update(customPurchaseInvoice); } return(customPurchaseInvoiceDetail); }