public JsonResult CreateDeb(Debt debt)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    EmployeeVw employee = EmployeeVwServices.Get(debt.Employee);
                    if (employee == null)
                    {
                        return(Json(new { status = false, message = "الرقم الذاتي غير صحيح" }, JsonRequestBehavior.AllowGet));
                    }
                    if (debt.Date == null)
                    {
                        debt.Date = System.DateTime.Now;
                    }
                    debt = DebtServices.Insert(CurrentUser.Id, debt, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }
            else
            {
                string errorMsg = "";
                foreach (ModelState item in ModelState.Values)
                {
                    if (item.Errors.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        for (int i = 0; i < item.Errors.Count; i++)
                        {
                            errorMsg += item.Errors[i].ErrorMessage + "\n";
                        }
                    }
                }

                return(Json(new
                {
                    status = false,
                    message = errorMsg,
                }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = true, Data = debt.Id }, JsonRequestBehavior.AllowGet));
        }
 public JsonResult GetEmployeeInformation(int employeeId)
 {
     try
     {
         EmployeeVw employee = EmployeeVwServices.Get(employeeId);
         return(Json(new { Employee = employee }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception exc)
     {
         return(Json(new { error = "Error", message = "Invalide Id" }, JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult Calculate(int employeeId, int productTypeId, float amount, int period, float netAmount, float deductions)
        {
            try
            {
                EmployeeVw employee = EmployeeVwServices.Get(employeeId);
                if (employee == null)
                {
                    return(Json(new { status = false, message = "الرقم الذاتي غير صحيح" }, JsonRequestBehavior.AllowGet));
                }

                EmployeeProductCalculatorFilter f = new EmployeeProductCalculatorFilter()
                {
                    EmployeeId    = employeeId,
                    ProductTypeId = (short)productTypeId,
                    Amount        = (decimal)amount,
                    Period        = (short)period
                };

                EmployeeProductCalculatorResult result = db.EmployeeProductCalculatorFirstOrDefault(f);
                if (result == null)
                {
                    return(Json(new { status = false, message = "NoResult" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    GetEmployeeSolvencyFilter filter = new GetEmployeeSolvencyFilter()
                    {
                        EmployeeId  = employeeId,
                        Amount      = (decimal)amount,
                        Date        = System.DateTime.Now,
                        Installment = result.Installment,
                        GrossSalary = (decimal)netAmount,
                        NetSalary   = (decimal)netAmount
                    };
                    GetEmployeeSolvencyResult solvencyResult = db.GetEmployeeSolvencyFirstOrDefault(filter);

                    return(Json(new { status = true, Calculator = result, Solevency = solvencyResult }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (CfException cfex)
            {
                //TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                return(Json(new { status = false, message = cfex.ErrorDefinition.LocalizedMessage }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //TempData["Failure"] = ex.Message;
                return(Json(new { status = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult GetEmployeeSolvency(int employeeId, float amount, float installment, float netSalary, float grossSalary)
        {
            try
            {
                // get employee information

                EmployeeVw employee = EmployeeVwServices.Get(employeeId);
                if (employee == null)
                {
                    return(Json(new { message = "الرقم الذاتي غير صحيح" }, JsonRequestBehavior.AllowGet));
                }

                GetEmployeeSolvencyFilter filter = new GetEmployeeSolvencyFilter()
                {
                    EmployeeId  = employeeId,
                    Amount      = (decimal)amount,
                    Date        = System.DateTime.Now,
                    Installment = (decimal)installment,
                    GrossSalary = (decimal)grossSalary,
                    NetSalary   = (decimal)netSalary
                };
                GetEmployeeSolvencyResult solvencyResult = db.GetEmployeeSolvencyFirstOrDefault(filter);

                return(Json(new { Employee = employee, Solevency = solvencyResult }, JsonRequestBehavior.AllowGet));
            }
            catch (CfException cfex)
            {
                TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
            }
            catch (Exception ex)
            {
                TempData["Failure"] = ex.Message;
            }

            return(Json("Error", JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateWarrant(WarrantVwViewModel model)
        {
            WarrantVwViewModel Model = new WarrantVwViewModel();

            try
            {
                EmployeeVw employee = EmployeeVwServices.Get(model.Instance.DebtEmployeeId);
                if (employee == null)
                {
                    TempData["Failure"] = "الرقم الذاتي غير صحيح";
                    Model.List          = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db);
                    return(PartialView("_WarrantsList", Model));
                }
                // check if this employee is not the debt employee
                Debt d = DebtServices.Get(model.Instance.DebtId, db);
                if (d != null)
                {
                    if (d.Employee == model.Instance.DebtEmployeeId)
                    {
                        TempData["Failure"] = "لا يمكن أن يكفل الموظف نفسه";
                        Model.List          = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db);
                        return(PartialView("_WarrantsList", Model));
                    }
                }


                // check if this employee has been added as a garantaur
                Warrant ewarrant = WarrantServices.GetByDebt_EmployeeFirstOrNull(model.Instance.DebtId, model.Instance.DebtEmployeeId);
                if (ewarrant != null)
                {
                    TempData["Failure"] = "هذا الموظف هو كفيل حالياً لهذه المديونية";
                }
                else
                {
                    Warrant w = new Warrant()
                    {
                        Debt     = model.Instance.DebtId,
                        Employee = model.Instance.DebtEmployeeId,
                        IsActive = model.Instance.IsActive,
                        Notes    = model.Instance.Notes
                    };
                    w = WarrantServices.Insert(CurrentUserId, w, db);
                }

                Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db);

                return(PartialView("_WarrantsList", Model));
            }
            catch (CfException cfex)
            {
                TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                //return Json(new { status = false, message = cfex.ErrorDefinition.LocalizedMessage }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                TempData["Failure"] = ex.Message;
                //return Json(new { status = false, message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
            Model.List = WarrantVwServices.GetByDebtId(model.Instance.DebtId, db);
            return(PartialView("_WarrantsList", Model));
        }