Exemple #1
0
 public bool ValidConfirmObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService,
                                IBarringService _barringService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
 {
     barringOrder.Errors.Clear();
     VConfirmObject(barringOrder, _barringOrderDetailService, _barringService, _itemService, _warehouseItemService);
     return(isValid(barringOrder));
 }
Exemple #2
0
        public dynamic GetInfo(int Id)
        {
            BarringOrder model = new BarringOrder();

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

            return(Json(new
            {
                model.Id,
                model.Code,
                model.ContactId,
                Contact = _contactService.GetObjectById(model.ContactId).Name,
                model.WarehouseId,
                WarehouseCode = _warehouseService.GetObjectById(model.WarehouseId).Code,
                Warehouse = _warehouseService.GetObjectById(model.WarehouseId).Name,
                model.QuantityReceived,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
 public BarringOrder VConfirmObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService, IBarringService _barringService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
 {
     VHasConfirmationDate(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VHasNotBeenConfirmed(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VHasBarringOrderDetails(barringOrder, _barringOrderDetailService);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VQuantityReceivedEqualDetails(barringOrder, _barringOrderDetailService);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VQuantityIsInStock(barringOrder, _barringOrderDetailService, _barringService, _itemService, _warehouseItemService);
     return(barringOrder);
 }
Exemple #4
0
        public BarringOrder VQuantityIsInStock(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService, IBarringService _barringService,
                                               IItemService _itemService, IWarehouseItemService _warehouseItemService)
        {
            IList <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);

            // itemId contains Id of the blanket, leftbar, and rightbar
            IDictionary <int, int> ValuePairItemIdQuantity = new Dictionary <int, int>();

            foreach (var detail in details)
            {
                Barring barring = _barringService.GetObjectById(detail.BarringId);
                // blanket
                if (ValuePairItemIdQuantity.ContainsKey(barring.BlanketItemId))
                {
                    ValuePairItemIdQuantity[barring.BlanketItemId] += 1;
                }
                else
                {
                    ValuePairItemIdQuantity.Add(barring.BlanketItemId, 1);
                }

                // leftbar
                if (barring.LeftBarItemId != null)
                {
                    if (ValuePairItemIdQuantity.ContainsKey((int)barring.LeftBarItemId))
                    {
                        ValuePairItemIdQuantity[(int)barring.LeftBarItemId] += 1;
                    }
                    else
                    {
                        ValuePairItemIdQuantity.Add((int)barring.LeftBarItemId, 1);
                    }
                }

                // rightbar
                if (barring.RightBarItemId != null)
                {
                    if (ValuePairItemIdQuantity.ContainsKey((int)barring.RightBarItemId))
                    {
                        ValuePairItemIdQuantity[(int)barring.RightBarItemId] += 1;
                    }
                    else
                    {
                        ValuePairItemIdQuantity.Add((int)barring.RightBarItemId, 1);
                    }
                }
            }

            foreach (var ValuePair in ValuePairItemIdQuantity)
            {
                WarehouseItem warehouseItem = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, ValuePair.Key);
                if (warehouseItem.Quantity < ValuePair.Value)
                {
                    barringOrder.Errors.Add("Generic", "Stock quantity BoM untuk barring tidak boleh kurang dari jumlah di dalam barring order");
                    return(barringOrder);
                }
            }
            return(barringOrder);
        }
 public BarringOrder CompleteObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService, IBarringService _barringService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
 {
     if (_validator.ValidCompleteObject(barringOrder, _barringOrderDetailService))
     {
         _repository.CompleteObject(barringOrder);
     }
     return(barringOrder);
 }
Exemple #6
0
 public BarringOrder VHasNotBeenCompleted(BarringOrder barringOrder)
 {
     if (barringOrder.IsCompleted)
     {
         barringOrder.Errors.Add("Generic", "Sudah complete");
     }
     return(barringOrder);
 }
Exemple #7
0
 public BarringOrder VHasBeenConfirmationDate(BarringOrder barringOrder)
 {
     if (barringOrder.ConfirmationDate == null)
     {
         barringOrder.Errors.Add("ConfirmationDate", "Tidak boleh kosong");
     }
     return(barringOrder);
 }
Exemple #8
0
 public BarringOrder VHasBeenConfirmed(BarringOrder barringOrder)
 {
     if (!barringOrder.IsConfirmed)
     {
         barringOrder.Errors.Add("Generic", "Belum dikonfirmasi");
     }
     return(barringOrder);
 }
Exemple #9
0
 public BarringOrder VHasBeenCompleted(BarringOrder barringOrder)
 {
     if (!barringOrder.IsCompleted)
     {
         barringOrder.Errors.Add("Generic", "Belum complete");
     }
     return(barringOrder);
 }
Exemple #10
0
 public BarringOrder VHasConfirmationDate(BarringOrder obj)
 {
     if (obj.ConfirmationDate == null)
     {
         obj.Errors.Add("ConfirmationDate", "Tidak boleh kosong");
     }
     return(obj);
 }
Exemple #11
0
 public BarringOrder VHasQuantityReceived(BarringOrder barringOrder)
 {
     if (barringOrder.QuantityReceived <= 0)
     {
         barringOrder.Errors.Add("QuantityReceived", "Harus lebih dari 0");
     }
     return(barringOrder);
 }
Exemple #12
0
 public BarringOrder VHasNotBeenConfirmed(BarringOrder barringOrder)
 {
     if (barringOrder.IsConfirmed)
     {
         barringOrder.Errors.Add("Generic", "Sudah dikonfirmasi");
     }
     return(barringOrder);
 }
Exemple #13
0
 public BarringOrder VCreateObject(BarringOrder barringOrder, IBarringOrderService _barringOrderService)
 {
     VHasUniqueCode(barringOrder, _barringOrderService);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VHasQuantityReceived(barringOrder);
     return(barringOrder);
 }
        public BarringOrderDetail VBarringOrderHasBeenConfirmed(BarringOrderDetail barringOrderDetail, IBarringOrderService _barringOrderService)
        {
            BarringOrder barringOrder = _barringOrderService.GetObjectById(barringOrderDetail.BarringOrderId);

            if (!barringOrder.IsConfirmed)
            {
                barringOrderDetail.Errors.Add("Generic", "Barring Order belum dikonfirmasi");
            }
            return(barringOrderDetail);
        }
        public BarringOrderDetail VHasBarringOrder(BarringOrderDetail barringOrderDetail, IBarringOrderService _barringOrderService)
        {
            BarringOrder barringOrder = _barringOrderService.GetObjectById(barringOrderDetail.BarringOrderId);

            if (barringOrder == null)
            {
                barringOrderDetail.Errors.Add("BarringOrderId", "Tidak terasosiasi dengan Barring Order");
            }
            return(barringOrderDetail);
        }
Exemple #16
0
        public BarringOrder VQuantityReceivedEqualDetails(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
        {
            IList <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);

            if (barringOrder.QuantityReceived != details.Count())
            {
                barringOrder.Errors.Add("QuantityReceived", "Jumlah quantity received dan jumlah barring order detail tidak sama");
            }
            return(barringOrder);
        }
Exemple #17
0
 public BarringOrder VUpdateObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService, IBarringOrderService _barringOrderService)
 {
     VHasNotBeenConfirmed(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VCreateObject(barringOrder, _barringOrderService);
     return(barringOrder);
 }
Exemple #18
0
        public BarringOrder VHasBarringOrderDetails(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
        {
            IList <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);

            if (!details.Any())
            {
                barringOrder.Errors.Add("Generic", "Harus membuat barring order detail dahulu");
            }
            return(barringOrder);
        }
Exemple #19
0
 public BarringOrder VDeleteObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
 {
     VHasNotBeenConfirmed(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VAllDetailsHaveNotBeenCutNorRejected(barringOrder, _barringOrderDetailService);
     return(barringOrder);
 }
        public BarringOrderDetail VBarringOrderHasNotBeenCompleted(BarringOrderDetail barringOrderDetail, IBarringOrderService _barringOrderService)
        {
            BarringOrder barringOrder = _barringOrderService.GetObjectById(barringOrderDetail.BarringOrderId);

            if (barringOrder.IsCompleted)
            {
                barringOrderDetail.Errors.Add("Generic", "Barring order sudah complete");
            }
            return(barringOrderDetail);
        }
 public BarringOrder ConfirmObject(BarringOrder barringOrder, DateTime ConfirmationDate, IBarringOrderDetailService _barringOrderDetailService, IBarringService _barringService,
                                   IItemService _itemService, IWarehouseItemService _warehouseItemService)
 {
     barringOrder.ConfirmationDate = ConfirmationDate;
     if (_validator.ValidConfirmObject(barringOrder, _barringOrderDetailService, _barringService, _itemService, _warehouseItemService))
     {
         _repository.ConfirmObject(barringOrder);
     }
     return(barringOrder);
 }
        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);
        }
        public BarringOrderDetail UnfinishObject(BarringOrderDetail barringOrderDetail, IBarringOrderService _barringOrderService, IStockMutationService _stockMutationService,
                                                 IBarringService _barringService, IItemService _itemService, IWarehouseItemService _warehouseItemService)
        {
            if (_validator.ValidUnfinishObject(barringOrderDetail, _barringOrderService))
            {
                _repository.UnfinishObject(barringOrderDetail);
                // deduce barring order quantity final
                BarringOrder barringOrder = _barringOrderService.GetObjectById(barringOrderDetail.BarringOrderId);
                barringOrder.QuantityFinal -= 1;
                _barringOrderService.AdjustQuantity(barringOrder);

                // reverse stock mutation
                Barring               barring          = _barringService.GetObjectById(barringOrderDetail.BarringId);
                WarehouseItem         warehouseBarring = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, barring.Id);
                IList <StockMutation> stockMutations   = _stockMutationService.SoftDeleteStockMutationForBarringOrder(barringOrderDetail, warehouseBarring);
                foreach (var stockMutation in stockMutations)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
                }

                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);
                        IList <StockMutation> stockMutationLeftBars = _stockMutationService.SoftDeleteStockMutationForBarringOrder(barringOrderDetail, warehouseLeftBar);
                        foreach (var stockMutationLeftBar in stockMutationLeftBars)
                        {
                            _stockMutationService.ReverseStockMutateObject(stockMutationLeftBar, _itemService, _barringService, _warehouseItemService);
                        }
                    }
                    if (rightbar != null)
                    {
                        WarehouseItem         warehouseRightBar      = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, rightbar.Id);
                        IList <StockMutation> stockMutationRightBars = _stockMutationService.SoftDeleteStockMutationForBarringOrder(barringOrderDetail, warehouseRightBar);
                        foreach (var stockMutationRightBar in stockMutationRightBars)
                        {
                            _stockMutationService.ReverseStockMutateObject(stockMutationRightBar, _itemService, _barringService, _warehouseItemService);
                        }
                    }
                }

                WarehouseItem         warehouseBlanket      = _warehouseItemService.FindOrCreateObject(barringOrder.WarehouseId, barring.BlanketItemId);
                IList <StockMutation> stockMutationBlankets = _stockMutationService.SoftDeleteStockMutationForBarringOrder(barringOrderDetail, warehouseBlanket);
                foreach (var stockMutationBlanket in stockMutationBlankets)
                {
                    _stockMutationService.ReverseStockMutateObject(stockMutationBlanket, _itemService, _barringService, _warehouseItemService);
                }
            }
            return(barringOrderDetail);
        }
Exemple #24
0
 public BarringOrder VHasUniqueCode(BarringOrder barringOrder, IBarringOrderService _barringOrderService)
 {
     if (String.IsNullOrEmpty(barringOrder.Code) || barringOrder.Code.Trim() == "")
     {
         barringOrder.Errors.Add("Code", "Tidak boleh kosong");
     }
     if (_barringOrderService.IsCodeDuplicated(barringOrder))
     {
         barringOrder.Errors.Add("Code", "Tidak boleh ada duplikasi");
     }
     return(barringOrder);
 }
Exemple #25
0
        public string PrintError(BarringOrder 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 BarringOrder SoftDeleteObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
 {
     if (_validator.ValidDeleteObject(barringOrder, _barringOrderDetailService))
     {
         ICollection <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);
         foreach (var detail in details)
         {
             // delete details
             _barringOrderDetailService.GetRepository().SoftDeleteObject(detail);
         }
         _repository.SoftDeleteObject(barringOrder);
     }
     return(barringOrder);
 }
Exemple #27
0
        public BarringOrder VAllDetailsHaveNotBeenCutNorRejected(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
        {
            IList <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);

            foreach (var detail in details)
            {
                if (detail.IsCut || detail.IsRejected)
                {
                    barringOrder.Errors.Add("Generic", "Semua barring order detail harus belum di cut atau di reject");
                    return(barringOrder);
                }
            }
            return(barringOrder);
        }
Exemple #28
0
        public BarringOrder VAllDetailsHaveBeenFinishedOrRejected(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
        {
            IList <BarringOrderDetail> details = _barringOrderDetailService.GetObjectsByBarringOrderId(barringOrder.Id);

            foreach (var detail in details)
            {
                if (!detail.IsFinished && !detail.IsRejected)
                {
                    barringOrder.Errors.Add("Generic", "Semua barring order detail harus telah selesai atau di reject");
                    return(barringOrder);
                }
            }
            return(barringOrder);
        }
Exemple #29
0
 public BarringOrder VCompleteObject(BarringOrder barringOrder, IBarringOrderDetailService _barringOrderDetailService)
 {
     VHasBeenConfirmed(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VHasNotBeenCompleted(barringOrder);
     if (!isValid(barringOrder))
     {
         return(barringOrder);
     }
     VAllDetailsHaveBeenFinishedOrRejected(barringOrder, _barringOrderDetailService);
     return(barringOrder);
 }
Exemple #30
0
        public dynamic Insert(BarringOrder model)
        {
            try
            {
                model = _barringOrderService.CreateObject(model);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                model.Errors.Add("Generic", "Error : " + ex);
            }

            return(Json(new
            {
                model.Errors
            }));
        }