public IHttpActionResult ApproveRequisition([FromBody] RequisitionMobileViewModel requisition)
        {
            try
            {
                // Update requisition status to Approved
                var req = requisitionService.Get(requisition.RequisitionId);
                req.Status = CustomStatus.Approved;
                requisitionService.Save(req);

                var inventoryList        = (List <Inventory>)inventoryService.GetAll();
                var itemRequisitionList  = itemRequisitionService.GetAllByRequisitionId(requisition.RequisitionId);
                var itemDisbursementList = new List <ItemDisbursement>();

                // Add Disbursement
                var disbursement = new Disbursement()
                {
                    DepartmentId = requisition.DepartmentId,
                    Status       = CustomStatus.ForRetrieval
                };

                //Retrieve all itemDisbursements meant for retrieval
                var allItemDisbursements = (List <ItemDisbursement>)disbursementService.getAllItemDisbursementsByStatus(CustomStatus.ForRetrieval);

                //Allocate itemrequisition details to itemdisbursement
                foreach (var itemReq in itemRequisitionList)
                {
                    var itemDisbursement = new ItemDisbursement()
                    {
                        DisbursementId    = disbursement.Id,
                        ItemId            = itemReq.ItemId,
                        RequestedQuantity = itemReq.Quantity,
                        AvailableQuantity = 0
                    };
                    itemDisbursementList.Add(itemDisbursement);
                }

                disbursementService.Save(disbursement);

                //Allocate available quantity by inventory availability
                List <ItemDisbursement> finalItemDisbursementList = AllocateAvailableQtyAndStatus(itemDisbursementList, inventoryList, allItemDisbursements);
                foreach (var ib in finalItemDisbursementList)
                {
                    itemDisbursementService.Save(ib);
                }
            }
            catch (Exception)
            {
                return(BadRequest("Requisition already approved"));
            }

            return(Ok());
        }
Exemple #2
0
        public ActionResult Approve(string id)
        {
            var requisition = requisitionService.Get(id);

            requisition.Status = CustomStatus.Approved;
            requisitionService.Save(requisition);


            var inventoryList        = (List <Inventory>)InventoryService.GetAll();
            var itemRequisitionList  = itemRequisitionService.GetAllByRequisitionId(requisition.Id);
            var itemDisbursementList = new List <ItemDisbursement>();

            // Add Disbursement
            var disbursement = new Disbursement()
            {
                DepartmentId = requisition.DepartmentId,
                Status       = CustomStatus.ForRetrieval
            };

            //Retrieve all itemDisbursements meant for retrieval
            var allItemDisbursements = (List <ItemDisbursement>)disbursementService.getAllItemDisbursementsByStatus(CustomStatus.ForRetrieval);

            //Allocate itemrequisition details to itemdisbursement
            foreach (var req in itemRequisitionList)
            {
                var itemDisbursement = new ItemDisbursement()
                {
                    DisbursementId    = disbursement.Id,
                    ItemId            = req.ItemId,
                    RequestedQuantity = req.Quantity,
                    AvailableQuantity = 0
                };
                itemDisbursementList.Add(itemDisbursement);
            }

            disbursementService.Save(disbursement);

            //Allocate available quantity by inventory availability
            List <ItemDisbursement> finalItemDisbursementList = AllocateAvailableQtyAndStatus(itemDisbursementList, inventoryList, allItemDisbursements);

            foreach (var ib in finalItemDisbursementList)
            {
                itemDisbursementService.Save(ib);
            }

            return(Json(new { id = requisition.Id }));
        }
Exemple #3
0
        public void Save(ItemDisbursement itemDisbursement)
        {
            ItemDisbursement id = itemDisbursementContext.Get(itemDisbursement.Id);

            if (id == null)
            {
                itemDisbursementContext.Add(itemDisbursement);
            }
            else
            {
                id.ItemId            = itemDisbursement.ItemId;
                id.DisbursementId    = itemDisbursement.DisbursementId;
                id.RequestedQuantity = itemDisbursement.RequestedQuantity;
                id.AvailableQuantity = itemDisbursement.AvailableQuantity;
                id.Remark            = itemDisbursement.Remark;
                id.Status            = itemDisbursement.Status;
            }

            itemDisbursementContext.Commit();
        }