public WarehouseMutationOrder VDontHaveDetails(WarehouseMutationOrder warehouseMutationOrder, IWarehouseMutationOrderDetailService _warehouseMutationOrderDetailService)
        {
            IList <WarehouseMutationOrderDetail> details = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(warehouseMutationOrder.Id);

            if (details.Any())
            {
                warehouseMutationOrder.Errors.Add("Generic", "Tidak boleh memiliki WarehouseMutationOrder Details");
            }
            return(warehouseMutationOrder);
        }
        public WarehouseMutationOrder VHasWarehouseMutationOrderDetails(WarehouseMutationOrder warehouseMutationOrder, IWarehouseMutationOrderDetailService _warehouseMutationOrderDetailService)
        {
            IList <WarehouseMutationOrderDetail> details = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(warehouseMutationOrder.Id);

            if (!details.Any())
            {
                warehouseMutationOrder.Errors.Add("Generic", "Harus memiliki WarehouseMutationOrder Details");
            }
            return(warehouseMutationOrder);
        }
        public WarehouseMutationOrderDetail VUniqueItem(WarehouseMutationOrderDetail warehouseMutationOrderDetail, IWarehouseMutationOrderDetailService _warehouseMutationOrderDetailService, IItemService _itemService)
        {
            IList <WarehouseMutationOrderDetail> details = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(warehouseMutationOrderDetail.WarehouseMutationOrderId);

            foreach (var detail in details)
            {
                if (detail.ItemId == warehouseMutationOrderDetail.ItemId && detail.Id != warehouseMutationOrderDetail.Id)
                {
                    warehouseMutationOrderDetail.Errors.Add("Generic", "Tidak boleh ada duplikasi item dalam 1 Stock Adjustment");
                }
            }
            return(warehouseMutationOrderDetail);
        }
        public WarehouseMutationOrder VDetailsAreVerifiedConfirmable(WarehouseMutationOrder warehouseMutationOrder, IWarehouseMutationOrderService _warehouseMutationOrderService, IWarehouseMutationOrderDetailService _warehouseMutationOrderDetailService,
                                                                     IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService)
        {
            IList <WarehouseMutationOrderDetail> details = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(warehouseMutationOrder.Id);

            foreach (var detail in details)
            {
                WarehouseItem warehouseItemFrom = _warehouseItemService.FindOrCreateObject(warehouseMutationOrder.WarehouseFromId, detail.ItemId);
                if (warehouseItemFrom.Quantity < detail.Quantity)
                {
                    warehouseMutationOrder.Errors.Add("Generic", "Stock barang tidak boleh kurang dari stock yang akan dimutasikan");
                    return(warehouseMutationOrder);
                }
            }
            return(warehouseMutationOrder);
        }
        public dynamic GetListDetail(string _search, long nd, int rows, int?page, string sidx, string sord, int id, string filters = "")
        {
            // Construct where statement

            string strWhere = GeneralFunction.ConstructWhere(filters);

            // Get Data
            var query = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(id).Where(d => d.IsDeleted == false);

            var list = query as IEnumerable <WarehouseMutationOrderDetail>;

            var pageIndex    = Convert.ToInt32(page) - 1;
            var pageSize     = rows;
            var totalRecords = query.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            // default last page
            if (totalPages > 0)
            {
                if (!page.HasValue)
                {
                    pageIndex = totalPages - 1;
                    page      = totalPages;
                }
            }

            list = list.Skip(pageIndex * pageSize).Take(pageSize);

            return(Json(new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from model in list
                    select new
                {
                    id = model.Id,
                    cell = new object[] {
                        model.Code,
                        model.ItemId,
                        _itemService.GetObjectById(model.ItemId).Name,
                        model.Quantity
                    }
                }).ToArray()
            }, JsonRequestBehavior.AllowGet));
        }
 public WarehouseMutationOrder UnconfirmObject(WarehouseMutationOrder warehouseMutationOrder, IWarehouseMutationOrderDetailService _warehouseMutationOrderDetailService,
                                               IItemService _itemService, IBarringService _barringService, IWarehouseItemService _warehouseItemService,
                                               IStockMutationService _stockMutationService)
 {
     if (_validator.ValidUnconfirmObject(warehouseMutationOrder, this, _warehouseMutationOrderDetailService,
                                         _itemService, _barringService, _warehouseItemService))
     {
         IList <WarehouseMutationOrderDetail> warehouseMutationOrderDetails = _warehouseMutationOrderDetailService.GetObjectsByWarehouseMutationOrderId(warehouseMutationOrder.Id);
         foreach (var detail in warehouseMutationOrderDetails)
         {
             detail.Errors = new Dictionary <string, string>();
             _warehouseMutationOrderDetailService.UnconfirmObject(detail, this, _itemService, _barringService, _warehouseItemService, _stockMutationService);
         }
         _repository.UnconfirmObject(warehouseMutationOrder);
     }
     return(warehouseMutationOrder);
 }