Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions lib/org/openpsa/invoices/config/schemadb_send_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
'widget' => 'textarea',
'required' => true,
],
'attachments' => [
'title' => 'attachments',
'storage' => 'attachments',
'type' => 'select',
'type_config' => [
'options' => [],
'allow_multiple' => true,
],
'widget' => 'radiocheckselect',
],
],
],
];
30 changes: 21 additions & 9 deletions lib/org/openpsa/invoices/handler/invoice/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\HttpFoundation\Request;
use midcom\datamanager\controller;
use midcom\datamanager\datamanager;
use midcom\datamanager\storage\blobs;

/**
* Invoice action handler
Expand Down Expand Up @@ -176,14 +177,25 @@ private function get_email_type_config() : array
private function load_send_mail_controller(array $config) : controller
{
$schemadb = schemadb::from_path($this->_config->get('schemadb_send_mail'));

$pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice);
$invoice_pdf = $pdf_helper->get_attachment(true);

$attachment_options = [$invoice_pdf->guid => $invoice_pdf->name];
foreach (blobs::get_attachments($this->invoice, 'files') as $attachment) {
$attachment_options[$attachment->guid] = $attachment->name;
}
$schemadb->get('default')->get_field('attachments')['type_config']['options'] = $attachment_options;

$dm = new datamanager($schemadb);
$billing_data = $this->invoice->get_billing_data(true);
$to_email = $billing_data->email ?: $this->mail_recipient->email;

$dm->set_defaults([
'to_email'=> $to_email,
'subject' => $config['subject'],
'message' => $config['message']
'message' => $config['message'],
'attachments' => serialize([$invoice_pdf->guid]),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

do we really need the invoice PDF to be deselectable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, it was requested that the invoice PDF can be deselected

]);

return $dm->get_controller();
Expand Down Expand Up @@ -233,15 +245,15 @@ public function save_callback(controller $controller)
}
$invoice_date = $this->_l10n->get_formatter()->date($this->invoice->date);

$pdf_helper = new org_openpsa_invoices_invoice_pdf($this->invoice);
$attachment = $pdf_helper->get_attachment(true);

$mail = new org_openpsa_mail();
$mail->attachments[] = [
'name' => $attachment->name,
'mimetype' => "application/pdf",
'content' => $attachment->read()
];
foreach ($data['attachments'] as $attachment_guid) {
$attachment = new midcom_db_attachment($attachment_guid);
$mail->attachments[] = [
'name' => $attachment->name,
'mimetype' => $attachment->mimetype,
'content' => $attachment->read()
];
}

// define replacements for subject / body
$mail->parameters = [
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 @@ -480,6 +480,10 @@ Betreff
Nachricht
---STRINGEND

---STRING attachments
Anhänge
---STRINGEND

---STRING reminder_send_by_mail
Zahlungserinnerung versenden
---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 @@ -468,6 +468,10 @@ Subject
Message
---STRINGEND

---STRING attachments
Attachments
---STRINGEND

---STRING reminder_send_by_mail
Send payment reminder
---STRINGEND
Expand Down
5 changes: 5 additions & 0 deletions test/org/openpsa/invoices/handler/invoice/actionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use org_openpsa_invoices_invoice_item_dba;
use midcom;
use midcom_db_topic;
use mock_pdfbuilder;

/**
* OpenPSA testcase
Expand Down Expand Up @@ -143,6 +144,8 @@ public function testHandler_mark_paid()

public function testHandler_send_by_mail()
{
$this->set_config('org.openpsa.invoices', 'invoice_pdfbuilder_class', mock_pdfbuilder::class);

midcom::get()->auth->request_sudo('org.openpsa.invoices');

$invoice = $this->create_object(org_openpsa_invoices_invoice_dba::class, [
Expand All @@ -158,6 +161,8 @@ public function testHandler_send_by_mail()

public function testHandler_send_payment_reminder()
{
$this->set_config('org.openpsa.invoices', 'invoice_pdfbuilder_class', mock_pdfbuilder::class);

midcom::get()->auth->request_sudo('org.openpsa.invoices');

$invoice = $this->create_object(org_openpsa_invoices_invoice_dba::class, [
Expand Down
1 change: 1 addition & 0 deletions test/utilities/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

require __DIR__ . '/helpers/sessioning.php';
require __DIR__ . '/helpers/relocate.php';
require __DIR__ . '/helpers/pdfbuilder.php';
24 changes: 24 additions & 0 deletions test/utilities/helpers/pdfbuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @package openpsa.test
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
*/

/**
* Dummy invoice PDF builder for test runs
*
* @package openpsa.test
*/
class mock_pdfbuilder implements org_openpsa_invoices_interfaces_pdfbuilder
{
public function __construct(org_openpsa_invoices_invoice_dba $invoice)
{
}

public function render(string $output_filename)
{
file_put_contents($output_filename, '%PDF-1.4');
}
}