Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic for reminder generation #219

Merged
merged 31 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
29e947e
first commit
Mar 11, 2024
5ed3972
make class parameers optional / change classnames
Mar 11, 2024
f745895
add ability to distinguish between attachments
Mar 20, 2024
4489eb6
repair shemadb_default
Mar 20, 2024
000e1aa
remove superflous line
Mar 20, 2024
adccafb
remove lacalization
Mar 20, 2024
e76d759
add "create_reminder" to localization
Mar 20, 2024
2d2e6ad
remove lacalization from admin folder
Mar 20, 2024
ef788ca
repaired midgard l10n
Mar 20, 2024
1bcc255
make class name dynamic
Mar 21, 2024
e12885a
add typehint to get_attachment
Mar 21, 2024
7a6b8ed
hide button, when not needed / codingstyle
Mar 21, 2024
6374582
reminder button appers after 14 days
Mar 22, 2024
e2c5b00
use overdue for status
Mar 22, 2024
d49b802
remove $invoice variable /change reminder classname
Mar 25, 2024
6b24e4c
change seccess / error message reminder pdf creation
Mar 25, 2024
c059462
change config /remove lacalization
Mar 25, 2024
9072a3a
change dialog window on reminder re-creation
Mar 25, 2024
ff1df3e
remove 'kind switch'
Mar 25, 2024
7b987a9
remove "has alredy sent" message for overdue reminder
Mar 26, 2024
f0c7a80
include reminder view
Mar 26, 2024
58753de
remove nested if from populate_toolbar()
Mar 26, 2024
0329955
add l10n to filename
Mar 27, 2024
3553315
coding style / remove $kind variable / change l10n
Apr 2, 2024
4179a8c
change label name to reminder
Apr 2, 2024
1d20f78
remove bracelets
Apr 2, 2024
a2445c6
add reminder to l10n
Apr 3, 2024
630d85a
change Mahnung to mahnung.
Apr 4, 2024
764d7a9
change: title/spelling/logic
Apr 8, 2024
428c193
change mahnung lcfirst
Apr 8, 2024
e7dab81
add test
Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
428 changes: 318 additions & 110 deletions lib/midcom/admin/folder/locale/default.de.txt

Large diffs are not rendered by default.

428 changes: 318 additions & 110 deletions lib/midcom/admin/folder/locale/default.en.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/org/openpsa/invoices/config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ create_pdf:
path: /invoice/action/create_pdf/
defaults: { _controller: 'org_openpsa_invoices_handler_invoice_action::create_pdf' }

create_reminder:
path: /invoice/action/create_reminder/
defaults: { _controller: 'org_openpsa_invoices_handler_invoice_action::create_pdf_reminder' }

recalc_invoice:
path: /invoice/recalculation/{guid}/
defaults: { _controller: 'org_openpsa_invoices_handler_invoice_items::recalculation' }
Expand Down
11 changes: 11 additions & 0 deletions lib/org/openpsa/invoices/handler/invoice/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ public function _handler_create_pdf()
}
}

public function _handler_create_pdf_reminder()
{
$pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice);
try {
$pdf_helper->render_and_attach('reminder');
return $this->reply(true, $this->_l10n->get('pdf created'));
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
} catch (midcom_error $e) {
return $this->reply(false, $this->_l10n->get('pdf creation failed') . ': ' . $e->getMessage());
}
}

public function _handler_send_by_mail()
{
$customerCard = org_openpsa_widgets_contact::get($this->invoice->customerContact);
Expand Down
6 changes: 6 additions & 0 deletions lib/org/openpsa/invoices/handler/invoice/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private function load_datamanager() : datamanager

if ($this->_config->get('invoice_pdfbuilder_class')) {
$schemadb->get('default')->get_field('pdf_file')['hidden'] = false;
$schemadb->get('default')->get_field('pdf_file_reminder')['hidden'] = false;
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
}

$dm = new datamanager($schemadb);
Expand Down Expand Up @@ -96,6 +97,11 @@ private function populate_toolbar()
&& intval($billing_data->sendingoption) == 2) {
$buttons[] = $this->build_button('send_by_mail', 'paper-plane');
}

$button = $this->build_button('create_reminder', 'file-pdf-o');
$pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice);
$button[MIDCOM_TOOLBAR_OPTIONS] = $pdf_helper->get_button_options();
$buttons[] = $button;
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
}

if ($this->invoice->is_cancelable()) {
Expand Down
30 changes: 22 additions & 8 deletions lib/org/openpsa/invoices/invoice/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ public function __construct(org_openpsa_invoices_invoice_dba $invoice)
$this->invoice = $invoice;
}

public function get_attachment(bool $autocreate = false) : ?midcom_db_attachment
public function get_attachment(bool $autocreate = false, $kind = null) : ?midcom_db_attachment
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
{
$pdf_files = blobs::get_attachments($this->invoice, "pdf_file");
if ($kind == 'reminder') {
$pdf_files = blobs::get_attachments($this->invoice, "pdf_file_reminder");
} else {
$pdf_files = blobs::get_attachments($this->invoice, "pdf_file");
}
if (!empty($pdf_files)) {
return reset($pdf_files);
}
Expand Down Expand Up @@ -63,9 +67,14 @@ public function get_button_options() : array
];
}

public function render_and_attach() : midcom_db_attachment
public function render_and_attach(string $kind = null) : midcom_db_attachment
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
{
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
if($kind == null) {
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
}else {
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class_reminder');
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic to determine the $client_class based on $kind is hardcoded for reminders, which limits extensibility. Consider using a dynamic approach to support more kinds in the future without modifying this code.

-        if($kind == null) {
-            $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
-        }else {
-            $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class_reminder');
-        }
+        $config_key = 'invoice_pdfbuilder_class' . ($kind ? "_{$kind}" : '');
+        $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get($config_key);

This change makes the selection of the PDF builder class more flexible and easier to extend with additional types of PDFs in the future.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if($kind == null) {
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
}else {
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class_reminder');
}
$config_key = 'invoice_pdfbuilder_class' . ($kind ? "_{$kind}" : '');
$client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get($config_key);


SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
if (!class_exists($client_class)) {
throw new midcom_error('Could not find PDF renderer ' . $client_class);
}
Expand All @@ -78,15 +87,20 @@ public function render_and_attach() : midcom_db_attachment
}
// renders the pdf and attaches it to the invoice
$pdf_builder = new $client_class($this->invoice);
$filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '.pdf';
if ($kind == 'reminder') {
$name = "guids_pdf_file_reminder";
$filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '_reminder' . '.pdf';
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
} else {
$name = "guids_pdf_file";
$filename = midcom_helper_misc::urlize($this->invoice->get_label()) . '.pdf';
}

// tmp filename
$tmp_file = midcom::get()->config->get('midcom_tempdir') . "/" . $filename;

// render pdf to tmp filename
$pdf_builder->render($tmp_file);

$attachment = $this->get_attachment();
$attachment = $this->get_attachment(false, $kind); //sucht nach 'pdf_file'
SimonRautenberg marked this conversation as resolved.
Show resolved Hide resolved
if ($attachment) {
$attachment->name = $filename;
$attachment->title = $this->invoice->get_label();
Expand All @@ -95,7 +109,7 @@ public function render_and_attach() : midcom_db_attachment
} else {
$attachment = $this->invoice->create_attachment($filename, $this->invoice->get_label(), "application/pdf");
if ( !$attachment
|| !$this->invoice->set_parameter("midcom.helper.datamanager2.type.blobs", "guids_pdf_file", $attachment->guid . ":" . $attachment->guid)) {
|| !$this->invoice->set_parameter("midcom.helper.datamanager2.type.blobs", $name, $attachment->guid . ":" . $attachment->guid)) {
throw new midcom_error("Failed to create invoice attachment for pdf: " . midcom_connection::get_error_string());
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/org/openpsa/invoices/locale/default.de.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ Die derzeitige PDF-Datei wurde manuell hochgeladen. Soll diese Datei wirklich er
PDF erzeugen
---STRINGEND

---STRING create_reminder
Mahnung erzeugen
---STRINGEND

---STRING pdf created
PDF-Datei wurde erfolgreich erzeugt
---STRINGEND
Expand Down
4 changes: 4 additions & 0 deletions lib/org/openpsa/invoices/locale/default.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Billing data
Create invoice
---STRINGEND

---STRING create_reminder
Create reminder
---STRINGEND

---STRING customer
Customer
---STRINGEND
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [413-414]

Consider revising the punctuation and spacing around the question marks to maintain consistency and adhere to standard English grammar rules. Specifically, remove the space before the question mark and consider adding a comma for clarity if intended to indicate a pause in casual speech.

- shall it be replaced ? The current PDF file was manually uploaded. So shall it really be replaced ?
+ shall it be replaced? The current PDF file was manually uploaded. So, shall it really be replaced?

Expand Down