コード例 #1
0
        private SalesmanViewModel GetSalesmanViewModel(SLM slm)
        {
            SalesmanViewModel model = new SalesmanViewModel();

            model.NIK           = slm.NIK;
            model.Fullname      = slm.FullName;
            model.IsRole        = slm.Role;
            model.ValidFromDate = slm.ValidFrom;
            model.ValidToDate   = slm.ValidTo;

            model.FormattedValidFrom = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate);
            model.FormattedValidTo   = model.ValidToDate.ToString(AppConstant.DefaultFormatDate);

            return(model);
        }
コード例 #2
0
        public SalesmanViewModel GetDetail(int id)
        {
            IRepository <SLM> repo = _unitOfWork.GetRepository <SLM>();

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

            SLM slm = repo.Find().FirstOrDefault();

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

            SalesmanViewModel model = GetSalesmanViewModel(slm);

            return(model);
        }
コード例 #3
0
ファイル: BaseBusiness.cs プロジェクト: iwasug/Aida.Master.V2
        private void SetUserSLM(ref UserAuthenticated userAuth, int empID)
        {
            DateTime today = DateTime.UtcNow.ToUtcID();

            IRepository <SLM> repoSLM = _unitOfWork.GetRepository <SLM>();

            repoSLM.Condition = PredicateBuilder.True <SLM>().And(x => x.NIK == empID && x.ValidTo >= today);

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

            if (slm == null)
            {
                return;
            }

            userAuth.IsRoleValid = true;
            userAuth.NIK         = slm.NIK;
            userAuth.Fullname    = slm.FullName;
        }
コード例 #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);
        }
コード例 #5
0
        public AlertMessage Edit(SalesmanViewModel model)
        {
            AlertMessage alert = new AlertMessage();

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

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

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

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

            SLM slm = repo.Find().FirstOrDefault();

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

            DateTime now = DateTime.UtcNow.ToUtcID();

            //IRepository<RHHeader> repoHeader = _unitOfWork.GetRepository<RHHeader>();
            //repoHeader.Condition = PredicateBuilder.True<RHHeader>().And(x => x.SLM == model.NIK);

            //RHHeader rhHeader = repoHeader.Find().FirstOrDefault();

            //if (rhHeader != null)
            //{
            //    rhHeader.ValidFrom = DateTime.Parse(model.FormattedValidFrom);
            //    rhHeader.ValidTo = DateTime.Parse(model.FormattedValidTo);
            //    rhHeader.UpdatedBy = _userAuth.NIK.ToString();
            //    rhHeader.UpdatedOn = now;
            //}

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

            try
            {
                _unitOfWork.BeginTransaction();

                repo.Update(slm);
                //repoHeader.Update(rhHeader);

                _unitOfWork.Commit();

                alert.Status = 1;
                alert.Text   = string.Format(StaticMessage.SCS_EDIT, slm.NIK, slm.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);
        }
コード例 #6
0
        public AlertMessage Add(SalesmanViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.Salesman))
            {
                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 <SLM> repo = _unitOfWork.GetRepository <SLM>();
            SLM item = null;

            #region check NIK exist
            repo.Condition = PredicateBuilder.True <SLM>().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 SLM()
            {
                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);
        }
コード例 #7
0
        public AlertMessage Preview(ImportSalesViewModel model)
        {
            AlertMessage alert = new AlertMessage();

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

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

            List <HierSalesViewModel> listVM = GetListHierSalesViewModel(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>();
            FSS fss = null;
            SLM slm = 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>();

            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))
                {
                    continue;
                }

                listRemarks = new List <string>();

                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;
                    }
                }

                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;
                    }
                }

                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.ListHierSales = listVM;

            alert.Data = model;

            return(alert);
        }