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
|
|
|
$url = $this->router->generate('invoice_send_by_mail', ['guid' => $invoice->guid]); |
43
|
|
|
|
44
|
|
|
// generate next action button with data-url attribute |
45
|
|
|
return '<button id="invoice_' . $invoice->guid . '" class="' . $action . '" data-url="' . $url . '">' . $icon . ' ' . $this->_l10n->get($action) . '</button>'; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
$action = 'mark_sent'; |
49
|
1 |
|
$icon = '<i class="fa fa-paper-plane-o"></i>'; |
50
|
|
|
} else { |
51
|
|
|
// not paid yet (see above) |
52
|
|
|
$action = 'mark_paid'; |
53
|
|
|
$icon = '<i class="fa fa-check"></i>'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// generate next action buttons |
57
|
1 |
|
return '<button id="invoice_' . $invoice->guid . '" class="' . $action . '">' . $icon . ' ' . $this->_l10n->get($action) . '</button>'; |
58
|
|
|
} |
59
|
|
|
|
60
|
3 |
|
public function prepare_toolbar(bool $show_backlink = true) |
61
|
|
|
{ |
62
|
3 |
|
if ($show_backlink) { |
63
|
2 |
|
$this->_view_toolbar->add_item([ |
64
|
2 |
|
MIDCOM_TOOLBAR_URL => '', |
65
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('dashboard'), |
66
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-left', |
67
|
2 |
|
]); |
68
|
|
|
} |
69
|
3 |
|
if (midcom::get()->auth->can_user_do('midgard:create', class: org_openpsa_invoices_invoice_dba::class)) { |
70
|
3 |
|
$workflow = $this->get_workflow('datamanager'); |
|
|
|
|
71
|
3 |
|
$this->_view_toolbar->add_item($workflow->get_button($this->router->generate('invoice_new_nocustomer'), [ |
72
|
3 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create invoice'), |
73
|
3 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'plus', |
74
|
3 |
|
])); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
2 |
|
public function add_next_previous(org_openpsa_invoices_invoice_dba $object, string $urlprefix) |
79
|
|
|
{ |
80
|
2 |
|
$items = []; |
81
|
2 |
|
$url = ''; |
82
|
2 |
|
if ($object->number > 1) { |
83
|
|
|
$mc = org_openpsa_invoices_invoice_dba::new_collector(); |
84
|
|
|
$mc->add_constraint('number', '<', $object->number); |
85
|
|
|
$mc->set_limit(1); |
86
|
|
|
$mc->add_order('number', 'DESC'); |
87
|
|
|
|
88
|
|
|
if ($results = $mc->list_keys()) { |
89
|
|
|
$url = $urlprefix . key($results) . '/'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
2 |
|
$items[] = [ |
93
|
2 |
|
MIDCOM_TOOLBAR_URL => $url, |
94
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('previous'), |
95
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-left', |
96
|
2 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'p', |
97
|
2 |
|
MIDCOM_TOOLBAR_ENABLED => !empty($url) |
98
|
2 |
|
]; |
99
|
|
|
|
100
|
2 |
|
$url = ''; |
101
|
2 |
|
if (($object->number + 1) < $object->generate_invoice_number()) { |
102
|
|
|
$mc = org_openpsa_invoices_invoice_dba::new_collector(); |
103
|
|
|
$mc->add_constraint('number', '>', $object->number); |
104
|
|
|
$mc->set_limit(1); |
105
|
|
|
$mc->add_order('number', 'ASC'); |
106
|
|
|
|
107
|
|
|
if ($results = $mc->list_keys()) { |
108
|
|
|
$url = $urlprefix . key($results) . '/'; |
109
|
|
|
} |
110
|
|
|
} |
111
|
2 |
|
$items[] = [ |
112
|
2 |
|
MIDCOM_TOOLBAR_URL => $url, |
113
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('next'), |
114
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'chevron-right', |
115
|
2 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'n', |
116
|
2 |
|
MIDCOM_TOOLBAR_ENABLED => !empty($url) |
117
|
2 |
|
]; |
118
|
2 |
|
org_openpsa_widgets_ui::add_navigation_toolbar($items); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|