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