Exemplo n.º 1
0
 public void SetUserProperties(UserAccess ua)
 {
     // set all user properties here
     created_by_employee_id  = ua.employee_id;
     created_by_username     = ua.user_name;
     created_by_display_name = ua.display_name;
     my_department_id        = ua.my_department_id;
     my_access = ua.current_access;
 }
Exemplo n.º 2
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> Validate(UserAccess.access_type CurrentAccess,
                                      List <InspType> inspTypes)
        {
            // List of things that need to be validated:
            // 0) Make sure the permit is able to be scheduled to be inspected.
            // 1) Make sure this permit is valid
            // 2) Make sure the date is in the range expected
            // 3) Make sure the inspection type matches the permit type.
            // 4) Make sure the inspection type is a valid inspection type.
            // 5) Make sure the inspection type isn't already scheduled for this permit.
            // 6) Need to ensure an Inspection cannot be saved if a final inspection result is 'A' or 'P'
            List <string> Errors = new List <string>();

            // 0)
            List <InspType> finals = (from it in inspTypes
                                      where it.Final == true
                                      select it).ToList();

            List <string> finalInspectionCodes = (from it in inspTypes
                                                  where it.Final == true
                                                  select it.InspCd).ToList();

            var currentInspectionType = (from i in inspTypes
                                         where i.InspCd == InspectionCd
                                         select i).ToList().First();

            // DoImpactFeesMatter is how we indicate to the permit that the impact fees matter.
            this.DoImpactFeesMatter = finals.Any(f => f.InspCd == InspectionCd);
            if (currentInspectionType.InspCd == "205")
            {
                this.DoImpactFeesMatter = true;
            }
            //foreach (var f in finals)
            //{
            //  if (f.InspCd == this.InspectionCd)
            //    this.TryingToScheduleFinal = true;
            //}
            //Console.Write("Finals: ", finals);

            //= (List<InspType>)MyCache.GetItem("inspectiontypes,"+IsExternalUser.ToString());

            var Permits =
                (from p in Permit.Get(
                     this.PermitNo,
                     CurrentAccess,
                     $@"NewInspection.Validate();
                 User Access Level: {CurrentAccess};
                 PermitNo: {this.PermitNo}",
                     currentInspectionType,
                     DoImpactFeesMatter)
                 select p).ToList();


            Permit CurrentPermit = (from p in Permits
                                    where p.PermitNo == this.PermitNo
                                    select p).FirstOrDefault();



            if (CurrentPermit == null)
            {
                Errors.Add($"Permit number {PermitNo} was not found.");

                // If permit is not found, then exit
                // no need to validate other data
                return(Errors);
            }
            else
            {
                if (CurrentPermit.ErrorText.Length > 0)
                {
                    Errors.Add(CurrentPermit.ErrorText);
                }

                bool canSchedule = false;


                var mp = (from p in Permits
                          where p.CoClosed == 0
                          select p).DefaultIfEmpty(new Permit()).First();
                canSchedule = this.DoImpactFeesMatter && mp.CorrectImpactFeeCount && mp.TotalImpactFeesDue == 0;



                if (!canSchedule && this.DoImpactFeesMatter)
                {
                    List <string> newList = new List <string>();
                    newList.Add($@"A {currentInspectionType.InsDesc} cannot be scheduled if there are unpaid impact fees.
                          Please contact the building department for assistance.");
                    Errors = newList;
                    // TODO: add call to function here that will assess the Solid Waste Fee
                }

                // validate user selected date
                var start    = DateTime.Parse(CurrentPermit.Dates.minDate_string);
                var end      = DateTime.Parse(CurrentPermit.Dates.maxDate_string);
                var badDates = (from d in CurrentPermit.Dates.badDates_string
                                where DateTime.Parse(d) != start &&
                                DateTime.Parse(d) != end
                                select d).ToList <string>();

                // Is the scheduled date between the start and end date?
                if (SchecDateTime.Date < start ||
                    SchecDateTime.Date > end)
                {
                    Errors.Add("Invalid Date Selected");
                }
                // Is the scheduled date one of the dates they aren't allowed to use?
                if (badDates.Contains(SchecDateTime.ToShortDateString()))
                {
                    Errors.Add("Invalid Date Selected");
                }
                // Is the inspection type valid?
                if (!(from i in inspTypes
                      where i.InspCd == InspectionCd
                      select i).Any())
                {
                    Errors.Add("Invalid Inspection Type");
                }
                else
                {
                    // Does the inspection type match the permit type
                    var permitType = ' ';

                    switch (PermitNo[0])
                    {
                    case '1':
                    case '9':
                    case '0':
                        permitType = '1';
                        break;

                    default:
                        permitType = PermitNo[0];
                        break;
                    }


                    if (InspectionCd[0] != permitType)
                    {
                        Errors.Add("Invalid Inspection for this permit type");
                    }

                    List <Inspection> inspections = Inspection.Get(CurrentPermit.PermitNo);
                    CurrentPermit.Holds = Hold.Get(new List <string>()
                    {
                        CurrentPermit.PermitNo
                    });

                    var needsFireInspection = (from h in CurrentPermit.Holds
                                               where h.HldCd == "FD05"
                                               select h.HldCd.ToString()).ToList();

                    if (CurrentPermit.TotalFinalInspections > 0 && needsFireInspection.Count() == 0 && CurrentPermit.PermitNo[0] != '6')
                    {
                        Errors.Add($"Permit #{CurrentPermit.PermitNo} has passed final inspection");
                    }


                    var PassedOrScheduledInspections = (from ic in inspections
                                                        where (ic.ResultADC != "C" &&
                                                               ic.ResultADC != "D" &&
                                                               ic.ResultADC != "N")
                                                        select ic).ToList();

                    foreach (var i in PassedOrScheduledInspections)
                    {
                        if (this.PermitNo == i.PermitNo && this.InspectionCd == i.InspectionCode && string.IsNullOrEmpty(i.ResultADC))
                        {
                            Errors.Add("Inspection type exists on permit");
                        }
                        // commenting out debug code
                        //var IncompleteInspection = (from ic in PassedOrScheduledInspections
                        //                            where i.InspectionCode == this.InspectionCd &&
                        //                            string.IsNullOrEmpty(i.ResultADC)
                        //                            select ic).ToList();

                        //Console.Write(IncompleteInspection);
                    }



                    //Adds functionality to return error when saving an inspection for permit that has already passed a final inspection.

                    // To schedule a building final:
                    // 1. All fees, including Road impact and school impact fees, must be paid; AND
                    // 2. All associated permits must have a final inspection either scheduled, or passed.
                    // 3. The Final Building Inspection cannot be scheduled for any time before the latest incomplete
                    //    associated permit's final inspection.
                    var    PermitsWithScheduledOrPassedFinals   = new List <string>();
                    var    permitsWithNoFinalsScheduledOrPassed = new List <string>();
                    string masterPermit = "";
                    foreach (var f in finals)
                    {
                        PermitsWithScheduledOrPassedFinals.AddRange(from ic in PassedOrScheduledInspections
                                                                    where ic.InspectionCode == f.InspCd &&
                                                                    (ic.ResultADC != "C" &&
                                                                     ic.ResultADC != "D" &&
                                                                     ic.ResultADC != "N") &&
                                                                    !PermitsWithScheduledOrPassedFinals.Contains(ic.PermitNo)
                                                                    select ic.PermitNo);
                    }

                    foreach (var p in Permits)
                    {
                        if (p.GetIsVoided())
                        {
                            continue;
                        }
                        if (p.CoClosed != -1)
                        {
                            masterPermit = p.PermitNo;
                        }
                        var currentCheck = (from pf in PermitsWithScheduledOrPassedFinals
                                            where pf == p.PermitNo
                                            select pf).FirstOrDefault();

                        if (currentCheck == null)
                        {
                            permitsWithNoFinalsScheduledOrPassed.Add(p.PermitNo);
                        }
                        else
                        {
                            if (p.PermitNo == this.PermitNo)
                            {
                                Errors.Add($@"Permit {p.PermitNo} has a scheduled final inspection.");
                            }
                        }
                    }

                    foreach (var p in Permits)
                    {
                        if (p.CoClosed != -1)
                        {
                            permitsWithNoFinalsScheduledOrPassed.Remove(p.PermitNo);

                            if (Permits.Count > 1 &&
                                finalInspectionCodes.Contains(this.InspectionCd) &&
                                permitsWithNoFinalsScheduledOrPassed.Count > 0 &&
                                this.PermitNo.Trim() == masterPermit.Trim())
                            {
                                Errors.Add($@"All permits associated with permit #{p.PermitNo}
                           must have final inspections scheduled or passed, 
                           before a Building final can be scheduled.");
                            }
                            else if (this.InspectionCd == "123" && this.PermitNo == masterPermit && p.NoFinalInspections == true)
                            {
                                Errors.Add($@"Permit {masterPermit} has existing holds, 
                           this is preventing the Building Final
                           from being scheduled.");
                            }
                        }
                    }
                }
            }
            return(Errors);
        }