Esempio n. 1
0
        //---------------------------------Stationary_Retrival_Form--------------------------------------//
        //--------------------------------------------------------------------------------------//
        public ActionResult View_Stationary_Retrival_Form()
        {
            using (var db = new DataBaseContext())
            {
                var Result = db.orders_repository.Join(
                    db.department_repository,

                    orders => orders.staff_obj.department_obj.departmentId,
                    department => department.departmentId,
                    (orders, department) => new
                {
                    Order_Obj      = orders,
                    Department_Obj = department
                }

                    )
                             .Join(
                    db.item_warehouses_repository,

                    orders => orders.Order_Obj.item_obj.itemId,
                    items_warehouse => items_warehouse.item.itemId,

                    (orders, items_warehouse) => new
                {
                    Department_Obj      = orders.Department_Obj,
                    Order_Obj           = orders,
                    Item_Ware_House_Obj = items_warehouse
                }
                    ).Where(x => x.Order_Obj.Order_Obj.order_status == "Approved_by_Head").OrderBy(x => x.Order_Obj.Order_Obj.item_obj.itemId)
                             .ToList();

                List <orders>          orders_lis    = new List <orders>();
                List <items_warehouse> item_ware_lis = new List <items_warehouse>();
                List <department>      depart_lis    = new List <department>();

                for (int i = 0; i < Result.Count; i++)
                {
                    var             current_result       = Result[i];
                    orders          current_order_object = current_result.Order_Obj.Order_Obj;
                    items_warehouse item_ware_hourse     = current_result.Item_Ware_House_Obj;
                    department      department_obj       = current_result.Department_Obj;

                    orders_lis.Add(current_order_object);
                    item_ware_lis.Add(item_ware_hourse);
                    depart_lis.Add(department_obj);
                }

                for (int i = 0; i < orders_lis.Count; i++)
                {
                    orders_lis[i].item_obj  = orders_lis[i].item_obj;
                    orders_lis[i].staff_obj = orders_lis[i].staff_obj;
                }

                ViewBag.Item_Warehouse_List = item_ware_lis;
                ViewBag.Order_List          = orders_lis;
                ViewBag.Department_List     = depart_lis;
            }
            return(View());
        }
Esempio n. 2
0
        public Dictionary <string, int> SEND_ORDER_TO_SUPPLIERS(items_warehouse item_ware_obj)
        {
            Dictionary <string, int> supplier_and_quantity = new Dictionary <string, int>();

            Boolean flag          = false;
            Boolean supplier_flag = false;

            int target_quantity = item_ware_obj.reorder_quantity;

            int supplier_ID = 1;

            using (var db = new DataBaseContext())
            {
                do
                {
                    suppliers_warehouse target_sup_ware_obj = db.suppliers_warehouse_repository.Where(sup => sup.suppliers_warehouse_plus_supplier.suppliersId == supplier_ID && sup.suppliers_warehouse_plus_item.itemId == item_ware_obj.item.itemId).FirstOrDefault();

                    // Check SUPPLIER_WAREHOUSE + ITEM_ID in ITEM_WAREHOUSE
                    if (target_sup_ware_obj.stock_balance > 0)
                    {
                        // SUFFICIENT
                        if (target_sup_ware_obj.stock_balance >= item_ware_obj.reorder_quantity)
                        {
                            target_sup_ware_obj.stock_balance = target_sup_ware_obj.stock_balance - target_quantity;
                            db.SaveChanges();
                            supplier_and_quantity.Add(target_sup_ware_obj.suppliers_warehouse_plus_supplier.name, target_quantity);
                            flag            = true;
                            target_quantity = 0;
                        }
                        // NOT SUFFICIENT
                        else if (target_quantity != 0)
                        {
                            target_quantity = target_quantity - target_sup_ware_obj.stock_balance;
                            supplier_and_quantity.Add(target_sup_ware_obj.suppliers_warehouse_plus_supplier.name, target_sup_ware_obj.stock_balance);
                            target_sup_ware_obj.stock_balance = 0;
                            db.SaveChanges();
                            supplier_ID++;
                        }
                    }
                    else
                    {
                        supplier_ID++;
                    }

                    if (supplier_ID == 4)
                    {
                        supplier_flag = true;
                    }
                } while (!flag && !supplier_flag);

                if (supplier_flag)
                {
                    supplier_and_quantity.Add("OUT_OF_STOCK_IN_SUPPLIER", 404);
                }
            }
            return(supplier_and_quantity);
        }
        internal static items_warehouse FindByItemId(int itemId)
        {
            items_warehouse it = new items_warehouse();

            using (var db = new DataBaseContext())
            {
                if (db.item_warehouses_repository.Where(x => x.item.itemId == itemId).Any())
                {
                    it = db.item_warehouses_repository.Where(x => x.item.itemId == itemId).FirstOrDefault();
                }
            }
            return(it);
        }
        internal static void UpdateReOrderLevelByItemId(int itemId, int newreorderlevel)
        {
            items_warehouse itw = new items_warehouse();

            using (var db = new DataBaseContext())
            {
                if (db.item_warehouses_repository.Where(x => x.item.itemId == itemId).Any())
                {
                    itw = db.item_warehouses_repository.Where(x => x.item.itemId == itemId).FirstOrDefault();
                }
                itw.reorder_level = newreorderlevel;
                db.SaveChanges();
            }
        }
Esempio n. 5
0
 //---------------------------------------------------------------------------------------------
 // --------------------------------------  PURCHASE ORDER -----------------------------------------------------
 public ActionResult View_Purchase_Order()
 {
     using (var db = new DataBaseContext())
     {
         List <items_warehouse> item_ware_lis = db.item_warehouses_repository.Where(i => i.stock_balance < i.reorder_level).ToList();
         for (int i = 0; i < item_ware_lis.Count; i++)
         {
             items_warehouse temp_item_ware_obj = item_ware_lis[i];
             item_ware_lis[i].item = temp_item_ware_obj.item;
         }
         ViewBag.Item_WareHouse_lis = item_ware_lis;
     }
     return(View());
 }
Esempio n. 6
0
        // Approve Department Request
        public ActionResult Ajax_Approve_Department_Request(ajax_model ajax_model_data)
        {
            string quantity_status = "";
            int    stock_level     = 0;
            string order_id_status = "";

            Dictionary <string, int> item_and_quantity_of_department = new Dictionary <string, int>();

            ajax_model ajax_data = new ajax_model
            {
                name      = ajax_model_data.name,
                main_data = ajax_model_data.main_data,
            };

            using (var db = new DataBaseContext())
            {
                List <orders> order_lis = db.orders_repository.Where(or => or.staff_obj.department_obj.department_name == ajax_data.name && or.order_status == "Approved_by_Head").ToList();

                Dictionary <int, int> item_quantity = new Dictionary <int, int>();

                List <items_warehouse> item_ware_lis = db.item_warehouses_repository.ToList();

                foreach (items_warehouse temp_item in item_ware_lis)
                {
                    item_quantity.Add(temp_item.item.itemId, temp_item.stock_balance);
                }

                for (int i = 0; i < order_lis.Count; i++)
                {
                    orders temp_order = order_lis[i];

                    stock_level = item_quantity[temp_order.item_obj.itemId];

                    stock_level = stock_level - temp_order.proposed_quantity;

                    order_id_status = temp_order.ordersId.ToString();

                    // For Stock Card
                    item_and_quantity_of_department.Add(temp_order.item_obj.item_description, temp_order.proposed_quantity);

                    if (stock_level < 0)
                    {
                        quantity_status = "OUT_OF_STOCK";
                        break;
                    }
                    else
                    {
                        item_quantity[temp_order.item_obj.itemId] = stock_level;
                    }
                }

                if (quantity_status != "OUT_OF_STOCK")
                {
                    foreach (KeyValuePair <int, int> data in item_quantity)
                    {
                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(k => k.item.itemId == data.Key).FirstOrDefault();
                        item_ware_obj.stock_balance = data.Value;
                        db.SaveChanges();
                        quantity_status = "QUANTITY_SUFFICIENT";

                        // Add ACTUAL_QUANTITY and DELIVERY DATE
                        foreach (orders temp_order in order_lis)
                        {
                            temp_order.actual_delivered_quantity_by_clerk = temp_order.proposed_quantity;
                            temp_order.delivered_order_date = DateTime.Now.ToString();
                            db.SaveChanges();
                        }
                    }

                    // For Stock Card
                    foreach (KeyValuePair <string, int> temp_data in item_and_quantity_of_department)
                    {
                        item item_obj = db.item_repository.Where(i => i.item_description == temp_data.Key).FirstOrDefault();

                        // STOCK CARD UPDATE
                        stock_card stock_card_obj = new stock_card(ajax_data.name, DateTime.Now.ToString(), " - " + temp_data.Value, item_obj);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();
                    }

                    foreach (orders temp_order in order_lis)
                    {
                        temp_order.order_status = "Approved_by_Clerk";
                        db.SaveChanges();
                    }
                }
            }
            object reply_to_client = new
            {
                item_quantity_status  = quantity_status,
                stock_level_status    = stock_level,
                order_identity_status = order_id_status,
            };

            return(Json(reply_to_client, JsonRequestBehavior.AllowGet));
        }
Esempio n. 7
0
        public ActionResult Create_Stationary_Retrival_Form(FormCollection form_data)
        {
            using (var db = new DataBaseContext())
            {
                int input_bx_count = Int32.Parse(form_data["input_bx_count_name"]);

                for (int i = 1; i <= input_bx_count; i++)
                {
                    string actual_quantity_delivered = form_data["Actual_Quantity_Delivered_" + i];
                    string store_order_id            = form_data["Store_Order_ID_" + i];

                    string[] store_order_id_lis = store_order_id.Split('_');

                    System.Diagnostics.Debug.WriteLine("STORE ID LIST: " + store_order_id_lis);
                    System.Diagnostics.Debug.WriteLine("ACTUAL QUANTITY : " + actual_quantity_delivered);

                    if (store_order_id_lis.Length == 1)
                    {
                        int    order_id        = Int32.Parse(store_order_id_lis[0]);
                        int    actual_quantity = Int32.Parse(actual_quantity_delivered);
                        orders order_obj       = db.orders_repository.Where(x => x.ordersId == order_id).FirstOrDefault();
                        order_obj.actual_delivered_quantity_by_clerk = actual_quantity;
                        order_obj.order_status = "Approved_by_Clerk";
                        db.SaveChanges();

                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(x => x.item.itemId == order_obj.item_obj.itemId).FirstOrDefault();
                        item_ware_obj.stock_balance = item_ware_obj.stock_balance - actual_quantity;
                        db.SaveChanges();
                    }
                    else
                    {
                        int actual_quantity = Int32.Parse(actual_quantity_delivered);
                        int temp_item_id    = 0;

                        for (int j = 0; j < store_order_id_lis.Length; j++)
                        {
                            int temp_order_id = Int32.Parse(store_order_id_lis[j]);

                            orders order_obj = db.orders_repository.Where(x => x.ordersId == temp_order_id).FirstOrDefault();

                            temp_item_id = order_obj.item_obj.itemId;

                            if (actual_quantity - order_obj.proposed_quantity > 0)
                            {
                                int temp_amount = actual_quantity - order_obj.proposed_quantity;
                                actual_quantity = actual_quantity - order_obj.proposed_quantity;

                                order_obj.actual_delivered_quantity_by_clerk = temp_amount;
                                order_obj.order_status = "Approved_by_Clerk";
                                db.SaveChanges();
                            }
                            else
                            {
                                order_obj.actual_delivered_quantity_by_clerk = actual_quantity;
                                order_obj.order_status = "Approved_by_Clerk";
                                db.SaveChanges();
                            }
                        }
                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(x => x.item.itemId == temp_item_id).FirstOrDefault();
                        item_ware_obj.stock_balance = item_ware_obj.stock_balance - actual_quantity;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("View_Adjustment_Voucher", "Clerk"));
            }
        }
Esempio n. 8
0
        public JsonResult Ajax_Purchase_Order(ajax_model ajax_data)
        {
            ajax_model data = new ajax_model
            {
                name      = ajax_data.name,
                main_data = ajax_data.main_data,
            };
            Dictionary <string, int> supplier_and_quantity;
            string supplier_status = "NOT_OUT_OF_STOCK_IN_SUPPLIER";

            using (var db = new DataBaseContext())
            {
                int temp_item_ware_id = Int32.Parse(data.name);

                items_warehouse item_ware_obj = db.item_warehouses_repository.Where(it => it.items_warehouseId == temp_item_ware_id).FirstOrDefault();

                supplier_and_quantity = SEND_ORDER_TO_SUPPLIERS(item_ware_obj);

                // Add Total Quantity From Suppliers
                foreach (KeyValuePair <string, int> temp_data in supplier_and_quantity)
                {
                    item_ware_obj.stock_balance = item_ware_obj.stock_balance + temp_data.Value;
                    suppliers sup_obj = db.suppliers_repository.Where(s => s.name == temp_data.Key).FirstOrDefault();

                    if (temp_data.Key == "OUT_OF_STOCK_IN_SUPPLIER")
                    {
                        supplier_status = "OUT_OF_STOCK_IN_SUPPLIER";
                    }
                    else if (sup_obj.suppliersId == 1)
                    {
                        item_ware_obj.first_supplier_balance = item_ware_obj.first_supplier_balance + temp_data.Value;
                        db.SaveChanges();

                        // STOCK CARD UPDATE
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();
                    }
                    else if (sup_obj.suppliersId == 2)
                    {
                        item_ware_obj.second_supplier_balance = item_ware_obj.second_supplier_balance + temp_data.Value;
                        db.SaveChanges();

                        // STOCK CARD UPDATE
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();
                    }
                    else if (sup_obj.suppliersId == 3)
                    {
                        item_ware_obj.third_supplier_balance = item_ware_obj.third_supplier_balance + temp_data.Value;
                        db.SaveChanges();

                        // STOCK CARD UPDATE
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();
                    }
                }
            }
            object reply_to_client = new
            {
                supplier_and_quantity_key    = supplier_and_quantity,
                supplier_out_of_stock_status = supplier_status,
            };

            return(Json(reply_to_client, JsonRequestBehavior.AllowGet));
        }
        protected override void Seed(DataBaseContext context)
        {
            // ITEM INITIALIZATION
            string[] item_code         = new string[] { "C001", "C002", "C003", "E001", "E002", "E003", "F020", "F021", "F022", "H011", "H012", "H013", "P010", "P011", "P012", "R002", "R001", "S100", "S040", "S101", "T001", "T002", "T003" };
            string[] category          = new string[] { "Clip", "Clip", "Clip", "Envelope", "Envelope", "Envelope", "File", "File", "File", "Pen", "Pen", "Pen", "Pad", "Pad", "Pad", "Ruler", "Ruler", "Scissors", "Tape", "Tape", "Tracks", "Tacks", "Tacks" };
            string[] description       = new string[] { "Clips Double 1\"", "Clips Double 2\"", "Clips Double 3/4 \"", "Envelope Brown 3*6", "Envelope Brown 4*7", "Envelope Brown 5*7", "File Separator", "File-Blue Plain", "File-Blue with Logo", "Highlighter Blue", "Highlighter Green", "Highlighter Pink", "Hole Puncher 2 holes", "Hole Puncher 3 holes", "Hole Puncher Adjustable", "Ruler 12\"", "Ruler 6\"", "Scissors", "Scotch Tape", "Scotch Tape Dispenser", "Thumb Tacks Large", "Thumb Tacks Medium", "Thumb Tacks Small" };
            Random   unit_price_random = new Random();

            List <item> item_list = new List <item>();

            for (int i = 0; i < item_code.Length; i++)
            {
                item item_obj = new item();
                item_obj.item_code        = item_code[i];
                item_obj.item_description = description[i];
                item_obj.category         = category[i];
                item_obj.unit_price       = unit_price_random.Next(1, 20);
                item_list.Add(item_obj);

                context.item_repository.Add(item_obj);
                context.SaveChanges();
            }

            // SUPPLIER INITIALIZATION
            string[]         supplier_code = new string[] { "ALPA", "CHEP", "BANE", "OMEG" };
            string[]         supplier_name = new string[] { "ALPHA Office Supplies", "Cheap Stationer", "BANE SHOP", "OMEGA Stationery Supplier" };
            string[]         contact_name  = new string[] { "Ms Irene Tan", "Mr Soh Kway Koh", "Mr Loh Ah Pek", "Mr Ronnie Ho" };
            int[]            phone_no      = new int[] { 46119928, 3543234, 4781234, 7671233 };
            int[]            fax           = new int[] { 4612238, 4742434, 4792434, 7671234 };
            string[]         address       = new string[] { " Blk 1128, Ang Mo Kio Industrial Park,#02-1108 Ang Mo Kio Street 62,Singapore 622262", "Blk 34, Clementi Road,#07-02 Ban Ban Soh Building,Singapore 110525", " Blk 124, Alexandra Road,#03-04 Banes Building,Singapore 550315", "Blk 11, Hillview Avenue,#03-04,Singapore 679036" };
            List <suppliers> suppliers_lis = new List <suppliers>();

            for (int i = 0; i < supplier_code.Length; i++)
            {
                suppliers supplier_obj = new suppliers(supplier_code[i], supplier_name[i], contact_name[i], fax[i], address[i], phone_no[i]);
                suppliers_lis.Add(supplier_obj);

                context.suppliers_repository.Add(supplier_obj);
                context.SaveChanges();
            }

            // SUPPLIER WAREHOUSE
            // WAREHOUSE For FIRST SUPPLIER
            int[] quantity_item = new int[] { 50, 100, 75, 55, 125, 400, 500, 300, 100, 200, 800, 900, 700, 230, 840, 120, 320, 410, 470, 340, 320, 160, 750 };
            int[] price         = new int[] { 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
            int[] item_id       = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };

            suppliers first_supplier_obj = new suppliers();
            List <suppliers_warehouse> suppliers_warehouse_lis = new List <suppliers_warehouse>();

            for (int k = 0; k < 3; k++)
            {
                for (int i = 0; i < item_code.Length; i++)
                {
                    item      item_obj     = (item)item_list[i];
                    suppliers supplier_obj = (suppliers)suppliers_lis[k];

                    suppliers_warehouse supplier_ware_obj = new suppliers_warehouse(quantity_item[i], quantity_item[i], price[i]);

                    supplier_ware_obj.suppliers_warehouse_plus_item     = item_obj;
                    supplier_ware_obj.suppliers_warehouse_plus_supplier = supplier_obj;

                    suppliers_warehouse_lis.Add(supplier_ware_obj);

                    context.suppliers_warehouse_repository.Add(supplier_ware_obj);
                    context.SaveChanges();
                }
            }

            // DEPARTMENT Initialization
            string[]          depart_code              = new string[] { "ENGL", "CPSC", "Stationery Store Inventory System", "REGR", "ZOOL" };
            string[]          depart_name              = new string[] { "English Dept", "Computer Science", "Commerce Dept", "Registrar Dept", "Zoology Dept" };
            string[]          dept_contact_name        = new string[] { "Mrs Pamela Kow", "Mr Wee Kian Fatt", "Mr Mohd. Azman", "Ms Helen Ho", "Mr. Peter Tan Ah Meng" };
            int[]             dept_tel_no              = new int[] { 8742234, 8901235, 8741284, 8901266, 8901266 };
            int[]             dept_fax_no              = new int[] { 8921456, 8921457, 8921256, 8921465, 8921465 };
            string[]          dept_head_name           = new string[] { "Prof Ezra Pound", "Dr. Soh Kian Wee", "Dr. Chia Leow Bee", "Mrs Low Kway Boo", "Prof Tan" };
            string[]          collection_point_list    = new string[] { "Stationery Store", "Managament School", "Medical School", "Engineering School", "Science School", "University Hospital" };
            string[]          representative_name_list = new string[] { "KayKay", "KyawKyaw", "AungAung", "TinTin", "NawNaw" };
            List <department> depart_lis = new List <department>();

            for (int i = 0; i < depart_code.Length; i++)
            {
                department dept_obj = new department(depart_code[i], depart_name[i], dept_contact_name[i], dept_tel_no[i], dept_fax_no[i], dept_head_name[i], collection_point_list[i], representative_name_list[i]);

                depart_lis.Add(dept_obj);

                context.department_repository.Add(dept_obj);
                context.SaveChanges();
            }

            // STAFF Initialization
            List <staff> staff_lis = new List <staff>();
            // EMPLOYEE INITIALIZATION
            // First Department
            staff staff_obj = new staff("KayKay", "*****@*****.**", "kay1234", 21, "male", "Employee", depart_lis[0]);

            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("NayNay", "*****@*****.**", "nay1234", 27, "female", "Employee", depart_lis[0]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("ZawZaw", "*****@*****.**", "zaw1234", 32, "male", "Employee", depart_lis[0]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // Second Department
            staff_obj = new staff("KyawKyaw", "*****@*****.**", "kyaw1234", 21, "male", "Employee", depart_lis[1]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("MgMg", "*****@*****.**", "mg1234", 22, "male", "Employee", depart_lis[1]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // Third Department
            staff_obj = new staff("AungAung", "*****@*****.**", "aung1234", 21, "male", "Employee", depart_lis[2]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("HtikeHtike", "*****@*****.**", "htike1234", 22, "female", "Employee", depart_lis[2]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // Fourth Department
            staff_obj = new staff("TinTin", "*****@*****.**", "tin1234", 24, "male", "Employee", depart_lis[3]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("MyintMyint", "*****@*****.**", "myint1234", 22, "female", "Employee", depart_lis[3]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // Fifth Department
            staff_obj = new staff("NawNaw", "*****@*****.**", "naw1234", 25, "male", "Employee", depart_lis[4]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("MawMaw", "*****@*****.**", "maw1234", 29, "female", "Employee", depart_lis[4]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // HEAD INITIALIZATION
            staff_obj = new staff("HtetMoeHlyan", "*****@*****.**", "htet1234", 22, "male", "Head", depart_lis[0]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("KaungPyaeHtet", "*****@*****.**", "kaung1234", 24, "male", "Head", depart_lis[1]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("MyintThein", "*****@*****.**", "myint1234", 22, "female", "Head", depart_lis[2]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("ChoChoMaw", "*****@*****.**", "cho1234", 25, "female", "Head", depart_lis[3]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            staff_obj = new staff("MayThin", "*****@*****.**", "may1234", 29, "female", "Head", depart_lis[4]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();
            // SUPERVISOR INITIALIZATION
            staff_obj = new staff("YeeMonAung", "*****@*****.**", "yee1234", 22, "female", "Supervisor", depart_lis[2]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();

            /*
             * staff_obj = new staff("YanMueAung", "*****@*****.**", "htet1234", 22, "male", "Supervisor", depart_lis[0]);
             * staff_lis.Add(staff_obj);
             * context.staff_repository.Add(staff_obj);
             * context.SaveChanges();
             * staff_obj = new staff("KaungKhantKyaw", "*****@*****.**", "khant1234", 24, "male", "Supervisor", depart_lis[1]);
             * staff_lis.Add(staff_obj);
             * context.staff_repository.Add(staff_obj);
             * context.SaveChanges();
             * staff_obj = new staff("KhaingSuWai", "*****@*****.**", "khaing1234", 25, "female", "Supervisor", depart_lis[3]);
             * staff_lis.Add(staff_obj);
             * context.staff_repository.Add(staff_obj);
             * context.SaveChanges();
             * staff_obj = new staff("PhyuPhyuThein", "*****@*****.**", "phyu1234", 29, "female", "Supervisor", depart_lis[4]);
             * staff_lis.Add(staff_obj);
             * context.staff_repository.Add(staff_obj);
             * context.SaveChanges();
             */
            // MANAGER INITIALIZATION
            staff_obj = new staff("NuNu", "*****@*****.**", "nu1234", 61, "female", "Manager", depart_lis[2]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();

            // CLERK INITIALIZATION
            staff_obj = new staff("AyeMoePhyu", "*****@*****.**", "amp1234", 29, "female", "Clerk", depart_lis[4]);
            staff_lis.Add(staff_obj);
            context.staff_repository.Add(staff_obj);
            context.SaveChanges();

            // STAFF REPRESENTATIVE

            // ORDER ITEM Initialization
            Random rand = new Random();

            int[]         staff_member         = new int[] { 0, 3, 5, 9, 10 };
            int[]         specific_item_number = new int[] { 2, 5, 1, 4, 6, 8, 9, 13, 16, 20 };
            List <orders> order_item_lis       = new List <orders>();

            for (int k = 0; k < staff_member.Length; k++)
            {
                staff temp_staff = staff_lis[staff_member[k]];

                for (int j = 0; j < specific_item_number.Length; j++)
                {
                    item temp_item = item_list[j];

                    orders temp_order_item_obj = new orders(temp_staff, temp_item, rand.Next(20, 100), DateTime.Now.ToString());

                    order_item_lis.Add(temp_order_item_obj);

                    context.orders_repository.Add(temp_order_item_obj);

                    context.SaveChanges();
                }
            }

            // ITEM WAREHOUSE Initialization
            int    reorder_level    = 5;
            int    reorder_quantity = 10;
            string unit_of_measure  = "each";

            using (var db = new DataBaseContext())
            {
                // ALL DATA
                List <suppliers_warehouse> sup_ware_lis = db.suppliers_warehouse_repository.Where(x => x.suppliers_warehouse_plus_supplier.suppliersId == 1).Select(x => x).ToList();
                for (int i = 0; i < sup_ware_lis.Count; i++)
                {
                    //TARGET DATA
                    suppliers_warehouse sup_ware = sup_ware_lis[i];

                    //ITEM SPECIFIC
                    item specific_item_obj = db.item_repository.Where(x => x.itemId == sup_ware.suppliers_warehouse_plus_item.itemId).Select(x => x).FirstOrDefault();
                    int  sup_balance       = sup_ware.stock_balance;

                    if (sup_balance > reorder_level)
                    {
                        sup_balance = sup_balance - reorder_quantity;
                        items_warehouse item_ware = new items_warehouse(reorder_level, reorder_quantity, unit_of_measure, reorder_quantity, reorder_quantity, 0, 0, specific_item_obj);

                        // SUPPLIER WAREHOUSE
                        suppliers_warehouse db_sup_ware = db.suppliers_warehouse_repository.Where(x => x.suppliers_warehouseId == sup_ware.suppliers_warehouseId).FirstOrDefault();
                        db_sup_ware.stock_balance = sup_balance;

                        // STOCK CARD INITIALIZATION
                        stock_card stock_card_obj = new stock_card(db_sup_ware.suppliers_warehouse_plus_supplier.name, DateTime.Now.ToString(), "+" + reorder_quantity, specific_item_obj);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();

                        db.item_warehouses_repository.Add(item_ware);
                        db.SaveChanges();
                        db.suppliers_warehouse_repository.Add(db_sup_ware);
                        db.SaveChanges();
                    }
                }
            }

            base.Seed(context);
        }
Esempio n. 10
0
        public ActionResult Create_Stationary_Retrival_Form(FormCollection form_data)
        {
            using (var db = new DataBaseContext())
            {
                int input_bx_count = Int32.Parse(form_data["input_bx_count_name"]);

                for (int i = 1; i <= input_bx_count; i++)
                {
                    string actual_quantity_delivered = form_data["Actual_Quantity_Delivered_" + i];
                    string store_order_id            = form_data["Store_Order_ID_" + i];

                    string[] store_order_id_lis = store_order_id.Split('_');

                    System.Diagnostics.Debug.WriteLine("STORE ID LIST: " + store_order_id_lis);
                    System.Diagnostics.Debug.WriteLine("ACTUAL QUANTITY : " + actual_quantity_delivered);

                    if (store_order_id_lis.Length == 1)
                    {
                        int    order_id        = Int32.Parse(store_order_id_lis[0]);
                        int    actual_quantity = Int32.Parse(actual_quantity_delivered);
                        orders order_obj       = db.orders_repository.Where(x => x.ordersId == order_id).FirstOrDefault();
                        order_obj.actual_delivered_quantity_by_clerk = actual_quantity;
                        order_obj.order_status         = "Approved_by_Clerk";
                        order_obj.delivered_order_date = DateTime.Now.ToString();
                        db.SaveChanges();

                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(x => x.item.itemId == order_obj.item_obj.itemId).FirstOrDefault();
                        item_ware_obj.stock_balance    = item_ware_obj.stock_balance - actual_quantity;
                        order_obj.delivered_order_date = DateTime.Now.ToString();
                        db.SaveChanges();

                        //Email Notification
                        staff  rep      = StaffData.GetStaffByName(order_obj.staff_obj.department_obj.representative_name);
                        string emailadd = rep.email;
                        Task   task     = Task.Run(() => {
                            EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Disbursment Order Reminder", "There is a new disbursment order to your department was just approved by store clerk. please get ready to receive it.");
                        });
                    }
                    else
                    {
                        int actual_quantity = Int32.Parse(actual_quantity_delivered);
                        int temp_item_id    = 0;

                        for (int j = 0; j < store_order_id_lis.Length; j++)
                        {
                            int temp_order_id = Int32.Parse(store_order_id_lis[j]);

                            orders order_obj = db.orders_repository.Where(x => x.ordersId == temp_order_id).FirstOrDefault();

                            temp_item_id = order_obj.item_obj.itemId;

                            if (actual_quantity - order_obj.proposed_quantity > 0)
                            {
                                int temp_amount = actual_quantity - order_obj.proposed_quantity;
                                actual_quantity = actual_quantity - order_obj.proposed_quantity;

                                order_obj.actual_delivered_quantity_by_clerk = temp_amount;
                                order_obj.order_status         = "Approved_by_Clerk";
                                order_obj.delivered_order_date = DateTime.Now.ToString();
                                db.SaveChanges();

                                //Email Notification
                                staff  rep      = StaffData.GetStaffByName(order_obj.staff_obj.department_obj.representative_name);
                                string emailadd = rep.email;
                                Task   task     = Task.Run(() => {
                                    EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Disbursment Order Reminder", "There is a new disbursment order to your department was just approved by store clerk. please get ready to receive it.");
                                });
                            }
                            else
                            {
                                order_obj.actual_delivered_quantity_by_clerk = actual_quantity;
                                order_obj.order_status         = "Approved_by_Clerk";
                                order_obj.delivered_order_date = DateTime.Now.ToString();
                                db.SaveChanges();
                            }
                        }
                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(x => x.item.itemId == temp_item_id).FirstOrDefault();
                        item_ware_obj.stock_balance = item_ware_obj.stock_balance - actual_quantity;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("View_Adjustment_Voucher", "Clerk"));
            }
        }
Esempio n. 11
0
        // Approve Department Request
        public ActionResult Ajax_Approve_Department_Request(ajax_model ajax_model_data)
        {
            string quantity_status = "";
            int    stock_level     = 0;
            string order_id_status = "";

            Dictionary <string, int> item_and_quantity_of_department = new Dictionary <string, int>();

            ajax_model ajax_data = new ajax_model
            {
                name      = ajax_model_data.name,
                main_data = ajax_model_data.main_data,
            };

            using (var db = new DataBaseContext())
            {
                List <orders> order_lis = db.orders_repository.Where(or => or.staff_obj.department_obj.department_name == ajax_data.name && or.order_status == "Approved_by_Head").ToList();

                Dictionary <int, int> item_quantity = new Dictionary <int, int>();

                List <items_warehouse> item_ware_lis = db.item_warehouses_repository.ToList();

                foreach (items_warehouse temp_item in item_ware_lis)
                {
                    item_quantity.Add(temp_item.item.itemId, temp_item.stock_balance);
                }

                for (int i = 0; i < order_lis.Count; i++)
                {
                    orders temp_order = order_lis[i];

                    stock_level = item_quantity[temp_order.item_obj.itemId];

                    stock_level = stock_level - temp_order.proposed_quantity;

                    order_id_status = temp_order.ordersId.ToString();

                    // For Stock Card
                    item_and_quantity_of_department.Add(temp_order.item_obj.item_description, temp_order.proposed_quantity);

                    if (stock_level < 0)
                    {
                        quantity_status = "OUT_OF_STOCK";
                        break;
                    }
                    else
                    {
                        item_quantity[temp_order.item_obj.itemId] = stock_level;
                    }
                }

                if (quantity_status != "OUT_OF_STOCK")
                {
                    foreach (KeyValuePair <int, int> data in item_quantity)
                    {
                        items_warehouse item_ware_obj = db.item_warehouses_repository.Where(k => k.item.itemId == data.Key).FirstOrDefault();
                        item_ware_obj.stock_balance = data.Value;
                        db.SaveChanges();
                        quantity_status = "QUANTITY_SUFFICIENT";

                        // Add ACTUAL_QUANTITY and DELIVERY DATE
                        foreach (orders temp_order in order_lis)
                        {
                            temp_order.actual_delivered_quantity_by_clerk = temp_order.proposed_quantity;
                            temp_order.delivered_order_date = DateTime.Now.ToString();
                            db.SaveChanges();
                        }
                    }

                    // For Stock Card
                    foreach (KeyValuePair <string, int> temp_data in item_and_quantity_of_department)
                    {
                        item item_obj = db.item_warehouse_repository.Where(i => i.item_description == temp_data.Key).FirstOrDefault();

                        // STOCK CARD UPDATE
                        int        stockbalance   = StockcardData.GetStockBalanceByItemId(item_obj.itemId);
                        stock_card stock_card_obj = new stock_card(ajax_data.name, DateTime.Now.ToString(), " - " + temp_data.Value, item_obj, stockbalance - temp_data.Value);
                        db.stock_card_repository.Add(stock_card_obj);
                        db.SaveChanges();
                    }

                    foreach (orders temp_order in order_lis)
                    {
                        temp_order.order_status = "Approved_by_Clerk";
                        db.SaveChanges();
                    }
                }
            }
            object reply_to_client = new
            {
                item_quantity_status  = quantity_status,
                stock_level_status    = stock_level,
                order_identity_status = order_id_status,
            };

            //Email Notification
            staff  rep      = StaffData.GetStaffByName(DepartmentData.GetRepresentativebyDepName(ajax_data.name));
            string emailadd = rep.email;
            Task   task     = Task.Run(() => {
                EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Disbursment Order Reminder", "There is a new disbursment order to your department was just approved by store clerk. please get ready to receive it.");
            });


            return(Json(reply_to_client, JsonRequestBehavior.AllowGet));
        }
        /////////////////////////////////////////////////////////Trend Report
        public async Task <ActionResult> View_Trend_Analysis_Detail(int itemId, int?depId)
        {
            List <orders> listorders = new List <orders>();

            listorders = OrdersData.GetAllDeliveredOrders();

            int           dId         = depId ?? 0;
            List <orders> listorders1 = new List <orders>();

            if (dId != 0)
            {
                listorders1    = listorders.Where(x => x.staff_obj.department_obj.departmentId == dId).ToList();
                ViewBag.depart = DepartmentData.GetDepartmentById(dId);
            }
            else
            {
                listorders1 = listorders;
            }


            Dictionary <string, int> itemsbtrend = new Dictionary <string, int>();
            Dictionary <string, int> itemtrend   = new Dictionary <string, int>();



            Dictionary <int, Dictionary <string, int> > trendlist = (Dictionary <int, Dictionary <string, int> >)Session["trendlist"];
            item          item    = ItemData.GetItemById(itemId); // get the item by given itemId
            List <string> monlist = new List <string>();


            for (int i = 11; i >= 0; i--)
            {
                //string dt = string.Format("{0}/{1}", DateTime.Today.AddMonths(-i).Month, DateTime.Today.AddMonths(-i).Year);
                string dt = DateTime.Today.AddMonths(-i).ToString("MM/yyyy");
                monlist.Add(dt);//list of last 12 months
                /////////////////////////////////////////////////////////////////////////
                //Get stockbalance on given month, put in dictionary "itemsbtrend", key is month string, value is stockbalance of the month.
                //////////////////////////////////////////////////////////////////

                char[] separator = { '/', ' ' };



                List <stock_card> list = StockcardData.GetStockCardByItemId(itemId);//give proper value here.


                List <stock_card> mlist = list.Where(x => x.Arrival_Date.Split(separator)[0].Equals(dt.Split(separator)[0]) && x.Arrival_Date.Split(separator)[2].Equals(dt.Split(separator)[1])).ToList();
                int stockbalance        = mlist[mlist.Count - 1].stockbalance;
                itemsbtrend.Add(dt, stockbalance);
            }

            int[] cons = trendlist[itemId].Values.ToArray();


            foreach (string m in monlist)
            {
                char[]   separator   = { '/', ' ' };
                string[] dtmonthyear = m.Split(separator);
                //Get monthly consumption quant on given month
                int consumedquant = listorders1.Where(x => x.delivered_order_date.Split(separator)[0].Equals(dtmonthyear[0]) && x.delivered_order_date.Split(separator)[2].Equals(dtmonthyear[1])).Select(x => x.actual_received_quantity_by_representative).Sum();//Get correct value here
                itemtrend.Add(m, consumedquant);
            }


            // send request and get response from python server
            int[] prelist  = new int[4];
            int[] paralist = new int[13];
            paralist[0] = itemId;
            for (int i = 1; i < 13; i++)
            {
                paralist[i] = cons[i - 1];
            }
            string conshist = string.Join(", ", paralist);


            using (var client = new HttpClient())
            {
                string xValue = conshist;


                // send a GET request to the server uri with the data and get the response as HttpResponseMessage object
                HttpResponseMessage res = await client.GetAsync("http://127.0.0.1:5000/model1?x=" + xValue);

                // Return the result from the server if the status code is 200 (everything is OK)
                // should raise exception or error if it's not
                if (res.IsSuccessStatusCode)
                {
                    // pass the result to update the user preference
                    // have to read as string for the data in response.body
                    //pre = Convert.ToInt32(res.Content.ReadAsStringAsync().Result); //if only display one month prediction.
                    string arr = res.Content.ReadAsStringAsync().Result;
                    prelist = arr.Split(',').Select(str => int.Parse(str)).ToArray();
                }
                else
                {
                    prelist = new int[4] {
                        0, 0, 0, 0
                    }
                };
            }

            items_warehouse iwh = ItemWarehouseData.FindByItemId(itemId);

            ViewBag.departList    = DepartmentData.GetAllDep();
            ViewBag.cons          = itemtrend.Values.ToArray();
            ViewBag.months        = monlist.ToArray();
            ViewBag.Item          = item;
            ViewBag.sbalance      = itemsbtrend.Values.ToArray();
            ViewBag.prediction    = prelist;
            ViewBag.itemwarehouse = iwh;
            return(View());
        }