private static object InitItem(string key)
        {
            string[] s = key.Split(new[] { "," }, StringSplitOptions.None);

            switch (s[0].ToLower())
            {
            case "quickremarks":
                return(QuickRemark.GetInspectionQuickRemarks());

            case "inspector":
                return(Inspector.Get());

            //case "useraccess":
            //  return UserAccess.GetAllUserAccess();
            case "inspectiontypes":
                return(InspType.Get());

            case "datecache":
                bool IsExternal = bool.Parse(s[1]);
                return(new DateCache(IsExternal));

            default:
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static List <Permit> BulkValidate(
            List <Permit> permits,
            InspType newInspectionType)
        {
            var MasterPermit = (from prmt in permits
                                where prmt.CoClosed != -1
                                select prmt.PermitNo).DefaultIfEmpty("").First();

            var holds = Hold.Get((from prmt in permits
                                  select prmt.PermitNo).ToList <string>());

            foreach (var h in holds)
            {
                if (h.PermitNo == null)
                {
                    h.PermitNo = MasterPermit;
                }
            }

            var CannotInspectPermits = (from h in holds
                                        where h.SatNoInspection == 1 &&
                                        h.PermitNo != MasterPermit
                                        select h.PermitNo).ToList();


            foreach (var prmt in permits)
            {
                if (prmt.PermitNo == MasterPermit && (newInspectionType == null || newInspectionType.InspCd != "205"))
                {
                    prmt.Charges.RemoveAll(c => c.ImpactFee_Relevant);
                }
            }
            var ChargePermits = (from prmt in permits
                                 where prmt.Charges.Count > 0
                                 select prmt.PermitNo).ToList();

            var p = IsMasterClosed(permits);

            if (p.Any())
            {
                return(p);
            }
            p = ChargesExist(permits, ChargePermits, MasterPermit);

            p = HoldsExist(p, holds, CannotInspectPermits, MasterPermit, newInspectionType);



            // this will only be reached if there are no bulk charge, hold, or master closed errors.
            permits = BulkContractorStatusCheck(p, MasterPermit);

            return(p);
        }
Ejemplo n.º 3
0
        private static List <Permit> HoldsExist(
            List <Permit> permits,
            List <Hold> holds,
            List <string> CannotInspectPermits,
            string MasterPermit,
            InspType newInspectionType = null)
        {
            if (!holds.Any() && !CannotInspectPermits.Any())
            {
                return(permits);
            }
            // first let's check for any SatFinalflg holds and update the permits
            var NoFinals = (from h in holds
                            where h.SatFinalFlg == 1
                            select(h.PermitNo ?? MasterPermit)).Distinct().ToList();

            var HoldsThatAllowPreInspections = (from h in holds
                                                where h.AllowPreInspections
                                                select h.HldCd).ToList();

            var holdsAffectingMaster = (from h in holds
                                        where (h.PermitNo == null || h.PermitNo == MasterPermit)
                                        select h).ToList();


            var isBuildingFinal = newInspectionType != null &&
                                  newInspectionType.Final == true &&
                                  newInspectionType.InspCd[0] == 1;

            foreach (var p in permits)
            {
                p.NoFinalInspections = NoFinals.Contains(p.PermitNo);
            }

            if (!isBuildingFinal)
            {
                holdsAffectingMaster.RemoveAll(h => h.SatFinalFlg == 1);
            }

            if (newInspectionType == null || newInspectionType.PreInspection == true)
            {
                holdsAffectingMaster.RemoveAll(h => HoldsThatAllowPreInspections.Contains(h.HldCd));
            }


            // Now let's check to see if we have any master permits that have
            // any holds
            if (MasterPermit.Length > 0 && holdsAffectingMaster.Any())
            {
                var Error = $@"Permit #{ MasterPermit} has existing holds, no inspections can be scheduled. Contact
                       the building department for assistance";
                return(BulkUpdateError(permits, Error));
            }

            // Do any permits have a hold where the flag SatNoInspection = 1?
            // Any permits that have a hold with this flag cannot have inspections scheduled.

            if (!CannotInspectPermits.Any())
            {
                return(permits);
            }
            {
                foreach (var p in permits)
                {
                    if (p.ErrorText.Length != 0)
                    {
                        continue;
                    }

                    if (!CannotInspectPermits.Contains(p.PermitNo) && p.PermitNo != MasterPermit)
                    {
                        continue;
                    }

                    if (p.PermitNo == MasterPermit)
                    {
                        if (permits.Count() > 1 && holdsAffectingMaster.Any())
                        {
                            p.ErrorText = "There is a hold on an associated permit, no inspections can be scheduled";
                        }
                    }
                    else
                    {
                        p.ErrorText = $@"Permit #{p.PermitNo} has existing holds, no inspections can be scheduled.";
                    }
                }
            }
            return(permits);
        }
Ejemplo n.º 4
0
        public static List <Permit> Get(
            string AssocKey,
            UserAccess.access_type CurrentAccess,
            string callingFunction,
            InspType newInspectionType = null,
            bool DoImpactFeesMatter    = false
            )
        {
            /**
             * Need to add the following functionality to this
             * query:
             *
             *    1. check if the permit has been issued (DateTime PermitIssueDate)
             *    2. check if holds exist
             *      a. does hold allow a pre-inspection to be scheduled? bool HoldAllowPre
             *        - Need a way to determine if get() is being called from NewInspection so
             *          hold will count against a new inspection being scheduled.\
             *        - If not called from NewInsection, AllowPreInspection holds will not generate an error
             *          to prevent a scheduling attempt.
             *        - If hold allows pre-Inspections, only pre-Inspections can be scheduled for that hold only.
             *        - If other holds exist, then those controls still apply.
             *
             *      b. does hold stop final? (bool HoldStopFinal) -- This may be unecessary
             *      c. does hold stop all?  (bool HoldStopAll)
             *
             *    3. check if there are charges (bool ChargesExist)
             *      a. does charge prevent final? bool ChargeStopFinal)
             *      b. does charge prevent all? (bool ChargeStopAll)
             *    4. Is Master Permit Co'd? (bool MasterCoClosed)
             *
             **/
            try
            {
                var permits = GetRaw(AssocKey, DoImpactFeesMatter);
                if (permits.Any(p => p.PermitNo == AssocKey))
                {
                    permits = BulkValidate(permits, newInspectionType);
                    var PrivProvCheck = (from prmt in permits
                                         where prmt.CoClosed != -1
                                         select prmt.PrivateProvider).DefaultIfEmpty("").First();


                    /// NEED TO BE ABLE TO DETECT THAT A PROXY IS IN USE BEFORE CHECKING FOR PROD HOST. NEED TO BE ABLE TO CREATE LINK TO
                    string host = Constants.UseProduction() ? "claybccims" : "claybccimstrn";
                    foreach (Permit l in permits)
                    {
                        l.Permit_URL = l.PermitTypeString == "BL" ?
                                       $@"http://{host}/WATSWeb/Permit/MainBL.aspx?PermitNo={l.PermitNo}&Nav=PL&OperId=&PopUp=" :
                                       $@"http://{host}/WATSWeb/Permit/APermit{l.PermitTypeString}.aspx?PermitNo={l.PermitNo}";
                        l.access = CurrentAccess;
                        if (l.access == UserAccess.access_type.public_access)
                        {
                            // l.Permit_URL = "";
                            if (l.Confidential == 1)
                            {
                                l.ProjAddrCombined = "Confidential";
                                l.ProjCity         = "Confidential";
                            }
                        }
                        if (l.ErrorText.Length == 0)
                        {
                            l.Validate();
                        }
                        if (l.ErrorText.Length == 0 && l.IsVoided)
                        {
                            l.ErrorText = "This permit or the master permit have been voided. Please contact the building department for assistance.";
                        }
                    }
                }
                else
                {
                    return(new List <Permit>());
                }

                return(permits);
            }
            catch (Exception ex)
            {
                Constants.Log(
                    ex.StackTrace.Contains("line 151") ? (@"GetRaw(" + AssocKey + "); returned with " + ex.Message):
                    ("Error on Permit: " + AssocKey + ",returned with" + ex.Message),
                    ex.StackTrace.Contains("line 151") ? @"Error in GetRaw":"",
                    ex.StackTrace,
                    @"Error Function: Permit.Get(...",
                    "Query from Permit.GetRaw, line 99");

                return(null);
            }
        }
        public List <string> Save(UserAccess ua)
        {
            List <InspType> inspTypes = InspType.GetCachedInspectionTypes();
            List <string>   errors    = this.Validate(ua.current_access, inspTypes);

            if (errors.Count > 0)
            {
                return(errors);
            }

            int    IRID           = this.AddIRID();
            string InitialComment = $"Inspection Request scheduled for {this.SchecDateTime.Date.ToShortDateString()}.";

            var dbArgs = new Dapper.DynamicParameters();

            dbArgs.Add("@PermitNo", this.PermitNo);
            dbArgs.Add("@InspCd", this.InspectionCd);
            dbArgs.Add("@SelectedDate", this.SchecDateTime.Date);
            dbArgs.Add("@Username", ua.user_name.Trim(), dbType: DbType.String, size: 7);
            dbArgs.Add("@DisplayName", ua.display_name);
            dbArgs.Add("@IRID", (IRID == -1) ? null : IRID.ToString());
            dbArgs.Add("@InitialComment", InitialComment);
            dbArgs.Add("@Comment", Comment);
            dbArgs.Add("@SavedInspectionID", -1, dbType: DbType.Int32, direction: ParameterDirection.Output, size: 8);

            string sql = $@"
      USE WATSC;     

      WITH last_completed_inspection_of_this_type AS (
  
        SELECT TOP 1
          BaseId,
          inspreqid,
          ResultADC
        FROM bpINS_REQUEST
        where inspectionCode = @InspCd
          AND PermitNo = @PermitNo
        order by inspreqid desc

      )

      INSERT INTO bpINS_REQUEST
          (PermitNo,
          InspectionCode,
          Inspector,
          SchecDateTime,
          ReqDateTime,
          BaseId,
          ReceivedBy,
          PrivProvIRId,
          ReinspectionId)
      SELECT TOP 1
          @PermitNo,
          @InspCd,
          CASE WHEN @IRId IS NOT NULL THEN 'PPI' ELSE NULL END inspector,
          CAST(@SelectedDate AS DATE), 
          GETDATE(),
          B.BaseId,
          @Username,
          @IRID,
          CASE WHEN L.ResultADC IN ('D','N') THEN L.InspReqID ELSE NULL END ReinspectionId
      FROM bpBASE_PERMIT B
      LEFT OUTER JOIN bpMASTER_PERMIT M ON M.BaseID = B.BaseID
      LEFT OUTER JOIN bpASSOC_PERMIT A ON B.BaseID = A.BaseID
      LEFT OUTER JOIN last_completed_inspection_of_this_type L ON L.BaseId = B.BaseID
      WHERE (A.PermitNo = @PermitNo OR M.PermitNo = @PermitNo)


      SET @SavedInspectionID = SCOPE_IDENTITY();

      EXEC add_inspection_comment @DisplayName, @SavedInspectionID, @InitialComment, @Comment;";

            try
            {
                //bool isFinal = (from it in inspTypes
                //                where it.InspCd == this.InspectionCd
                //                select it.Final).First();
                //Console.WriteLine("isFinal:", isFinal);


                var i = Constants.Exec_Query(sql, dbArgs);
                if (i > -1)
                {
                    int SavedInspectionId = dbArgs.Get <int>("@SavedInspectionID");


                    string inspDesc = (from it in inspTypes
                                       where it.InspCd == this.InspectionCd
                                       select it.InsDesc).First();
                    errors.Add(inspDesc + " inspection has been scheduled for permit #" + this.PermitNo + ", on " + this.SchecDateTime.ToShortDateString() + ". This was saved with request id " + SavedInspectionId + ".");
                }
                else
                {
                    errors.Add("No Record Saved, Please Try again. Contact the Building department if issues persist.");
                }
            }
            catch (Exception ex)
            {
                Constants.Log(ex, sql);
                errors.Add("No Record Saved, Please Try again. Contact the Building department if issues persist.");
            }
            return(errors);
        }