Ejemplo n.º 1
0
        public AlertMessage Edit(FakturisViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.Fakturis))
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            if (!IsEditable())
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            IRepository <TFakturis> repo = _unitOfWork.GetRepository <TFakturis>();

            repo.Condition = PredicateBuilder.True <TFakturis>().And(x => x.NIK == model.NIK);

            TFakturis item = repo.Find().FirstOrDefault();

            if (item == null)
            {
                alert.Text = StaticMessage.ERR_DATA_NOT_FOUND;
                return(alert);
            }

            DateTime now = DateTime.UtcNow.ToUtcID();

            item.FULLNAME  = model.Fullname;
            item.Role      = model.IsRole;
            item.ValidFrom = DateTime.Parse(model.FormattedValidFrom);
            item.ValidTo   = DateTime.Parse(model.FormattedValidTo);
            item.UpdatedBy = _userAuth.NIK.ToString();
            item.UpdatedOn = now;

            try
            {
                _unitOfWork.BeginTransaction();

                repo.Update(item);

                _unitOfWork.Commit();

                alert.Status = 1;
                alert.Text   = string.Format(StaticMessage.SCS_EDIT, item.NIK, item.FULLNAME);
            }
            catch (Exception ex)
            {
                alert.Text = StaticMessage.ERR_SAVE_FAILED;
            }
            finally
            {
                _unitOfWork.Dispose();
            }

            return(alert);
        }
Ejemplo n.º 2
0
        private FakturisViewModel GetFakturisViewModel(TFakturis item)
        {
            FakturisViewModel model = new FakturisViewModel();

            model.NIK                = (int)item.NIK;
            model.Fullname           = item.FULLNAME;
            model.IsRole             = item.Role;
            model.ValidFromDate      = item.ValidFrom;
            model.FormattedValidFrom = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate);
            model.ValidToDate        = item.ValidTo;
            model.FormattedValidTo   = model.ValidToDate.ToString(AppConstant.DefaultFormatDate);

            return(model);
        }
Ejemplo n.º 3
0
        public FakturisViewModel GetDetail(int id)
        {
            IRepository <TFakturis> repo = _unitOfWork.GetRepository <TFakturis>();

            repo.Condition = PredicateBuilder.True <TFakturis>().And(x => x.NIK == id);

            TFakturis item = repo.Find().FirstOrDefault();

            if (item == null)
            {
                return(null);
            }

            return(GetFakturisViewModel(item));
        }
Ejemplo n.º 4
0
        public AlertMessage Preview(ImportTagihViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.MasterTagih))
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            List <HierTagihViewModel> listVM = GetListHierTagihViewModel(model.InputFile);

            if (listVM == null)
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
                return(alert);
            }

            IRepository <FSS>          repoFSS         = _unitOfWork.GetRepository <FSS>();
            IRepository <SLM>          repoSLM         = _unitOfWork.GetRepository <SLM>();
            IRepository <TCollector>   repoCollector   = _unitOfWork.GetRepository <TCollector>();
            IRepository <TFakturis>    repoFakturis    = _unitOfWork.GetRepository <TFakturis>();
            IRepository <TSPVFakturis> repoSPVFakturis = _unitOfWork.GetRepository <TSPVFakturis>();
            FSS          fss         = null;
            SLM          slm         = null;
            TCollector   collector   = null;
            TFakturis    fakturis    = null;
            TSPVFakturis spvFakturis = null;

            DateTime dtMaxValidTo = DateTime.ParseExact(AppConstant.DefaultValidTo, AppConstant.DefaultFormatDate, _cultureInfo);

            Dictionary <int, string>  dcExistingFSS         = new Dictionary <int, string>();
            Dictionary <int, string>  dcExistingSLM         = new Dictionary <int, string>();
            Dictionary <long, string> dcExistingCollector   = new Dictionary <long, string>();
            Dictionary <long, string> dcExistingFakturis    = new Dictionary <long, string>();
            Dictionary <long, string> dcExistingSPVFakturis = new Dictionary <long, string>();

            DateTime today = DateTime.UtcNow.ToUtcID().Date;

            List <string> listRemarks = null;

            foreach (var item in listVM)
            {
                if (!string.IsNullOrEmpty(item.Remarks))
                {
                    continue;
                }

                if (dcExistingFSS.ContainsKey(item.FSSNik) &&
                    dcExistingSLM.ContainsKey(item.SLMNik) &&
                    item.CollectorNik != null &&
                    dcExistingCollector.ContainsKey(item.CollectorNik.Value) &&
                    item.FakturisNik != null &&
                    dcExistingFakturis.ContainsKey(item.FakturisNik.Value) &&
                    item.SPVFakturisNik != null &&
                    dcExistingSPVFakturis.ContainsKey(item.SPVFakturisNik.Value))
                {
                    continue;
                }

                listRemarks = new List <string>();

                #region check FSS
                if (item.FSSNik != 0 && !dcExistingFSS.ContainsKey(item.FSSNik))
                {
                    repoFSS.Condition = PredicateBuilder.True <FSS>().And(x => x.NIK == item.FSSNik);
                    repoFSS.OrderBy   = new SqlOrderBy("CreatedOn", SqlOrderType.Descending);

                    fss = repoFSS.Find().FirstOrDefault();

                    if (fss == null)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_FSS_NOT_FOUND, item.FSSNik));
                    }
                    else if (fss.ValidTo < today)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_FSS_NOT_ACTIVE, item.FSSNik));
                    }
                    else
                    {
                        dcExistingFSS[fss.NIK] = fss.FullName;
                    }
                }
                #endregion

                #region check SLM
                if (item.SLMNik != 0 && !dcExistingSLM.ContainsKey(item.SLMNik))
                {
                    repoSLM.Condition = PredicateBuilder.True <SLM>().And(x => x.NIK == item.SLMNik);
                    repoSLM.OrderBy   = new SqlOrderBy("CreatedOn", SqlOrderType.Descending);

                    slm = repoSLM.Find().FirstOrDefault();

                    if (slm == null)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_SLM_NOT_FOUND, item.SLMNik));
                    }
                    else if (slm.ValidTo < today)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_SLM_NOT_ACTIVE, item.SLMNik));
                    }
                    else
                    {
                        dcExistingSLM[slm.NIK] = slm.FullName;
                    }
                }
                #endregion

                #region check Controller
                if (item.CollectorNik != null && item.CollectorNik.Value != 0 && !dcExistingCollector.ContainsKey(item.CollectorNik.Value))
                {
                    repoCollector.Condition = PredicateBuilder.True <TCollector>().And(x => x.NIK == item.CollectorNik.Value);
                    repoCollector.OrderBy   = new SqlOrderBy("CreatedOn", SqlOrderType.Descending);

                    collector = repoCollector.Find().FirstOrDefault();

                    if (collector == null)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_COLLECTOR_NOT_FOUND, item.CollectorNik.Value));
                    }
                    else if (collector.ValidTo < today)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_COLLECTOR_NOT_ACTIVE, item.CollectorNik.Value));
                    }
                    else
                    {
                        dcExistingCollector[collector.NIK] = collector.FULLNAME;
                    }
                }
                #endregion

                #region check Fakturis
                if (item.FakturisNik != null && item.FakturisNik.Value != 0 && !dcExistingFakturis.ContainsKey(item.FakturisNik.Value))
                {
                    repoFakturis.Condition = PredicateBuilder.True <TFakturis>().And(x => x.NIK == item.FakturisNik.Value);
                    repoFakturis.OrderBy   = new SqlOrderBy("CreatedOn", SqlOrderType.Descending);

                    fakturis = repoFakturis.Find().FirstOrDefault();

                    if (fakturis == null)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_FAKTURIS_NOT_FOUND, item.FakturisNik.Value));
                    }
                    else if (fakturis.ValidTo < today)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_FAKTURIS_NOT_ACTIVE, item.FakturisNik.Value));
                    }
                    else
                    {
                        dcExistingFakturis[fakturis.NIK] = fakturis.FULLNAME;
                    }
                }
                #endregion

                #region check SPV Fakturis
                if (item.SPVFakturisNik != null && item.SPVFakturisNik.Value != 0 && !dcExistingFakturis.ContainsKey(item.SPVFakturisNik.Value))
                {
                    repoSPVFakturis.Condition = PredicateBuilder.True <TSPVFakturis>().And(x => x.NIK == item.SPVFakturisNik.Value);
                    repoSPVFakturis.OrderBy   = new SqlOrderBy("CreatedOn", SqlOrderType.Descending);

                    spvFakturis = repoSPVFakturis.Find().FirstOrDefault();

                    if (spvFakturis == null)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_SPV_FAKTURIS_NOT_FOUND, item.SPVFakturisNik.Value));
                    }
                    else if (spvFakturis.ValidTo < today)
                    {
                        listRemarks.Add(string.Format(StaticMessage.ERR_SPV_FAKTURIS_NOT_ACTIVE, item.SPVFakturisNik.Value));
                    }
                    else
                    {
                        dcExistingSPVFakturis[spvFakturis.NIK] = spvFakturis.FULLNAME;
                    }
                }
                #endregion

                if (listRemarks.Count > 0)
                {
                    item.Remarks = String.Join("; ", listRemarks.ToArray());
                }
            }

            int numError = listVM.Count(x => !string.IsNullOrEmpty(x.Remarks));

            if (numError > 0)
            {
                alert.Status = 0;
                alert.Text   = string.Format(StaticMessage.ERR_PREVIEW_CONTAINS_ERROR, numError);
            }

            model.ListHierTagih = listVM;

            alert.Data = model;

            return(alert);
        }
Ejemplo n.º 5
0
        public AlertMessage Add(FakturisViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.Fakturis))
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            if (!IsEditable())
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            DateTime now       = DateTime.UtcNow.ToUtcID();
            DateTime validFrom = now.AddMonths(-1).AddDays(1).Date;
            DateTime validTo   = new DateTime(9999, 12, 31);

            //model.ValidFromDate = DateTime.ParseExact(model.FormattedValidFrom, AppConstant.DefaultFormatDate, _cultureInfo);
            //model.ValidToDate = DateTime.ParseExact(model.FormattedValidTo, AppConstant.DefaultFormatDate, _cultureInfo);

            IRepository <TFakturis> repo = _unitOfWork.GetRepository <TFakturis>();
            TFakturis item = null;

            #region check NIK exist
            repo.Condition = PredicateBuilder.True <TFakturis>().And(x => x.NIK == model.NIK);

            item = repo.Find().FirstOrDefault();

            if (item != null)
            {
                alert.Text = string.Format(StaticMessage.ERR_NIK_EXIST, item.NIK);
                return(alert);
            }
            #endregion

            item = new TFakturis()
            {
                NIK       = model.NIK,
                FULLNAME  = model.Fullname,
                Role      = model.IsRole,
                ValidFrom = validFrom,
                ValidTo   = validTo,
                CreatedBy = _userAuth.NIK.ToString(),
                CreatedOn = now,
                UpdatedBy = _userAuth.NIK.ToString(),
                UpdatedOn = now,
            };

            try
            {
                _unitOfWork.BeginTransaction();

                repo.Insert(item);

                _unitOfWork.Commit();

                alert.Status = 1;
                alert.Text   = string.Format(StaticMessage.SCS_ADD_MASTER, item.NIK, item.FULLNAME);
            }
            catch (Exception ex)
            {
                _logger.Write("error", DateTime.Now, ex.Message, _userAuth.Fullname, ex);
                alert.Text = StaticMessage.ERR_SAVE_FAILED;
            }
            finally
            {
                _unitOfWork.Dispose();
            }

            return(alert);
        }