Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
34 / 34 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
| ticket_invoice_mail | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Shared invoice email builder used by staff and guest invoicesend actions. |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | require_once __DIR__.'/../../Legacy/common/translate.php'; |
| 11 | require_once __DIR__.'/../../Legacy/mailing/mailing.php'; |
| 12 | |
| 13 | if (!function_exists('ticket_invoice_mail')) { |
| 14 | /** |
| 15 | * Build invoice email HTML and send with attachments. |
| 16 | * |
| 17 | * @param callable $emailSend function (string &$html, string $from, string $to, string $subject, array &$attachments): bool |
| 18 | * @param string|null $facturaeXml Optional Factura-e XML content (null = PDF only). |
| 19 | */ |
| 20 | function ticket_invoice_mail( |
| 21 | string $lang, |
| 22 | string $usermail, |
| 23 | string $pdfname, |
| 24 | string $pdffile, |
| 25 | $facturaeXml, |
| 26 | callable $emailSend |
| 27 | ): bool { |
| 28 | $language = new \Language($lang); |
| 29 | $content = '<p>@invoice_email_norespond</p>'. |
| 30 | '<p><b>@invoice_email_pfa</b></p>'; |
| 31 | |
| 32 | email_begin($html, '@invoice_email_title'); |
| 33 | email_content($html, $content, null, null); |
| 34 | email_end($html, '@invoice_email_footer'); |
| 35 | |
| 36 | $replace = []; |
| 37 | $search = [ |
| 38 | '@invoice_email_title', |
| 39 | '@invoice_email_footer', |
| 40 | '@invoice_email_norespond', |
| 41 | '@invoice_email_pfa', |
| 42 | ]; |
| 43 | foreach ($search as $str) { |
| 44 | $replace[] = $language->translate($str); |
| 45 | } |
| 46 | |
| 47 | $attach = []; |
| 48 | $subject = $language->translate('@invoice_email_title'); |
| 49 | $html = str_replace($search, $replace, $html); |
| 50 | $attach[] = [ |
| 51 | 'name' => $pdfname, |
| 52 | 'mime' => 'application/pdf', |
| 53 | 'content' => $pdffile, |
| 54 | ]; |
| 55 | |
| 56 | if (\is_string($facturaeXml) && $facturaeXml !== '') { |
| 57 | $xmlname = pathinfo($pdfname, PATHINFO_FILENAME).'.xml'; |
| 58 | $attach[] = [ |
| 59 | 'name' => $xmlname, |
| 60 | 'mime' => 'application/xml', |
| 61 | 'content' => $facturaeXml, |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | return (bool) $emailSend($html, \AppConstants::NoReplyMail, $usermail, $subject, $attach); |
| 66 | } |
| 67 | } |