mdarby (owner)

Revisions

gist: 183065 Download_button fork
public
Public Clone URL: git://gist.github.com/183065.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 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