예제 #1
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
                        int        stockbalance   = StockcardData.GetStockBalanceByItemId(item_ware_obj.item.itemId);
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item, stockbalance + temp_data.Value);
                        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
                        int        stockbalance   = StockcardData.GetStockBalanceByItemId(item_ware_obj.item.itemId);
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item, stockbalance + temp_data.Value);
                        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
                        int        stockbalance   = StockcardData.GetStockBalanceByItemId(item_ware_obj.item.itemId);
                        stock_card stock_card_obj = new stock_card(sup_obj.name, DateTime.Now.ToString(), "+ " + temp_data.Value, item_ware_obj.item, stockbalance + temp_data.Value);
                        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));
        }
예제 #2
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));
        }