|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package org.openpsa.expenses |
|
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Hour report based cost/price calculator |
|
13
|
|
|
* |
|
14
|
|
|
* @package org.openpsa.expenses |
|
15
|
|
|
*/ |
|
16
|
|
|
class org_openpsa_expenses_calculator extends org_openpsa_sales_calculator_default |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
4 |
|
public function get_invoice_items(org_openpsa_invoices_invoice_dba $invoice) : array |
|
22
|
|
|
{ |
|
23
|
|
|
// Mark the tasks (and hour reports) related to this agreement as invoiced |
|
24
|
4 |
|
$qb = org_openpsa_projects_task_dba::new_query_builder(); |
|
25
|
4 |
|
$qb->add_constraint('agreement', '=', $this->deliverable->id); |
|
26
|
4 |
|
$tasks = $this->_find_tasks($qb); |
|
27
|
|
|
|
|
28
|
4 |
|
if (empty($tasks)) { |
|
29
|
1 |
|
return parent::get_invoice_items($invoice); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
$items = []; |
|
33
|
3 |
|
foreach ($tasks as $task) { |
|
34
|
3 |
|
$hours_marked = org_openpsa_expenses_hour_report_dba::mark_invoiced($task, $invoice); |
|
35
|
3 |
|
$items[] = $this->generate_invoice_item($task->title, $hours_marked, $invoice->id, $task); |
|
36
|
|
|
|
|
37
|
3 |
|
$qb = org_openpsa_projects_task_dba::new_query_builder(); |
|
38
|
3 |
|
$qb->add_constraint('up', 'INTREE', $task->id); |
|
39
|
3 |
|
foreach ($this->_find_tasks($qb) as $subtask) { |
|
40
|
|
|
$hours_marked = org_openpsa_expenses_hour_report_dba::mark_invoiced($subtask, $invoice); |
|
41
|
|
|
$items[] = $this->generate_invoice_item($subtask->title, $hours_marked, $invoice->id, $subtask); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
3 |
|
return $items; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
4 |
|
private function _find_tasks(midcom_core_querybuilder $qb) : array |
|
49
|
|
|
{ |
|
50
|
4 |
|
if ($this->deliverable->invoiceByActualUnits) { |
|
51
|
2 |
|
$qb->add_constraint('invoiceableHours', '>', 0); |
|
52
|
|
|
} else { |
|
53
|
2 |
|
$qb->get_doctrine() |
|
54
|
2 |
|
->leftJoin('org_openpsa_invoice_item', 'i', Join::WITH, 'i.task = c.id') |
|
55
|
2 |
|
->where('i.deliverable IS NULL'); |
|
56
|
|
|
} |
|
57
|
4 |
|
return $qb->execute(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|