public ActionResult ImportTagih(ImportTagihViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            model = null;

            if (TempData["ImportTagih"] != null)
            {
                model = TempData["ImportTagih"] as ImportTagihViewModel;
            }
            else
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
            }

            if (model != null)
            {
                HierTagihBusiness business = new HierTagihBusiness();
                business.SetUserAuth(ViewBag.UserAuth);

                alert = business.ImportTagih(model);
            }

            TempData["AlertMessage"] = alert;

            return(RedirectToAction("Index"));
        }
        public ActionResult PreviewImportTagih(ImportTagihViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!ModelState.IsValid)
            {
                alert.Text = string.Join(System.Environment.NewLine, ModelState.Values
                                         .SelectMany(v => v.Errors)
                                         .Select(e => e.ErrorMessage));
            }
            else
            {
                HierTagihBusiness business = new HierTagihBusiness();
                business.SetUserAuth(ViewBag.UserAuth);

                alert = business.Preview(model);
            }

            TempData["AlertMessage"] = alert;

            if (alert.Data != null)
            {
                TempData["ImportTagih"] = alert.Data;

                return(View(alert.Data));
            }
            else
            {
                return(RedirectToAction("ImportTagih"));
            }
        }
Example #3
0
        public AlertMessage ImportTagih(ImportTagihViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            _logger.Write("info", DateTime.Now, string.Format("Upload Master Hier Tagih Total : {0}", model.ListHierTagih.Count), _userAuth.Fullname);
            if (!IsAccessible(ModuleCode.MasterTagih))
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            int month = 0;
            int year  = 0;

            try
            {
                string[] arr = model.FormattedValidDate.Split('-');

                month = Convert.ToInt16(arr[0]);
                year  = Convert.ToInt16(arr[1]);
            }
            catch (Exception ex)
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
                return(alert);
            }

            if (month == 0 || year == 0)
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
                return(alert);
            }

            //IRepository<UploadHier> repoUploadHier = _unitOfWork.GetRepository<UploadHier>();
            IRepository <UploadHierTagih2> repoUploadHierTagih = _unitOfWork.GetRepository <UploadHierTagih2>();
            UploadHierTagih2 hier = null;

            foreach (var item in model.ListHierTagih)
            {
                hier = new UploadHierTagih2()
                {
                    RayonCode    = item.RayonCode,
                    Plant        = item.PlantCode,
                    NSM          = item.NSMNik,
                    ASM          = item.ASMNik,
                    FSS          = item.FSSNik,
                    SLM          = item.SLMNik,
                    Collector    = item.CollectorNik.Value,
                    Fakturis     = item.FakturisNik.Value,
                    SPVFakturis  = item.SPVFakturisNik.Value,
                    CreatedByNIK = _userAuth.NIK
                };

                try
                {
                    repoUploadHierTagih.Insert(hier, true);
                }
                catch (Exception ex)
                {
                    item.Remarks = ex.Message;
                }
            }

            #region execute SP
            List <SqlParameter> listSqlParam = new List <SqlParameter>()
            {
                new SqlParameter("@inMonth", month),
                new SqlParameter("@inYear", year),
                new SqlParameter("@nik", _userAuth.NIK),
            };

            bool   isError    = false;
            string connString = GetConnectionString();

            Dictionary <int, dynamic> dc = null;

            try
            {
                //dc = SqlHelper.ExecuteProcedureWithReturnRecords(connString, "sp_uploadHier", listSqlParam);
                //dc = SqlHelper.ExecuteProcedureWithReturnRecords(connString, "sp_uploadHierTagih", listSqlParam);
                dc = SqlHelper.ExecuteProcedureWithReturnRecords(connString, "sp_uploadHierTagih_v2", listSqlParam);

                if (dc.ContainsKey(0))
                {
                    isError = true;
                }
            }
            catch (Exception ex)
            {
                _logger.Write("error", DateTime.Now, ex.Message, _userAuth.Fullname, ex);
                isError = true;
            }
            #endregion

            if (isError)
            {
                // delete all records from table UploadML
                var condition = PredicateBuilder.True <UploadHierTagih2>().And(x => x.CreatedByNIK == _userAuth.NIK);
                repoUploadHierTagih.Delete(condition, true);
            }
            else if (dc != null)
            {
                dynamic val;

                DataTable dt = null;

                if (dc.TryGetValue(1, out val))
                {
                    dt = val as DataTable;
                }
            }

            _unitOfWork.Dispose();

            if (isError)
            {
                alert.Text = StaticMessage.ERR_SAVE_FAILED;
            }
            else
            {
                int numSuccess = model.ListHierTagih.Count(x => string.IsNullOrEmpty(x.Remarks));

                alert.Status = 1;
                alert.Text   = string.Format(StaticMessage.SCS_IMPORT, numSuccess);
            }

            return(alert);
        }
Example #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);
        }