Project reports

This commit is contained in:
David Bomba 2025-03-24 13:21:12 +11:00
parent 790d57f7c8
commit 07c30aea66
4 changed files with 147 additions and 131 deletions

View File

@ -63,8 +63,7 @@ class ProjectReport extends BaseExport
$user_name = $user ? $user->present()->name() : ''; $user_name = $user ? $user->present()->name() : '';
$projects = \App\Models\Project::with(['invoices','expenses','tasks'])->where('company_id', $this->company->id)
$projects = \App\Models\Project::where('company_id', $this->company->id)
->whereIn('id', $this->transformKeys($this->input['projects'])) ->whereIn('id', $this->transformKeys($this->input['projects']))
->get(); ->get();
@ -83,6 +82,7 @@ class ProjectReport extends BaseExport
$ts_instance = $ts->setCompany($this->company) $ts_instance = $ts->setCompany($this->company)
->setData($data) ->setData($data)
->setRawTemplate(file_get_contents(resource_path($this->template))) ->setRawTemplate(file_get_contents(resource_path($this->template)))
->setGlobals()
->parseNinjaBlocks() ->parseNinjaBlocks()
->save(); ->save();

View File

@ -1063,6 +1063,7 @@ class TemplateService
'custom_value2' => $expense->custom_value2 ?: '', 'custom_value2' => $expense->custom_value2 ?: '',
'custom_value3' => $expense->custom_value3 ?: '', 'custom_value3' => $expense->custom_value3 ?: '',
'custom_value4' => $expense->custom_value4 ?: '', 'custom_value4' => $expense->custom_value4 ?: '',
'number' => $expense->number ?: '',
'calculate_tax_by_amount' => (bool) $expense->calculate_tax_by_amount, 'calculate_tax_by_amount' => (bool) $expense->calculate_tax_by_amount,
'uses_inclusive_taxes' => (bool) $expense->uses_inclusive_taxes, 'uses_inclusive_taxes' => (bool) $expense->uses_inclusive_taxes,
'client' => $this->getClient($expense), 'client' => $this->getClient($expense),

View File

@ -5569,6 +5569,7 @@ $lang = array(
'plan_selected' => 'Plan Selected', 'plan_selected' => 'Plan Selected',
'invalid_date_create_syntax' => 'Invalid date syntax', 'invalid_date_create_syntax' => 'Invalid date syntax',
'start_and_end_date_required' => 'Start and end date are required', 'start_and_end_date_required' => 'Start and end date are required',
'project_value' => 'Project Value',
); );
return $lang; return $lang;

View File

@ -90,13 +90,17 @@
background: #34495e; background: #34495e;
color: white; color: white;
padding: 6px; padding: 6px;
text-align: center; text-align: left;
} }
td { td {
padding: 6px; padding: 6px;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
text-align: center; text-align: left;
}
td li {
text-align: left;
} }
tr { tr {
@ -140,63 +144,72 @@
background: #e8f5e9; background: #e8f5e9;
color: #2e7d32; color: #2e7d32;
} }
.page-break {
page-break-before: always;
}
</style> </style>
</head> </head>
<body> <body>
<ninja> <ninja>
{% if projects|e %} {% if projects|e %}
{% for project in projects %} {% for project in projects %}
<div class="page-break">
<h1>{{ project.name }}</h1>
<h3>Due: {{ project.due_date }}</h3>
<h6>{{ project.current_hours }} / {{ project.budgeted_hours }}: (Hours / Budgeted Hours @ {{ project.task_rate
}}) -
Report generated on {{ "now"|date('Y-m-d') }}</h6>
<table>
<thead>
<tr>
<th>{{ t('date') }}</th>
<th>{{ t('description') }}</th>
<th>{{ t('duration') }}</th>
</tr>
</thead>
<tbody>
{% for task in project.tasks %}
<h1>{{ project.name }}</h1> {% for log in task.time_log%}
<h3>Due: {{ project.due_date }}</h3>
<h6>{{ project.current_hours }} / {{ project.budgeted_hours }}: (Hours / Budgeted Hours @ {{ project.task_rate }}) -
Report generated on {{ "now"|date('Y-m-d') }}</h6>
<table>
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
{% for task in project.tasks %}
{% for log in task.time_log%} <tr>
<td>{{ log.start_date }}</td>
<td>
<div>
<ul>
<li>{{ log.description }}</li>
<li>{{ task.user.name }}</li>
</ul>
</div>
<tr> </td>
<td>{{ log.start_date }}</td> <td>{{ log.duration|date('h:i:s')}}</td>
<td> </tr>
<div> {% endfor %}
<ul> {% endfor %}
<li>{{ log.description }}</li> </tbody>
<li>{{ task.user.name }}</li> </table>
</ul>
</div>
</td> {% if project.invoices %}
<td>{{ log.duration|date('h:i:s')}}</td> <div style="text-align: center;">
</tr> <h2>{{ t('invoices') }}</h2>
{% endfor %} </div>
{% endfor %} <table>
</tbody> <thead>
</table> <tr>
<th>{{ t('date')}}</th>
{% if project.invoices %} <th>{{ t('invoice_number')}}</th>
<table> <th>{{ t('amount') }}</th>
<thead> <th>{{ t('balance') }}</th>
<tr> </tr>
<th>{{ t('date')}}</th> </thead>
<th>{{ t('invoice_number')}}</th> <tbody>
<th>{{ t('amount') }}</th> {% set total_amount = 0 %}
<th>{{ t('balance') }}</th> {% set total_balance = 0 %}
</tr> {% for invoice in project.invoices %}
</thead>
<tbody>
{% set total_amount = 0 %}
{% set total_balance = 0 %}
{% for invoice in project.invoices %}
<tr> <tr>
<td>{{ invoice.date }}</td> <td>{{ invoice.date }}</td>
<td>{{ invoice.number }}</td> <td>{{ invoice.number }}</td>
@ -205,86 +218,87 @@
</tr> </tr>
{% set total_amount = total_amount + invoice.amount_raw %} {% set total_amount = total_amount + invoice.amount_raw %}
{% set total_balance = total_balance + invoice.balance_raw %} {% set total_balance = total_balance + invoice.balance_raw %}
{% endfor%} {% endfor%}
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td></td> <td></td>
<td></td> <td></td>
<td>{{ total_amount }}</td> <td>{{ total_amount|format_currency(currency_code) }}</td>
<td>{{ total_balance }}</td> <td>{{ total_balance|format_currency(currency_code) }}</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
{% endif %} {% endif %}
{% if project.expenses %} {% if project.expenses %}
<table> <div style="text-align: center;">
<thead> <h2>{{ t('expenses') }}</h2>
<tr> </div>
<th>{{ t('date')}}</th> <table>
<th>{{ t('number')}}</th> <thead>
<th>{{ t('amount') }}</th> <tr>
</tr> <th>{{ t('date')}}</th>
</thead> <th>{{ t('number')}}</th>
<tbody> <th>{{ t('amount') }}</th>
{% set total_expense_amount = 0 %} </tr>
{% for expense in project.expenses %} </thead>
<tr> <tbody>
<td>{{ expense.date }}</td> {% set total_expense_amount = 0 %}
<td>{{ expense.number }}</td> {% for expense in project.expenses %}
<td>{{ expense.amount }}</td> <tr>
</tr> <td>{{ expense.date }}</td>
{% set total_amount = total_amount + expense.amount_raw %} <td>{{ expense.number }}</td>
{% endfor%} <td>{{ expense.amount }}</td>
</tbody> </tr>
<tfoot> {% set total_expense_amount = total_expense_amount + expense.amount_raw %}
<tr> {% endfor%}
<td></td> </tbody>
<td></td> <tfoot>
<td>{{ total_expense_amount }}</td> <tr>
</tr> <td></td>
</tfoot> <td></td>
</table> <td>{{ total_expense_amount|format_currency(currency_code) }}</td>
{% endif %} </tr>
</tfoot>
</table>
{% endif %}
<table> <table>
<thead> <thead>
<tr> <tr>
<th>Summary</th> <th>{{ t('summary') }}</th>
<th></th> <th>{{ t('amount') }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>{{ t('expenses') }}</td> <td>{{ t('project_value') }}</td>
<td>{{ total_expense_amount }}</td> <td>{{ (project.budgeted_hours * project.task_rate_raw)|format_currency(currency_code) }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ t('invoices') }}</td> <td>{{ t('invoice_task_hours') }}</td>
<td>{{ total_amount }}</td> <td>{{ (project.current_hours * project.task_rate_raw)|format_currency(currency_code) }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ t('budgeted') }}</td> <td>{{ t('invoiced') }}</td>
<td>{{ project.budgeted_hours * project.task_rate_raw }}</td> <td>{{ total_amount|format_currency(currency_code) }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ t('budgeted') }}</td> <td>{{ t('expenses') }}</td>
<td>{{ project.budgeted_hours * project.task_rate_raw }}</td> <td>{{ total_expense_amount|format_currency(currency_code) }}</td>
</tr> </tr>
<tr>
<td>Budget - Expenses</td> <tr>
<td>{{ (project.budgeted_hours * project.task_rate_raw) - total_expense_amount }}</td> <td>{{ t('profit') }}</td>
</tr> <td>{{ (total_amount - total_expense_amount)|format_currency(currency_code) }}</td>
<tr> </tr>
<td>Invoices - Expenses</td> </tbody>
<td>{{ total_amount - total_expense_amount }}</td> </table>
</tr> </div>
</tbody> {% endfor %}
</table> {% endif %}
{% endfor %} </ninja>
{% endif %}
</ninja>
</body> </body>
</html> </html>