Example #1
0
        public dynamic DeleteDetail(SalarySlipDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Master))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _salarySlipDetailService.GetObjectById(model.Id);
                model = _salarySlipDetailService.SoftDeleteObject(data);
            }
            catch (Exception ex)
            {
                LOG.Error("Delete Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors,
            }));
        }
Example #2
0
 public SalarySlipDetail VIsValidMaxValue(SalarySlipDetail salarySlipDetail)
 {
     if (salarySlipDetail.HasMinValue && salarySlipDetail.HasMaxValue && salarySlipDetail.MaxValue < salarySlipDetail.MinValue)
     {
         salarySlipDetail.Errors.Add("MaxValue", "Harus lebih besar atau sama dengan MinValue");
     }
     return(salarySlipDetail);
 }
Example #3
0
        //public SalarySlipDetail VHasSalaryItem(SalarySlipDetail salarySlipDetail, ISalaryItemService _salaryItemService)
        //{
        //    SalaryItem salaryItem = _salaryItemService.GetObjectById(salarySlipDetail.SalaryItemId);
        //    if (salaryItem == null)
        //    {
        //        salarySlipDetail.Errors.Add("SalaryItem", "Tidak ada");
        //    }
        //    return salarySlipDetail;
        //}

        public SalarySlipDetail VHasFormula(SalarySlipDetail salarySlipDetail, IFormulaService _formulaService)
        {
            Formula formula = _formulaService.GetObjectById(salarySlipDetail.FormulaId);

            if (formula == null)
            {
                salarySlipDetail.Errors.Add("Formula", "Tidak ada");
            }
            return(salarySlipDetail);
        }
Example #4
0
        public SalarySlipDetail VHasSalarySlip(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService)
        {
            SalarySlip salarySlip = _salarySlipService.GetObjectById(salarySlipDetail.SalarySlipId);

            if (salarySlip == null)
            {
                salarySlipDetail.Errors.Add("SalarySlip", "Tidak ada");
            }
            return(salarySlipDetail);
        }
 public SalarySlipDetail CreateObject(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService, IFormulaService _formulaService)
 {
     salarySlipDetail.Errors = new Dictionary <String, String>();
     if (_validator.ValidCreateObject(salarySlipDetail, _salarySlipService, _formulaService))
     {
         salarySlipDetail.Index = GetQueryable().Count() + 1;
         _repository.CreateObject(salarySlipDetail);
     }
     return(salarySlipDetail);
 }
Example #6
0
        public string PrintError(SalarySlipDetail obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
Example #7
0
 public bool ValidCreateObject(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService, IFormulaService _formulaService)
 {
     VHasSalarySlip(salarySlipDetail, _salarySlipService);
     if (!isValid(salarySlipDetail))
     {
         return(false);
     }
     VHasFormula(salarySlipDetail, _formulaService); // VHasSalaryItem
     if (!isValid(salarySlipDetail))
     {
         return(false);
     }
     VIsValidMaxValue(salarySlipDetail);
     return(isValid(salarySlipDetail));
 }
        public SalarySlipDetail CreateObject(int SalarySlipId, int SalarySign, string FirstSalaryItemCode, string Operator, string SecondSalaryItemCode, decimal SecondValue,
                                             bool HasMinValue, decimal MinValue, bool HasMaxValue, decimal MaxValue,
                                             ISalarySlipService _salarySlipService, IFormulaService _formulaService, ISalaryItemService _salaryItemService)
        {
            SalaryItem salaryItem = _salaryItemService.GetObjectByCode(FirstSalaryItemCode);
            Formula    formula    = new Formula
            {
                FirstSalaryItemId = salaryItem.Id,
                FormulaOp         = Operator,
            };

            salaryItem = _salaryItemService.GetObjectByCode(SecondSalaryItemCode);
            if (salaryItem == null)
            {
                formula.IsSecondValue = true;
                formula.SecondValue   = SecondValue;
                //formula.ValueSign = (int)Constant.SalarySign.Income;
            }
            else
            {
                formula.SecondSalaryItemId = salaryItem.Id;
            }
            _formulaService.CreateObject(formula, _salaryItemService);

            SalarySlipDetail salarySlipDetail = new SalarySlipDetail
            {
                SalarySlipId = SalarySlipId,
                SalarySign   = SalarySign,
                FormulaId    = formula.Id,
                HasMinValue  = HasMinValue,
                MinValue     = MinValue,
                HasMaxValue  = HasMaxValue,
                MaxValue     = MaxValue,
            };

            CreateObject(salarySlipDetail, _salarySlipService, _formulaService);
            if (salarySlipDetail.Errors.Any())
            {
                _formulaService.DeleteObject(formula.Id);
            }
            else
            {
                formula.SalarySlipDetailId = salarySlipDetail.Id;
                _formulaService.UpdateObject(formula, _salaryItemService);
            }
            return(salarySlipDetail);
        }
Example #9
0
        public dynamic GetInfoDetail(int Id)
        {
            SalarySlipDetail model = new SalarySlipDetail();

            try
            {
                model = _salarySlipDetailService.GetObjectById(Id);
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                model.Errors = new Dictionary <string, string>();
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model.Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.Index,
                model.SalarySlipId,
                model.SalarySign,
                model.FormulaId,
                FirstCode = model.Formula.FirstSalaryItem.Code,
                model.Formula.FormulaOp,
                SecondCode = model.Formula.IsSecondValue ? model.Formula.SecondValue.ToString() : model.Formula.SecondSalaryItem.Code,
                model.Formula.IsSecondValue,
                model.Formula.SecondValue,
                model.HasMinValue,
                model.MinValue,
                model.HasMaxValue,
                model.MaxValue,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
        public decimal CalcSalarySlipDetail(SalarySlipDetail salarySlipDetail, IDictionary <string, decimal> salaryItemsValue, IEnumerable <SalaryItem> salaryItems, IFormulaService _formulaService)
        {
            decimal val = 0;

            if (salarySlipDetail != null)
            {
                Formula formula = _formulaService.GetObjectById(salarySlipDetail.FormulaId);
                if (formula != null)
                {
                    val = /*Math.Abs*/ (_formulaService.CalcFormula(formula, salaryItemsValue, salaryItems));
                    if (salarySlipDetail.HasMinValue)
                    {
                        val = Math.Max(val, salarySlipDetail.MinValue);
                    }
                    if (salarySlipDetail.HasMaxValue)
                    {
                        val = Math.Min(val, salarySlipDetail.MaxValue);
                    }
                }
                salarySlipDetail.Value = val;
            }
            return(val);
        }
Example #11
0
 public bool ValidUpdateObject(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService, IFormulaService _formulaService)
 {
     salarySlipDetail.Errors.Clear();
     ValidCreateObject(salarySlipDetail, _salarySlipService, _formulaService);
     return(isValid(salarySlipDetail));
 }
Example #12
0
        public dynamic UpdateDetail(int FirstSalaryItem, string FormulaOp, int SecondSalaryItem, bool IsSecondValue, Nullable <decimal> SecondValue, SalarySlipDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Utility))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var     data    = _salarySlipDetailService.GetObjectById(model.Id);
                Formula formula = _formulaService.GetObjectById(data.FormulaId);
                if (formula != null)
                {
                    formula.FirstSalaryItemId  = FirstSalaryItem;
                    formula.FormulaOp          = FormulaOp;
                    formula.IsSecondValue      = IsSecondValue;
                    formula.SecondValue        = SecondValue.GetValueOrDefault();
                    formula.SecondSalaryItemId = SecondSalaryItem;
                }
                _formulaService.UpdateObject(formula, _salaryItemService);

                data.Index        = model.Index;
                data.SalarySlipId = model.SalarySlipId;
                data.SalarySign   = model.SalarySign;
                data.HasMinValue  = model.HasMinValue;
                data.MinValue     = model.MinValue;
                data.HasMaxValue  = model.HasMaxValue;
                data.MaxValue     = model.MaxValue;
                model             = _salarySlipDetailService.UpdateObject(data, _salarySlipService, _formulaService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors,
            }));
        }
 public SalarySlipDetail SoftDeleteObject(SalarySlipDetail salarySlipDetail)
 {
     return(salarySlipDetail = _validator.ValidDeleteObject(salarySlipDetail) ?
                               _repository.SoftDeleteObject(salarySlipDetail) : salarySlipDetail);
 }
 public SalarySlipDetail UpdateObject(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService, IFormulaService _formulaService)
 {
     return(salarySlipDetail = _validator.ValidUpdateObject(salarySlipDetail, _salarySlipService, _formulaService) ? _repository.UpdateObject(salarySlipDetail) : salarySlipDetail);
 }
Example #15
0
        public dynamic InsertDetail(int FirstSalaryItem, string FormulaOp, int SecondSalaryItem, bool IsSecondValue, Nullable <decimal> SecondValue, SalarySlipDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Utility))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }
                Formula formula = new Formula
                {
                    FirstSalaryItemId  = FirstSalaryItem,
                    FormulaOp          = FormulaOp,
                    IsSecondValue      = IsSecondValue,
                    SecondValue        = SecondValue.GetValueOrDefault(),
                    SecondSalaryItemId = SecondSalaryItem,
                };
                _formulaService.CreateObject(formula, _salaryItemService);
                model.FormulaId = formula.Id;
                model           = _salarySlipDetailService.CreateObject(model, _salarySlipService, _formulaService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors,
            }));
        }
Example #16
0
        public bool isValid(SalarySlipDetail obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Example #17
0
 public bool ValidDeleteObject(SalarySlipDetail salarySlipDetail)
 {
     salarySlipDetail.Errors.Clear();
     return(isValid(salarySlipDetail));
 }