aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorCamil Staps2016-07-31 23:39:22 +0200
committerCamil Staps2016-07-31 23:39:22 +0200
commit87b38e1cb5d5d5ebddfa4601a9088c3eadaf7ef0 (patch)
treed3bae56b43ab75e0939040c8af271abc7631387e /classes
parentMail: add SMTP_AUTH_TYPE (diff)
Easier emails
Diffstat (limited to 'classes')
-rw-r--r--classes/Correspondence.php179
-rw-r--r--classes/Offer.php22
2 files changed, 137 insertions, 64 deletions
diff --git a/classes/Correspondence.php b/classes/Correspondence.php
index 09873c3..80c4c87 100644
--- a/classes/Correspondence.php
+++ b/classes/Correspondence.php
@@ -51,62 +51,65 @@ class Correspondence extends FPDF {
*
* @see _() A function to translate
*/
- protected static $translations = array(
- 'adres' => array(
- 'en' => 'Address',
- 'nl' => 'Adres'),
- 'amount' => array(
- 'en' => 'Amount',
- 'nl' => 'Subtotaal'),
- 'amount-due' => array(
- 'en' => 'Total amount due',
- 'nl' => 'Te voldoen'),
- 'biccode' => array(
- 'en' => 'The BIC code of our bank is %%.',
- 'nl' => 'De BIC-code van de bank is %%.'),
- 'btwnr' => array(
- 'en' => 'VAT nr',
- 'nl' => 'BTW nr'),
- 'description' => array(
- 'en' => 'Description',
- 'nl' => 'Omschrijving'),
- 'due-date' => array(
- 'en' => 'Due date',
- 'nl' => 'Vervaldatum'),
- 'email' => array(
- 'en' => 'Email',
- 'nl' => 'Email'),
- 'iban' => array(
- 'en' => 'IBAN',
- 'nl' => 'IBAN'),
- 'invoice' => array(
- 'en' => 'Invoice',
- 'nl' => 'Factuur'),
- 'invoice-date' => array(
- 'en' => 'Invoice date',
- 'nl' => 'Factuurdatum'),
- 'invoice-nr' => array(
- 'en' => 'Invoice number',
- 'nl' => 'Factuurnummer'),
- 'price-excl' => array(
- 'en' => 'Price excl.',
- 'nl' => 'Prijs excl.'),
- 'price-incl' => array(
- 'en' => 'Price incl.',
- 'nl' => 'Prijs incl.'),
- 'request' => array(
- 'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.',
- 'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'),
- 'tel-nr' => array(
- 'en' => 'Tel.',
- 'nl' => 'Tel.'),
- 'total' => array(
- 'en' => 'Total',
- 'nl' => 'Totaal'),
- 'vat' => array(
- 'en' => 'VAT',
- 'nl' => 'BTW'),
- );
+ protected static $translations = [
+ 'adres' => [
+ 'en' => 'Address',
+ 'nl' => 'Adres'],
+ 'amount' => [
+ 'en' => 'Amount',
+ 'nl' => 'Subtotaal'],
+ 'amount-due' => [
+ 'en' => 'Total amount due',
+ 'nl' => 'Te voldoen'],
+ 'biccode' => [
+ 'en' => 'The BIC code of our bank is %%.',
+ 'nl' => 'De BIC-code van de bank is %%.'],
+ 'btwnr' => [
+ 'en' => 'VAT nr',
+ 'nl' => 'BTW nr'],
+ 'description' => [
+ 'en' => 'Description',
+ 'nl' => 'Omschrijving'],
+ 'due-date' => [
+ 'en' => 'Due date',
+ 'nl' => 'Vervaldatum'],
+ 'email' => [
+ 'en' => 'Email',
+ 'nl' => 'Email'],
+ 'iban' => [
+ 'en' => 'IBAN',
+ 'nl' => 'IBAN'],
+ 'invoice' => [
+ 'en' => 'Invoice',
+ 'nl' => 'Factuur'],
+ 'invoice-date' => [
+ 'en' => 'Invoice date',
+ 'nl' => 'Factuurdatum'],
+ 'invoice-nr' => [
+ 'en' => 'Invoice number',
+ 'nl' => 'Factuurnummer'],
+ 'price-excl' => [
+ 'en' => 'Price excl.',
+ 'nl' => 'Prijs excl.'],
+ 'price-incl' => [
+ 'en' => 'Price incl.',
+ 'nl' => 'Prijs incl.'],
+ 'request' => [
+ 'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.',
+ 'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'],
+ 'tel-nr' => [
+ 'en' => 'Tel.',
+ 'nl' => 'Tel.'],
+ 'total' => [
+ 'en' => 'Total',
+ 'nl' => 'Totaal'],
+ 'vat' => [
+ 'en' => 'VAT',
+ 'nl' => 'BTW'],
+ 'mail-offer' => [
+ 'en' => "Dear {{getContact-name}},\r\n\r\nPlease find attached your invoice. You can either pay by bank transfer, as indicated on the invoice, or using Paypal or a credit card on {{getPaymentUrl}}.\r\n\r\nThank you in advance,\r\n\r\n{{{invoice_name}}}",
+ 'nl' => "Beste {{getContact-name}},\r\n\r\nBijgevoegd vindt u uw factuur. U kunt per bankoverschrijving betalen, zoals aangegeven op de factuur, of met Paypal of een credit card op {{getPaymentUrl}}.\r\n\r\nAlvast hartelijk dank,\r\n\r\n{{{invoice_name}}}"],
+ ];
/** @var $page_height The height of a page in millimeters */
protected static $page_height = 297; // A4
@@ -119,7 +122,6 @@ class Correspondence extends FPDF {
* @see $translations The array holding the translations
*
* @param string $key The string to translate
- * @param string $lang The language to translate to (two-letter code)
*
* @return string The translated string
*/
@@ -130,6 +132,69 @@ class Correspondence extends FPDF {
}
/**
+ * Translate a string, statically
+ *
+ * @param string $key The string to translate
+ * @param string $lang The language to translate to (two-letter code)
+ *
+ * @return string The translated string
+ */
+ public static function __($key, $lang) {
+ if (!array_key_exists($key, self::$translations))
+ return $key;
+ if (!array_key_exists($lang, self::$translations[$key]))
+ return $key;
+ return self::$translations[$key][$lang];
+ }
+
+ /**
+ * Translate a string, statically, and resolve (@see resolve) it
+ *
+ * @param string $key The string to translate
+ * @param string $lang The language to translate to (two-letter code)
+ * @param mixed $obj The object to resolve
+ *
+ * @return string The resolved translated string
+ */
+ public static function __r($key, $lang, $obj) {
+ return self::resolve(self::__($key, $lang), $obj);
+ }
+
+ /**
+ * Resolve a string
+ *
+ * Resolves {{keyA-keyB-keyC}} to e.g. $obj->keyA()->keyB->keyC(), where
+ * first the function (e.g. keyA()) is tried, and then the property (e.g.
+ * keyB).
+ *
+ * Resolves {{{const}}} to Constants::const.
+ *
+ * @param string $string The string to resolve
+ * @param mixed $obj The object to use
+ *
+ * @return string The generated string
+ */
+ public static function resolve($string, $obj) {
+ $string = preg_replace_callback('/\{\{\{(\w+)\}\}\}/', function ($matches) {
+ $key = $matches[1];
+ return constant("Constants::$key");
+ }, $string);
+ $string = preg_replace_callback('/\{\{([\w-]+)\}\}/', function ($matches) use ($obj) {
+ $keys = explode('-', $matches[1]);
+ $temp = $obj;
+ foreach ($keys as $key) {
+ if (method_exists($temp, $key)) {
+ $temp = call_user_func([$temp, $key]);
+ } else {
+ $temp = $temp->$key;
+ }
+ }
+ return $temp;
+ }, $string);
+ return $string;
+ }
+
+ /**
* Create a new PDF
*
* @param string $orientation See the FPDF class specs
diff --git a/classes/Offer.php b/classes/Offer.php
index 7b0d2fc..2a48604 100644
--- a/classes/Offer.php
+++ b/classes/Offer.php
@@ -87,6 +87,15 @@ class Offer extends Model{
}
/**
+ * Get the URL on which the offer can be paid
+ *
+ * @return string The URL
+ */
+ public function getPaymentUrl() {
+ return Constants::url_external . "pay?id={$this->id}&key={$this->payment_key}";
+ }
+
+ /**
* Get the contact that this offer is linked to
*
* @return contact The contact
@@ -301,6 +310,11 @@ class Offer extends Model{
public function mailer() {
$mailer = new Mailer($this->pdo);
$mailer->setOffer($this);
+
+ $mailer->addAttachment($this->getInvoiceFile()->getFilenamePath());
+ $mailer->Subject = 'Your invoice';
+ $mailer->Body = Correspondence::__r('mail-offer', $this->getContact()->language, $this);
+
return $mailer;
}
@@ -310,13 +324,7 @@ class Offer extends Model{
* @return bool The result of Mailer::send
*/
public function send() {
- $mailer = $this->mailer();
-
- $mailer->addAttachment($this->getInvoiceFile()->getFilenamePath());
- $mailer->Subject = 'Your invoice';
- $mailer->Body = 'Here is your invoice.';
-
- return $mailer->send();
+ return $this->mailer()->send();
}
/**