1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package org.openpsa.invoices |
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
|
|
|
/** |
10
|
|
|
* Handler addons |
11
|
|
|
* |
12
|
|
|
* @package org.openpsa.invoices |
13
|
|
|
*/ |
14
|
|
|
trait org_openpsa_invoices_handler |
15
|
|
|
{ |
16
|
5 |
|
public function get_vat_options(string $percentages) : array |
17
|
|
|
{ |
18
|
5 |
|
$values = []; |
19
|
5 |
|
foreach (explode(',', $percentages) as $entry) { |
20
|
5 |
|
$values[$entry] = "{$entry}%"; |
21
|
|
|
} |
22
|
5 |
|
return $values; |
23
|
|
|
} |
24
|
|
|
|
25
|
1 |
|
public function render_invoice_actions(org_openpsa_invoices_invoice_dba $invoice) : string |
26
|
|
|
{ |
27
|
1 |
|
if ($invoice->paid) { |
28
|
|
|
return date('Y-m-d', $invoice->paid); |
29
|
|
|
} |
30
|
1 |
|
if (!$invoice->can_do('midgard:update')) { |
31
|
|
|
return ''; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
// unsent invoices |
35
|
1 |
|
if ($invoice->sent == 0) { |
36
|
|
|
// sending per mail enabled in billing data? |
37
|
1 |
|
$billing_data = org_openpsa_invoices_billing_data_dba::get_by_object($invoice); |
38
|
|
|
// only show if mail was chosen as option |
39
|
1 |
|
if ($billing_data->sendingoption === 2) { |
40
|
|
|
$action = 'send_by_mail'; |
41
|
|
|
$icon = '<i class="fa fa-paper-plane"></i>'; |
42
|
|
|
} else { |
43
|
1 |
|
$action = 'mark_sent'; |
44
|
1 |
|
$icon = '<i class="fa fa-paper-plane-o"></i>'; |
45
|
|
|
} |
46
|
|
|
} else { |
47
|
|
|
// not paid yet (see above) |
48
|
|
|
$action = 'mark_paid'; |
49
|
|
|
$icon = '<i class="fa fa-check"></i>'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// generate next action buttons |
53
|
1 |
|
return '<button id="invoice_' . $invoice->guid . '" class="' . $action . '">' . $icon . ' ' . $this->_l10n->get($action) . '</button>'; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function prepare_toolbar(bool $show_backlink = true) |
57
|
|
|
{ |
58
|
3 |
|
if ($show_backlink) { |
59
|
2 |
|
$this->_view_toolbar->add_item([ |
60
|
2 |
|
MIDCOM_TOOLBAR_URL => '', |
61
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('dashboard'), |
62
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-left', |
63
|
2 |
|
]); |
64
|
|
|
} |
65
|
3 |
|
if (midcom::get()->auth->can_user_do('midgard:create', class: org_openpsa_invoices_invoice_dba::class)) { |
66
|
3 |
|
$workflow = $this->get_workflow('datamanager'); |
|
|
|
|
67
|
3 |
|
$this->_view_toolbar->add_item($workflow->get_button($this->router->generate('invoice_new_nocustomer'), [ |
68
|
3 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create invoice'), |
69
|
3 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'plus', |
70
|
3 |
|
])); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function add_next_previous(org_openpsa_invoices_invoice_dba $object, string $urlprefix) |
75
|
|
|
{ |
76
|
2 |
|
$items = []; |
77
|
2 |
|
$url = ''; |
78
|
2 |
|
if ($object->number > 1) { |
79
|
|
|
$mc = org_openpsa_invoices_invoice_dba::new_collector(); |
80
|
|
|
$mc->add_constraint('number', '<', $object->number); |
81
|
|
|
$mc->set_limit(1); |
82
|
|
|
$mc->add_order('number', 'DESC'); |
83
|
|
|
|
84
|
|
|
if ($results = $mc->list_keys()) { |
85
|
|
|
$url = $urlprefix . key($results) . '/'; |
86
|
|
|
} |
87
|
|
|
} |
88
|
2 |
|
$items[] = [ |
89
|
2 |
|
MIDCOM_TOOLBAR_URL => $url, |
90
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('previous'), |
91
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-left', |
92
|
2 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'p', |
93
|
2 |
|
MIDCOM_TOOLBAR_ENABLED => !empty($url) |
94
|
2 |
|
]; |
95
|
|
|
|
96
|
2 |
|
$url = ''; |
97
|
2 |
|
if (($object->number + 1) < $object->generate_invoice_number()) { |
98
|
|
|
$mc = org_openpsa_invoices_invoice_dba::new_collector(); |
99
|
|
|
$mc->add_constraint('number', '>', $object->number); |
100
|
|
|
$mc->set_limit(1); |
101
|
|
|
$mc->add_order('number', 'ASC'); |
102
|
|
|
|
103
|
|
|
if ($results = $mc->list_keys()) { |
104
|
|
|
$url = $urlprefix . key($results) . '/'; |
105
|
|
|
} |
106
|
|
|
} |
107
|
2 |
|
$items[] = [ |
108
|
2 |
|
MIDCOM_TOOLBAR_URL => $url, |
109
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('next'), |
110
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-right', |
111
|
2 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'n', |
112
|
2 |
|
MIDCOM_TOOLBAR_ENABLED => !empty($url) |
113
|
2 |
|
]; |
114
|
2 |
|
org_openpsa_widgets_ui::add_navigation_toolbar($items); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|