private static string FormatRateString(HetRentalAgreementRate rentalRate, RentalAgreementDocViewModel agreement)
        {
            string temp = "";

            // format the rate
            if (rentalRate.Rate != null && rentalRate.Set)
            {
                temp = $"$ {rentalRate.Rate:0.00} / Set";
            }
            else if (rentalRate.Rate != null)
            {
                temp = $"$ {rentalRate.Rate:0.00} / {FormatRatePeriod(agreement.RatePeriod)}";
            }

            return(temp);
        }
        /// <summary>
        /// Printed rental agreement view agreement
        /// </summary>
        /// <param name="agreement"></param>
        /// <param name="agreementCity"></param>
        /// <returns></returns>
        public static RentalAgreementDocViewModel GetRentalAgreementReportModel(this HetRentalAgreement agreement, string agreementCity)
        {
            RentalAgreementDocViewModel docModel = new RentalAgreementDocViewModel();

            if (agreement != null)
            {
                docModel.AgreementCity     = agreementCity;
                docModel.Equipment         = agreement.Equipment;
                docModel.EquipmentRate     = agreement.EquipmentRate;
                docModel.EstimateHours     = agreement.EstimateHours;
                docModel.EstimateStartWork = ConvertDate(agreement.EstimateStartWork);
                docModel.Number            = agreement.Number;
                docModel.Project           = agreement.Project;
                docModel.RateComment       = agreement.RateComment;
                docModel.RatePeriod        = agreement.RatePeriodType.Description;
                docModel.AgreementCity     = agreement.AgreementCity;
                docModel.DatedOn           = (agreement.DatedOn ?? DateTime.UtcNow).ToString("MM/dd/yyyy");
                docModel.DoingBusinessAs   = agreement.Equipment.Owner.DoingBusinessAs;
                docModel.EmailAddress      = agreement.Equipment.Owner.PrimaryContact.EmailAddress;

                // format owner address
                string tempAddress = agreement.Equipment.Owner.Address2;

                if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.City))
                {
                    tempAddress = $"{agreement.Equipment.Owner.City}";
                }

                if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.City) && agreement.Equipment.Owner.City.Trim() != tempAddress.Trim())
                {
                    tempAddress = $"{tempAddress}, {agreement.Equipment.Owner.City}";
                }

                if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.Province))
                {
                    tempAddress = $"{agreement.Equipment.Owner.Province}";
                }

                if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.Province))
                {
                    tempAddress = $"{tempAddress}, {agreement.Equipment.Owner.Province}";
                }

                if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.PostalCode))
                {
                    tempAddress = $"{agreement.Equipment.Owner.PostalCode}";
                }

                if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.PostalCode))
                {
                    tempAddress = $"{tempAddress}  {agreement.Equipment.Owner.PostalCode}";
                }

                agreement.Equipment.Owner.Address2 = tempAddress;

                // format the note
                if (!string.IsNullOrEmpty(agreement.Note))
                {
                    string   temp      = Regex.Replace(agreement.Note, @"\n", "<BR>");
                    string[] tempArray = temp.Split("<BR>");

                    docModel.Note = new List <NoteLine>();

                    foreach (string row in tempArray)
                    {
                        NoteLine line = new NoteLine {
                            Line = row
                        };
                        docModel.Note.Add(line);
                    }
                }

                // ensure they are ordered the way they were added
                docModel.RentalAgreementConditions = agreement.HetRentalAgreementCondition
                                                     .OrderBy(x => x.RentalAgreementConditionId)
                                                     .ToList();

                docModel.RentalAgreementRates = agreement.HetRentalAgreementRate.Where(x => x.Active).ToList();
                docModel.Status            = agreement.RentalAgreementStatusType.Description;
                docModel.ConditionsPresent = agreement.HetRentalAgreementCondition.Count > 0;

                foreach (HetRentalAgreementCondition condition in docModel.RentalAgreementConditions)
                {
                    if (!string.IsNullOrEmpty(condition.Comment))
                    {
                        condition.ConditionName = condition.Comment;
                    }
                }

                docModel = CalculateTotals(docModel);

                // classification (Rental Agreement)
                docModel.Classification = $"23010-30/{agreement.Number}";
            }

            return(docModel);
        }
        /// <summary>
        /// Uses the rates data to calculate the totals and setup the required data for printing
        /// </summary>
        public static RentalAgreementDocViewModel CalculateTotals(RentalAgreementDocViewModel agreement)
        {
            // **********************************************
            // setup the rates lists ->
            // 1. overtime records
            // 2. records in the total and
            // 3. records not included
            // **********************************************
            agreement.RentalAgreementRatesOvertime = agreement.RentalAgreementRates
                                                     .FindAll(x => x.Overtime)
                                                     .OrderBy(x => x.RentalAgreementRateId).ToList();

            agreement.RentalAgreementRatesWithTotal = agreement.RentalAgreementRates
                                                      .FindAll(x => x.IsIncludedInTotal && !x.Overtime)
                                                      .OrderBy(x => x.RentalAgreementRateId).ToList();

            agreement.RentalAgreementRatesWithoutTotal = agreement.RentalAgreementRates
                                                         .FindAll(x => !x.IsIncludedInTotal && !x.Overtime)
                                                         .OrderBy(x => x.RentalAgreementRateId).ToList();

            // **********************************************
            // calculate the total
            // **********************************************
            float temp = 0.0F;

            foreach (HetRentalAgreementRate rentalRate in agreement.RentalAgreementRatesWithTotal)
            {
                if (rentalRate.Rate != null)
                {
                    temp = temp + (float)rentalRate.Rate;
                }

                // format the rate / percent at the same time
                rentalRate.RateString = FormatRateString(rentalRate, agreement, rentalRate.RatePeriodType.RatePeriodTypeCode);
            }

            // add the base amount to the total too
            if (agreement.EquipmentRate != null)
            {
                temp = temp + (float)agreement.EquipmentRate;
            }

            agreement.AgreementTotal = temp;

            // format the base rate
            agreement.BaseRateString = $"$ {agreement.EquipmentRate:0.00} / {FormatRatePeriod(agreement.RatePeriod)}";

            // format the total
            agreement.AgreementTotalString =
                $"$ {agreement.AgreementTotal:0.00} / {FormatRatePeriod(agreement.RatePeriod)}";

            // **********************************************
            // format the rate / percent values
            // **********************************************
            foreach (HetRentalAgreementRate rentalRate in agreement.RentalAgreementRatesOvertime)
            {
                rentalRate.RateString = FormatOvertimeRateString(rentalRate);
            }

            foreach (HetRentalAgreementRate rentalRate in agreement.RentalAgreementRatesWithoutTotal)
            {
                rentalRate.RateString = FormatRateString(rentalRate, agreement, rentalRate.RatePeriodType.RatePeriodTypeCode);
            }

            return(agreement);
        }