Exemple #1
0
        private static string FormatRateString(HetRentalAgreementRate rentalRate, RentalAgreementPdfViewModel agreement)
        {
            string temp = "";

            // format the rate
            if (rentalRate.Rate != null)
            {
                temp = string.Format("$ {0:0.00} / {1}", rentalRate.Rate, FormatRatePeriod(agreement.RatePeriod));
            }

            return(temp);
        }
Exemple #2
0
        /// <summary>
        /// Printed rental agreement view agreement
        /// </summary>
        /// <param name="agreement"></param>
        /// <param name="agreementCity"></param>
        /// <returns></returns>
        public static RentalAgreementPdfViewModel ToPdfModel(this HetRentalAgreement agreement, string agreementCity)
        {
            RentalAgreementPdfViewModel pdfModel = new RentalAgreementPdfViewModel();

            if (agreement != null)
            {
                pdfModel.DatedOn           = ConvertDate(agreement.DatedOn);
                pdfModel.AgreementCity     = agreementCity;
                pdfModel.Equipment         = agreement.Equipment;
                pdfModel.EquipmentRate     = agreement.EquipmentRate;
                pdfModel.EstimateHours     = agreement.EstimateHours;
                pdfModel.EstimateStartWork = ConvertDate(agreement.EstimateStartWork);
                pdfModel.Id          = agreement.RentalAgreementId;
                pdfModel.Note        = agreement.Note;
                pdfModel.Number      = agreement.Number;
                pdfModel.Project     = agreement.Project;
                pdfModel.RateComment = agreement.RateComment;
                pdfModel.RatePeriod  = agreement.RatePeriodType.Description;
                pdfModel.RentalAgreementConditions = agreement.HetRentalAgreementCondition.ToList();
                pdfModel.RentalAgreementRates      = agreement.HetRentalAgreementRate.Where(x => x.Active).ToList();
                pdfModel.Status            = agreement.RentalAgreementStatusType.Description;
                pdfModel.ConditionsPresent = agreement.HetRentalAgreementCondition.Count > 0;

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

                pdfModel = CalculateTotals(pdfModel);
            }

            return(pdfModel);
        }
Exemple #3
0
        /// <summary>
        /// Uses the rates data to calculate the totals and setup the required data for printing
        /// </summary>
        public static RentalAgreementPdfViewModel CalculateTotals(RentalAgreementPdfViewModel 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);
            }

            // 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 = string.Format("$ {0:0.00} / {1}", agreement.EquipmentRate, FormatRatePeriod(agreement.RatePeriod));

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

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

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

            return(agreement);
        }