/*
        protected void ddlAdjustID_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id =Convert.ToInt32(ddlAdjustID.SelectedItem.Text);
            AdjustmentDetailsBLL adjust_detailsbll = new AdjustmentDetailsBLL();
            var list = adjust_detailsbll.getAdjustListByPerson(id);
            gvAdjustmentReport.DataSource = list;
            gvAdjustmentReport.DataBind();

        }
         */
        protected void btnCheck_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(ddlAdjustID.SelectedItem.Text);
            AdjustmentDetailsBLL adjust_detailsbll = new AdjustmentDetailsBLL();
            var list = adjust_detailsbll.getAdjustListByPerson(id);
            gvAdjustmentReport.DataSource = list;
            gvAdjustmentReport.DataBind();
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            adjustment_View adjust_view = new adjustment_View();
            AdjustmentBLL adjustbll = new AdjustmentBLL();

            //int adjustBy_Id = 1005;
              // int loginUserId = 1002;// current login User who will make Adjustment Report
            int loginUserId = Convert.ToInt32(Session["loginUser"]);
            DateTime adjustDate = DateTime.Now;
            //DateTime adjustDate = DateTime.Today;

            int itemPrice = Convert.ToInt32(ddlPrice.SelectedItem.Value);

            //int approvedBy = null;
            //DateTime approveDate = null;
            //string approveStatus = null;
            double total_price = 0;
            foreach (GridViewRow row in gvAdjustList.Rows)
            {

                string item_code = row.Cells[1].Text;
                int qty = Convert.ToInt32(row.Cells[2].Text);

                StockItemBLL itemBll = new StockItemBLL();
                double price = itemBll.GetItemPrice(item_code);

                total_price = total_price + (price * qty);

                /********* Don't delete lbl testing line **********/
                //lblPrice.Text = price.ToString();
                //lblTotalPrice.Text = total_price.ToString(); // don't delete

            }
            string authorizedBy = null;

            if (total_price <= 250)
            {
                authorizedBy = "Supervisor";
            }
            else
            {
                authorizedBy = "Manager";
            }
            int adjustid = adjustbll.addAdjustment(loginUserId, adjustDate, authorizedBy);

            foreach (GridViewRow row in gvAdjustList.Rows)
            {
                string item_code = row.Cells[1].Text;
                int qty = Convert.ToInt32(row.Cells[2].Text);
                string reason = row.Cells[3].Text;
                string status = row.Cells[4].Text;

                AdjustmentDetailsBLL adjust_details_bll = new AdjustmentDetailsBLL();
                int adjustment_details_Id = adjust_details_bll.addAdjustmentDetails(adjustid, item_code, qty, reason, status);

            }

            Employee emp_bll = new Employee();
            //int loginUserId = 1002;
            string email_body = "Adjustment Report is submitted to Supervier or Manager by StoreClerk";
            string email_subj = "Issue Adjustment Report";
            string email_msg = SendEmailNotification(loginUserId, email_body, email_subj, authorizedBy);

            lblSubmitMsg.Text = "Adjustment Report Submittion is successful. " + email_msg;
        }