def getTotalOverheadPerQuarter(self, year): per_quarter_overhead = (self.allocated_salary_expense + self.sga_expense) / 4 total_overhead = [ per_quarter_overhead, per_quarter_overhead, per_quarter_overhead, per_quarter_overhead, self.allocated_salary_expense + self.sga_expense ] for u in self.users: if u.end_date is None: u.end_date = datetime.datetime(int(year), 12, 31) if u.percent_billable < 100: quarterly_non_billable = quarterly_money( year, u.start_date, u.end_date, u.loaded_non_billable_salary_per_day) for x in range(0, 4): total_overhead[x] += quarterly_non_billable[x] total_overhead[4] += quarterly_non_billable[x] for f in self.freelancers: quarterly_nb_freelancers = quarterly_money(year, f.start_date, f.end_date, f.rate_per_day) for x in range(0, 4): total_overhead[x] += quarterly_nb_freelancers[x] total_overhead[4] += quarterly_nb_freelancers[x] return total_overhead
def calculateRevenue(self): revenue = quarterly_money(self.year, self.project.start_date, self.project.end_date, self.project.revenue_per_day) self.Q1 = revenue[0] self.Q2 = revenue[1] self.Q3 = revenue[2] self.Q4 = revenue[3]
def calculateRevenue(self): revenue = quarterly_money(self.year, self.ghost_project.start_date, self.ghost_project.end_date, self.ghost_project.revenue_per_day, None, "ghost_revenue") self.Q1 = revenue[0] self.Q2 = revenue[1] self.Q3 = revenue[2] self.Q4 = revenue[3] self.Q1_weighted = self.Q1 * (self.ghost_project.likelihood / 100) self.Q2_weighted = self.Q2 * (self.ghost_project.likelihood / 100) self.Q3_weighted = self.Q3 * (self.ghost_project.likelihood / 100) self.Q4_weighted = self.Q4 * (self.ghost_project.likelihood / 100)
def getTotalBillableCompPerQuarter(self, year): total_comp = [0, 0, 0, 0, 0] for u in self.users: end_date = u.end_date if end_date is None: next_year = int(year) + 1 end_date = datetime.datetime(next_year, 1, 1) quarterly_comp = quarterly_money(year, u.start_date, end_date, u.loaded_billable_salary_per_day) for x in range(0, 4): total_comp[x] += quarterly_comp[x] total_comp[4] += quarterly_comp[x] return total_comp
def calculateFinancials(self): self.initializeVariables() try: for client in self.office.clients: if client.is_active: client_financials = ClientFinancials( client, self.year, self.user) for x in range(0, 5): self.expense_salary_billable[ x] += client_financials.expense_salary[x] self.expense_open_req_billable[ x] += client_financials.expense_ghost[x] self.expense_freelance_billable[ x] += client_financials.expense_freelance[x] self.expense_freelance_billable_if_employee[ x] += client_financials.expense_freelance_if_employee[ x] self.revenue_closed[ x] += client_financials.revenue_projects[x] self.revenue_client_opportunities[ x] += client_financials.revenue_client_opportunities[ x] self.non_billable_expenses[ x] += client_financials.non_billable_expenses[x] if client_financials.revenue_total[x] > 0: self.client_financials.append(client_financials) for ghost_client in self.office.ghost_clients: if ghost_client.is_active: tbg_financials = None prospect_financials = None if ghost_client.is_tbg: tbg_financials = GhostClientFinancials( ghost_client, self.year, self.user) else: prospect_financials = GhostClientFinancials( ghost_client, self.year, self.user) for x in range(0, 5): if prospect_financials is not None: self.expense_salary_prospects[ x] += prospect_financials.expense_salary[x] self.expense_open_req_prospects[ x] += prospect_financials.expense_ghost[x] self.revenue_prospects[ x] += prospect_financials.revenue[x] self.revenue_prospects_weighted[ x] += prospect_financials.weighted_revenue[x] if tbg_financials is not None: self.revenue_tbg[x] += tbg_financials.revenue[x] if prospect_financials is not None and prospect_financials.revenue[ x] > 0: self.prospect_financials.append(prospect_financials) if tbg_financials is not None and tbg_financials.revenue[ x] > 0: self.tbg_financials.append(tbg_financials) for user in self.office.users: total_salary_for_user = quarterly_salary( self.year, user, user.start_date, datetime.datetime(int(self.year) + 1, 1, 1)) expense_salary_non_billable_for_user = quarterly_salary( self.year, user, user.start_date, datetime.datetime(int(self.year) + 1, 1, 1), "non-billable") full_billable_salary_for_user = quarterly_salary( self.year, user, user.start_date, datetime.datetime(int(self.year) + 1, 1, 1), "billable") for x in range(0, 4): self.total_salary[x] += total_salary_for_user[x] self.expense_salary_non_billable[ x] += expense_salary_non_billable_for_user[x] self.full_billable_salary[ x] += full_billable_salary_for_user[x] for freelancer in self.office.freelancers: comp_per_freelancer = quarterly_money(self.year, freelancer.start_date, freelancer.end_date, freelancer.rate_per_day) comp_per_freelancer_if_employee = quarterly_money( self.year, freelancer.start_date, freelancer.end_date, freelancer.rate_per_day_if_employee) for x in range(0, 4): self.expense_freelance_non_billable[ x] += comp_per_freelancer[x] self.expense_freelance_non_billable[ 4] += comp_per_freelancer[x] self.expense_freelance_non_billable_if_employee[ x] += comp_per_freelancer_if_employee[x] self.expense_freelance_non_billable_if_employee[ 4] += comp_per_freelancer_if_employee[x] for ghost_user in self.office.ghost_users: total_open_req = quarterly_money( self.year, ghost_user.start_date, datetime.datetime(int(self.year) + 1, 1, 1), ghost_user.loaded_salary_per_day, None, "ghost_salary") expense_open_req_non_billable = quarterly_money( self.year, ghost_user.start_date, datetime.datetime(int(self.year) + 1, 1, 1), ghost_user.loaded_non_billable_salary_per_day, None, "ghost_salary") full_open_req_billable = quarterly_money( self.year, ghost_user.start_date, datetime.datetime(int(self.year) + 1, 1, 1), ghost_user.loaded_billable_salary_per_day, None, "ghost_salary") for x in range(0, 4): self.total_open_req[x] += total_open_req[x] self.expense_open_req_non_billable[ x] += expense_open_req_non_billable[x] self.full_open_req_billable[x] += full_open_req_billable[x] for x in range(0, 4): self.total_salary[4] += self.total_salary[x] self.expense_salary_non_billable[ 4] += self.expense_salary_non_billable[x] self.full_billable_salary[4] += self.full_billable_salary[x] self.total_open_req[4] += self.total_open_req[x] self.expense_open_req_non_billable[ 4] += self.expense_open_req_non_billable[x] self.full_open_req_billable[4] += self.full_open_req_billable[ x] for actual_expense in self.office.actual_expenses: if actual_expense.quarter_end_date.year == self.year: if actual_expense.quarter_end_date.month == 3: if actual_expense.expense_local is not None: self.expense_sga[ 0] = actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: self.expense_salary_global[ 0] = actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 6: if actual_expense.expense_local is not None: self.expense_sga[ 1] = actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: self.expense_salary_global[ 1] = actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 9: if actual_expense.expense_local is not None: self.expense_sga[ 2] = actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: self.expense_salary_global[ 2] = actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 12: if actual_expense.expense_local is not None: self.expense_sga[ 3] = actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: self.expense_salary_global[ 3] = actual_expense.expense_global * self.usd_to_local self.expense_sga[4] = self.expense_sga[0] + self.expense_sga[ 1] + self.expense_sga[2] + self.expense_sga[3] for x in range(0, 5): # not totally accurate; does not account for people billed out to clients in other offices - fix self.expense_salary_bench[x] = self.full_billable_salary[x] - ( self.expense_salary_billable[x] + self.expense_salary_prospects[x]) # hack because of the qarterly money quirk if self.expense_salary_bench[x] < 0: self.expense_salary_bench[x] = 0 # end hack self.expense_open_req_bench[x] = self.full_open_req_billable[ x] - (self.expense_open_req_billable[x] + self.expense_open_req_prospects[x]) if self.expense_sga[4] == 0: if x == 4: self.expense_sga[ x] = self.office.sga_expense * self.usd_to_local elif self.office.allocated_salary_expense is not None: self.expense_sga[x] = (self.office.sga_expense * self.usd_to_local) / 4 if self.expense_salary_global[x] == 0: if x == 4: self.expense_salary_global[ x] = self.office.allocated_salary_expense * self.usd_to_local elif self.office.allocated_salary_expense is not None: self.expense_salary_global[x] = ( self.office.allocated_salary_expense * self.usd_to_local) / 4 self.expense_total[x] = self.non_billable_expenses[ x] + self.expense_salary_billable[x] + self.expense_salary_non_billable[ x] + self.expense_salary_prospects[ x] + self.expense_salary_bench[ x] + self.expense_open_req_billable[ x] + self.expense_open_req_non_billable[ x] + self.expense_open_req_prospects[ x] + self.expense_open_req_bench[ x] + self.expense_freelance_billable[ x] + self.expense_freelance_non_billable[ x] + self.expense_sga[x] self.revenue_total[x] = self.revenue_closed[ x] + self.revenue_client_opportunities[ x] + self.revenue_prospects[x] + self.revenue_tbg[x] self.profit[x] = self.revenue_total[x] - self.expense_total[x] if self.revenue_total[x] > 0: self.margin[x] = int( (self.profit[x] / self.revenue_total[x]) * 100) else: self.margin[x] = 0 #calculate potential revenue and margin, which is based on ratios from last full quarter applied moving forward if datetime.datetime.now().year > self.year: for x in range(0, 4): if (self.expense_salary_billable[x] + self.expense_freelance_billable_if_employee[x] ) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ x] / ( self.expense_salary_billable[x] + self.expense_freelance_billable_if_employee[x]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[x] = self.revenue_total[x] + ( (self.expense_salary_bench[x] + self.expense_salary_prospects[x] + self.expense_salary_tbg[x]) * revenue_per_dollar_salary_freelance) elif datetime.datetime.now().month < 4: old_office_financials = OfficeFinancials( self.office, self.year - 1, self.user) if (old_office_financials.expense_salary_billable[4] + old_office_financials. expense_freelance_billable_if_employee[4]) > 0: revenue_per_dollar_salary_freelance = old_office_financials.revenue_total[ 4] / (old_office_financials.expense_salary_billable[4] + old_office_financials. expense_freelance_billable_if_employee[4]) else: revenue_per_dollar_salary_freelance = 0 for x in range(0, 4): self.potential_revenue[x] = self.revenue_total[x] + ( (self.expense_salary_bench[x] + self.expense_salary_prospects[x] + self.expense_salary_tbg[x]) * revenue_per_dollar_salary_freelance) elif datetime.datetime.now().month < 7: revenue_per_dollar_salary_freelance = self.revenue_total[0] / ( self.expense_salary_billable[0] + self.expense_freelance_billable_if_employee[0]) for x in range(0, 4): self.potential_revenue[x] = self.revenue_total[x] + ( (self.expense_salary_bench[x] + self.expense_salary_prospects[x] + self.expense_salary_tbg[x]) * revenue_per_dollar_salary_freelance) elif datetime.datetime.now().month < 10: if (self.expense_salary_billable[0] + self.expense_freelance_billable_if_employee[0]) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ 0] / (self.expense_salary_billable[0] + self.expense_freelance_billable_if_employee[0]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[0] = self.revenue_total[0] + ( (self.expense_salary_bench[0] + self.expense_salary_prospects[0] + self.expense_salary_tbg[0]) * revenue_per_dollar_salary_freelance) if (self.expense_salary_billable[1] + self.expense_freelance_billable_if_employee[1]) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ 1] / (self.expense_salary_billable[1] + self.expense_freelance_billable_if_employee[1]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[1] = self.revenue_total[1] + ( (self.expense_salary_bench[1] + self.expense_salary_prospects[1] + self.expense_salary_tbg[1]) * revenue_per_dollar_salary_freelance) self.potential_revenue[2] = self.revenue_total[2] + ( (self.expense_salary_bench[2] + self.expense_salary_prospects[2] + self.expense_salary_tbg[2]) * revenue_per_dollar_salary_freelance) self.potential_revenue[3] = self.revenue_total[3] + ( (self.expense_salary_bench[3] + self.expense_salary_prospects[3] + self.expense_salary_tbg[3]) * revenue_per_dollar_salary_freelance) else: if (self.expense_salary_billable[0] + self.expense_freelance_billable_if_employee[0]) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ 0] / (self.expense_salary_billable[0] + self.expense_freelance_billable_if_employee[0]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[0] = self.revenue_total[0] + ( (self.expense_salary_bench[0] + self.expense_salary_prospects[0] + self.expense_salary_tbg[0]) * revenue_per_dollar_salary_freelance) if (self.expense_salary_billable[1] + self.expense_freelance_billable_if_employee[1]) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ 1] / (self.expense_salary_billable[1] + self.expense_freelance_billable_if_employee[1]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[1] = self.revenue_total[1] + ( (self.expense_salary_bench[1] + self.expense_salary_prospects[1] + self.expense_salary_tbg[1]) * revenue_per_dollar_salary_freelance) if (self.expense_salary_billable[2] + self.expense_freelance_billable_if_employee[2]) > 0: revenue_per_dollar_salary_freelance = self.revenue_total[ 2] / (self.expense_salary_billable[2] + self.expense_freelance_billable_if_employee[2]) else: revenue_per_dollar_salary_freelance = 0 self.potential_revenue[2] = self.revenue_total[2] + ( (self.expense_salary_bench[2] + self.expense_salary_prospects[2] + self.expense_salary_tbg[2]) * revenue_per_dollar_salary_freelance) self.potential_revenue[3] = self.revenue_total[3] + ( (self.expense_salary_bench[3] + self.expense_salary_prospects[3] + self.expense_salary_tbg[3]) * revenue_per_dollar_salary_freelance) self.potential_revenue[ 4] = self.potential_revenue[0] + self.potential_revenue[ 1] + self.potential_revenue[2] + self.potential_revenue[3] for x in range(0, 5): self.potential_profit[x] = self.potential_revenue[x] - ( self.expense_total[x] - (self.expense_freelance_billable[x] + self.expense_freelance_non_billable[x] - (self.expense_freelance_billable_if_employee[x] + self.expense_freelance_non_billable_if_employee[x]))) if self.potential_revenue[x] > 0: self.potential_margin[x] = int( (self.potential_profit[x] / self.potential_revenue[x]) * 100) else: self.potential_margin[x] = 0 except: traceback.print_exc()
def calculateFinancials(self): self.initializeVariables() try: for project in self.user.account.projects: if project.is_active and project.client.is_active: for budget_allocation in project.budget_allocations: if budget_allocation.department_id == self.department.id: revenue = quarterly_money(self.year,project.start_date,project.end_date,project.revenue_per_day,project.actual_revenues) project_revenue = ProjectRevenue(project,self.year) project_revenue.Q1 = revenue[0] * (budget_allocation.percent_allocation/100) project_revenue.Q2 = revenue[1] * (budget_allocation.percent_allocation/100) project_revenue.Q3 = revenue[2] * (budget_allocation.percent_allocation/100) project_revenue.Q4 = revenue[3] * (budget_allocation.percent_allocation/100) if project_revenue.Q1 > 0 or project_revenue.Q2 > 0 or project_revenue.Q3 > 0 or project_revenue.Q4 > 0: self.project_revenues.append(project_revenue) for project_revenue in self.project_revenues: self.revenue_closed[0] += project_revenue.Q1 self.revenue_closed[1] += project_revenue.Q2 self.revenue_closed[2] += project_revenue.Q3 self.revenue_closed[3] += project_revenue.Q4 self.revenue_closed[4] = self.revenue_closed[0] + self.revenue_closed[1] + self.revenue_closed[2] + self.revenue_closed[3] for ghost_project in self.user.account.ghost_projects: if ghost_project.is_active == True and (ghost_project.client is not None and ghost_project.client.is_active): for budget_allocation in ghost_project.budget_allocations: if budget_allocation.department_id == self.department.id: revenue = quarterly_money(self.year,ghost_project.start_date,ghost_project.end_date,ghost_project.revenue_per_day,None,"ghost_revenue") ghost_project_revenue = GhostProjectRevenue(ghost_project,self.year) ghost_project_revenue.Q1 = revenue[0] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q2 = revenue[1] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q3 = revenue[2] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q4 = revenue[3] * (budget_allocation.percent_allocation/100) if ghost_project_revenue.Q1 > 0 or ghost_project_revenue.Q2 > 0 or ghost_project_revenue.Q3 > 0 or ghost_project_revenue.Q4 > 0: self.ghost_project_revenues.append(ghost_project_revenue) elif ghost_project.is_active == True and (ghost_project.ghost_client is not None and ghost_project.ghost_client.is_active and ghost_project.ghost_client.is_tbg == False): for budget_allocation in ghost_project.budget_allocations: if budget_allocation.department_id == self.department.id: revenue = quarterly_money(self.year,ghost_project.start_date,ghost_project.end_date,ghost_project.revenue_per_day,None,"ghost_revenue") ghost_project_revenue = GhostProjectRevenue(ghost_project,self.year) ghost_project_revenue.Q1 = revenue[0] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q2 = revenue[1] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q3 = revenue[2] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q4 = revenue[3] * (budget_allocation.percent_allocation/100) if ghost_project_revenue.Q1 > 0 or ghost_project_revenue.Q2 > 0 or ghost_project_revenue.Q3 > 0 or ghost_project_revenue.Q4 > 0: self.ghost_project_revenues_from_ghost_clients.append(ghost_project_revenue) elif ghost_project.is_active == True and (ghost_project.ghost_client is not None and ghost_project.ghost_client.is_active and ghost_project.ghost_client.is_tbg == True): for budget_allocation in ghost_project.budget_allocations: if budget_allocation.department_id == self.department.id: revenue = quarterly_money(self.year,ghost_project.start_date,ghost_project.end_date,ghost_project.revenue_per_day,None,"ghost_revenue") ghost_project_revenue = GhostProjectRevenue(ghost_project,self.year) ghost_project_revenue.Q1 = revenue[0] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q2 = revenue[1] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q3 = revenue[2] * (budget_allocation.percent_allocation/100) ghost_project_revenue.Q4 = revenue[3] * (budget_allocation.percent_allocation/100) if ghost_project_revenue.Q1 > 0 or ghost_project_revenue.Q2 > 0 or ghost_project_revenue.Q3 > 0 or ghost_project_revenue.Q4 > 0: self.ghost_project_revenues_from_tbg.append(ghost_project_revenue) for ghost_project_revenue in self.ghost_project_revenues: self.revenue_client_opportunities[0] += ghost_project_revenue.Q1 self.revenue_client_opportunities[1] += ghost_project_revenue.Q2 self.revenue_client_opportunities[2] += ghost_project_revenue.Q3 self.revenue_client_opportunities[3] += ghost_project_revenue.Q4 for ghost_project_revenue in self.ghost_project_revenues_from_ghost_clients: self.revenue_prospects[0] += ghost_project_revenue.Q1 self.revenue_prospects[1] += ghost_project_revenue.Q2 self.revenue_prospects[2] += ghost_project_revenue.Q3 self.revenue_prospects[3] += ghost_project_revenue.Q4 for ghost_project_revenue in self.ghost_project_revenues_from_tbg: self.revenue_tbg[0] += ghost_project_revenue.Q1 self.revenue_tbg[1] += ghost_project_revenue.Q2 self.revenue_tbg[2] += ghost_project_revenue.Q3 self.revenue_tbg[3] += ghost_project_revenue.Q4 self.revenue_client_opportunities[4] = self.revenue_client_opportunities[0] + self.revenue_client_opportunities[1] + self.revenue_client_opportunities[2] + self.revenue_client_opportunities[3] self.revenue_prospects[4] = self.revenue_prospects[0] + self.revenue_prospects[1] + self.revenue_prospects[2] + self.revenue_prospects[3] self.revenue_tbg[4] = self.revenue_tbg[0] + self.revenue_tbg[1] + self.revenue_tbg[2] + self.revenue_tbg[3] for x in range(0,5): self.revenue_total[x] = self.revenue_closed[x] + self.revenue_client_opportunities[x] + self.revenue_prospects[x] + self.revenue_tbg[x] for user in self.user.account.users: all_salary = quarterly_salary(self.year,user,user.start_date,datetime.datetime(int(self.year) + 1,1,1)) if user.department_id == self.department.id: total_salary_for_user = all_salary expense_salary_non_billable_for_user = quarterly_salary(self.year,user,user.start_date,datetime.datetime(int(self.year) + 1,1,1),"non-billable") full_billable_salary_for_user = quarterly_salary(self.year,user,user.start_date,datetime.datetime(int(self.year) + 1,1,1),"billable") for x in range(0,4): self.total_salary[x] += total_salary_for_user[x] self.expense_salary_non_billable[x] += expense_salary_non_billable_for_user[x] self.full_billable_salary[x] += full_billable_salary_for_user[x] for x in range(0,4): self.all_salary[x] += all_salary[x] for ghost_user in self.user.account.ghost_users: if ghost_user.department_id == self.department.id: total_open_req = quarterly_money(self.year,ghost_user.start_date,datetime.datetime(int(self.year)+1,1,1),ghost_user.loaded_salary_per_day,None,"ghost_salary") expense_open_req_non_billable = quarterly_money(self.year,ghost_user.start_date,datetime.datetime(int(self.year)+1,1,1),ghost_user.loaded_non_billable_salary_per_day,None,"ghost_salary") full_open_req_billable = quarterly_money(self.year,ghost_user.start_date,datetime.datetime(int(self.year)+1,1,1),ghost_user.loaded_billable_salary_per_day,None,"ghost_salary") for x in range(0,4): self.total_open_req[x] += total_open_req[x] self.expense_open_req_non_billable[x] += expense_open_req_non_billable[x] self.full_open_req_billable[x] += full_open_req_billable[x] for x in range(0,4): self.total_salary[4] += self.total_salary[x] self.expense_salary_non_billable[4] += self.expense_salary_non_billable[x] self.full_billable_salary[4] += self.full_billable_salary[x] self.total_open_req[4] += self.total_open_req[x] self.expense_open_req_non_billable[4] += self.expense_open_req_non_billable[x] self.full_open_req_billable[4] += self.full_open_req_billable[x] for office in self.user.account.offices: q1_l_found = False q2_l_found = False q3_l_found = False q4_l_found = False q1_g_found = False q2_g_found = False q3_g_found = False q4_g_found = False for actual_expense in office.actual_expenses: if actual_expense.quarter_end_date.year == self.year: if actual_expense.quarter_end_date.month == 3: if actual_expense.expense_local is not None: q1_l_found = True self.all_expense_sga[0] += actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: q1_g_found = True self.all_expense_salary_global[0] += actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 6: if actual_expense.expense_local is not None: q2_l_found = True self.all_expense_sga[1] += actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: q2_g_found = True self.all_expense_salary_global[1] += actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 9: if actual_expense.expense_local is not None: q3_l_found = True self.all_expense_sga[2] += actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: q3_g_found = True self.all_expense_salary_global[2] += actual_expense.expense_global * self.usd_to_local elif actual_expense.quarter_end_date.month == 12: if actual_expense.expense_local is not None: q4_l_found = True self.all_expense_sga[3] += actual_expense.expense_local * self.usd_to_local if actual_expense.expense_global is not None: q4_g_found = True self.all_expense_salary_global[3] += actual_expense.expense_global * self.usd_to_local if not q1_l_found: self.all_expense_sga[0] += (office.sga_expense * self.usd_to_local) / 4 if not q2_l_found: self.all_expense_sga[1] += (office.sga_expense * self.usd_to_local) / 4 if not q3_l_found: self.all_expense_sga[2] += (office.sga_expense * self.usd_to_local) / 4 if not q4_l_found: self.all_expense_sga[3] += (office.sga_expense * self.usd_to_local) / 4 if not q1_g_found: self.all_expense_salary_global[0] += (office.allocated_salary_expense * self.usd_to_local) / 4 if not q2_g_found: self.all_expense_salary_global[1] += (office.allocated_salary_expense * self.usd_to_local) / 4 if not q3_g_found: self.all_expense_salary_global[2] += (office.allocated_salary_expense * self.usd_to_local) / 4 if not q4_g_found: self.all_expense_salary_global[3] += (office.allocated_salary_expense * self.usd_to_local) / 4 self.all_expense_sga[4] = self.all_expense_sga[0] + self.all_expense_sga[1] + self.all_expense_sga[2] + self.all_expense_sga[3] self.all_expense_salary_global[4] = self.all_expense_salary_global[0] + self.all_expense_salary_global[1] + self.all_expense_salary_global[2] + self.all_expense_salary_global[3] if self.all_salary[4] > 0: percent_allocated_to_department = self.total_salary[4] / self.all_salary[4] else: percent_allocated_to_department = 0 for x in range(0,5): self.expense_sga[x] += self.all_expense_sga[x] * percent_allocated_to_department self.expense_salary_global[x] += self.expense_salary_global[x] * percent_allocated_to_department for x in range(0,5): self.expense_salary_bench[x] = self.full_billable_salary[x] - (self.expense_salary_billable[x] + self.expense_salary_prospects[x]) # hack because of the qarterly money quirk if self.expense_salary_bench[x] < 0: self.expense_salary_bench[x] = 0 # end hack self.expense_open_req_bench[x] = self.full_open_req_billable[x] - (self.expense_open_req_billable[x] + self.expense_open_req_prospects[x]) self.expense_total[x] = self.non_billable_expenses[x] + self.expense_salary_billable[x] + self.expense_salary_non_billable[x] + self.expense_salary_prospects[x] + self.expense_salary_bench[x]+self.expense_open_req_billable[x]+self.expense_open_req_non_billable[x]+self.expense_open_req_prospects[x]+self.expense_open_req_bench[x]+self.expense_freelance_billable[x]+self.expense_freelance_non_billable[x]+self.expense_sga[x] self.revenue_total[x] = self.revenue_closed[x] + self.revenue_client_opportunities[x] + self.revenue_prospects[x] + self.revenue_tbg[x] self.profit[x] = self.revenue_total[x] - self.expense_total[x] if self.revenue_total[x] > 0 and self.profit[x] > 0: self.margin[x] = int((self.profit[x] / self.revenue_total[x]) * 100) else: self.margin[x] = 0 except: traceback.print_exc()
def calculateFinancials(self): try: self.initializeVariables() for project in self.client.projects: if project.is_active == True: revenue = quarterly_money(self.year, project.start_date, project.end_date, project.revenue_per_day, project.actual_revenues) project_revenue = ProjectRevenue(project, self.year) project_revenue.Q1 = revenue[0] project_revenue.Q2 = revenue[1] project_revenue.Q3 = revenue[2] project_revenue.Q4 = revenue[3] if project_revenue.Q1 > 0 or project_revenue.Q2 > 0 or project_revenue.Q3 > 0 or project_revenue.Q4 > 0: self.project_revenues.append(project_revenue) for project_revenue in self.project_revenues: self.revenue_projects[0] += project_revenue.Q1 self.revenue_projects[1] += project_revenue.Q2 self.revenue_projects[2] += project_revenue.Q3 self.revenue_projects[3] += project_revenue.Q4 for ghost_project in self.client.ghost_projects: if ghost_project.is_active == True: revenue = quarterly_money(self.year, ghost_project.start_date, ghost_project.end_date, ghost_project.revenue_per_day, None, "ghost_revenue") ghost_project_revenue = GhostProjectRevenue( ghost_project, self.year) ghost_project_revenue.Q1 = revenue[0] ghost_project_revenue.Q2 = revenue[1] ghost_project_revenue.Q3 = revenue[2] ghost_project_revenue.Q4 = revenue[3] if ghost_project_revenue.Q1 > 0 or ghost_project_revenue.Q2 > 0 or ghost_project_revenue.Q3 > 0 or ghost_project_revenue.Q4 > 0: self.ghost_project_revenues.append( ghost_project_revenue) for ghost_project_revenue in self.ghost_project_revenues: self.revenue_client_opportunities[ 0] += ghost_project_revenue.Q1 self.revenue_client_opportunities[ 1] += ghost_project_revenue.Q2 self.revenue_client_opportunities[ 2] += ghost_project_revenue.Q3 self.revenue_client_opportunities[ 3] += ghost_project_revenue.Q4 for user_allocation in self.client.team: user_salary = quarterly_salary(self.year, user_allocation.user, user_allocation.start_date, user_allocation.end_date, "total", user_allocation.utilization) for x in range(0, 4): self.expense_salary[x] += user_salary[x] self.expense_salary[4] += user_salary[x] for ghost_allocation in self.client.ghost_team: salary_per_day = ( ghost_allocation.ghost_user.loaded_salary_per_day * ghost_allocation.utilization / 100) * self.usd_to_local ghost_salary = quarterly_money(self.year, ghost_allocation.start_date, ghost_allocation.end_date, salary_per_day, None, "ghost_salary") for x in range(0, 4): self.expense_ghost[x] += ghost_salary[x] self.expense_ghost[4] += ghost_salary[x] for freelancer in self.client.freelancers: comp_per_freelancer = quarterly_money(self.year, freelancer.start_date, freelancer.end_date, freelancer.rate_per_day) comp_per_freelancer_if_employee = quarterly_money( self.year, freelancer.start_date, freelancer.end_date, freelancer.rate_per_day_if_employee) for x in range(0, 4): self.expense_freelance[x] += comp_per_freelancer[x] self.expense_freelance[4] += comp_per_freelancer[x] self.expense_freelance_if_employee[ x] += comp_per_freelancer_if_employee[x] self.expense_freelance_if_employee[ 4] += comp_per_freelancer_if_employee[x] percent_allocated = [0, 0, 0, 0, 0] total_office_salaries = self.client.office.getTotalBillableCompPerQuarter( self.year) total_office_overhead = self.client.office.getTotalOverheadPerQuarter( self.year) for actual_expense in self.client.actual_expenses: if actual_expense.quarter_end_date.year == self.year: if actual_expense.quarter_end_date.month == 3: self.non_billable_expenses[ 0] = actual_expense.expense_local elif actual_expense.quarter_end_date.month == 6: self.non_billable_expenses[ 1] = actual_expense.expense_local elif actual_expense.quarter_end_date.month == 9: self.non_billable_expenses[ 2] = actual_expense.expense_local elif actual_expense.quarter_end_date.month == 12: self.non_billable_expenses[ 3] = actual_expense.expense_local self.non_billable_expenses[4] = self.non_billable_expenses[ 0] + self.non_billable_expenses[1] + self.non_billable_expenses[ 2] + self.non_billable_expenses[3] for x in range(0, 5): if total_office_salaries[x] > 0: percent_allocated[ x] = self.expense_salary[x] / total_office_salaries[x] else: percent_allocated[x] = 0 if percent_allocated[x] > 0: self.expense_overhead[ x] = total_office_overhead[x] * percent_allocated[x] else: self.expense_overhead[x] = 0 self.expense_total[x] += self.non_billable_expenses[ x] + self.expense_ghost[x] + self.expense_freelance[ x] + self.expense_salary[x] + self.expense_overhead[x] for x in range(0, 4): self.revenue_client_opportunities[ 4] += self.revenue_client_opportunities[x] self.revenue_projects[4] += self.revenue_projects[x] self.revenue_total[x] = self.revenue_projects[ x] + self.revenue_client_opportunities[x] self.revenue_total[4] += self.revenue_total[x] self.profit[x] = self.revenue_total[x] - self.expense_total[x] self.profit[4] += self.profit[x] if self.revenue_total[x] > 0: self.margin[x] = int( (self.profit[x] / self.revenue_total[x]) * 100) else: self.margin[x] = 0 if self.revenue_total[4] > 0: self.margin[4] = int( (self.profit[4] / self.revenue_total[4]) * 100) else: self.margin[4] = 0 except: traceback.print_exc()
def calculateFinancials(self): self.initializeVariables() if self.ghost_client is None: return for ghost_project in self.ghost_client.ghost_projects: if ghost_project.is_active is True: ghost_project_revenue = GhostProjectRevenue( ghost_project, self.year) if ghost_project_revenue.Q1 > 0 or ghost_project_revenue.Q2 > 0 or ghost_project_revenue.Q3 > 0 or ghost_project_revenue.Q4 > 0: self.ghost_project_revenues.append(ghost_project_revenue) for ghost_project_revenue in self.ghost_project_revenues: self.revenue[0] = self.revenue[0] + ghost_project_revenue.Q1 self.revenue[1] = self.revenue[1] + ghost_project_revenue.Q2 self.revenue[2] = self.revenue[2] + ghost_project_revenue.Q3 self.revenue[3] = self.revenue[3] + ghost_project_revenue.Q4 self.weighted_revenue[0] = self.weighted_revenue[ 0] + ghost_project_revenue.Q1_weighted self.weighted_revenue[1] = self.weighted_revenue[ 1] + ghost_project_revenue.Q2_weighted self.weighted_revenue[2] = self.weighted_revenue[ 2] + ghost_project_revenue.Q3_weighted self.weighted_revenue[3] = self.weighted_revenue[ 3] + ghost_project_revenue.Q4_weighted for user_allocation in self.ghost_client.team: user_salary = quarterly_salary(self.year, user_allocation.user, user_allocation.start_date, user_allocation.end_date, "total", user_allocation.utilization) for x in range(0, 4): self.expense_salary[x] += user_salary[x] self.expense_salary[4] += user_salary[x] for ghost_allocation in self.ghost_client.ghost_team: #eventually change this so it is the average of existing people in this role salary_per_day = ghost_allocation.ghost_user.loaded_salary_per_day * ( ghost_allocation.utilization / 100) * self.usd_to_local ghost_salary = quarterly_money(self.year, ghost_allocation.start_date, ghost_allocation.end_date, salary_per_day, None, "ghost_salary") for x in range(0, 4): self.expense_ghost[x] += ghost_salary[x] self.expense_ghost[4] += ghost_salary[x] for x in range(0, 4): self.expense_overhead[x] = int( (self.expense_salary[x] * self.ghost_client.office.expense_overhead) / 100) self.expense_overhead[ 4] = self.expense_overhead[4] + self.expense_overhead[x] self.expense_total[x] = self.expense_total[x] + self.expense_ghost[ x] + self.expense_salary[x] + self.expense_overhead[x] self.expense_total[ 4] = self.expense_total[4] + self.expense_total[x] self.revenue[4] = self.revenue[4] + self.revenue[x] self.weighted_revenue[ 4] = self.weighted_revenue[4] + self.weighted_revenue[x] self.profit[x] = self.revenue[x] - self.expense_total[x] self.profit[4] = self.profit[4] + self.profit[x] if self.revenue[x] > 0: self.margin[x] = int((self.profit[x] / self.revenue[x]) * 100) else: self.margin[x] = 0 if self.revenue[4] > 0: self.margin[4] = int((self.profit[4] / self.revenue[4]) * 100) else: self.margin[4] = 0