diff --git a/Admin/Install/Messages.install.json b/Admin/Install/Messages.install.json
new file mode 100755
index 0000000..e076a08
--- /dev/null
+++ b/Admin/Install/Messages.install.json
@@ -0,0 +1,23 @@
+[
+ {
+ "type": "email_template",
+ "from": "",
+ "to": "",
+ "cc": "",
+ "bcc": "",
+ "ishtml": true,
+ "l11n": {
+ "en": {
+ "subject": "Billing",
+ "body": "
BillingBillingDear {user_name}, Thank you for for doing business with us. Attached kindly find your bill. Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn |
|
",
+ "bodyalt": "Dear {user_name},\n\nThank you for doing business with us.\n\nAttached kindly find your bill.\n\n\nJingga e.K. - www.jingga.app - CEO Dennis Eichhorn"
+ },
+ "de": {
+ "subject": "Rechnungsstellung",
+ "body": "AbrechnungAbrechnungSehr geehrte/r {user_name}, Vielen Dank für Ihre Geschäftsbeziehung mit uns. Im Anhang finden Sie Ihre Rechnung. Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn |
|
",
+ "bodyalt": "Sehr geehrte/r {user_name},\n\nvielen Dank für Ihre Geschäftsbeziehung mit uns.\n\nIm Anhang finden Sie freundlicherweise Ihre Rechnung.\n\n\nJingga e.K. - www.jingga.app - CEO Dennis Eichhorn"
+ }
+ },
+ "send": false
+ }
+]
\ No newline at end of file
diff --git a/Admin/Install/Messages.php b/Admin/Install/Messages.php
new file mode 100755
index 0000000..b447f3e
--- /dev/null
+++ b/Admin/Install/Messages.php
@@ -0,0 +1,67 @@
+ __DIR__ . '/Messages.install.json']);
+
+ /** @var \Modules\Admin\Controller\ApiController $module */
+ $module = $app->moduleManager->get('Admin');
+
+ $settings = [
+ [
+ 'id' => null,
+ 'name' => SettingsEnum::BILLING_CUSTOMER_EMAIL_TEMPLATE,
+ 'content' => (string) $messages['email_template'][0]['id'],
+ 'module' => 'Billing',
+ ],
+ ];
+
+ $response = new HttpResponse();
+ $request = new HttpRequest(new HttpUri(''));
+
+ $request->header->account = 1;
+ $request->setData('settings', \json_encode($settings));
+
+ $module->apiSettingsSet($request, $response);
+ }
+}
diff --git a/Controller/ApiBillController.php b/Controller/ApiBillController.php
index 5e6d4e1..01027c3 100755
--- a/Controller/ApiBillController.php
+++ b/Controller/ApiBillController.php
@@ -30,10 +30,11 @@ use Modules\ClientManagement\Models\ClientMapper;
use Modules\ItemManagement\Models\Item;
use Modules\ItemManagement\Models\ItemMapper;
use Modules\Media\Models\CollectionMapper;
+use Modules\Media\Models\Media;
use Modules\Media\Models\MediaMapper;
-use Modules\Media\Models\NullCollection;
use Modules\Media\Models\PathSettings;
use Modules\Media\Models\UploadStatus;
+use Modules\Messages\Models\EmailMapper;
use Modules\SupplierManagement\Models\NullSupplier;
use Modules\SupplierManagement\Models\SupplierMapper;
use phpOMS\Autoloader;
@@ -41,6 +42,7 @@ use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO4217CharEnum;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Message\Http\RequestStatusCode;
+use phpOMS\Message\Mail\Email;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
@@ -901,6 +903,25 @@ final class ApiBillController extends Controller
unit: $this->app->unitId
);
+ // Send bill via email
+ // @todo: maybe not all bill types, and bill status (e.g. deleted should not be sent)
+ $client = ClientMapper::get()
+ ->with('account')
+ ->with('attributes')
+ ->with('attributes/type')
+ ->with('attributes/value')
+ ->where('id', $bill->client->id)
+ ->where('attributes/type/name', ['bill_emails', 'bill_email_address'], 'IN')
+ ->execute();
+
+ if ($client->getAttribute('bill_emails')->value->getValue() === 1) {
+ $email = empty($tmp = $client->getAttribute('bill_email_address')->value->getValue())
+ ? $tmp
+ : $client->account->getEmail();
+
+ $this->sendBillEmail($media, $email, $response->getLanguage());
+ }
+
$this->createModelRelation(
$request->header->account,
$bill->id,
@@ -921,6 +942,36 @@ final class ApiBillController extends Controller
);
}
+ public function sendBillEmail(Media $media, string $email, string $language = 'en') : void
+ {
+ $handler = $this->app->moduleMaanger->get('Admin', 'Api')->setUpServerMailHandler();
+
+ $emailSettings = $this->app->appSettings->get(
+ names: AdminSettingsEnum::MAIL_SERVER_ADDR,
+ module: 'Admin'
+ );
+
+ $emailSettings = $this->app->appSettings->get(
+ names: SettingsEnum::BILLING_CUSTOMER_EMAIL_TEMPLATE,
+ module: 'Billing'
+ );
+
+ $mail = EmailMapper::get()
+ ->with('l11n')
+ ->where('id', (int) $emailSettings->content)
+ ->where('l11n/language', $language)
+ ->execute();
+
+ $mail = new Email();
+ $mail->setFrom($emailSettings->content);
+ $mail->addTo($email);
+ $mail->addAttachment($media->getAbsolutePath(), $media->name);
+
+ $handler->send($mail);
+
+ $this->app->moduleManager->get('Billing', 'Api')->sendMail($mail);
+ }
+
/**
* Api method to create bill files
*
diff --git a/Controller/CliController.php b/Controller/CliController.php
index b837701..afe03f2 100755
--- a/Controller/CliController.php
+++ b/Controller/CliController.php
@@ -28,6 +28,7 @@ use phpOMS\Localization\LanguageDetection\Language;
use phpOMS\Localization\Money;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
+use phpOMS\Stdlib\Base\FloatInt;
use phpOMS\Views\View;
/**
diff --git a/Models/SettingsEnum.php b/Models/SettingsEnum.php
index 07af36a..c81b267 100755
--- a/Models/SettingsEnum.php
+++ b/Models/SettingsEnum.php
@@ -31,4 +31,6 @@ abstract class SettingsEnum extends Enum
public const ORIGINAL_MEDIA_TYPE = '1005100002'; // original document (mostly supplier invoice/delivery note)
public const VALID_BILL_LANGUAGES = '1005100003'; // List of valid languages for bills
+
+ public const BILLING_CUSTOMER_EMAIL_TEMPLATE = '1005100004'; // Email template for customer billing
}
diff --git a/info.json b/info.json
index 7d66b30..3f570d3 100755
--- a/info.json
+++ b/info.json
@@ -30,7 +30,8 @@
"Admin": "*",
"Navigation": "*",
"Media": "*",
- "Workflow": "*"
+ "Workflow": "*",
+ "Messages": "*"
},
"load": [
{