Пример #1
0
        public DisbursementModelCollection getAllThatCanBeSignedOff(string currentUser)
        {
            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            List <Request> efRequests = context.Requests
                                        .Where(x => x.current_status == RequestStatus.APPROVED ||
                                               x.current_status == RequestStatus.PART_DISBURSED &&
                                               x.deleted != "Y"
                                               ).ToList();

            List <DisbursementModel> results = new List <DisbursementModel>();

            if (efRequests.Count == 0)
            {
                //throw new ItemNotFoundException("No records exist");
                return(new DisbursementModelCollection(results));
            }

            foreach (var efRequest in efRequests)
            {
                DisbursementModel disbursing = findLatestSignOffsByRequestId(efRequest.request_id, currentUser);
                if (disbursing == null)
                {
                    continue;                     // SKIP
                }
                results.Add(disbursing);
            }

            return(new DisbursementModelCollection(results));
        }
        // update the disbursement
        public static DisbursementModel UpdateDisbursement(DisbursementModel dism, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            disbursement   ndism    = new disbursement();

            try
            {
                // finding the inventory object using Inventory API model
                ndism = entities.disbursements.Where(p => p.disid == dism.Disid).First <disbursement>();

                // transfering data from API model to DB Model
                ndism.disid = dism.Disid;
                ndism.reqid = dism.Reqid;
                ndism.ackby = dism.Ackby;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                dism = GetDisbursementByDisbursementId(ndism.disid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dism);
        }
        //create the disbursement
        public static DisbursementModel CreateDisbursement(DisbursementModel dism, out string error)
        {
            // initialize the error variable to return only blank if there is no error
            error = "";
            //initialize the entities , dibursement
            LUSSISEntities entities = new LUSSISEntities();
            disbursement   disb     = new disbursement();

            try
            {
                //add the data to the disbursement  database
                disb.reqid = dism.Reqid;
                disb.ackby = dism.Ackby;
                disb       = entities.disbursements.Add(disb);
                entities.SaveChanges();
                //get the newly added disbursement
                dism = GetDisbursementByDisbursementId(disb.disid, out error);
            }

            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dism);
        }
Пример #4
0
        public static DisbursementModel GetDisbursementByDisid(string token, int id, out string error)
        {
            string            url    = APIHelper.Baseurl + "disbursement/disid/" + id;
            DisbursementModel dblist = APIHelper.Execute <DisbursementModel>(token, url, out error);

            return(dblist);
        }
Пример #5
0
        public DisbursementModelCollection getAllPossibleDisbursementsForCollectionPoint(int collectionPointId)
        {
            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            List <Request> efRequests = context.Requests
                                        .Where(x =>
                                               (x.current_status == RequestStatus.DISBURSED ||
                                                x.current_status == RequestStatus.PART_DISBURSED) &&
                                               x.Department.collection_point == collectionPointId &&
                                               x.deleted != "Y"
                                               ).ToList();

            List <DisbursementModel> results = new List <DisbursementModel>();

            if (efRequests.Count == 0)
            {
                //throw new ItemNotFoundException("No records exist");
                return(new DisbursementModelCollection(results));
            }

            foreach (var efRequest in efRequests)
            {
                DisbursementModel disbursement = findLatestPossibleDisbursingByRequestId(efRequest.request_id);
                if (disbursement == null)
                {
                    continue;                       // SKIP
                }
                results.Add(disbursement);
            }

            return(new DisbursementModelCollection(results));
        }
        // Convert From Auto Generated DB Model to APIModel for Requisition
        private static DisbursementModel CovertDBDisbursementtoAPIDisbursement(disbursement disb)
        {
            DisbursementModel reqm = new DisbursementModel(disb.disid, disb.reqid, disb.ackby, disb.requisition.reqdate,
                                                           disb.requisition.status, disb.requisition.collectionpoint.cpname, disb.user.username,
                                                           disb.user.department.deptname, new List <DisbursementDetailsModel>());

            return(reqm);
        }
Пример #7
0
        public static DisbursementModel CreateRequisitionwithDetails(DisbursementModel reqm, string token, out string error)
        {
            string            url          = APIHelper.Baseurl + "/disbursement/createdetails/";
            string            objectstring = JsonConvert.SerializeObject(reqm);
            DisbursementModel db           = APIHelper.Execute <DisbursementModel>(token, objectstring, url, out error);

            return(db);
        }
Пример #8
0
        public static DisbursementModel UpadateDisbursement(DisbursementModel reqm, string token, out string error)
        {
            string            url          = APIHelper.Baseurl + "/disbursement/update/";
            string            objectstring = JsonConvert.SerializeObject(reqm);
            DisbursementModel db           = APIHelper.Execute <DisbursementModel>(token, objectstring, url, out error);

            return(db);
        }
Пример #9
0
        public IHttpActionResult CreateRequisitionwithDetails(DisbursementModel dism)
        {
            string            error = "";
            DisbursementModel dis   = DisbursementRepo.CreateDisbursementwithDetails(dism, dism.Disbursementlist, out error);

            if (error != "" || dis == null)
            {
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(dis));
        }
Пример #10
0
        public IHttpActionResult UpadateDisbursement(DisbursementModel dism)
        {
            string            error = "";
            DisbursementModel disbm = DisbursementRepo.UpdateDisbursement(dism, out error);

            if (error != "" || disbm == null)
            {
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(disbm));
        }
Пример #11
0
        public DisbursementModelCollection getAllThatWereDisbursed()
        {
            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            List <Request> efRequests = context.Requests
                                        .Where(x => (x.current_status == RequestStatus.DISBURSED ||
                                                     x.current_status == RequestStatus.PART_DISBURSED) &&
                                               x.deleted != "Y"
                                               ).ToList();

            List <DisbursementModel> results = new List <DisbursementModel>();

            if (efRequests.Count == 0)
            {
                //throw new ItemNotFoundException("No records exist");
                return(new DisbursementModelCollection(results));
            }

            foreach (var efRequest in efRequests)
            {
                Dictionary <ItemModel, int> items = new Dictionary <ItemModel, int>();

                var details = efRequest.Request_Details.Where(x => x.deleted != "Y");

                var events = details.Select(s => s.Request_Event.OrderByDescending(o => o.date_time)
                                            .Where(w => w.status == EventStatus.DISBURSED).DefaultIfEmpty(null).FirstOrDefault());

                //var list = efRequest.Request_Details
                //    .Select(s => s.Request_Event.OrderByDescending(o => o.date_time)
                //    .Where(w => w.status == EventStatus.DISBURSED)
                //    .First());

                foreach (var item in events)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    items.Add(new ItemModel(item.Request_Details.Stock_Inventory), item.quantity);
                }

                DisbursementModel disbursed = new DisbursementModel(efRequest, items);
                if (disbursed == null)
                {
                    continue;                    // SKIP
                }
                results.Add(disbursed);
            }

            return(new DisbursementModelCollection(results));
        }
        // Convert From Auto Generated DB Model to APIModel for Requsition with Requisition Details data
        private static DisbursementModel CovertDBDisbursementtoAPIDisbursementwithDetails(disbursement disb)
        {
            List <DisbursementDetailsModel> reqdm = new List <DisbursementDetailsModel>();

            foreach (disbursementdetail rqdm in disb.disbursementdetails)
            {
                reqdm.Add(new DisbursementDetailsModel(rqdm.disid, rqdm.itemid, rqdm.item.description, rqdm.qty, rqdm.item.category.name, rqdm.item.uom));
            }
            DisbursementModel reqm = new DisbursementModel(disb.disid, disb.reqid, disb.ackby, disb.requisition.reqdate,
                                                           disb.requisition.status, disb.requisition.collectionpoint.cpname, disb.user.username,
                                                           disb.user.department.deptname, reqdm);

            return(reqm);
        }
Пример #13
0
        public IHttpActionResult GetDisbursementByDisid(int disid)
        {
            string            error = "";
            DisbursementModel dism  = DisbursementRepo.GetDisbursementByDisbursementId(disid, out error);

            if (error != "" || dism == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "Requisition Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(dism));
        }
Пример #14
0
        public JsonResult UpdateQuantity(DisbursementModel model)
        {
            int              id             = model.id;
            string           disbursementId = model.disbursementId;
            List <ItemModel> items          = model.items;

            //int id, string disbursementId, JArray items

            if (String.IsNullOrEmpty(disbursementId))
            {
                return(Json(new { status = "Bad" }, JsonRequestBehavior.AllowGet));
            }

            Disbursement d = _disbursementDAO.FindById(Int32.Parse(disbursementId));



            if (d == null)
            {
                return(Json(new { status = "Bad" }, JsonRequestBehavior.AllowGet));
            }
            else if (d.Status.Label.Equals("Received"))
            {
                return(Json(new { status = "Bad" }, JsonRequestBehavior.AllowGet));
            }

            bool isAuth = false;

            foreach (CPClerk cpclerk in d.CollectionPoint.CPClerks)
            {
                if (cpclerk.IdStoreClerk == id)
                {
                    isAuth = true;
                }
            }
            if (isAuth == false)
            {
                return(Json(new { status = "Bad" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                _disbursementItemDAO.UpdateQuantityIssued(Int32.Parse(disbursementId), items);
            }

            return(Json(new { status = "Ok" }, JsonRequestBehavior.AllowGet));
        }
        //Create new Disbursement with Detials
        public static DisbursementModel CreateDisbursementwithDetails(DisbursementModel disb, List <DisbursementDetailsModel> disdm, out string error)
        {
            // initialize the error variable to return only blank if there is no error
            error = "";
            //initialize the entities , dibursement and disbursement list
            LUSSISEntities            entities = new LUSSISEntities();
            disbursement              dis      = new disbursement();
            List <disbursementdetail> dbdlist  = new List <disbursementdetail>();

            try
            {
                // add the data to the disbursement
                dis.reqid = disb.Reqid;
                dis.ackby = disb.Ackby;
                dis       = entities.disbursements.Add(dis);
                entities.SaveChanges();
                // add the arrary data to the disbursement details list
                foreach (DisbursementDetailsModel dbdm in disdm)
                {
                    disbursementdetail dbm = new disbursementdetail
                    {
                        disid  = dis.disid,
                        itemid = dbdm.Itemid,
                        qty    = dbdm.Qty
                    };
                    dbm = entities.disbursementdetails.Add(dbm);
                    entities.SaveChanges();
                    dbdlist.Add(dbm);
                }
                //get the added disbursement
                disb = GetDisbursementByDisbursementId(dis.disid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(disb);
        }
        // to get the Disbursement by the DisbursementId
        public static DisbursementModel GetDisbursementByDisbursementId(int disid, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";

            disbursement      disbursement = new disbursement();
            DisbursementModel dism         = new DisbursementModel();

            try
            {
                disbursement = entities.disbursements.Where(p => p.disid == disid).FirstOrDefault <disbursement>();
                dism         = CovertDBDisbursementtoAPIDisbursementwithDetails(disbursement);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dism);
        }
Пример #17
0
        private DisbursementModel _findLatestBetweenStatuses(int requestId, string fromStatus, string toStatus, string currentUser)
        { // For signing off forms (all disbursing ones)
            Request efRequest = context.Requests
                                .Where(x => x.request_id == requestId &&
                                       (x.current_status == RequestStatus.APPROVED ||
                                        x.current_status == RequestStatus.PART_DISBURSED)
                                       ).First();

            if (efRequest == null)
            {
                throw new ItemNotFoundException("No records exist");
            }

            Dictionary <ItemModel, int> itemsToFulfill = new Dictionary <ItemModel, int>();

            List <Request_Details> details = efRequest.Request_Details.ToList();

            foreach (var detail in details)
            {
                //int itemQty = 0;
                if (detail.deleted == "Y")
                {
                    continue;
                }

                List <Request_Event> events = detail.Request_Event.Where(w => w.deleted != "Y").ToList();

                // If there are no events for some reason, SKIP
                if (events.Count == 0)
                {
                    continue;
                }

                Request_Event eventItem = events.First();

                // If the event does not have anything allocated to it, SKIP
                if (eventItem.allocated.HasValue && eventItem.allocated.Value == 0)
                {
                    continue;
                }



                // Only add if it's retrieving AND it was by the currentUser
                if (eventItem.status == fromStatus && eventItem.allocated.HasValue)
                {
                    // currentUser was specified, skip if it's not by them
                    if (currentUser != null &&
                        eventItem.username != currentUser)
                    {
                        continue;
                    }

                    Stock_Inventory s = detail.Stock_Inventory;
                    itemsToFulfill.Add(new ItemModel(s), eventItem.allocated.Value);
                }
            }

            if (itemsToFulfill.Count == 0)
            {
                return(null);
            }

            DisbursementModel retrieved = new DisbursementModel(efRequest, itemsToFulfill);

            return(retrieved);
        }