# This code is taken from the "bills in progress" report
# It takes projected invoicing calculations and applies them to an array of Jobs.
# Grab the projected Invoicing for this Job and at the specified date (see line #54 for implementation)
pi_data = Invoice.projected_invoicing(job, date)
# Renaming variables ("proj_pct_to_bill_by_pcts" is the field you're looking for)
phase_id = pi_data[:phase_id]
phase = pi_data[:phase]
phase_end_date = pi_data[:phase_end_date]
proj_phase_pct_to_bill = pi_data[:proj_phase_pct_to_bill]
proj_total_pct_to_bill = pi_data[:proj_total_pct_to_bill]
proj_pct_to_bill_by_pcts_sum = pi_data[:proj_pct_to_bill_by_pcts_sum]
# THIS USES THE FIELD IN QUESTION <------------------------------
proj_pct_to_bill_by_pcts = pi_data[:proj_pct_to_bill_by_pcts]
# Take the job's fee times the project total percentage to bill minus what we've already billed
# This is the PREDICTED BILLING AMOUNT
pred_bill = job.fee * proj_total_pct_to_bill - previously_billed;
# THIS USES THE FIELD IN QUESTION <------------------------------
# Take the job's fee times the projected percentage to bill's sum, minus what we've already billed
# This is the ACTUAL BILLING AMOUNT
act_bill = job.fee * proj_pct_to_bill_by_pcts_sum - previously_billed
# Take the projected total percentage to bill times the job's fee minus what we've already billed
# This is the PREDICTED INVOICE PERCENTAGE
predicted_invoice_percentage = proj_total_pct_to_bill * job.fee - previously_billed
# If the predicted or actual amounts are less than zero, don't count them
pred_bill = 0.0 if pred_bill < 0
act_bill = 0.0 if act_bill < 0
# The code then sums up these values and displays them on the page
#--------------------------------------------------------------------------------------------------------------------------
# This code is used in the "bills in progress", "work in progress", and "future fees" reports
def projected_invoicing(job, date = Date.today)
phase_pool = # For every Job during a date range and should have an interpolated bill, grab all of its Phases
# Loop through all Phases, and sum up their percentage to bill, and average their percentage to bill
inv[:pct_to_bill_sum] = phase_pool.map(&:percentage_to_bill).sum / phase_pool.size rescue 0.0
# Set a bunch of variables with calculated fields
phase_pool.each do |phase|
inv[:phase_id] = phase.id
inv[:phase] = phase.name
inv[:phase_end_date] = phase.end_date
inv[:phase_pct_fee] = phase.percentage_of_fee
inv[:curr_phase_pct_to_bill] = phase.percentage_to_bill
inv[:proj_phase_pct_to_bill] = phase.percentage_complete(date)
inv[:proj_total_pct_to_bill] += phase.percentage_complete(date) * phase.percentage_of_fee
# THIS IS THE FIELD IN QUESTION <------------------------------
inv[:proj_pct_to_bill_by_pcts] = phase.predicted_percentage_to_bill
# THIS USES THE FIELD IN QUESTION <------------------------------
inv[:proj_pct_to_bill_by_pcts_sum] += phase.percentage_of_fee * phase.predicted_percentage_to_bill
end
end