public CashSalesInvoiceDetail ConfirmObject(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService, IWarehouseItemService _warehouseItemService, IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService) { if (_validator.ValidConfirmObject(cashSalesInvoiceDetail, _cashSalesInvoiceService, _warehouseItemService)) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(cashSalesInvoice.WarehouseId, cashSalesInvoiceDetail.ItemId); Item item = _itemService.GetObjectById(cashSalesInvoiceDetail.ItemId); StockMutation stockMutation = new StockMutation() { ItemId = cashSalesInvoiceDetail.ItemId, ItemCase = Core.Constants.Constant.ItemCase.Ready, Status = Core.Constants.Constant.MutationStatus.Deduction, Quantity = cashSalesInvoiceDetail.Quantity, SourceDocumentCode = cashSalesInvoice.Code, SourceDocumentId = cashSalesInvoice.Id, SourceDocumentType = Core.Constants.Constant.SourceDocumentType.CashSalesInvoice, SourceDocumentDetailCode = cashSalesInvoiceDetail.Code, SourceDocumentDetailId = cashSalesInvoiceDetail.Id, SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.CashSalesInvoiceDetail, WarehouseId = cashSalesInvoice.WarehouseId, WarehouseItemId = warehouseItem.Id }; stockMutation = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService); stockMutation.CreatedAt = (DateTime)cashSalesInvoice.ConfirmationDate.GetValueOrDefault(); _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService); _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService); cashSalesInvoiceDetail.CoGS = cashSalesInvoiceDetail.Quantity * item.AvgPrice; cashSalesInvoiceDetail = _repository.ConfirmObject(cashSalesInvoiceDetail); } return(cashSalesInvoiceDetail); }
public dynamic GetInfo(int Id) { CashSalesReturn model = new CashSalesReturn(); try { model = _cashSalesReturnService.GetObjectById(Id); } catch (Exception ex) { LOG.Error("GetInfo", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Id, model.Code, model.Description, model.ReturnDate, model.Allowance, model.Total, model.CashBankId, CashBank = _cashBankService.GetObjectById((int)model.CashBankId.GetValueOrDefault()).Name, model.CashSalesInvoiceId, CashSalesInvoice = _cashSalesInvoiceService.GetObjectById(model.CashSalesInvoiceId).Code, model.Errors }, JsonRequestBehavior.AllowGet)); }
public CashSalesReturn VHasCashSalesInvoice(CashSalesReturn cashSalesReturn, ICashSalesInvoiceService _cashSalesInvoiceService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesReturn.CashSalesInvoiceId); if (cashSalesInvoice == null) { cashSalesReturn.Errors.Add("CashSalesInvoiceId", "Tidak valid"); } return(cashSalesReturn); }
public CashSalesInvoiceDetail VHasCashSalesInvoice(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); if (cashSalesInvoice == null) { cashSalesInvoiceDetail.Errors.Add("CashSalesInvoiceId", "Tidak valid"); } return(cashSalesInvoiceDetail); }
public CashSalesInvoiceDetail VIsValidQuantity(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService, IWarehouseItemService _warehouseItemService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(cashSalesInvoice.WarehouseId, cashSalesInvoiceDetail.ItemId); if (cashSalesInvoiceDetail.Quantity <= 0 || cashSalesInvoiceDetail.Quantity > warehouseItem.Quantity) { cashSalesInvoiceDetail.Errors.Add("Quantity", "Quantity harus lebih besar dari 0 dan lebih kecil atau sama dengan WarehouseItem Quantity"); return(cashSalesInvoiceDetail); } return(cashSalesInvoiceDetail); }
/*public CashSalesInvoiceDetail VHasQuantityPricing(CashSalesInvoiceDetail cashSalesInvoiceDetail, IItemService _itemService, IQuantityPricingService _quantityPricingService) * { * Item item = _itemService.GetObjectById(cashSalesInvoiceDetail.ItemId); * IList<QuantityPricing> quantityPricings = _quantityPricingService.GetObjectsByItemTypeId(item.ItemTypeId); * if (quantityPricings.Any()) * { * cashSalesInvoiceDetail.Errors.Add("Generic", "Tidak ada QuantityPricing terasosiasi"); * } * return cashSalesInvoiceDetail; * }*/ public CashSalesInvoiceDetail VIsValidQuantityOrdered(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService, IWarehouseItemService _warehouseItemService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(cashSalesInvoice.WarehouseId, cashSalesInvoiceDetail.ItemId); if (warehouseItem.Quantity - cashSalesInvoiceDetail.Quantity < 0) { cashSalesInvoiceDetail.Errors.Add("Generic", "Quantity harus lebih kecil atau sama dengan WarehouseItem Quantity"); return(cashSalesInvoiceDetail); } return(cashSalesInvoiceDetail); }
public CashSalesInvoiceDetail SoftDeleteObject(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService) { if (_validator.ValidDeleteObject(cashSalesInvoiceDetail, _cashSalesInvoiceService)) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); _repository.SoftDeleteObject(cashSalesInvoiceDetail); cashSalesInvoice.Total = CalculateTotal(cashSalesInvoice.Id); cashSalesInvoice.CoGS = CalculateCoGS(cashSalesInvoice.Id); _cashSalesInvoiceService.GetRepository().Update(cashSalesInvoice); } ; return(cashSalesInvoiceDetail); }
public CashSalesReturn VIsValidCashSalesInvoice(CashSalesReturn cashSalesReturn, ICashSalesInvoiceService _cashSalesInvoiceService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesReturn.CashSalesInvoiceId); if (cashSalesInvoice == null) { cashSalesReturn.Errors.Add("Generic", "CashSalesInvoice Tidak valid"); } else if (!(cashSalesInvoice.IsConfirmed && cashSalesInvoice.IsPaid)) { cashSalesReturn.Errors.Add("Generic", "CashSalesInvoice Harus sudah terkonfirmasi dan terbayar"); } return(cashSalesReturn); }
public CashSalesInvoiceDetail VIsParentNotConfirmed(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService) { CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); if (cashSalesInvoice != null) { if (cashSalesInvoice.IsConfirmed) { cashSalesInvoiceDetail.Errors.Add("Generic", "CashSalesInvoice tidak boleh terkonfirmasi"); } } else { cashSalesInvoiceDetail.Errors.Add("Generic", "CashSalesInvoice tidak ada"); } return(cashSalesInvoiceDetail); }
public CashSalesInvoiceDetail CreateObject(CashSalesInvoiceDetail cashSalesInvoiceDetail, ICashSalesInvoiceService _cashSalesInvoiceService, IItemService _itemService, IWarehouseItemService _warehouseItemService, IQuantityPricingService _quantityPricingService) { cashSalesInvoiceDetail.Errors = new Dictionary <String, String>(); if (_validator.ValidCreateObject(cashSalesInvoiceDetail, _cashSalesInvoiceService, this, _itemService, _warehouseItemService, _quantityPricingService)) { Item item = _itemService.GetObjectById(cashSalesInvoiceDetail.ItemId); QuantityPricing quantityPricing = _quantityPricingService.GetObjectByItemTypeIdAndQuantity(item.ItemTypeId, cashSalesInvoiceDetail.Quantity); decimal price = item.SellingPrice; decimal discount = cashSalesInvoiceDetail.Discount; if (cashSalesInvoiceDetail.IsManualPriceAssignment) { price = cashSalesInvoiceDetail.AssignedPrice; } else { cashSalesInvoiceDetail.AssignedPrice = 0; } if (quantityPricing != null) { if (cashSalesInvoiceDetail.Discount <= 0) { discount = quantityPricing.Discount; } ; } cashSalesInvoiceDetail.Amount = (price * (100 - discount) / 100) * cashSalesInvoiceDetail.Quantity; cashSalesInvoiceDetail.CoGS = cashSalesInvoiceDetail.Quantity * item.AvgPrice; CashSalesInvoice cashSalesInvoice = _cashSalesInvoiceService.GetObjectById(cashSalesInvoiceDetail.CashSalesInvoiceId); cashSalesInvoiceDetail.PriceMutationId = item.PriceMutationId; cashSalesInvoiceDetail = _repository.CreateObject(cashSalesInvoiceDetail); cashSalesInvoice.Total = CalculateTotal(cashSalesInvoice.Id); cashSalesInvoice.CoGS = CalculateCoGS(cashSalesInvoice.Id); _cashSalesInvoiceService.GetRepository().Update(cashSalesInvoice); } return(cashSalesInvoiceDetail); }