public dynamic GetInfo(int Id)
        {
            RecoveryOrder model = new RecoveryOrder();

            try
            {
                model = _recoveryOrderService.GetObjectById(Id);
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                model.Errors.Add("Generic", "Error : " + ex);
            }

            return(Json(new
            {
                model.Id,
                model.Code,
                model.WarehouseId,
                model.CoreIdentificationId,
                CoreIdentification = _coreIdentificationService.GetObjectById(model.CoreIdentificationId).Code,
                WarehouseCode = _warehouseService.GetObjectById(model.WarehouseId).Code,
                Warehouse = _warehouseService.GetObjectById(model.WarehouseId).Name,
                model.QuantityReceived,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
        public RecoveryOrderDetail VRecoveryOrderHasNotBeenCompleted(RecoveryOrderDetail recoveryOrderDetail, IRecoveryOrderService _recoveryOrderService)
        {
            RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(recoveryOrderDetail.RecoveryOrderId);

            if (recoveryOrder.IsCompleted)
            {
                recoveryOrderDetail.Errors.Add("Generic", "Recovery order sudah complete");
            }
            return(recoveryOrderDetail);
        }
        public RecoveryOrderDetail VHasRecoveryOrder(RecoveryOrderDetail recoveryOrderDetail, IRecoveryOrderService _recoveryOrderService)
        {
            RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(recoveryOrderDetail.RecoveryOrderId);

            if (recoveryOrder == null)
            {
                recoveryOrderDetail.Errors.Add("RecoveryOrderId", "Tidak terasosiasi dengan Recovery Order");
            }
            return(recoveryOrderDetail);
        }
        public RecoveryAccessoryDetail VQuantityInStock(RecoveryAccessoryDetail recoveryAccessoryDetail, IRecoveryOrderService _recoveryOrderService, IRecoveryOrderDetailService _recoveryOrderDetailService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
        {
            RecoveryOrderDetail detail        = _recoveryOrderDetailService.GetObjectById(recoveryAccessoryDetail.RecoveryOrderDetailId);
            RecoveryOrder       recoveryOrder = _recoveryOrderService.GetObjectById(detail.RecoveryOrderId);
            WarehouseItem       warehouseItem = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, recoveryAccessoryDetail.ItemId);

            if (warehouseItem.Quantity < recoveryAccessoryDetail.Quantity)
            {
                recoveryAccessoryDetail.Errors.Add("Quantity", "Tidak boleh lebih dari jumlah stock barang");
            }
            return(recoveryAccessoryDetail);
        }
        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);
        }
        public RecoveryOrderDetail UndoRejectObject(RecoveryOrderDetail recoveryOrderDetail, ICoreIdentificationService _coreIdentificationService, ICoreIdentificationDetailService _coreIdentificationDetailService,
                                                    IRecoveryOrderService _recoveryOrderService, IRecoveryAccessoryDetailService _recoveryAccessoryDetailService, ICoreBuilderService _coreBuilderService, IRollerBuilderService _rollerBuilderService,
                                                    IItemService _itemService, IWarehouseItemService _warehouseItemService, IBarringService _barringService, IStockMutationService _stockMutationService)
        {
            if (_validator.ValidUndoRejectObject(recoveryOrderDetail, _recoveryOrderService))
            {
                _repository.UndoRejectObject(recoveryOrderDetail);

                // add recovery order quantity reject
                // if valid, complete recovery order = true
                RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(recoveryOrderDetail.RecoveryOrderId);
                recoveryOrder.QuantityRejected -= 1;
                _recoveryOrderService.AdjustQuantity(recoveryOrder);

                // reverse stock mutate compound
                RollerBuilder         rollerBuilder          = _rollerBuilderService.GetObjectById(recoveryOrderDetail.RollerBuilderId);
                Item                  compound               = _itemService.GetObjectById(rollerBuilder.CompoundId);
                WarehouseItem         warehouseCompound      = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, compound.Id);
                IList <StockMutation> stockMutationCompounds = _stockMutationService.SoftDeleteStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseCompound);
                foreach (var stockMutationCompound in stockMutationCompounds)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationCompound, _itemService, _barringService, _warehouseItemService);
                }

                // reverse stock mutate core
                CoreIdentificationDetail coreIdentificationDetail = _coreIdentificationDetailService.GetObjectById(recoveryOrderDetail.CoreIdentificationDetailId);
                _coreIdentificationDetailService.SetJobScheduled(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);

                IList <StockMutation> stockMutationCores = _stockMutationService.SoftDeleteStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseCore);
                foreach (var stockMutationCore in stockMutationCores)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationCore, _itemService, _barringService, _warehouseItemService);
                }

                // accesories uncounted
            }
            return(recoveryOrderDetail);
        }
Esempio n. 7
0
        public CoreIdentificationDetail VSetJobScheduled(CoreIdentificationDetail coreIdentificationDetail, IRecoveryOrderService _recoveryOrderService,
                                                         IRecoveryOrderDetailService _recoveryOrderDetailService)
        {
            IList <RecoveryOrderDetail> details = _recoveryOrderDetailService.GetObjectsByCoreIdentificationDetailId(coreIdentificationDetail.Id);

            if (!details.Any())
            {
                coreIdentificationDetail.Errors.Add("Generic", "Tidak ada job yang ter schedule");
                return(coreIdentificationDetail);
            }
            foreach (var detail in details)
            {
                RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(detail.RecoveryOrderId);
                if (!recoveryOrder.IsConfirmed)
                {
                    coreIdentificationDetail.Errors.Add("Generic", "Job masih belum terkonfirmasi");
                    return(coreIdentificationDetail);
                }
            }
            return(coreIdentificationDetail);
        }
        public RecoveryOrderDetail UnfinishObject(RecoveryOrderDetail recoveryOrderDetail, ICoreIdentificationService _coreIdentificationService, ICoreIdentificationDetailService _coreIdentificationDetailService,
                                                  IRecoveryOrderService _recoveryOrderService, IRecoveryAccessoryDetailService _recoveryAccessoryDetailService, ICoreBuilderService _coreBuilderService, IRollerBuilderService _rollerBuilderService,
                                                  IItemService _itemService, IWarehouseItemService _warehouseItemService, IBarringService _barringService, IStockMutationService _stockMutationService)
        {
            if (_validator.ValidUnfinishObject(recoveryOrderDetail, _recoveryOrderService, _recoveryAccessoryDetailService))
            {
                // unfinish object
                _repository.UnfinishObject(recoveryOrderDetail);

                // add recovery order quantity final
                RecoveryOrder recoveryOrder = _recoveryOrderService.GetObjectById(recoveryOrderDetail.RecoveryOrderId);
                recoveryOrder.QuantityFinal += 1;
                _recoveryOrderService.AdjustQuantity(recoveryOrder);

                // reverse stock mutate compound
                RollerBuilder         rollerBuilder          = _rollerBuilderService.GetObjectById(recoveryOrderDetail.RollerBuilderId);
                Item                  compound               = _itemService.GetObjectById(rollerBuilder.CompoundId);
                WarehouseItem         warehouseCompound      = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, compound.Id);
                IList <StockMutation> stockMutationCompounds = _stockMutationService.SoftDeleteStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseCompound);
                foreach (var stockMutationCompound in stockMutationCompounds)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationCompound, _itemService, _barringService, _warehouseItemService);
                }

                // reverse stock mutate core
                CoreIdentificationDetail coreIdentificationDetail = _coreIdentificationDetailService.GetObjectById(recoveryOrderDetail.CoreIdentificationDetailId);
                _coreIdentificationDetailService.SetJobScheduled(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);
                IList <StockMutation> stockMutationCores = _stockMutationService.SoftDeleteStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseCore);
                foreach (var stockMutationCore in stockMutationCores)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationCore, _itemService, _barringService, _warehouseItemService);
                }

                // reverse stock mutate roller
                Item roller = (coreIdentificationDetail.MaterialCase == Core.Constants.Constant.MaterialCase.New) ?
                              _rollerBuilderService.GetRollerNewCore(rollerBuilder.Id) : _rollerBuilderService.GetRollerUsedCore(rollerBuilder.Id);
                WarehouseItem         warehouseRoller      = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, roller.Id);
                IList <StockMutation> stockMutationRollers = _stockMutationService.SoftDeleteStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseRoller);
                foreach (var stockMutationRoller in stockMutationRollers)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationRoller, _itemService, _barringService, _warehouseItemService);
                }

                // reverse stock mutate accessories
                IList <RecoveryAccessoryDetail> recoveryAccessoryDetails = _recoveryAccessoryDetailService.GetObjectsByRecoveryOrderDetailId(recoveryOrderDetail.Id);
                if (recoveryAccessoryDetails.Any())
                {
                    foreach (var recoveryAccessoryDetail in recoveryAccessoryDetails)
                    {
                        Item                  accessory                = _itemService.GetObjectById(recoveryAccessoryDetail.ItemId);
                        WarehouseItem         warehouseAccessory       = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, accessory.Id);
                        IList <StockMutation> stockMutationAccessories = _stockMutationService.SoftDeleteStockMutationForRecoveryAccessory(recoveryAccessoryDetail, warehouseAccessory);
                        foreach (var stockMutationAccessory in stockMutationAccessories)
                        {
                            _stockMutationService.ReverseStockMutateObject(stockMutationAccessory, _itemService, _barringService, _warehouseItemService);
                        }
                    }
                }
            }
            return(recoveryOrderDetail);
        }
        public RecoveryOrderDetail FinishObject(RecoveryOrderDetail recoveryOrderDetail, DateTime FinishedDate, ICoreIdentificationService _coreIdentificationService, ICoreIdentificationDetailService _coreIdentificationDetailService,
                                                IRecoveryOrderService _recoveryOrderService, IRecoveryAccessoryDetailService _recoveryAccessoryDetailService, ICoreBuilderService _coreBuilderService, IRollerBuilderService _rollerBuilderService,
                                                IItemService _itemService, IWarehouseItemService _warehouseItemService, IBarringService _barringService, IStockMutationService _stockMutationService)
        {
            recoveryOrderDetail.FinishedDate = FinishedDate;
            if (_validator.ValidFinishObject(recoveryOrderDetail, _recoveryOrderService, _recoveryAccessoryDetailService))
            {
                // set object to finish
                _repository.FinishObject(recoveryOrderDetail);

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

                bool CaseAdditionCompound = false;
                bool CaseAdditionCore     = false;
                bool CaseAdditionRoller   = true;

                // 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, CaseAdditionCompound);
                _stockMutationService.StockMutateObject(stockMutationCompound, _itemService, _barringService, _warehouseItemService);

                CoreIdentificationDetail coreIdentificationDetail = _coreIdentificationDetailService.GetObjectById(recoveryOrderDetail.CoreIdentificationDetailId);
                _coreIdentificationDetailService.UnsetJobScheduled(coreIdentificationDetail, _recoveryOrderService, this);
                _coreIdentificationDetailService.BuildRoller(coreIdentificationDetail);

                // deduce core
                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, CaseAdditionCore);
                _stockMutationService.StockMutateObject(stockMutationCore, _itemService, _barringService, _warehouseItemService);

                // add roller
                Item roller = (coreIdentificationDetail.MaterialCase == Core.Constants.Constant.MaterialCase.New) ?
                              _rollerBuilderService.GetRollerNewCore(rollerBuilder.Id) : _rollerBuilderService.GetRollerUsedCore(rollerBuilder.Id);
                WarehouseItem warehouseRoller     = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, roller.Id);
                StockMutation stockMutationRoller = _stockMutationService.CreateStockMutationForRecoveryOrder(recoveryOrderDetail, warehouseRoller, CaseAdditionRoller);
                _stockMutationService.StockMutateObject(stockMutationRoller, _itemService, _barringService, _warehouseItemService);

                // deduce accessories
                IList <RecoveryAccessoryDetail> recoveryAccessoryDetails = _recoveryAccessoryDetailService.GetObjectsByRecoveryOrderDetailId(recoveryOrderDetail.Id);
                if (recoveryAccessoryDetails.Any())
                {
                    foreach (var recoveryAccessoryDetail in recoveryAccessoryDetails)
                    {
                        Item          accessory              = _itemService.GetObjectById(recoveryAccessoryDetail.ItemId);
                        WarehouseItem warehouseAccessory     = _warehouseItemService.FindOrCreateObject(recoveryOrder.WarehouseId, accessory.Id);
                        StockMutation stockMutationAccessory = _stockMutationService.CreateStockMutationForRecoveryAccessory(recoveryAccessoryDetail, warehouseAccessory);
                        _stockMutationService.StockMutateObject(stockMutationAccessory, _itemService, _barringService, _warehouseItemService);
                    }
                }
            }
            return(recoveryOrderDetail);
        }