예제 #1
0
        public bool SetRepresentative(string repname, HttpSessionStateBase session)
        {
            if (repname is null)
            {
                session["MessageBack"] = "Please choose an employee to represent";
                return(false);
            }
            string[] emplist = (string[])session["AuthEmployeeList"];
            if (!emplist.Contains(repname))
            {
                session["MessageBack"] = "No such employee (" + repname + ") in this department";
                return(false);
            }
            session["MessageBack"] = "";
            string deptid = session["DepartmentID"].ToString();
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptid).First();
            string newrepID      = new string(repname.Where(Char.IsDigit).ToArray());
            string username      = session["Username"].ToString();
            string password      = session["Password"].ToString();
            string statusMessage = WebAccessSetRepresentative(username, password, newrepID);

            if (statusMessage == "Success")
            {
                deptDetails.representative = newrepID;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = session["EmployeeID"].ToString();
                string             receipient    = newrepID;
                emailBizLogic.SendEmail("assignRep", receipient, sender, null, null, null);
            }
            db.SaveChangesAsync();
            return(true);
        }
예제 #2
0
        public async Task CancelAuthorisedPerson(HttpSessionStateBase session)
        {
            string deptid = session["DepartmentID"].ToString();
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptid).First();

            if (deptDetails.authorisedPerson == null)
            {
                return;
            }
            string newempID      = "";
            string username      = session["Username"].ToString();
            string password      = session["Password"].ToString();
            string statusMessage = WebAccessSetAuthorisedPerson(username, password, newempID);

            if (statusMessage == "Success")
            {
                string             removedAuth   = db.DeptCollectionDetails.Find(deptid).authorisedPerson;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = session["EmployeeID"].ToString();
                string             receipient    = removedAuth;
                emailBizLogic.SendEmail("removeAuth", receipient, sender, null, null, null);
                db.DeptCollectionDetails.Find(deptid).authorisedPerson = null;
                db.DeptCollectionDetails.Find(deptid).validDateStart   = null;
                db.DeptCollectionDetails.Find(deptid).validDateEnd     = null;
            }
            else
            {
                return;
            }
            await db.SaveChangesAsync();
        }
예제 #3
0
        public async Task CancelRepresentative(string deptId, HttpSessionStateBase session)
        {
            if (db.DeptCollectionDetails.Find(deptId).representative == null)
            {
                return;
            }
            string deptid = session["DepartmentID"].ToString();
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptid).First();
            string newrepID      = "";
            string username      = session["Username"].ToString();
            string password      = session["Password"].ToString();
            string statusMessage = WebAccessSetRepresentative(username, password, newrepID);

            if (statusMessage == "Success")
            {
                string removedRep = db.DeptCollectionDetails.Find(deptId).representative;
                db.DeptCollectionDetails.Find(deptId).representative = null;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = session["EmployeeID"].ToString();
                string             receipient    = removedRep;
                emailBizLogic.SendEmail("removeRep", receipient, sender, null, null, null);
            }
            else
            {
                return;
            }
            await db.SaveChangesAsync();
        }
예제 #4
0
        public string CancelRepresentativeWebAPI(string deptID, string headID, string username, string password)
        {
            if (db.DeptCollectionDetails.Find(deptID).representative == null)
            {
                return("Success");
            }
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptID).First();
            string newrepID      = "";
            string statusMessage = WebAccessSetRepresentative(username, password, newrepID);

            if (statusMessage == "Success")
            {
                string removedRep = db.DeptCollectionDetails.Find(deptID).representative;
                db.DeptCollectionDetails.Find(deptID).representative = null;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = headID;
                string             receipient    = removedRep;
                emailBizLogic.SendEmail("removeRep", receipient, sender, null, null, null);
            }
            else
            {
                return(statusMessage);
            }
            db.SaveChangesAsync();
            return("Success");
        }
예제 #5
0
        public string SetRepresentativeWebAPI(string newrepid, string deptID, string headID, string username, string password)
        {
            Dictionary <string, string> emplist = GetEmployeeList(username, password, deptID);

            if (newrepid is null)
            {
                return("Please choose an employee to represent");
            }
            if (!emplist.ContainsKey(newrepid))
            {
                return("No such employee of id:" + newrepid + " in this department");
            }
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptID).First();
            string statusMessage             = WebAccessSetRepresentative(username, password, newrepid);

            if (statusMessage == "Success")
            {
                deptDetails.representative = newrepid;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = headID;
                string             receipient    = newrepid;
                emailBizLogic.SendEmail("assignRep", receipient, sender, null, null, null);
            }
            db.SaveChangesAsync();
            return("Success");
        }
예제 #6
0
        public string CreateAdjustmentVoucher(AdjustmentVoucherViewModel avvm)
        {
            //ItemInventoryLocation - 1 - StockQty, 2 - DisburseQty, 3 - AdjustQty (not used)
            decimal totalAdjAmt = 0M;

            //Initiate Adjustment entry
            Adjustment adjustment = new Adjustment();

            adjustment.voucherId  = avvm.voucherID;
            adjustment.clerk      = new string(avvm.clerkIDName.Where(Char.IsDigit).ToArray());
            adjustment.supervisor = new string(avvm.supervisorIDName.Where(Char.IsDigit).ToArray());
            adjustment.date       = avvm.voucherDate;
            adjustment.status     = "Submitted";

            foreach (AdjustmentVoucherViewModelDetail avvmd in avvm.itemList)
            {
                AdjustmentDetail adjustmentDetail = new AdjustmentDetail();
                Inventory        inventory        = db.Inventories.Find(avvmd.itemID);

                //edit Adj detail
                adjustmentDetail.itemId    = avvmd.itemID;
                adjustmentDetail.quantity  = avvmd.itemQty;
                adjustmentDetail.voucherId = avvm.voucherID;
                if (avvmd.itemInventoryLocation == 1)
                {
                    //Adj inventory
                    inventory.storeQuantity = avvmd.itemQty < 0 ? inventory.storeQuantity - Math.Abs(avvmd.itemQty) : inventory.storeQuantity + avvmd.itemQty;
                    inventory.adjQuantity  -= avvmd.itemQty;
                    avvmd.remark           += (" Adjusted Item code : " + avvmd.itemID + " Qty : " + avvmd.itemQty + " from StoreQty");
                }
                else if (avvmd.itemInventoryLocation == 2)
                {
                    inventory.disburseQuantity += avvmd.itemQty < 0 ? inventory.disburseQuantity - Math.Abs(avvmd.itemQty) : inventory.disburseQuantity + avvmd.itemQty;
                    inventory.adjQuantity      -= avvmd.itemQty;
                    avvmd.remark += (" Adjusted Item code : " + avvmd.itemID + " Qty : " + avvmd.itemQty + " from DisburseQty");
                }
                string  supplier  = db.Catalogues.Find(avvmd.itemID).firstSupplier;
                decimal itemPrice = db.SupplierQuotations.Where(x => x.itemId == avvmd.itemID && x.supplierId == supplier).First().price;
                totalAdjAmt            += (itemPrice * avvmd.itemQty);
                adjustmentDetail.remark = avvmd.remark;
                db.AdjustmentDetails.Add(adjustmentDetail);
            }
            avvm.needAuthority = totalAdjAmt > 250M ? true : false;
            avvm.status        = "Submitted";

            //Set need authority (Logic - if need manager approval, set manager id - else null)
            adjustment.needAuthority   = avvm.needAuthority == true ? new string(avvm.managerIDName.Where(Char.IsDigit).ToArray()) : null;
            adjustment.adjustmentValue = totalAdjAmt;
            db.Adjustments.Add(adjustment);
            db.SaveChanges();
            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             receipient    = avvm.needAuthority == true ? adjustment.needAuthority : adjustment.supervisor;
            string             sender        = adjustment.clerk;
            string             linkref       = "http://" + ConstantsConfig.linkrefURLPartial + "/Adjustment/AdjustmentDetail?adjustmentID=" + avvm.voucherID;

            emailBizLogic.SendEmail("submitAdj", receipient, sender, null, null, linkref);
            return(adjustment.voucherId);
        }
예제 #7
0
        public bool SetAuthorisedPerson(string authperson, string startdate, string enddate, HttpSessionStateBase session)
        {
            if (authperson is null || startdate is null || enddate is null)
            {
                session["MessageBack"] = "Please enter all necessary fields";
                return(false);
            }
            string[] emplist = (string[])session["AuthEmployeeList"];
            if (!emplist.Contains(authperson))
            {
                session["MessageBack"] = "No such employee (" + authperson + ") in this department";
                return(false);
            }
            DateTime startDate = new DateTime();
            DateTime endDate   = new DateTime();

            DateTime.TryParse(startdate, out startDate);
            DateTime.TryParse(enddate, out endDate);
            DateTime compareDate = DateTime.Now.Date;

            if (startDate < compareDate || endDate < compareDate)
            {
                session["MessageBack"] = "Please ensure both start date (" + startdate + ") and end date (" + enddate + ") are not earlier the date today (" + compareDate.ToString() + ")";
                return(false);
            }
            if (startDate > endDate)
            {
                session["MessageBack"] = "Your selected start date " + startdate + "is earlier than your selected end date " + enddate;
                return(false);
            }
            session["MessageBack"] = "";
            string deptid = session["DepartmentID"].ToString();
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptid).First();
            string newempID      = new string(authperson.Where(Char.IsDigit).ToArray());
            string username      = session["Username"].ToString();
            string password      = session["Password"].ToString();
            string statusMessage = WebAccessSetAuthorisedPerson(username, password, newempID);

            if (statusMessage == "Success")
            {
                deptDetails.authorisedPerson = newempID;
                deptDetails.validDateStart   = startDate;
                deptDetails.validDateEnd     = endDate;
            }
            else
            {
                return(false);
            }
            db.SaveChanges();
            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             sender        = session["EmployeeID"].ToString();
            string             receipient    = newempID;

            emailBizLogic.SendEmail("assignAuth", receipient, sender, null, null, null);
            return(true);
        }
예제 #8
0
        public DisbursementViewModel CreateDisbursementAdjustmentVoucher(DisbursementViewModel model, HttpSessionStateBase session)
        {
            Adjustment adjustment = new Adjustment();
            DateTime   date       = DateTime.Now;

            adjustment.date = date.Date;
            string timestamp = date.ToString("yyyyMMddhhmmss");

            adjustment.clerk      = session["EmployeeID"].ToString();
            adjustment.status     = "Submitted";
            adjustment.supervisor = session["HeadID"].ToString();
            adjustment.voucherId  = "ADJ" + adjustment.clerk + timestamp;
            string  disburseID = model.disbursementID;
            decimal totalvalue = 0;
            Dictionary <string, string> storeEmpList = GetStoreEmployeeList(session["Username"].ToString(), session["Password"].ToString());
            string managerIDName = storeEmpList["manager"];

            foreach (DisbursementViewModelDetail dvmd in model.dvmdList)
            {
                if (dvmd.adjQty == 0 || dvmd.adjQty == null)
                {
                    continue;
                }
                AdjustmentDetail adjDetail = new AdjustmentDetail();
                adjDetail.itemId    = dvmd.itemID;
                adjDetail.quantity  = (int)dvmd.adjQty;
                adjDetail.remark    = "Disbursement (" + disburseID + ") Adjustment";
                adjDetail.voucherId = adjustment.voucherId;
                string  supplier  = db.Catalogues.Find(dvmd.itemID).firstSupplier;
                decimal itemPrice = db.SupplierQuotations.Where(x => x.itemId == dvmd.itemID && x.supplierId == supplier).First().price;
                totalvalue += (itemPrice * adjDetail.quantity);
                db.AdjustmentDetails.Add(adjDetail);
            }
            //Set need authority (Logic - if need manager approval, set manager id - else null)
            bool needAuthority = totalvalue > 250M ? true : false;;

            adjustment.needAuthority   = needAuthority == true ? new string(managerIDName.Where(Char.IsDigit).ToArray()) : null;
            adjustment.adjustmentValue = totalvalue;
            db.Adjustments.Add(adjustment);
            Disbursement disbursement = db.Disbursements.Find(disburseID);

            disbursement.adjustmentID = adjustment.voucherId;
            db.SaveChanges();

            model.status       = "Adjustment Performed";
            model.adjustmentID = adjustment.voucherId;

            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             receipient    = needAuthority ? adjustment.needAuthority : adjustment.supervisor;
            string             sender        = adjustment.clerk;
            string             linkref       = "http://" + ConstantsConfig.linkrefURLPartial + "/Adjustment/AdjustmentDetail?adjustmentID=" + adjustment.voucherId;

            emailBizLogic.SendEmail("submitAdj", receipient, sender, null, null, linkref);

            return(model);
        }
예제 #9
0
        public string SetAuthorisedPersonWebAPI(string authperson, string headID, string deptID, string startdate, string enddate, string username, string password)
        {
            Dictionary <string, string> emplist = GetEmployeeList(username, password, deptID);

            if (deptID is null || startdate is null || enddate is null)
            {
                return("Important Parameters cannot be null");
            }
            if (!emplist.ContainsKey(authperson))
            {
                return("Please ensure that employee authorised is in your department");
            }
            DateTime startDate   = new DateTime();
            DateTime endDate     = new DateTime();
            bool     date1pass   = DateTime.TryParse(startdate, out startDate);
            bool     date2pass   = DateTime.TryParse(enddate, out endDate);
            DateTime compareDate = DateTime.Now.Date;

            if (!date1pass || !date2pass)
            {
                return("Please ensure dates are in valid format");
            }
            if (startDate < compareDate || endDate < compareDate)
            {
                return("Please ensure both start date (" + startdate + ") and end date (" + enddate + ") are not earlier the date today (" + compareDate.ToString() + ")");
            }
            if (startDate > endDate)
            {
                return("Your selected start date " + startdate + "is earlier than your selected end date " + enddate);
            }

            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptID).First();
            string statusMessage             = WebAccessSetAuthorisedPerson(username, password, authperson);

            if (statusMessage == "Success")
            {
                deptDetails.authorisedPerson = authperson;
                deptDetails.validDateStart   = startDate;
                deptDetails.validDateEnd     = endDate;
            }
            else
            {
                return(statusMessage);
            }
            db.SaveChanges();
            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             sender        = headID;
            string             receipient    = authperson;

            emailBizLogic.SendEmail("assignAuth", receipient, sender, null, null, null);
            return("ok");
        }
예제 #10
0
        public async Task <Requisition> SaveRequisitionForm(Requisition req, HttpSessionStateBase session)
        {
            req.status = "Submitted";
            db.Requisitions.Add(req);
            await db.SaveChangesAsync();

            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             receipient    = req.approvalPerson;
            string             sender        = req.employee;
            string             linkref       = "http://" + ConstantsConfig.linkrefURLPartial + "/Requisition/ReqFormDetail?id=" + req.requisitionId;

            emailBizLogic.SendEmail("submitNewReq", receipient, sender, null, null, linkref);
            return(req);
        }
예제 #11
0
        public async Task UserConfirmDisbursement(string disburseID)
        {
            Disbursement disbursement = db.Disbursements.Find(disburseID);

            if (disbursement != null)
            {
                disbursement.status = "Collection Confirmed";
                await db.SaveChangesAsync();
            }
            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            Requisition        req           = db.Requisitions.Where(x => x.disbursementId == disburseID).First();
            string             deptID        = req.departmentId;
            string             sender        = db.Retrievals.Find(req.retrievalId).clerkId;
            string             linkref       = "http://" + ConstantsConfig.linkrefURLPartial + "/Disbursement/DisbursementDetailForRep?disburseID=" + disburseID;

            emailBizLogic.SendEmail("confirmDisburse", null, sender, deptID, null, linkref);
            await Task.CompletedTask;
        }
예제 #12
0
        public async Task <Requisition> ApproveRequisitionForm(Requisition req, HttpSessionStateBase session)
        {
            Requisition requisition    = db.Requisitions.Where(x => x.requisitionId == req.requisitionId).First();
            string      approvalPerson = session["EmployeeID"].ToString();

            requisition.approvalPerson = approvalPerson;
            requisition.status         = "Approved";
            requisition.approvalDate   = DateTime.Now;
            await db.SaveChangesAsync();

            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             sender        = approvalPerson;
            string             receipient    = req.employee;
            string             linkref       = "http://" + ConstantsConfig.linkrefURLPartial + "/Requisition/ReqFormDetail?id=" + req.requisitionId;

            emailBizLogic.SendEmail("updateReqStatus", receipient, sender, null, "Approved", linkref);
            emailBizLogic.SendEmail("sendStoreClerkReq", receipient, null, req.departmentId, null, linkref);
            return(requisition);
        }
예제 #13
0
        public AdjustmentVoucherViewModel ApproveVoucher(AdjustmentVoucherViewModel avvm)
        {
            Adjustment         adjustment    = db.Adjustments.Find(avvm.voucherID);
            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();

            if (avvm.needAuthority == true)
            {
                adjustment.status = "Approved by " + avvm.managerIDName;
                avvm.status       = "Approved by " + avvm.managerIDName;
            }
            else
            {
                adjustment.status = "Approved by " + avvm.supervisorIDName;
                avvm.status       = "Approved by " + avvm.supervisorIDName;
            }
            db.SaveChanges();
            string receipient = adjustment.clerk;
            string sender     = avvm.needAuthority == true ? adjustment.needAuthority : adjustment.supervisor;
            string linkref    = "http://" + ConstantsConfig.linkrefURLPartial + "/Adjustment/AdjustmentDetail?adjustmentID=" + avvm.voucherID;

            emailBizLogic.SendEmail("approveAdj", receipient, sender, null, null, linkref);
            return(avvm);
        }
예제 #14
0
        public async Task <Requisition> RejectRequisitionForm(Requisition req, HttpSessionStateBase session)
        {
            Requisition requisition = db.Requisitions.Where(x => x.requisitionId == req.requisitionId).First();

            if (session["Role"].ToString() == "clerk")
            {
                requisition.status = "Rejected by store clerk";
            }
            else
            {
                requisition.status = "Rejected by head";
            }
            requisition.remark = req.remark;
            await db.SaveChangesAsync();

            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
            string             sender        = session["EmployeeID"].ToString();
            string             receipient    = req.employee;
            string             linkref       = "http://" + ConstantsConfig.ipaddress + "/Requisition/ReqFormDetail?id=" + req.requisitionId;

            emailBizLogic.SendEmail("updateReqStatus", receipient, sender, null, "Rejected", linkref);
            return(requisition);
        }
예제 #15
0
        public string CancelAuthorisedPersonWebAPI(string headID, string deptID, string username, string password)
        {
            DeptCollectionDetail deptDetails = db.DeptCollectionDetails.Where(x => x.departmentId == deptID).First();

            if (deptDetails == null)
            {
                return("No such department exits");
            }
            else
            {
                if (deptDetails.authorisedPerson == null)
                {
                    return("Success");
                }
            }
            string newempID      = "";
            string statusMessage = WebAccessSetAuthorisedPerson(username, password, newempID);

            if (statusMessage == "Success")
            {
                string             removedAuth   = db.DeptCollectionDetails.Find(deptID).authorisedPerson;
                EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();
                string             sender        = headID;
                string             receipient    = removedAuth;
                emailBizLogic.SendEmail("removeAuth", receipient, sender, null, null, null);
                db.DeptCollectionDetails.Find(deptID).authorisedPerson = null;
                db.DeptCollectionDetails.Find(deptID).validDateStart   = null;
                db.DeptCollectionDetails.Find(deptID).validDateEnd     = null;
            }
            else
            {
                return("Fail");
            }
            db.SaveChangesAsync();
            return("Success");
        }
예제 #16
0
        public async Task DisbursementAllocation(List <RetrievalListModel> validatedRetrievalListModels, HttpSessionStateBase session)
        {
            validatedRetrievalListModels.Sort(new RetrievalListComparerBySpecial());
            Dictionary <string, string> departmentIDs = new Dictionary <string, string>();
            string deptID      = "";
            int    specCounter = 0;

            //Settle all Specials
            foreach (RetrievalListModel x in validatedRetrievalListModels)
            {
                specCounter++;
                //Disbursement is handled via departments
                Disbursement tempDisbursement = new Disbursement();
                DateTime     time             = DateTime.Now;
                string       timeStamp        = time.ToString("yyyyMMddhhmmssffff");
                string       disburseID       = "";
                //only create disbursement if there is an allocation (no allocation no disbursement)
                if (x.allocateQty != 0)
                {
                    if (departmentIDs.ContainsKey(x.department))
                    {
                        disburseID = departmentIDs[x.department];
                        tempDisbursement.comment = tempDisbursement.comment == null ? "-" + x.requisitionID : tempDisbursement.comment + "-" + x.requisitionID;
                    }
                    else
                    {
                        tempDisbursement.disbursementId = "DIS-" + x.department + "-" + timeStamp;
                        tempDisbursement.comment        = x.requisitionID;
                        tempDisbursement.disburseDate   = time;
                        tempDisbursement.status         = "Awaiting Collection";
                        string repid = db.DeptCollectionDetails.Find(x.department).representative;
                        tempDisbursement.repID = repid;
                        db.Disbursements.Add(tempDisbursement);
                        departmentIDs.Add(x.department, tempDisbursement.disbursementId);
                        disburseID = tempDisbursement.disbursementId;
                    }
                }

                if (x.requisitionID.Contains("Special"))
                {
                    SpecialRequest    tempSpecial        = new SpecialRequest();
                    Requisition       tempRequisition    = new Requisition();
                    RequisitionDetail tempRequisitionDet = new RequisitionDetail();

                    //Fulfilling Special - Special will be removed from the retrieval processes
                    // note Reqid to be lookuped since reqid is specialID for specials
                    string reqID = db.SpecialRequests.Where(z => z.specialId == x.requisitionID).First().requisitionId;
                    tempRequisition    = db.Requisitions.Find(reqID);
                    tempSpecial        = db.SpecialRequests.Where(y => y.specialId == x.requisitionID && y.itemId == x.itemID).First();
                    tempSpecial.status = "Disbursed";

                    //trace back original requisition id to clear special flag
                    tempRequisitionDet        = db.RequisitionDetails.Where(z => z.requisitionId == reqID && z.itemId == x.itemID).First();
                    tempRequisitionDet.remark = tempRequisitionDet.remark == null ? "Fulfilled Qty:" + x.adjQty + " by " + disburseID : tempRequisitionDet.remark + " , Fulfilled Qty:" + x.adjQty + " by " + disburseID;

                    //trace back special requisition to edit status and remark
                    Requisition specialReq = db.Requisitions.Find("Special-" + reqID);
                    specialReq.disbursementId = disburseID;
                    specialReq.remark         = specialReq.remark == null ? "Fulfilled by " + disburseID : specialReq.remark + " , Fulfilled by " + disburseID;
                    specialReq.status         = "Full Disburse";
                    specialReq.RequisitionDetails.First().remark = "Fulfilled Qty:" + x.adjQty + " by " + disburseID;

                    //clear requisition if all reqdets are fulfiled
                    if (tempRequisition.RequisitionDetails.Select(z => z.remark.Contains("Fulfilled")).Count() == tempRequisition.RequisitionDetails.Count)
                    {
                        tempRequisition.status = "Full Disburse";
                        tempRequisition.remark = tempRequisition.remark == null ? "Fully Fulfilled by " + disburseID : tempRequisition.remark + " , Fully Fulfilled by " + disburseID;
                    }
                    else
                    {
                        tempRequisition.status = "Partial Disburse";
                        tempRequisition.remark = tempRequisition.remark == null ? "Partially Fulfilled by " + disburseID : tempRequisition.remark + " , Fully Fulfilled by " + disburseID;
                    }

                    //Moving stock from inventory to disbursement
                    Inventory invItem = db.Inventories.Where(y => y.itemId == x.itemID).First();
                    if (x.adjQty != null)
                    {
                        invItem.storeQuantity    = invItem.storeQuantity - (int)x.adjQty;
                        invItem.disburseQuantity = invItem.disburseQuantity + (int)x.adjQty;
                    }
                    else
                    {
                        invItem.storeQuantity    = invItem.storeQuantity - x.allocateQty;
                        invItem.disburseQuantity = invItem.disburseQuantity + x.allocateQty;
                    }
                }
                else
                {
                    SpecialRequest    tempSpecial        = new SpecialRequest();
                    Requisition       tempRequisition    = new Requisition();
                    RequisitionDetail tempRequisitionDet = new RequisitionDetail();

                    //Not special => retrieveQty can be lower than request
                    int delta = 0;
                    tempRequisitionDet = db.RequisitionDetails.Where(z => z.requisitionId == x.requisitionID && z.itemId == x.itemID).First();
                    tempRequisition    = db.Requisitions.Where(z => z.requisitionId == x.requisitionID).First();
                    //full fulfillment
                    if (tempRequisitionDet.retrieveQty >= tempRequisitionDet.requestQty)
                    {
                        if (tempRequisitionDet.retrieveQty == tempRequisitionDet.requestQty)
                        {
                            tempRequisitionDet.remark = tempRequisitionDet.remark == null ? "Fulfilled normally" : tempRequisitionDet.remark + " , Fulfilled normally";
                        }
                        else
                        {
                            tempRequisitionDet.remark = tempRequisitionDet.remark == null ? "Over - Fulfilled by" + (tempRequisitionDet.retrieveQty - tempRequisitionDet.requestQty) :
                                                        tempRequisitionDet.remark + " , Over - Fulfilled by" + (tempRequisitionDet.retrieveQty - tempRequisitionDet.requestQty);
                        }
                    }
                    //adjustment result in partial / zero fulfillment
                    else if (tempRequisitionDet.retrieveQty < tempRequisitionDet.requestQty)
                    {
                        //finds the delta - which goes to the special creation
                        delta = tempRequisitionDet.requestQty - (int)tempRequisitionDet.retrieveQty;

                        //create special for shortfall
                        tempSpecial.itemId        = x.itemID;
                        tempSpecial.requestQty    = delta;
                        tempSpecial.requisitionId = x.requisitionID;
                        tempSpecial.status        = "Special";
                        tempSpecial.specialId     = "Special-" + x.requisitionID + specCounter;
                        tempRequisitionDet.remark = tempRequisitionDet.remark == null ? " Special created (ID:" + tempSpecial.specialId + ") for qty:" + delta : tempRequisitionDet.remark + " Special created (ID:" + tempSpecial.specialId + ") for qty:" + delta;
                        db.SpecialRequests.Add(tempSpecial);

                        //create special requisitions after settling the specials
                        Requisition specialRequisition = new Requisition();
                        specialRequisition.approvalDate       = tempRequisition.approvalDate;
                        specialRequisition.approvalPerson     = tempRequisition.approvalPerson;
                        specialRequisition.departmentId       = tempRequisition.departmentId;
                        specialRequisition.employee           = tempRequisition.employee;
                        specialRequisition.remark             = "Special created for " + tempRequisition.requisitionId + " Item : " + tempRequisitionDet.itemId + " Amount : " + delta;
                        specialRequisition.requisitionId      = "Special-" + tempRequisition.requisitionId + "-" + tempRequisitionDet.itemId;
                        specialRequisition.requestDate        = tempRequisition.requestDate;
                        specialRequisition.status             = "Special";
                        specialRequisition.RequisitionDetails = new List <RequisitionDetail>();
                        RequisitionDetail specialReqDet = new RequisitionDetail();
                        specialReqDet.adjustQty     = delta;
                        specialReqDet.requestQty    = delta;
                        specialReqDet.adjustQty     = delta;
                        specialReqDet.itemId        = tempRequisitionDet.itemId;
                        specialReqDet.requisitionId = specialRequisition.requisitionId;
                        specialReqDet.remark        = "Special";
                        specialRequisition.RequisitionDetails.Add(specialReqDet);
                        db.Requisitions.Add(specialRequisition);
                    }
                    //adjust inventory as long as not zero retrieval
                    if (tempRequisitionDet.retrieveQty != 0)
                    {
                        Inventory invItem = db.Inventories.Where(y => y.itemId == x.itemID).First();
                        invItem.storeQuantity    = invItem.storeQuantity - (int)x.allocateQty;
                        invItem.disburseQuantity = invItem.disburseQuantity + (int)x.allocateQty;
                        //disbursement will also happen
                        tempRequisition.disbursementId = disburseID;
                    }
                }
            }
            await db.SaveChangesAsync();

            //adjust status of Requisition status after adjustments to reqdetail
            foreach (KeyValuePair <string, string> kvp in departmentIDs)
            {
                List <Requisition> reqlist = db.Requisitions.Where(x => x.disbursementId == kvp.Value).ToList();
                if (reqlist.Any())
                {
                    foreach (Requisition req in reqlist)
                    {
                        if (req.status != "Full Disburse")
                        {
                            if (req.RequisitionDetails.Where(y => y.remark.Contains("Fulfilled")).ToList <RequisitionDetail>().Count == req.RequisitionDetails.Count)
                            {
                                req.status = "Full Disburse";
                                req.remark = req.remark + " , Fully Fulfilled by " + kvp.Value;
                            }
                            else
                            {
                                req.status = "Partial Disburse";
                                req.remark = req.remark + " , Partially Fulfilled by " + kvp.Value;
                            }
                        }
                    }
                }
            }
            await db.SaveChangesAsync();

            EmailBusinessLogic emailBizLogic = new EmailBusinessLogic();

            foreach (KeyValuePair <string, string> kvp in departmentIDs)
            {
                deptID = kvp.Key;
                string linkref = "http://" + ConstantsConfig.linkrefURLPartial + "/Disbursement/DisbursementDetailForRep?disburseID=" + kvp.Value;
                emailBizLogic.SendEmail("collectDisburse", null, null, deptID, null, linkref);
            }

            await Task.CompletedTask;
        }