2namespace dbx\myInvoices;
13 private const INVOICE_DD =
'myInvoices|invoice';
14 private const ITEM_DD =
'myInvoices|invoiceItem';
15 private const FORM_FD =
'myInvoices|invoice-form';
16 private const REPORT_FD =
'myInvoices|rpt-invoice-selection';
18 private int $invoicePageTotalCents = 0;
19 private int $itemTotalCents = 0;
24 private function euro(
int $cents):
string
26 return number_format($cents / 100, 2,
',',
'.') .
' EUR';
36 private function url(
string $run, array $params = array()):
string
38 $url =
'?dbx_modul=myInvoices&dbx_run1=' . rawurlencode(
$run);
39 foreach ($params as $key =>
$value) {
40 $url .=
'&' . rawurlencode((
string)$key)
41 .
'=' . rawurlencode((
string)
$value);
54 public function form(): string
56 $ridValue =
dbx()->get_modul_var(
61 $rid = $ridValue ===
'new' ? 0 : (int)$ridValue;
64 $form =
dbx()->get_system_obj(
'dbxForm');
65 $form->init(
'invoice-form',
'myInvoices|invoice-form');
66 $form->_dd = self::INVOICE_DD;
67 $form->_fd = self::FORM_FD;
68 $form->load_fd_messages();
71 ? array(
'status' =>
'draft')
72 :
dbx()->get_system_obj(
'dbxDB')->select1(
77 if (!$isNew && (
int)($data[
'id'] ?? 0) <= 0) {
78 return dbx()->get_system_obj(
'dbxTPL')->get_tpl(
80 array(
'msg' =>
$form->get_fd_message(
'not_found'))
84 $form->_data = is_array($data) ? $data : array();
86 $form->_action = $this->url(
'form', array(
87 'rid' => $isNew ?
'new' : $rid,
89 $form->_msg_info =
$form->get_fd_message(
'form_info');
92 $form->get_fd_message(
93 $isNew ?
'form_title_new' :
'form_title_edit'
98 $form->get_fd_message(
'help_title')
100 $form->add_rep(
'list_url', $this->url(
'report'));
103 if (
$form->submit()) {
104 if (!
$form->errors()) {
107 $isNew ?
'new' : $rid
109 $savedRid = (int)
$form->_rid;
110 if (
$ok && $isNew && $savedRid > 0) {
111 $form->_action = $this->url(
113 array(
'rid' => $savedRid)
117 $form->get_fd_message(
'form_title_edit')
145 if (!is_array($record)) {
149 $id = (int)($record[
'id'] ?? 0);
150 $totalCents = (int)round(
151 (
float)($record[
'total_gross'] ?? 0) * 100
154 $this->invoicePageTotalCents += $totalCents;
156 'invoice_report_total',
157 $this->euro($this->invoicePageTotalCents)
159 $record[
'action'] =
dbx()->get_system_obj(
'dbxTPL')->get_tpl(
160 'myInvoices|invoice-row-action',
162 'edit_url' => $this->url(
'form', array(
'rid' => $id)),
164 $this->url(
'delete', array(
'rid' => $id))
166 'delete_title' =>
$report->get_fd_message(
169 'delete_question' =>
$report->format_fd_message(
173 'delete_hint' =>
$report->get_fd_message(
178 $status = (string)($record[
'status'] ??
'');
179 if ($status !==
'') {
180 $record[
'status'] =
$report->get_fd_message(
185 $record[
'total_gross'] = $this->euro($totalCents);
186 $record[
'positions_call'] =
187 '[modul=myInvoices]dbx_run1=positions&invoice_id='
206 string $success =
'',
209 $db =
dbx()->get_system_obj(
'dbxDB');
213 'myInvoices|invoice-report'
215 $report->_dd = self::INVOICE_DD;
217 $report->_action = $this->url(
'report');
220 $report->_create_row_select =
false;
221 $report->_create_row_edit =
false;
222 $report->_create_row_delete =
false;
223 $report->add_rep(
'install_url', $this->url(
'install'));
224 $report->create_selection_fields(self::REPORT_FD);
227 $report->get_fd_message(
'report_title')
229 $report->_msg_success = $success ===
''
231 :
$report->get_fd_message($success, $success);
232 $report->_msg_error = $error ===
''
234 :
$report->get_fd_message($error, $error);
236 $this->invoicePageTotalCents = 0;
242 $search = trim((
string)
$report->get_fld_val(
247 $status = (string)
$report->get_fld_val(
252 $pageSize = max(10, min(50, (
int)
$report->get_fld_val(
257 $position = max(0, (
int)
$report->get_fld_val(
262 $sort = (string)
$report->get_fld_val(
267 $direction = strtoupper((
string)
$report->get_fld_val(
273 $allowedSort = array(
280 if (!in_array($sort, $allowedSort,
true)) {
281 $sort =
'invoice_date';
283 if (!in_array($direction, array(
'ASC',
'DESC'),
true)) {
288 if (in_array($status, array(
'draft',
'open',
'paid'),
true)) {
289 $where[
'status'] = $status;
291 if ($search !==
'') {
292 $where[
'search'] = array(
294 'like' => array(
'invoice_no',
'customer'),
295 'mode' =>
'contains',
318 if (!is_array(
$rows)) {
319 return dbx()->get_system_obj(
'dbxTPL')->get_tpl(
320 'myInvoices|install-required',
321 array(
'install_url' => $this->url(
'install'))
326 'invoice_no' =>
$report->get_fd_message(
'column_invoice_no'),
327 'invoice_date' =>
$report->get_fd_message(
328 'column_invoice_date'
330 'customer' =>
$report->get_fd_message(
'column_customer'),
331 'status' =>
$report->get_fd_message(
'column_status'),
332 'action' =>
$report->get_fd_message(
'column_action'),
333 'total_gross' =>
$report->get_fd_message(
'column_total'),
336 'invoice_date' =>
'php-date-usr',
341 $report->_count_all =
$db->count(self::INVOICE_DD);
342 $report->_rcount =
$db->count(self::INVOICE_DD, $where);
359 if (!is_array($record)) {
363 $quantity = (float)($record[
'quantity'] ?? 0);
364 $unitPrice = (float)($record[
'unit_price'] ?? 0);
365 $sumCents = (int)round($quantity * $unitPrice * 100);
367 $this->itemTotalCents += $sumCents;
370 $this->euro($this->itemTotalCents)
372 $record[
'quantity'] = number_format($quantity, 2,
',',
'.');
373 $record[
'unit_price'] = $this->euro(
374 (
int)round($unitPrice * 100)
376 $record[
'sum'] = $this->euro($sumCents);
392 $invoiceId = (int)
dbx()->get_modul_var(
397 if ($invoiceId <= 0) {
401 $db =
dbx()->get_system_obj(
'dbxDB');
402 $invoice =
$db->select1(
404 array(
'id' => $invoiceId),
405 array(
'id',
'invoice_no')
407 if ((
int)($invoice[
'id'] ?? 0) <= 0) {
413 array(
'invoice_id' => $invoiceId),
427 'invoice-items-report',
428 'myInvoices|invoice-items-report'
431 $report->_fd = self::REPORT_FD;
435 $report->_create_row_select =
false;
436 $report->_create_row_edit =
false;
437 $report->_create_row_delete =
false;
440 (
string)$invoice[
'invoice_no']
443 $this->itemTotalCents = 0;
446 'position_no' =>
$report->get_fd_message(
449 'article_no' =>
$report->get_fd_message(
452 'description' =>
$report->get_fd_message(
'column_article'),
453 'quantity' =>
$report->get_fd_message(
'column_quantity'),
454 'unit_price' =>
$report->get_fd_message(
457 'sum' =>
$report->get_fd_message(
'column_total'),
477 public function delete(): string
479 $rid = (int)
dbx()->get_modul_var(
'rid', 0,
'int');
488 $db =
dbx()->get_system_obj(
'dbxDB');
489 if (
$db->begin(self::INVOICE_DD) !== 1) {
496 $itemsDeleted =
$db->delete(
498 array(
'invoice_id' => $rid)
500 $invoiceDeleted = in_array($itemsDeleted, array(0, 1),
true)
501 ?
$db->delete(self::INVOICE_DD, array(
'id' => $rid))
504 if ($invoiceDeleted !== 1
505 ||
$db->commit(self::INVOICE_DD) !== 1
507 $db->rollback(self::INVOICE_DD);
514 return $this->
report(
'delete_success');
527 $form =
dbx()->get_system_obj(
'dbxForm');
529 'myInvoices-install',
530 'myInvoices|invoice-install'
532 $form->_fd =
'myInvoices|invoice-install';
533 $form->load_fd_messages();
536 $form->get_fd_message(
'bar_title')
539 if (!
dbx()->
can(
'admin')) {
540 return dbx()->get_system_obj(
'dbxTPL')->get_tpl(
542 array(
'msg' =>
$form->get_fd_message(
'admin_required'))
546 $form->_action = $this->url(
'install');
547 $form->_msg_info =
$form->get_fd_message(
'install_info');
548 $form->_data = array_merge(
550 array(
'install_demo' => 1)
552 $form->add_rep(
'report_url', $this->url(
'report'));
560 if (
$form->submit()) {
561 if (
$form->errors()) {
567 'myInvoicesFixtures',
571 if ((
int)(
$result[
'ok'] ?? 0) === 1) {
572 $form->_msg_success =
$form->format_fd_message(
575 'invoices' => (
int)
$result[
'created_invoices'],
576 'items' => (
int)
$result[
'created_items'],
577 'existing' => (
int)
$result[
'existing_invoices'],
585 'Installation failed',
586 (
string)(
$result[
'message'] ??
'')
Fachservice des ausführbaren Rechnungs-Referenzmoduls.
invoice_items_report_next_record($report, $record)
Berechnet und formatiert die virtuelle Summenspalte einer Position.
installation()
Rendert den dbxForm-geschützten Installations- und Fixture-POST.
invoice_report_next_record($report, $record)
Bereitet eine Rechnungszeile unmittelbar vor dem Rendern auf.
report(string $success='', string $error='')
Rendert den paginierten Rechnungsreport.
form()
Rendert und verarbeitet das Rechnungskopfformular.
positions()
Rendert die zweite Listenstufe einer konkreten Rechnung.
if((string)($formActionPolicy['action'] ?? '') !=='dbxAction.save'||!dbx() ->check_action_token((string)($formActionPolicy['scope'] ?? ''),(string)($formActionRoute['params']['dbx_token'] ?? ''))) $report
action_url(string $url, string $action='', array $bindings=array())
Tokenisiert eine automatisch erkannte zustandsaendernde Route.
dbx()
Liefert die zentrale dbXapp-API als Singleton.
can($access_groups='', $user_groups='')
Prueft Gruppenrechte gegen den aktuellen oder uebergebenen Benutzer.
DBX schema administration.