//Tharrani – End

        //Esther
        public string CreateAdjustment(String token, WCF_Adjustment adj)
        {
            if (AuthenticateToken(token))
            {
                String       now      = DateTime.Now.ToString("yyyy-MM-dd");
                WCF_Employee employee = GetEmployeeByToken(token);
                adjustment   a        = new adjustment()
                {
                    adjustment_date     = DateTime.ParseExact(now, "yyyy-MM-dd", null),
                    employee_id         = employee.EmployeeId,
                    item_number         = adj.ItemNumber.Trim(),
                    adjustment_quantity = Int32.Parse(adj.AdjustmentQty.Trim()),
                    adjustment_price    = BusinessLogic.Adjprice(adj.ItemNumber) * Int32.Parse(adj.AdjustmentQty.Trim()),
                    adjustment_status   = "Pending",
                    employee_remark     = adj.EmployeeRemark,
                    manager_remark      = null,
                };
                String result1 = BusinessLogic.CreateAdjustment(a);
                String email   = BusinessLogic.SendEmailAdjustmentApproval(a);
                try
                {
                    BusinessLogic.sendMail(email, "New Adjustment Request", employee.EmployeeName + " raised new adjustment request.");
                }
                catch (Exception ex)
                {
                    return("email exception " + ex.Message);
                }
                return(result1);
            }
            else
            {
                return("invalid token");
            }
        }
        //Add new requisition order
        public string AddNewRequest(WCF_Token token)
        {
            string x = token.gettoken.Replace(@"\", "").Trim();

            if (AuthenticateToken(x))
            {
                WCF_Employee emp    = GetEmployeeByToken(x);
                int          emp_id = Convert.ToInt32(emp.EmployeeId); //16;
                string       Depid  = emp.DepartmentId.Trim();         //ENGL;
                DateTime     d      = DateTime.Now.Date;
                unique_id    u      = BusinessLogic.getlastrequestid(Depid);
                int          i      = (int)u.req_id + 1;
                string       id     = Depid + "/" + DateTime.Now.Year.ToString() + "/" + i;
                BusinessLogic.AddNewRequisitionOrder(id, emp_id, d);
                BusinessLogic.updatelastrequestid(Depid, i);
                int    head_id = Convert.ToInt32(BusinessLogic.GetDepartmenthead(Depid).head_id);
                string to      = BusinessLogic.GetEmployee(head_id).email_id;
                //string to = "*****@*****.**";
                string ename = BusinessLogic.GetEmployee(emp_id).employee_name;
                string sub   = "Stationery System: New request raised for your approval";
                string body  = "New Request ID" + id + "has been placed by" + ename + "for your approval";
                BusinessLogic.sendMail(to, sub, body);
                return(id);
            }
            else
            {
                return(null);
            }
        }
        /*
         * Logs the user into the system.
         *
         * Takes username and password in
         * If the username and password is valid, this generates a token for the employee
         * This token is stored into the database for validation when using in other methods.
         */

        public WCF_Employee Login(string username, string password)
        {
            WCF_Employee wcfEmployee = null;

            // If login succeeds, fetch the token, otherwise, return null
            // Validate username and password
            if (Membership.ValidateUser(username, password))
            {
                // Fetch or generate token
                var context = new LogicUniversityEntities();
                var query   = from x in context.employees where x.user_id == username select x;
                var result  = query.ToList();

                if (query.Any())
                {
                    // Generate a token for the resulting employee.
                    String token = GenerateToken();

                    // Store token in database
                    var first = result.First();
                    first.token = token;
                    System.Diagnostics.Debug.WriteLine(context.SaveChanges());

                    // Pass the token to the service consumer
                    wcfEmployee = new WCF_Employee(first.employee_id, first.employee_name, first.email_id, username, first.department_id, first.supervisor_id, token, Roles.GetRolesForUser(username).FirstOrDefault());
                }
            }

            // Return the token to user
            return(wcfEmployee);
        }
 // to update the collection location - android
 public void updatelocation(string token, WCF_collectionpoint cp)
 {
     if (AuthenticateToken(token))
     {
         WCF_Employee emp  = GetEmployeeByToken(token);
         string       dept = emp.DepartmentId;
         BusinessLogic.updatecollectionlocation(dept, Convert.ToInt32(cp.id));
     }
     else
     {
     }
 }
 // to get the budget of the current month- both allocated and spent for a particular department - Android
 public WCF_Budget getbudget(string token)
 {
     if (AuthenticateToken(token))
     {
         WCF_Employee emp  = GetEmployeeByToken(token);
         string       dept = emp.DepartmentId;
         int          b1   = BusinessLogic.getbudgetbydept(dept);
         int          b2   = BusinessLogic.getspentbudgetbydept(dept);
         WCF_Budget   x    = new WCF_Budget(b1.ToString(), b2.ToString());
         return(x);
     }
     else
     {
         return(null);
     }
 }
 // to get the item details of the particular ro- android
 public List <WCF_itemdetails> getitemdetails(string token, string id)
 {
     if (AuthenticateToken(token))
     {
         WCF_Employee emp = GetEmployeeByToken(token);
         List <getitemdetails_Result> list  = BusinessLogic.pendinggetitemdetails(id);
         List <WCF_itemdetails>       list1 = new List <WCF_itemdetails>();
         foreach (getitemdetails_Result r in list)
         {
             list1.Add(new WCF_itemdetails(r.description.TrimEnd(), r.item_requisition_quantity.ToString()));
         }
         return(list1);
     }
     else
     {
         return(null);
     }
 }
        // to get the history of collection of the department -android

        public List <WCF_collectionhistory> gethistory(string token)
        {
            if (AuthenticateToken(token))
            {
                WCF_Employee emp  = GetEmployeeByToken(token);
                string       dept = emp.DepartmentId;
                List <getcollectiondetailsbydepartment_Result> list = BusinessLogic.getdepartmentcollection(dept);
                List <WCF_collectionhistory> list1 = new List <WCF_collectionhistory>();
                foreach (getcollectiondetailsbydepartment_Result r in list)
                {
                    list1.Add(new WCF_collectionhistory(r.collection_place.TrimEnd(), r.collection_date.ToString("dd-MM-yyyy")));
                }
                return(list1);
            }
            else
            {
                return(null);
            }
        }
        //Esther end

        //Sruthi start

        //to find the pending ros for the android

        public List <WCF_approvero> Findpendingros(string token)
        {
            if (AuthenticateToken(token))
            {
                WCF_Employee emp  = GetEmployeeByToken(token);
                string       dept = emp.DepartmentId;
                List <getpendingrequestsbydepartment_Result> pendingros = BusinessLogic.ViewPendingRequests(dept);
                List <WCF_approvero> list = new List <WCF_approvero>();
                foreach (getpendingrequestsbydepartment_Result ro in pendingros)
                {
                    double sum = (ro.Sum.HasValue ? ro.Sum.Value : 0);
                    list.Add(new WCF_approvero(ro.id.TrimEnd(), ro.Date.ToString("dd-MM-yyyy"), ro.Name.TrimEnd(), ro.status, sum.ToString()));
                }
                return(list);
            }
            else
            {
                return(null);
            }
        }