示例#1
0
        public StockAdjustment VDetailsAreVerifiedConfirmable(StockAdjustment stockAdjustment, IStockAdjustmentService _stockAdjustmentService, IStockAdjustmentDetailService _stockAdjustmentDetailService,
                                                              IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService)
        {
            IList <StockAdjustmentDetail> details = _stockAdjustmentDetailService.GetObjectsByStockAdjustmentId(stockAdjustment.Id);

            foreach (var stockAdjustmentDetail in details)
            {
                int           stockAdjustmentDetailQuantity = stockAdjustmentDetail.Quantity;
                decimal       stockAdjustmentDetailPrice    = stockAdjustmentDetail.Price;
                Item          item          = _itemService.GetObjectById(stockAdjustmentDetail.ItemId);
                WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(stockAdjustment.WarehouseId, item.Id);
                if (item.Quantity + stockAdjustmentDetailQuantity < 0)
                {
                    stockAdjustment.Errors.Add("Generic", "Stock barang tidak boleh menjadi kurang dari 0");
                }
                else if (warehouseItem.Quantity + stockAdjustmentDetailQuantity < 0)
                {
                    stockAdjustmentDetail.Errors.Add("Generic", "Stock di dalam warehouse tidak boleh kurang dari 0");
                }

                else if (_itemService.CalculateAvgPrice(item, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice) < 0)
                {
                    stockAdjustment.Errors.Add("Generic", "AvgPrice tidak boleh kurang dari 0");
                }
            }
            return(stockAdjustment);
        }
        public StockAdjustmentDetail VNonNegativeStockQuantity(StockAdjustmentDetail stockAdjustmentDetail, IStockAdjustmentService _stockAdjustmentService,
                                                               IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService, bool ToConfirm)
        {
            int             stockAdjustmentDetailQuantity = ToConfirm ? stockAdjustmentDetail.Quantity : ((-1) * stockAdjustmentDetail.Quantity);
            decimal         stockAdjustmentDetailPrice    = ToConfirm ? stockAdjustmentDetail.Price : ((-1) * stockAdjustmentDetail.Price);
            Item            item            = _itemService.GetObjectById(stockAdjustmentDetail.ItemId);
            StockAdjustment stockAdjustment = _stockAdjustmentService.GetObjectById(stockAdjustmentDetail.StockAdjustmentId);
            WarehouseItem   warehouseItem   = _warehouseItemService.FindOrCreateObject(stockAdjustment.WarehouseId, item.Id);

            if (item.Quantity + stockAdjustmentDetailQuantity < 0)
            {
                stockAdjustmentDetail.Errors.Add("Quantity", "Stock barang tidak boleh menjadi kurang dari 0");
                return(stockAdjustmentDetail);
            }
            if (warehouseItem.Quantity + stockAdjustmentDetailQuantity < 0)
            {
                stockAdjustmentDetail.Errors.Add("Quantity", "Stock di dalam warehouse tidak boleh kurang dari 0");
            }

            if (_itemService.CalculateAvgPrice(item, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice) < 0)
            {
                stockAdjustmentDetail.Errors.Add("AvgPrice", "Tidak boleh kurang dari 0");
            }

            return(stockAdjustmentDetail);
        }
        public StockAdjustmentDetail VNonNegativeItemAvgPrice(StockAdjustmentDetail stockAdjustmentDetail, IItemService _itemService)
        {
            Item    item     = _itemService.GetObjectById(stockAdjustmentDetail.ItemId);
            decimal AvgPrice = _itemService.CalculateAvgPrice(item, stockAdjustmentDetail.Quantity, stockAdjustmentDetail.Price);

            if (AvgPrice < 0)
            {
                stockAdjustmentDetail.Errors.Add("Generic", "Item AvgPrice Tidak boleh menjadi Negatif");
            }
            return(stockAdjustmentDetail);
        }
 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);
 }