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);
 }
示例#2
0
        public async Task TestCorrect()
        {
            StockController       controller = ControllerCreator.CreateStockControllerCorrectToken();
            string                dateTime   = Json.Serialize <DateTime>(DateTime.Now.AddDays(-10));
            ActionResult <string> result     = await controller.GetMutations(1, 10, dateTime);

            string resultValue = (result.Result as OkObjectResult).Value as string;

            StockMutation[] mutations = Json.Deserialize <StockMutation[]>(resultValue);

            StockMutation[] expectedMutations = new StockMutation[]
            {
                new StockMutation(1, 1, 1, -2, MutationReason.Sold, DateTime.Now.AddDays(-9)),
                new StockMutation(2, 1, 1, -2, MutationReason.Sold, DateTime.Now.AddDays(-8)),
                new StockMutation(3, 1, 1, -3, MutationReason.Broken, DateTime.Now.AddDays(-7)),
                new StockMutation(4, 1, 1, 10, MutationReason.Bought, DateTime.Now.AddDays(-6)),
                new StockMutation(5, 1, 1, -4, MutationReason.Sold, DateTime.Now.AddDays(-4))
            };

            Assert.Multiple(() =>
            {
                Assert.IsInstanceOf <OkObjectResult>(result.Result);
                Assert.AreEqual(expectedMutations, mutations);
            });
        }
 public StockMutation VCreateObject(StockMutation stockMutation, IWarehouseService _warehouseService, IWarehouseItemService _warehouseItemService)
 {
     VHasWarehouse(stockMutation, _warehouseService);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VHasWarehouseItem(stockMutation, _warehouseItemService);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VItemCase(stockMutation);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VStatus(stockMutation);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VSourceDocumentType(stockMutation);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VSourceDocumentDetailType(stockMutation);
     if (!isValid(stockMutation))
     {
         return(stockMutation);
     }
     VNonNegativeNorZeroQuantity(stockMutation);
     return(stockMutation);
 }
示例#4
0
        public async Task <StockMutation[]> GetMutationHistory(int selectedStoreId, long selectProductId, int timeSpanInDays, DateTime startingDate)
        {
            string query = "select * from stockmutation where storeId = @0 and productId = @1 and `datetime` > @3 and `datetime` < date_add(@3, interval @2 day);";

            object[][] result = await QueryExecutor.SelectMultiple(dbConnectionString, query, MySqlDbType.Int32, selectedStoreId, MySqlDbType.Int32, selectProductId, MySqlDbType.Int32, timeSpanInDays, MySqlDbType.DateTime, startingDate);

            StockMutation[] mutations = new StockMutation[result.Length];
            int             counter   = 0;

            foreach (object[] row in result)
            {
                int            mutationId   = (int)row[0];
                int            storeId      = (int)row[1];
                int            productId    = (int)row[2];
                int            amount       = (int)row[3];
                string         reasonString = (string)row[4];
                MutationReason reason       = Enum.Parse <MutationReason>(reasonString);
                DateTime       dateTime     = (DateTime)row[5];

                StockMutation mutation = new StockMutation(mutationId, storeId, productId, amount, reason, dateTime);
                mutations[counter] = mutation;
                counter++;
            }
            if (counter > 0)
            {
                return(mutations);
            }
            else
            {
                return(null);
            }
        }
 public StockMutation VNonNegativeNorZeroQuantity(StockMutation stockMutation)
 {
     if (stockMutation.Quantity <= 0)
     {
         stockMutation.Errors.Add("Generic", "Tidak boleh negatif atau 0");
     }
     return(stockMutation);
 }
        public async Task TestWrongToken()
        {
            StockController       controller     = ControllerCreator.CreateStockControllerWrongToken();
            StockMutation         mutation       = new StockMutation(null, 1, 1, -1, MutationReason.Sold, DateTime.Now.AddDays(-1));
            string                mutationString = Json.Serialize <StockMutation>(mutation);
            ActionResult <string> result         = await controller.PostMutation(mutationString);

            Assert.IsInstanceOf <UnauthorizedObjectResult>(result.Result);
        }
 public StockMutation VStatus(StockMutation stockMutation)
 {
     if (!stockMutation.Status.Equals(Constant.MutationStatus.Addition) &&
         !stockMutation.Status.Equals(Constant.MutationStatus.Deduction))
     {
         stockMutation.Errors.Add("Generic", "Harus merupakan bagian dari Constant.MutationStatus");
     }
     return(stockMutation);
 }
 public StockMutation VItemCase(StockMutation stockMutation)
 {
     if (!stockMutation.ItemCase.Equals(Constant.ItemCase.Ready) &&
         !stockMutation.ItemCase.Equals(Constant.ItemCase.PendingDelivery) &&
         !stockMutation.ItemCase.Equals(Constant.ItemCase.PendingReceival))
     {
         stockMutation.Errors.Add("Generic", "Harus merupakan bagian dari Constant.ItemCase");
     }
     return(stockMutation);
 }
        public StockMutation VHasWarehouseItem(StockMutation stockMutation, IWarehouseItemService _warehouseItemService)
        {
            WarehouseItem warehouseItem = _warehouseItemService.GetObjectById((int)stockMutation.WarehouseItemId.GetValueOrDefault());

            if (warehouseItem == null)
            {
                stockMutation.Errors.Add("Generic", "Tidak terasosiasi dengan item di warehouse");
            }
            return(stockMutation);
        }
        public StockMutation VHasWarehouseItem(StockMutation stockMutation, IWarehouseItemService _warehouseItemService)
        {
            WarehouseItem warehouseItem = _warehouseItemService.GetObjectById(stockMutation.WarehouseItemId);

            if (warehouseItem == null)
            {
                stockMutation.Errors.Add("WarehouseItemId", "Tidak terasosiasi dengan item di warehouse");
            }
            return(stockMutation);
        }
        public BarringOrderDetail FinishObject(BarringOrderDetail barringOrderDetail, DateTime FinishedDate, IBarringOrderService _barringOrderService, IStockMutationService _stockMutationService,
                                               IBarringService _barringService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
        {
            barringOrderDetail.FinishedDate = FinishedDate;
            if (_validator.ValidFinishObject(barringOrderDetail, _barringOrderService))
            {
                _repository.FinishObject(barringOrderDetail);

                // add barring order quantity final
                // if valid, complete barring order = true
                BarringOrder barringOrder = _barringOrderService.GetObjectById(barringOrderDetail.BarringOrderId);
                barringOrder.QuantityFinal += 1;
                _barringOrderService.AdjustQuantity(barringOrder);
                if (_barringOrderService.GetValidator().ValidCompleteObject(barringOrder, this))
                {
                    _barringOrderService.CompleteObject(barringOrder, this, _barringService, _itemService, _warehouseItemService);
                }

                bool CaseAdditionElse    = false;
                bool CaseAdditionBarring = true;

                // add barring quantity
                Barring       barring          = _barringService.GetObjectById(barringOrderDetail.BarringId);
                WarehouseItem warehouseBarring = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, barring.Id);
                StockMutation stockMutation    = _stockMutationService.CreateStockMutationForBarringOrder(barringOrderDetail, warehouseBarring, CaseAdditionBarring);
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);

                // deduce bars quantity
                if (barringOrderDetail.IsBarRequired)
                {
                    Item leftbar  = (barringOrderDetail.HasLeftBar && barring.LeftBarItemId != null) ? _itemService.GetObjectById((int)barring.LeftBarItemId) : null;
                    Item rightbar = (barringOrderDetail.HasRightBar && barring.RightBarItemId != null) ? _itemService.GetObjectById((int)barring.RightBarItemId) : null;
                    if (leftbar != null)
                    {
                        WarehouseItem warehouseLeftBar     = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, leftbar.Id);
                        StockMutation stockMutationLeftBar = _stockMutationService.CreateStockMutationForBarringOrder(barringOrderDetail, warehouseLeftBar, CaseAdditionElse);
                        _stockMutationService.StockMutateObject(stockMutationLeftBar, _itemService, _barringService, _warehouseItemService);
                    }
                    if (rightbar != null)
                    {
                        WarehouseItem warehouseRightBar     = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, rightbar.Id);
                        StockMutation stockMutationRightBar = _stockMutationService.CreateStockMutationForBarringOrder(barringOrderDetail, warehouseRightBar, CaseAdditionElse);
                        _stockMutationService.StockMutateObject(stockMutationRightBar, _itemService, _barringService, _warehouseItemService);
                    }
                }

                // deduce blanket quantity
                WarehouseItem warehouseBlanket     = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, barring.BlanketItemId);
                StockMutation stockMutationBlanket = _stockMutationService.CreateStockMutationForBarringOrder(barringOrderDetail, warehouseBlanket, CaseAdditionElse);
                _stockMutationService.StockMutateObject(stockMutationBlanket, _itemService, _barringService, _warehouseItemService);
            }
            return(barringOrderDetail);
        }
示例#12
0
        public void StockMutateObject(StockMutation stockMutation, IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService)
        {
            // decimal stockAdjustmentDetailPrice = (stockMutation.Status == Constant.MutationStatus.Addition) ? stockAdjustmentDetail.Price : ((-1) * stockAdjustmentDetail.Price);
            // item.AvgCost = _barringService.CalculateAvgCost(item, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice);
            // barring.AvgCost = _barringService.CalculateAvgCost(barring, stockAdjustmentDetail.Quantity, stockAdjustmentDetailPrice);

            int           Quantity      = (stockMutation.Status == Constant.MutationStatus.Addition) ? stockMutation.Quantity : (-1) * stockMutation.Quantity;
            WarehouseItem warehouseItem = _warehouseItemService.GetObjectById(stockMutation.WarehouseItemId);
            Item          item          = _itemService.GetObjectById(stockMutation.ItemId);
            Barring       barring       = _barringService.GetObjectById(stockMutation.ItemId);

            if (warehouseItem != null)
            {
                if (stockMutation.ItemCase == Constant.ItemCase.Ready)
                {
                    _warehouseItemService.AdjustQuantity(warehouseItem, Quantity);
                }
            }

            if (barring == null)
            {
                // itemService in action
                if (stockMutation.ItemCase == Constant.ItemCase.Ready)
                {
                    _itemService.AdjustQuantity(item, Quantity);
                }
                else if (stockMutation.ItemCase == Constant.ItemCase.PendingDelivery)
                {
                    _itemService.AdjustPendingDelivery(item, Quantity);
                }
                else if (stockMutation.ItemCase == Constant.ItemCase.PendingReceival)
                {
                    _itemService.AdjustPendingReceival(item, Quantity);
                }
            }
            else
            {
                // barringService in action
                if (stockMutation.ItemCase == Constant.ItemCase.Ready)
                {
                    _barringService.AdjustQuantity(barring, Quantity);
                }
                else if (stockMutation.ItemCase == Constant.ItemCase.PendingDelivery)
                {
                    _barringService.AdjustPendingDelivery(barring, Quantity);
                }
                else if (stockMutation.ItemCase == Constant.ItemCase.PendingReceival)
                {
                    _barringService.AdjustPendingReceival(barring, Quantity);
                }
            }
        }
 public StockMutation VSourceDocumentDetailType(StockMutation stockMutation)
 {
     if (!stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.PurchaseOrderDetail) &&
         !stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.PurchaseReceivalDetail) &&
         !stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.SalesOrderDetail) &&
         !stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.DeliveryOrderDetail) &&
         !stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.RecoveryOrderDetail) &&
         !stockMutation.SourceDocumentDetailType.Equals(Constant.SourceDocumentDetailType.RecoveryAccessoryDetail))
     {
         stockMutation.Errors.Add("SourceDocumentDetailType", "Harus merupakan bagian dari Constant.SourceDocumentDetailType");
     }
     return(stockMutation);
 }
示例#14
0
        public string PrintError(StockMutation 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 StockAdjustmentDetail ConfirmObject(StockAdjustmentDetail stockAdjustmentDetail, DateTime ConfirmationDate, IStockAdjustmentService _stockAdjustmentService, IStockMutationService _stockMutationService,
                                            IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService)
 {
     stockAdjustmentDetail.ConfirmationDate = ConfirmationDate;
     if (_validator.ValidConfirmObject(stockAdjustmentDetail, _stockAdjustmentService, _itemService, _barringService, _warehouseItemService))
     {
         stockAdjustmentDetail = _repository.ConfirmObject(stockAdjustmentDetail);
         StockAdjustment stockAdjustment = _stockAdjustmentService.GetObjectById(stockAdjustmentDetail.StockAdjustmentId);
         Item            item            = _itemService.GetObjectById(stockAdjustmentDetail.ItemId);
         WarehouseItem   warehouseItem   = _warehouseItemService.FindOrCreateObject(stockAdjustment.WarehouseId, item.Id);
         StockMutation   stockMutation   = _stockMutationService.CreateStockMutationForStockAdjustment(stockAdjustmentDetail, warehouseItem);
         _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
     }
     return(stockAdjustmentDetail);
 }
        public PurchaseOrderDetail ConfirmObject(PurchaseOrderDetail purchaseOrderDetail, DateTime ConfirmationDate, IStockMutationService _stockMutationService,
                                                 IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService, IPurchaseOrderService _purchaseOrderService)
        {
            purchaseOrderDetail.ConfirmationDate = ConfirmationDate;
            if (_validator.ValidConfirmObject(purchaseOrderDetail))
            {
                purchaseOrderDetail = _repository.ConfirmObject(purchaseOrderDetail);

                Item          item          = _itemService.GetObjectById(purchaseOrderDetail.ItemId);
                StockMutation stockMutation = _stockMutationService.CreateStockMutationForPurchaseOrder(purchaseOrderDetail, item, _purchaseOrderService);
                // item.PendingReceival += purchaseOrderDetail.Quantity;
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
            }
            return(purchaseOrderDetail);
        }
示例#17
0
        public SalesOrderDetail ConfirmObject(SalesOrderDetail salesOrderDetail, DateTime ConfirmationDate, IStockMutationService _stockMutationService,
                                              IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService)
        {
            salesOrderDetail.ConfirmationDate = ConfirmationDate;
            if (_validator.ValidConfirmObject(salesOrderDetail))
            {
                salesOrderDetail = _repository.ConfirmObject(salesOrderDetail);

                Item          item          = _itemService.GetObjectById(salesOrderDetail.ItemId);
                StockMutation stockMutation = _stockMutationService.CreateStockMutationForSalesOrder(salesOrderDetail, item);
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
                // item.PendingDelivery += salesOrderDetail.Quantity;
            }
            return(salesOrderDetail);
        }
示例#18
0
        public StockMutation CreateStockMutationForRecoveryOrderCompound(RecoveryOrderDetail recoveryOrderDetail, WarehouseItem warehouseItem, bool CaseAddition)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = warehouseItem.ItemId;
            stockMutation.WarehouseId              = warehouseItem.WarehouseId;
            stockMutation.WarehouseItemId          = warehouseItem.Id;
            stockMutation.Quantity                 = recoveryOrderDetail.CompoundUsage;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.RecoveryOrder;
            stockMutation.SourceDocumentId         = recoveryOrderDetail.RecoveryOrderId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.RecoveryOrderDetail;
            stockMutation.SourceDocumentDetailId   = recoveryOrderDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.Ready;
            stockMutation.Status                   = CaseAddition ? Constant.MutationStatus.Addition : Constant.MutationStatus.Deduction;
            return(_repository.CreateObject(stockMutation));
        }
示例#19
0
        public StockMutation CreateStockMutationForPurchaseOrder(PurchaseOrderDetail purchaseOrderDetail, Item item)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = item.Id;
            stockMutation.WarehouseId              = 0;
            stockMutation.WarehouseItemId          = 0;
            stockMutation.Quantity                 = purchaseOrderDetail.Quantity;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.PurchaseOrder;
            stockMutation.SourceDocumentId         = purchaseOrderDetail.PurchaseOrderId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.PurchaseOrderDetail;
            stockMutation.SourceDocumentDetailId   = purchaseOrderDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.PendingReceival;
            stockMutation.Status                   = Constant.MutationStatus.Addition;
            return(_repository.CreateObject(stockMutation));
        }
示例#20
0
        public StockMutation CreateStockMutationForBarringOrder(BarringOrderDetail barringOrderDetail, WarehouseItem warehouseItem, bool CaseAddition)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = warehouseItem.ItemId;
            stockMutation.WarehouseId              = warehouseItem.WarehouseId;
            stockMutation.WarehouseItemId          = warehouseItem.Id;
            stockMutation.Quantity                 = 1;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.BarringOrder;
            stockMutation.SourceDocumentId         = barringOrderDetail.BarringOrderId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.BarringOrderDetail;
            stockMutation.SourceDocumentDetailId   = barringOrderDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.Ready;
            stockMutation.Status                   = CaseAddition ? Constant.MutationStatus.Addition : Constant.MutationStatus.Deduction;
            return(_repository.CreateObject(stockMutation));
        }
示例#21
0
        public StockMutation CreateStockMutationForRecoveryAccessory(RecoveryAccessoryDetail recoveryAccessoryDetail, WarehouseItem warehouseItem)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = warehouseItem.ItemId;
            stockMutation.WarehouseId              = warehouseItem.WarehouseId;
            stockMutation.WarehouseItemId          = warehouseItem.Id;
            stockMutation.Quantity                 = recoveryAccessoryDetail.Quantity;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.RecoveryOrderDetail;
            stockMutation.SourceDocumentId         = recoveryAccessoryDetail.RecoveryOrderDetailId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.RecoveryAccessoryDetail;
            stockMutation.SourceDocumentDetailId   = recoveryAccessoryDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.Ready;
            stockMutation.Status                   = Constant.MutationStatus.Deduction;
            return(_repository.CreateObject(stockMutation));
        }
示例#22
0
        public StockMutation CreateStockMutationForStockAdjustment(StockAdjustmentDetail stockAdjustmentDetail, WarehouseItem warehouseItem)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = warehouseItem.ItemId;
            stockMutation.WarehouseId              = warehouseItem.WarehouseId;
            stockMutation.WarehouseItemId          = warehouseItem.Id;
            stockMutation.Quantity                 = (stockAdjustmentDetail.Quantity >= 0) ? stockAdjustmentDetail.Quantity : (-1) * stockAdjustmentDetail.Quantity;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.StockAdjustment;
            stockMutation.SourceDocumentId         = stockAdjustmentDetail.StockAdjustmentId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.StockAdjustmentDetail;
            stockMutation.SourceDocumentDetailId   = stockAdjustmentDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.Ready;
            stockMutation.Status                   = (stockAdjustmentDetail.Quantity >= 0) ? Constant.MutationStatus.Addition : Constant.MutationStatus.Deduction;
            return(_repository.CreateObject(stockMutation));
        }
示例#23
0
        public StockMutation CreateStockMutationForSalesOrder(SalesOrderDetail salesOrderDetail, Item item)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = item.Id;
            stockMutation.WarehouseId              = 0;
            stockMutation.WarehouseItemId          = 0;
            stockMutation.Quantity                 = salesOrderDetail.Quantity;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.SalesOrder;
            stockMutation.SourceDocumentId         = salesOrderDetail.SalesOrderId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.SalesOrderDetail;
            stockMutation.SourceDocumentDetailId   = salesOrderDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.PendingDelivery;
            stockMutation.Status                   = Constant.MutationStatus.Addition;
            return(_repository.CreateObject(stockMutation));
        }
示例#24
0
        public StockMutation CreateStockMutationForCoreIdentification(CoreIdentificationDetail coreIdentificationDetail, WarehouseItem warehouseItem)
        {
            StockMutation stockMutation = new StockMutation();

            stockMutation.ItemId                   = warehouseItem.ItemId;
            stockMutation.WarehouseId              = warehouseItem.WarehouseId;
            stockMutation.WarehouseItemId          = warehouseItem.Id;
            stockMutation.Quantity                 = 1;
            stockMutation.SourceDocumentType       = Constant.SourceDocumentType.CoreIdentification;
            stockMutation.SourceDocumentId         = coreIdentificationDetail.CoreIdentificationId;
            stockMutation.SourceDocumentDetailType = Constant.SourceDocumentDetailType.CoreIdentificationDetail;
            stockMutation.SourceDocumentDetailId   = coreIdentificationDetail.Id;
            stockMutation.ItemCase                 = Constant.ItemCase.Ready;
            stockMutation.Status                   = Constant.MutationStatus.Addition;
            return(_repository.CreateObject(stockMutation));
        }
示例#25
0
        public async Task TestCorrect()
        {
            StockController       controller     = ControllerCreator.CreateStockControllerCorrectToken();
            StockMutation         mutation       = new StockMutation(null, 1, 1, -1, MutationReason.Sold, DateTime.Now.AddDays(-1));
            string                mutationString = Json.Serialize <StockMutation>(mutation);
            ActionResult <string> result         = await controller.PostMutation(mutationString);

            Assert.Multiple(async() =>
            {
                Assert.IsInstanceOf <OkObjectResult>(result.Result);

                ActionResult <string> resultCheck = await controller.GetCurrentStock(1);
                int?resultValue = (resultCheck.Result as OkObjectResult).Value as int?;
                Assert.NotNull(resultValue);
                Assert.AreEqual(8, resultValue);
            });
        }
示例#26
0
 public StockMutation VSourceDocumentType(StockMutation stockMutation)
 {
     if (!stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.PurchaseOrder) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.PurchaseReceival) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.SalesOrder) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.DeliveryOrder) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.RecoveryOrder) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.RecoveryOrderDetail) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.RetailSalesInvoice) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.RetailPurchaseInvoice) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.CashSalesInvoice) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.CashSalesReturn) &&
         !stockMutation.SourceDocumentType.Equals(Constant.SourceDocumentType.CustomPurchaseInvoice))
     {
         stockMutation.Errors.Add("Generic", "Harus merupakan bagian dari Constant.SourceDocumentType");
     }
     return(stockMutation);
 }
        public CustomPurchaseInvoiceDetail ConfirmObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService, IWarehouseItemService _warehouseItemService,
                                                         IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService, IPriceMutationService _priceMutationService)
        {
            if (_validator.ValidConfirmObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService, _warehouseItemService))
            {
                CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
                WarehouseItem         warehouseItem         = _warehouseItemService.FindOrCreateObject(customPurchaseInvoice.WarehouseId, customPurchaseInvoiceDetail.ItemId);
                Item          item          = _itemService.GetObjectById(customPurchaseInvoiceDetail.ItemId);
                StockMutation stockMutation = new StockMutation()
                {
                    ItemId                   = customPurchaseInvoiceDetail.ItemId,
                    ItemCase                 = Core.Constants.Constant.ItemCase.Ready,
                    Status                   = Core.Constants.Constant.MutationStatus.Addition,
                    Quantity                 = customPurchaseInvoiceDetail.Quantity,
                    SourceDocumentCode       = customPurchaseInvoice.Code,
                    SourceDocumentId         = customPurchaseInvoice.Id,
                    SourceDocumentType       = Core.Constants.Constant.SourceDocumentType.CustomPurchaseInvoice,
                    SourceDocumentDetailCode = customPurchaseInvoiceDetail.Code,
                    SourceDocumentDetailId   = customPurchaseInvoiceDetail.Id,
                    SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.CustomPurchaseInvoiceDetail,
                    WarehouseId              = customPurchaseInvoice.WarehouseId,
                    WarehouseItemId          = warehouseItem.Id
                };

                decimal hiPrice  = GetHighestPrice(/*customPurchaseInvoice.Id,*/ customPurchaseInvoiceDetail.ItemId);
                decimal newPrice = hiPrice * (100 + item.Margin) / 100;
                if (newPrice > item.SellingPrice)
                {
                    item.SellingPrice = newPrice;
                    PriceMutation priceMutation = _priceMutationService.CreateObject(item.Id, item.SellingPrice, DateTime.Now);
                    item.PriceMutationId = priceMutation.Id;
                }
                decimal itemPrice = customPurchaseInvoiceDetail.Amount / customPurchaseInvoiceDetail.Quantity;
                item.AvgPrice = _itemService.CalculateAndUpdateAvgPrice(item, customPurchaseInvoiceDetail.Quantity, itemPrice);

                stockMutation           = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                stockMutation.CreatedAt = (DateTime)customPurchaseInvoice.ConfirmationDate.GetValueOrDefault();
                _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
                customPurchaseInvoiceDetail.CoGS = customPurchaseInvoiceDetail.Quantity * item.AvgPrice;
                customPurchaseInvoiceDetail      = _repository.ConfirmObject(customPurchaseInvoiceDetail);
            }
            return(customPurchaseInvoiceDetail);
        }
        public RecoveryOrderDetail RejectObject(RecoveryOrderDetail recoveryOrderDetail, DateTime RejectedDate, ICoreIdentificationService _coreIdentificationService, ICoreIdentificationDetailService _coreIdentificationDetailService,
                                                IRecoveryOrderService _recoveryOrderService, IRecoveryAccessoryDetailService _recoveryAccessoryDetailService, ICoreBuilderService _coreBuilderService, IRollerBuilderService _rollerBuilderService,
                                                IItemService _itemService, IWarehouseItemService _warehouseItemService, IBarringService _barringService, IStockMutationService _stockMutationService)
        {
            recoveryOrderDetail.RejectedDate = RejectedDate;
            if (_validator.ValidRejectObject(recoveryOrderDetail, _recoveryOrderService))
            {
                _repository.RejectObject(recoveryOrderDetail);

                // add recovery order quantity reject
                // if valid, complete recovery order = true
                RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(recoveryOrderDetail.RecoveryOrderId);
                recoveryOrder.QuantityRejected += 1;
                _recoveryOrderService.AdjustQuantity(recoveryOrder);
                if (_recoveryOrderService.GetValidator().ValidCompleteObject(recoveryOrder, this, _recoveryAccessoryDetailService))
                {
                    _recoveryOrderService.CompleteObject(recoveryOrder, _coreIdentificationDetailService, this, _recoveryAccessoryDetailService);
                }

                bool CaseAddition = false;

                // deduce compound
                RollerBuilder rollerBuilder         = _rollerBuilderService.GetObjectById(recoveryOrderDetail.RollerBuilderId);
                Item          compound              = _itemService.GetObjectById(rollerBuilder.CompoundId);
                WarehouseItem warehouseCompound     = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, compound.Id);
                StockMutation stockMutationCompound = _stockMutationService.CreateStockMutationForRecoveryOrderCompound(recoveryOrderDetail, warehouseCompound, CaseAddition);
                _stockMutationService.StockMutateObject(stockMutationCompound, _itemService, _barringService, _warehouseItemService);

                // deduce core
                CoreIdentificationDetail coreIdentificationDetail = _coreIdentificationDetailService.GetObjectById(recoveryOrderDetail.CoreIdentificationDetailId);
                _coreIdentificationDetailService.UnsetJobScheduled(coreIdentificationDetail, _recoveryOrderService, this);

                CoreBuilder coreBuilder = _coreBuilderService.GetObjectById(coreIdentificationDetail.CoreBuilderId);
                Item        core        = (coreIdentificationDetail.MaterialCase == Core.Constants.Constant.MaterialCase.New) ?
                                          _coreBuilderService.GetNewCore(coreBuilder.Id) : _coreBuilderService.GetUsedCore(coreBuilder.Id);
                WarehouseItem warehouseCore     = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, core.Id);
                StockMutation stockMutationCore = _stockMutationService.CreateStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseCore, CaseAddition);
                _stockMutationService.StockMutateObject(stockMutationCore, _itemService, _barringService, _warehouseItemService);


                // accesories uncounted
            }
            return(recoveryOrderDetail);
        }
示例#29
0
        public IList <StockMutation> CreateStockMutationForDeliveryOrder(DeliveryOrderDetail deliveryOrderDetail, WarehouseItem warehouseItem)
        {
            IList <StockMutation> result = new List <StockMutation>();

            StockMutation stockMutationPendingDelivery = new StockMutation();

            stockMutationPendingDelivery.ItemId             = warehouseItem.ItemId;
            stockMutationPendingDelivery.WarehouseId        = warehouseItem.WarehouseId;
            stockMutationPendingDelivery.WarehouseItemId    = warehouseItem.Id;
            stockMutationPendingDelivery.ItemId             = deliveryOrderDetail.ItemId;
            stockMutationPendingDelivery.Quantity           = deliveryOrderDetail.Quantity;
            stockMutationPendingDelivery.SourceDocumentType = Constant.SourceDocumentType.DeliveryOrder;
            stockMutationPendingDelivery.SourceDocumentId   = deliveryOrderDetail.DeliveryOrderId;
            //stockMutationPendingDelivery.SourceDocumentCode = deliveryOrderDetail.DeliveryOrderCode;
            stockMutationPendingDelivery.SourceDocumentDetailType = Constant.SourceDocumentDetailType.DeliveryOrderDetail;
            stockMutationPendingDelivery.SourceDocumentDetailId   = deliveryOrderDetail.Id;
            stockMutationPendingDelivery.SourceDocumentDetailCode = deliveryOrderDetail.Code;
            stockMutationPendingDelivery.ItemCase = Constant.ItemCase.PendingDelivery;
            stockMutationPendingDelivery.Status   = Constant.MutationStatus.Deduction;
            stockMutationPendingDelivery          = _repository.CreateObject(stockMutationPendingDelivery);

            StockMutation stockMutationReady = new StockMutation();

            stockMutationReady.ItemId             = warehouseItem.ItemId;
            stockMutationReady.WarehouseId        = warehouseItem.WarehouseId;
            stockMutationReady.WarehouseItemId    = warehouseItem.Id;
            stockMutationReady.ItemId             = deliveryOrderDetail.ItemId;
            stockMutationReady.Quantity           = deliveryOrderDetail.Quantity;
            stockMutationReady.SourceDocumentType = Constant.SourceDocumentType.DeliveryOrder;
            stockMutationReady.SourceDocumentId   = deliveryOrderDetail.DeliveryOrderId;
            //stockMutationReady.SourceDocumentCode = deliveryOrderDetail.DeliveryOrderCode;
            stockMutationReady.SourceDocumentDetailType = Constant.SourceDocumentDetailType.DeliveryOrderDetail;
            stockMutationReady.SourceDocumentDetailId   = deliveryOrderDetail.Id;
            stockMutationReady.SourceDocumentDetailCode = deliveryOrderDetail.Code;
            stockMutationReady.ItemCase = Constant.ItemCase.Ready;
            stockMutationReady.Status   = Constant.MutationStatus.Deduction;
            stockMutationReady          = _repository.CreateObject(stockMutationReady);

            result.Add(stockMutationPendingDelivery);
            result.Add(stockMutationReady);
            return(result);
        }
示例#30
0
        public IList <StockMutation> CreateStockMutationForWarehouseMutationOrder(WarehouseMutationOrderDetail warehouseMutationOrderDetail, WarehouseItem warehouseItemFrom, WarehouseItem warehouseItemTo, IWarehouseMutationOrderService _warehouseMutationOrderService)
        {
            IList <StockMutation> stockMutations = new List <StockMutation>();

            StockMutation stockMutationFrom = new StockMutation();

            stockMutationFrom.ItemId                   = warehouseItemFrom.ItemId;
            stockMutationFrom.WarehouseId              = warehouseItemFrom.WarehouseId;
            stockMutationFrom.WarehouseItemId          = warehouseItemFrom.Id;
            stockMutationFrom.Quantity                 = warehouseMutationOrderDetail.Quantity;
            stockMutationFrom.SourceDocumentType       = Constant.SourceDocumentType.WarehouseMutationOrder;
            stockMutationFrom.SourceDocumentId         = warehouseMutationOrderDetail.WarehouseMutationOrderId;
            stockMutationFrom.SourceDocumentCode       = _warehouseMutationOrderService.GetObjectById(warehouseMutationOrderDetail.WarehouseMutationOrderId).Code;
            stockMutationFrom.SourceDocumentDetailType = Constant.SourceDocumentDetailType.WarehouseMutationOrderDetail;
            stockMutationFrom.SourceDocumentDetailId   = warehouseMutationOrderDetail.Id;
            stockMutationFrom.SourceDocumentDetailCode = warehouseMutationOrderDetail.Code;
            stockMutationFrom.ItemCase                 = Constant.ItemCase.Ready;
            stockMutationFrom.Status                   = Constant.MutationStatus.Deduction;
            stockMutationFrom = _repository.CreateObject(stockMutationFrom);

            StockMutation stockMutationTo = new StockMutation();

            stockMutationTo.ItemId                   = warehouseItemTo.ItemId;
            stockMutationTo.WarehouseId              = warehouseItemTo.WarehouseId;
            stockMutationTo.WarehouseItemId          = warehouseItemTo.Id;
            stockMutationTo.Quantity                 = warehouseMutationOrderDetail.Quantity;
            stockMutationTo.SourceDocumentType       = Constant.SourceDocumentType.WarehouseMutationOrder;
            stockMutationTo.SourceDocumentId         = warehouseMutationOrderDetail.WarehouseMutationOrderId;
            stockMutationTo.SourceDocumentCode       = _warehouseMutationOrderService.GetObjectById(warehouseMutationOrderDetail.WarehouseMutationOrderId).Code;
            stockMutationTo.SourceDocumentDetailType = Constant.SourceDocumentDetailType.WarehouseMutationOrderDetail;
            stockMutationTo.SourceDocumentDetailId   = warehouseMutationOrderDetail.Id;
            stockMutationTo.SourceDocumentDetailCode = warehouseMutationOrderDetail.Code;
            stockMutationTo.ItemCase                 = Constant.ItemCase.Ready;
            stockMutationTo.Status                   = Constant.MutationStatus.Addition;
            stockMutationTo = _repository.CreateObject(stockMutationTo);

            stockMutations.Add(stockMutationFrom);
            stockMutations.Add(stockMutationTo);
            return(stockMutations);
        }