public bool AskThreeSupplier(ItemWithQtyModel itemQty)
        {
            PurchaseOrderController CPOC = new PurchaseOrderController();
            int inventory1 = CPOC.GetInventoryFromSupplier(itemQty.FirstSupplier_ID, itemQty.Item_ID);
            int inventory2 = CPOC.GetInventoryFromSupplier(itemQty.SecondSupplier_ID, itemQty.Item_ID);
            int inventory3 = CPOC.GetInventoryFromSupplier(itemQty.ThirdSupplier_ID, itemQty.Item_ID);

            if (inventory1 + inventory2 + inventory3 >= itemQty.Qty)
            {
                qtyCanSuppList[0] = inventory1;
                qtyCanSuppList[1] = inventory2;
                qtyCanSuppList[2] = itemQty.Qty - inventory1 - inventory2;
                supplierList[0]   = itemQty.FirstSupplier_ID;
                supplierList[1]   = itemQty.SecondSupplier_ID;
                supplierList[2]   = itemQty.ThirdSupplier_ID;
                status            = 123;
                return(true);
            }

            else
            {
                qtyCanSuppList[0] = inventory1;
                qtyCanSuppList[1] = inventory2;
                qtyCanSuppList[2] = inventory3;
                supplierList[0]   = itemQty.FirstSupplier_ID;
                supplierList[1]   = itemQty.SecondSupplier_ID;
                supplierList[2]   = itemQty.ThirdSupplier_ID;
                status            = -3;
                return(false);
            }
        }
        public void DistributeToSuppliers(List <OrderDetailController> odList)
        {
            PurchaseOrderController CPOC = new PurchaseOrderController();

            foreach (OrderDetailController od in odList)
            {
                for (int i = 0; i < od.supplierList.Length; i++)
                {
                    Item item = CPOC.GetItemByItem_ID(od.Item_ID);
                    switch (od.supplierList[i])
                    {
                    case "ALPA":
                        ItemWithQtyModel iwq0 = new ItemWithQtyModel();
                        iwq0.Item_ID     = item.Item_ID;
                        iwq0.Qty         = od.qtyCanSuppList[i];
                        iwq0.Category_ID = item.ItemCategory.Category_ID;
                        iwq0.Item_Name   = item.Item_Name;
                        iwq0.UOM         = item.UOM;
                        ALPAod.Add(iwq0);
                        break;

                    case "BANE":
                        ItemWithQtyModel iwq1 = new ItemWithQtyModel();
                        iwq1.Item_ID     = item.Item_ID;
                        iwq1.Qty         = od.qtyCanSuppList[i];
                        iwq1.Category_ID = item.ItemCategory.Category_ID;
                        iwq1.Item_Name   = item.Item_Name;
                        iwq1.UOM         = item.UOM;

                        BANEod.Add(iwq1);
                        break;

                    case "CHEP":
                        ItemWithQtyModel iwq2 = new ItemWithQtyModel();
                        iwq2.Item_ID     = item.Item_ID;
                        iwq2.Qty         = od.qtyCanSuppList[i];
                        iwq2.Category_ID = item.ItemCategory.Category_ID;
                        iwq2.Item_Name   = item.Item_Name;
                        iwq2.UOM         = item.UOM;
                        CHEPod.Add(iwq2);
                        break;

                    case "OMEG":
                        ItemWithQtyModel iwq3 = new ItemWithQtyModel();
                        iwq3.Item_ID     = item.Item_ID;
                        iwq3.Qty         = od.qtyCanSuppList[i];
                        iwq3.Category_ID = item.ItemCategory.Category_ID;
                        iwq3.Item_Name   = item.Item_Name;
                        iwq3.UOM         = item.UOM;
                        OMEGod.Add(iwq3);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        public bool AskTwoSupplier(ItemWithQtyModel itemQty)
        {
            PurchaseOrderController CPOC = new PurchaseOrderController();
            int inventory1 = CPOC.GetInventoryFromSupplier(itemQty.FirstSupplier_ID, itemQty.Item_ID);
            int inventory2 = CPOC.GetInventoryFromSupplier(itemQty.SecondSupplier_ID, itemQty.Item_ID);

            if (inventory1 + inventory2 >= itemQty.Qty)
            {
                qtyCanSuppList[0] = inventory1;
                qtyCanSuppList[1] = itemQty.Qty - inventory1;
                supplierList[0]   = itemQty.FirstSupplier_ID;
                supplierList[1]   = itemQty.SecondSupplier_ID;
                status            = 12;
                return(true);
            }
            //means supplier 1 and supplier 2 can fulfill the order together
            else
            {
                inventory1 = CPOC.GetInventoryFromSupplier(itemQty.FirstSupplier_ID, itemQty.Item_ID);
                inventory2 = CPOC.GetInventoryFromSupplier(itemQty.ThirdSupplier_ID, itemQty.Item_ID);
                if (inventory1 + inventory2 >= itemQty.Qty)
                {
                    qtyCanSuppList[0] = inventory1;
                    qtyCanSuppList[1] = itemQty.Qty - inventory1;
                    supplierList[0]   = itemQty.FirstSupplier_ID;
                    supplierList[1]   = itemQty.ThirdSupplier_ID;
                    status            = 13;
                    return(true);
                }
                //means supplier 1 and supplier 3 can fulfill the order together
                else
                {
                    inventory1 = CPOC.GetInventoryFromSupplier(itemQty.SecondSupplier_ID, itemQty.Item_ID);
                    inventory2 = CPOC.GetInventoryFromSupplier(itemQty.ThirdSupplier_ID, itemQty.Item_ID);
                    if (inventory1 + inventory2 >= itemQty.Qty)
                    {
                        qtyCanSuppList[0] = inventory1;
                        qtyCanSuppList[1] = itemQty.Qty - inventory1;
                        supplierList[0]   = itemQty.SecondSupplier_ID;
                        supplierList[1]   = itemQty.ThirdSupplier_ID;
                        status            = 23;
                        return(true);
                    }
                    //means supplier 2 and supplier 3 can fulfill the order together
                    else
                    {
                        status = -2;
                        return(false);
                    }
                    //no two supplier can fulfill
                }
            }
        }
        public bool AskOneSupplier(ItemWithQtyModel itemQty)
        {
            PurchaseOrderController CPOC = new PurchaseOrderController();

            int inventory = CPOC.GetInventoryFromSupplier(itemQty.FirstSupplier_ID, itemQty.Item_ID);

            if (inventory >= itemQty.Qty)
            {
                qtyCanSuppList[0] = itemQty.Qty;
                supplierList[0]   = itemQty.FirstSupplier_ID;
                status            = 1;
                return(true);
            }
            //mean supplier 1 can fulfill the order
            else
            {
                inventory = CPOC.GetInventoryFromSupplier(itemQty.SecondSupplier_ID, itemQty.Item_ID);
                if (inventory >= itemQty.Qty)
                {
                    qtyCanSuppList[0] = itemQty.Qty;
                    supplierList[0]   = itemQty.SecondSupplier_ID;
                    status            = 2;
                    return(true);
                }
                //mean supplier 2 can fulfill the order
                else
                {
                    inventory = CPOC.GetInventoryFromSupplier(itemQty.ThirdSupplier_ID, itemQty.Item_ID);
                    if (inventory >= itemQty.Qty)
                    {
                        qtyCanSuppList[0] = itemQty.Qty;
                        supplierList[0]   = itemQty.ThirdSupplier_ID;
                        status            = 3;
                        return(true);
                    }
                    //mean supplier 3 can fulfill the order
                    else
                    {
                        status = -1;
                        return(false);
                    }
                    //no one supplier can fulfill
                }
            }
        }