mirror of
https://github.com/Karaka-Management/oms-Billing.git
synced 2026-01-29 07:48:40 +00:00
add billing email template and allow to client to specify separate invoice bill.
This commit is contained in:
parent
88ee85212f
commit
e7791bc127
23
Admin/Install/Messages.install.json
Executable file
23
Admin/Install/Messages.install.json
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
[
|
||||
{
|
||||
"type": "email_template",
|
||||
"from": "",
|
||||
"to": "",
|
||||
"cc": "",
|
||||
"bcc": "",
|
||||
"ishtml": true,
|
||||
"l11n": {
|
||||
"en": {
|
||||
"subject": "Billing",
|
||||
"body": "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Billing</title></head><body style=\"font-family: Arial, sans-serif; font-size: 16px; line-height: 1.5;\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td><table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"600\" style=\"margin: 0 auto; background-color: #ffffff;\"><tr><td style=\"padding: 40px 0; text-align: center;\"><h1 style=\"margin-top: 0; color: #000000; font-size: 24px;\">Billing</h1><p style=\"margin-bottom: 20px;\">Dear {user_name},</p><p style=\"margin-bottom: 20px;\">Thank you for for doing business with us.</p><p style=\"margin-bottom: 20px;\">Attached kindly find your bill.</p><p style=\"margin-top: 40px;\">Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn</p></td></tr></table></td></tr></table></body></html>",
|
||||
"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": "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Abrechnung</title></head><body style=\"font-family: Arial, sans-serif; font-size: 16px; line-height: 1.5;\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td><table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"600\" style=\"margin: 0 auto; background-color: #ffffff;\"><tr><td style=\"padding: 40px 0; text-align: center;\"><h1 style=\"margin-top: 0; color: #000000; font-size: 24px;\">Abrechnung</h1><p style=\"margin-bottom: 20px;\">Sehr geehrte/r {user_name},</p><p style=\"margin-bottom: 20px;\">Vielen Dank für Ihre Geschäftsbeziehung mit uns.</p><p style=\"margin-bottom: 20px;\">Im Anhang finden Sie Ihre Rechnung.</p><p style=\"margin-top: 40px;\">Jingga e.K. - www.jingga.app - CEO Dennis Eichhorn</p></td></tr></table></td></tr></table></body></html>",
|
||||
"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
|
||||
}
|
||||
]
|
||||
67
Admin/Install/Messages.php
Executable file
67
Admin/Install/Messages.php
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Billing\Admin\Install
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Billing\Admin\Install;
|
||||
|
||||
use Modules\Billing\Models\SettingsEnum;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
|
||||
/**
|
||||
* Media class.
|
||||
*
|
||||
* @package Modules\Billing\Admin\Install
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Messages
|
||||
{
|
||||
/**
|
||||
* Install media providing
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param string $path Module path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function install(ApplicationAbstract $app, string $path) : void
|
||||
{
|
||||
$messages = \Modules\Messages\Admin\Installer::installExternal($app, ['path' => __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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user