コード例 #1
0
    public Order RandomizeRequest()
    {
        Order order = new Order(0, 0, 0, 0, 0, 0);
        float specific_rooms_count = RandomValue(1, 20);

        for (int i = 0; i < specific_rooms_count; i++)
        {
            float    room_index = RandomValue(0, 5);
            RoomType type       = (RoomType)room_index;
            bool     added      = false;
            foreach (SpecialRequest r in order.requests)
            {
                if (r.type == type)
                {
                    r.roomAmount++;
                    added = true;
                }
            }
            if (!added)
            {
                SpecialRequest sp = new SpecialRequest(type);
                order.requests.Add(sp);
            }
        }
        order.safety  = Random.Range(0.3f, 0.75f);
        order.quality = Random.Range(1.25f, 2.75f);
        order.budget  = Cash(order);
        return(order);
    }
コード例 #2
0
        public ActionResult <string> UpdateSpecial([FromBody] SpecialRequest specialRequest)
        {
            string result = string.Empty;

            if (specialRequest.Type == SpecialType.Price)
            {
                var priceSpecial = new PriceSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                    specialRequest.IsActive, specialRequest.Price);
                result = _specialsDataAccessor.Update(priceSpecial);
            }
            else if (specialRequest.Type == SpecialType.Limit)
            {
                var limitSpecial = new LimitSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                    specialRequest.IsActive, specialRequest.DiscountQty, specialRequest.DiscountAmount, specialRequest.Limit);
                result = _specialsDataAccessor.Update(limitSpecial);
            }
            else if (specialRequest.Type == SpecialType.Restriction)
            {
                var restrictionSpecial = new RestrictionSpecial(specialRequest.ProductName, specialRequest.PurchaseQty,
                                                                specialRequest.IsActive, specialRequest.DiscountQty, specialRequest.DiscountAmount,
                                                                specialRequest.RestrictionType);

                result = _specialsDataAccessor.Update(restrictionSpecial);
            }

            return(result);
        }
コード例 #3
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;
        }
コード例 #4
0
        public void Setup()
        {
            validPriceSpecial        = new PriceSpecial("Can of soup", 2, true, 5);
            validPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 2,
                IsActive    = true,
                Price       = 5,
                Type        = SpecialType.Price
            };

            zeroPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 2,
                IsActive    = true,
                Price       = 0,
                Type        = SpecialType.Price
            };

            lessThanTwoQuantityPriceSpecialRequest = new SpecialRequest
            {
                ProductName = "Can of soup",
                PurchaseQty = 1,
                IsActive    = true,
                Price       = 5,
                Type        = SpecialType.Price
            };

            validLimitSpecial = new LimitSpecial("Can of beans", 2, true, 1, 0.5f, 6);

            validLimitSpecialRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 6,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutLimitRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 0,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutDiscountAmountRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0,
                Limit          = 4,
                Type           = SpecialType.Limit
            };

            limitSpecialWithoutDiscountQuantityRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 0,
                DiscountAmount = 0.5f,
                Limit          = 4,
                Type           = SpecialType.Limit
            };

            limitSpecialWithLimitLessThanPurchaseQtyRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 1,
                Type           = SpecialType.Limit
            };

            limitSpecialWithLimitNotAMultipleOfPurchaseQtyPlusDiscountQtyRequest = new SpecialRequest
            {
                ProductName    = "Can of beans",
                PurchaseQty    = 2,
                IsActive       = true,
                DiscountQty    = 1,
                DiscountAmount = 0.5f,
                Limit          = 5,
                Type           = SpecialType.Limit
            };

            validRestrictionSpecial = new RestrictionSpecial("Bananas", 2, true, 1, 0.5f, RestrictionType.Lesser);

            validRestrictionSpecialRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 1,
                DiscountAmount  = 0.5f,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            restrictionSpecialWithZeroDiscountAmountRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 1,
                DiscountAmount  = 0,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            restrictionSpecialWithZeroDiscountQtyRequest = new SpecialRequest
            {
                ProductName     = "Bananas",
                PurchaseQty     = 2,
                IsActive        = true,
                DiscountQty     = 0,
                DiscountAmount  = 0.5f,
                RestrictionType = RestrictionType.Lesser,
                Type            = SpecialType.Restriction
            };

            specialsList = new List <ISpecial>();
            specialsList.Add(validPriceSpecial);
            specialsList.Add(validLimitSpecial);
        }