public RetailSalesInvoiceDetail ConfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService, IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService) { if (_validator.ValidConfirmObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService)) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(retailSalesInvoice.WarehouseId, retailSalesInvoiceDetail.ItemId); Item item = _itemService.GetObjectById(retailSalesInvoiceDetail.ItemId); StockMutation stockMutation = new StockMutation() { ItemId = retailSalesInvoiceDetail.ItemId, ItemCase = Core.Constants.Constant.ItemCase.Ready, Status = Core.Constants.Constant.MutationStatus.Deduction, Quantity = retailSalesInvoiceDetail.Quantity, SourceDocumentCode = retailSalesInvoice.Code, SourceDocumentId = retailSalesInvoice.Id, SourceDocumentType = Core.Constants.Constant.SourceDocumentType.RetailSalesInvoice, SourceDocumentDetailCode = retailSalesInvoiceDetail.Code, SourceDocumentDetailId = retailSalesInvoiceDetail.Id, SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.RetailSalesInvoiceDetail, WarehouseId = retailSalesInvoice.WarehouseId, WarehouseItemId = warehouseItem.Id }; stockMutation = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService); stockMutation.CreatedAt = (DateTime)retailSalesInvoice.ConfirmationDate.GetValueOrDefault(); _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService); _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService); retailSalesInvoiceDetail.CoGS = retailSalesInvoiceDetail.Quantity * item.AvgPrice; retailSalesInvoiceDetail = _repository.ConfirmObject(retailSalesInvoiceDetail); } return(retailSalesInvoiceDetail); }
public bool ValidUpdateObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService, IItemService _itemService, IWarehouseItemService _warehouseItemService) { retailSalesInvoiceDetail.Errors.Clear(); VUpdateObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _retailSalesInvoiceDetailService, _itemService, _warehouseItemService); return(isValid(retailSalesInvoiceDetail)); }
public RetailSalesInvoiceDetail VIsValidAssignedPrice(RetailSalesInvoiceDetail retailSalesInvoiceDetail) { if (retailSalesInvoiceDetail.IsManualPriceAssignment && retailSalesInvoiceDetail.AssignedPrice < 0) { retailSalesInvoiceDetail.Errors.Add("AssignedPrice", "Harus lebih besar atau sama dengan 0"); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VIsValidDiscount(RetailSalesInvoiceDetail retailSalesInvoiceDetail) { if (retailSalesInvoiceDetail.Discount < 0 || retailSalesInvoiceDetail.Discount > 100) { retailSalesInvoiceDetail.Errors.Add("Discount", "Harus antara 0 sampai 100"); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VHasRetailSalesInvoice(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); if (retailSalesInvoice == null) { retailSalesInvoiceDetail.Errors.Add("RetailSalesInvoiceId", "Tidak valid"); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VHasItem(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IItemService _itemService) { Item item = _itemService.GetObjectById(retailSalesInvoiceDetail.ItemId); if (item == null) { retailSalesInvoiceDetail.Errors.Add("ItemId", "Tidak valid"); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VIsValidQuantityOrdered(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(retailSalesInvoice.WarehouseId, retailSalesInvoiceDetail.ItemId); if (warehouseItem.Quantity - retailSalesInvoiceDetail.Quantity < 0) { retailSalesInvoiceDetail.Errors.Add("Generic", "Quantity harus lebih kecil atau sama dengan WarehouseItem Quantity"); return(retailSalesInvoiceDetail); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VIsValidQuantity(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(retailSalesInvoice.WarehouseId, retailSalesInvoiceDetail.ItemId); if (retailSalesInvoiceDetail.Quantity <= 0 || retailSalesInvoiceDetail.Quantity > warehouseItem.Quantity) { retailSalesInvoiceDetail.Errors.Add("Quantity", "Harus lebih besar dari 0 dan lebih kecil atau sama dengan WarehouseItem Quantity"); return(retailSalesInvoiceDetail); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail SoftDeleteObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService) { if (_validator.ValidDeleteObject(retailSalesInvoiceDetail, _retailSalesInvoiceService)) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); _repository.SoftDeleteObject(retailSalesInvoiceDetail); retailSalesInvoice.Total = CalculateTotal(retailSalesInvoice.Id); retailSalesInvoice.Total = CalculateCoGS(retailSalesInvoice.Id); _retailSalesInvoiceService.GetRepository().Update(retailSalesInvoice); } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VUniqueItem(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService, IItemService _itemService) { IList <RetailSalesInvoiceDetail> details = _retailSalesInvoiceDetailService.GetObjectsByRetailSalesInvoiceId(retailSalesInvoiceDetail.RetailSalesInvoiceId); foreach (var detail in details) { if (detail.ItemId == retailSalesInvoiceDetail.ItemId && detail.Id != retailSalesInvoiceDetail.Id) { retailSalesInvoiceDetail.Errors.Add("Generic", "Tidak boleh ada duplikasi item dalam 1 RetailSalesInvoice"); } } return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VIsParentNotConfirmed(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService) { RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); if (retailSalesInvoice != null) { if (retailSalesInvoice.IsConfirmed) { retailSalesInvoiceDetail.Errors.Add("Generic", "RetailSalesInvoice tidak boleh terkonfirmasi"); } } return(retailSalesInvoiceDetail); }
public string PrintError(RetailSalesInvoiceDetail obj) { string erroroutput = ""; KeyValuePair <string, string> first = obj.Errors.ElementAt(0); erroroutput += first.Key + "," + first.Value; foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1)) { erroroutput += Environment.NewLine; erroroutput += pair.Key + "," + pair.Value; } return(erroroutput); }
public RetailSalesInvoiceDetail UnconfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IWarehouseItemService _warehouseItemService, IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService) { if (_validator.ValidUnconfirmObject(retailSalesInvoiceDetail)) { IList <StockMutation> stockMutations = _stockMutationService.GetObjectsBySourceDocumentDetailForItem(retailSalesInvoiceDetail.ItemId, Core.Constants.Constant.SourceDocumentDetailType.RetailSalesInvoiceDetail, retailSalesInvoiceDetail.Id); foreach (var stockMutation in stockMutations) { stockMutation.Errors = new Dictionary <string, string>(); _stockMutationService.ReverseStockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService); _stockMutationService.SoftDeleteObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService); } retailSalesInvoiceDetail.CoGS = 0; retailSalesInvoiceDetail = _repository.UnconfirmObject(retailSalesInvoiceDetail); } return(retailSalesInvoiceDetail); }
public dynamic UpdateDetail(RetailSalesInvoiceDetail model) { decimal total = 0; try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.RetailSalesInvoice, Core.Constants.Constant.MenuGroupName.Transaction)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Edit record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _retailSalesInvoiceDetailService.GetObjectById(model.Id); data.ItemId = model.ItemId; data.Quantity = model.Quantity; data.Discount = model.Discount; data.IsManualPriceAssignment = model.IsManualPriceAssignment; data.AssignedPrice = model.AssignedPrice; data.RetailSalesInvoiceId = model.RetailSalesInvoiceId; model = _retailSalesInvoiceDetailService.UpdateObject(data, _retailSalesInvoiceService, _itemService, _warehouseItemService, _priceMutationService); total = _retailSalesInvoiceService.GetObjectById(model.RetailSalesInvoiceId).Total; } catch (Exception ex) { LOG.Error("Update Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors, Total = total })); }
public RetailSalesInvoiceDetail VCreateObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService, IItemService _itemService, IWarehouseItemService _warehouseItemService) { VIsParentNotConfirmed(retailSalesInvoiceDetail, _retailSalesInvoiceService); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VHasRetailSalesInvoice(retailSalesInvoiceDetail, _retailSalesInvoiceService); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VIsValidQuantity(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VIsValidDiscount(retailSalesInvoiceDetail); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VIsValidAssignedPrice(retailSalesInvoiceDetail); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VHasItem(retailSalesInvoiceDetail, _itemService); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VUniqueItem(retailSalesInvoiceDetail, _retailSalesInvoiceDetailService, _itemService); if (!isValid(retailSalesInvoiceDetail)) { return(retailSalesInvoiceDetail); } VConfirmObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService); return(retailSalesInvoiceDetail); }
public dynamic DeleteDetail(RetailSalesInvoiceDetail model) { decimal total = 0; try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.RetailSalesInvoice, Core.Constants.Constant.MenuGroupName.Transaction)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Edit record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _retailSalesInvoiceDetailService.GetObjectById(model.Id); model = _retailSalesInvoiceDetailService.SoftDeleteObject(data, _retailSalesInvoiceService); total = _retailSalesInvoiceService.GetObjectById(model.RetailSalesInvoiceId).Total; } catch (Exception ex) { LOG.Error("Delete Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors, Total = total })); }
public RetailSalesInvoiceDetail CreateObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IItemService _itemService, IWarehouseItemService _warehouseItemService, IPriceMutationService _priceMutationService) { retailSalesInvoiceDetail.Errors = new Dictionary <String, String>(); if (_validator.ValidCreateObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, this, _itemService, _warehouseItemService)) { Item item = _itemService.GetObjectById(retailSalesInvoiceDetail.ItemId); RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId); PriceMutation priceMutation = _priceMutationService.GetObjectById(item.PriceMutationId); if (retailSalesInvoiceDetail.IsManualPriceAssignment) { //priceMutation = _priceMutationService.CreateObject(retailSalesInvoiceDetail.ItemId, retailSalesInvoiceDetail.AssignedPrice, DateTime.Now); retailSalesInvoiceDetail.PriceMutationId = priceMutation.Id; retailSalesInvoiceDetail.Amount = (retailSalesInvoiceDetail.AssignedPrice * retailSalesInvoiceDetail.Quantity) * (100 - retailSalesInvoiceDetail.Discount) / 100; //item.PriceMutationId = priceMutation.Id; //_itemService.GetRepository().Update(item); } else { retailSalesInvoiceDetail.PriceMutationId = item.PriceMutationId; retailSalesInvoiceDetail.Amount = (priceMutation.Amount * retailSalesInvoiceDetail.Quantity) * (100 - retailSalesInvoiceDetail.Discount) / 100; } retailSalesInvoiceDetail.CoGS = retailSalesInvoiceDetail.Quantity * item.AvgPrice; retailSalesInvoiceDetail = _repository.CreateObject(retailSalesInvoiceDetail); if (retailSalesInvoiceDetail.IsManualPriceAssignment) { priceMutation.CreatedAt = retailSalesInvoiceDetail.CreatedAt; _priceMutationService.GetRepository().Update(priceMutation); } retailSalesInvoice.Total = CalculateTotal(retailSalesInvoice.Id); retailSalesInvoice.Total = CalculateCoGS(retailSalesInvoice.Id); _retailSalesInvoiceService.GetRepository().Update(retailSalesInvoice); } return(retailSalesInvoiceDetail); }
public dynamic GetInfoDetail(int Id) { RetailSalesInvoiceDetail model = new RetailSalesInvoiceDetail(); try { model = _retailSalesInvoiceDetailService.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.RetailSalesInvoiceId, RetailSalesInvoice = _retailSalesInvoiceService.GetObjectById(model.RetailSalesInvoiceId).Code, model.ItemId, Item = _itemService.GetObjectById(model.ItemId).Name, model.Quantity, model.Discount, model.IsManualPriceAssignment, model.AssignedPrice, model.Amount, model.Errors }, JsonRequestBehavior.AllowGet)); }
public RetailSalesInvoiceDetail VConfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService) { VIsValidQuantityOrdered(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService); return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VDeleteObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService) { VIsParentNotConfirmed(retailSalesInvoiceDetail, _retailSalesInvoiceService); return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VUnconfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail) { return(retailSalesInvoiceDetail); }
public RetailSalesInvoiceDetail VUpdateObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService, IItemService _itemService, IWarehouseItemService _warehouseItemService) { return(VCreateObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _retailSalesInvoiceDetailService, _itemService, _warehouseItemService)); }
public bool ValidUnconfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail) { retailSalesInvoiceDetail.Errors.Clear(); VUnconfirmObject(retailSalesInvoiceDetail); return(isValid(retailSalesInvoiceDetail)); }
public bool ValidDeleteObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService) { retailSalesInvoiceDetail.Errors.Clear(); VDeleteObject(retailSalesInvoiceDetail, _retailSalesInvoiceService); return(isValid(retailSalesInvoiceDetail)); }
public bool isValid(RetailSalesInvoiceDetail obj) { bool isValid = !obj.Errors.Any(); return(isValid); }
public void PopulateRetailSalesData() { TimeSpan salesDate = new TimeSpan(10, 0, 0, 0); TimeSpan dueDate = new TimeSpan(3, 0, 0, 0); // Cash with GroupPricing rsi1 = new RetailSalesInvoice() { SalesDate = DateTime.Today.Subtract(salesDate), WarehouseId = localWarehouse.Id, CashBankId = cashBank.Id, ContactId = contact.Id, DueDate = DateTime.Today.Subtract(dueDate) }; _retailSalesInvoiceService.CreateObject(rsi1, _warehouseService); // Cash with GroupPricing rsi2 = new RetailSalesInvoice() { SalesDate = DateTime.Today.Subtract(salesDate), WarehouseId = localWarehouse.Id, CashBankId = cashBank.Id, ContactId = contact.Id, DueDate = DateTime.Today.Subtract(dueDate), IsGroupPricing = true, Discount = 25, Tax = 10, }; _retailSalesInvoiceService.CreateObject(rsi2, _warehouseService); // Bank without GroupPricing rsi3 = new RetailSalesInvoice() { SalesDate = DateTime.Today.Subtract(salesDate), WarehouseId = localWarehouse.Id, CashBankId = cashBank2.Id, ContactId = contact.Id, DueDate = DateTime.Today.Subtract(dueDate), IsGBCH = true, GBCH_DueDate = DateTime.Today.Subtract(dueDate), GBCH_No = "G0001" }; _retailSalesInvoiceService.CreateObject(rsi3, _warehouseService); rsid1 = new RetailSalesInvoiceDetail() { RetailSalesInvoiceId = rsi1.Id, Quantity = 100, ItemId = blanket1.Id, }; _retailSalesInvoiceDetailService.CreateObject(rsid1, _retailSalesInvoiceService, _itemService, _warehouseItemService, _priceMutationService); rsid2 = new RetailSalesInvoiceDetail() { RetailSalesInvoiceId = rsi2.Id, Quantity = 100, ItemId = blanket1.Id, }; _retailSalesInvoiceDetailService.CreateObject(rsid2, _retailSalesInvoiceService, _itemService, _warehouseItemService, _priceMutationService); rsid3 = new RetailSalesInvoiceDetail() { RetailSalesInvoiceId = rsi3.Id, Quantity = 100, ItemId = blanket1.Id, }; _retailSalesInvoiceDetailService.CreateObject(rsid3, _retailSalesInvoiceService, _itemService, _warehouseItemService, _priceMutationService); _retailSalesInvoiceService.ConfirmObject(rsi1, rsi1.SalesDate, contact.Id, _retailSalesInvoiceDetailService, _contactService, _priceMutationService, _receivableService, _retailSalesInvoiceService, _warehouseItemService, _warehouseService, _itemService, _barringService, _stockMutationService, _closingService); _retailSalesInvoiceService.ConfirmObject(rsi2, rsi2.SalesDate, contact2.Id, _retailSalesInvoiceDetailService, _contactService, _priceMutationService, _receivableService, _retailSalesInvoiceService, _warehouseItemService, _warehouseService, _itemService, _barringService, _stockMutationService, _closingService); _retailSalesInvoiceService.ConfirmObject(rsi3, rsi3.SalesDate, contact3.Id, _retailSalesInvoiceDetailService, _contactService, _priceMutationService, _receivableService, _retailSalesInvoiceService, _warehouseItemService, _warehouseService, _itemService, _barringService, _stockMutationService, _closingService); _retailSalesInvoiceService.PaidObject(rsi1, 200000, _cashBankService, _receivableService, _receiptVoucherService, _receiptVoucherDetailService, _contactService, _cashMutationService, _generalLedgerJournalService, _accountService, _closingService); _retailSalesInvoiceService.PaidObject(rsi2, rsi2.Total, _cashBankService, _receivableService, _receiptVoucherService, _receiptVoucherDetailService, _contactService, _cashMutationService, _generalLedgerJournalService, _accountService, _closingService); _retailSalesInvoiceService.PaidObject(rsi3, rsi3.Total, _cashBankService, _receivableService, _receiptVoucherService, _receiptVoucherDetailService, _contactService, _cashMutationService, _generalLedgerJournalService, _accountService, _closingService); }
public bool ValidCreateObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService, IItemService _itemService, IWarehouseItemService _warehouseItemService) { VCreateObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _retailSalesInvoiceDetailService, _itemService, _warehouseItemService); return(isValid(retailSalesInvoiceDetail)); }