mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Credit Emailer
This commit is contained in:
parent
0a02323792
commit
2c40adca8d
@ -12,7 +12,6 @@
|
||||
namespace App\Events\Credit;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditWasViewed;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
|
90
app/Mail/Engine/CreditEmailEngine.php
Normal file
90
app/Mail/Engine/CreditEmailEngine.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Credit Ninja (https://creditninja.com).
|
||||
*
|
||||
* @link https://github.com/creditninja/creditninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Credit Ninja LLC (https://creditninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Mail\Engine;
|
||||
|
||||
use App\Utils\Number;
|
||||
|
||||
class CreditEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
public $invitation;
|
||||
|
||||
public $client;
|
||||
|
||||
public $credit;
|
||||
|
||||
public $contact;
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
public function __construct($invitation, $reminder_template)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->credit = $invitation->credit;
|
||||
$this->contact = $invitation->contact;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
$body_template = trans(
|
||||
'texts.credit_message',
|
||||
[
|
||||
'credit' => $this->credit->number,
|
||||
'company' => $this->credit->company->present()->name(),
|
||||
'amount' => Number::formatMoney($this->credit->balance, $this->client),
|
||||
],
|
||||
null,
|
||||
$this->client->locale()
|
||||
);
|
||||
}
|
||||
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
$subject_template = trans(
|
||||
'texts.credit_subject',
|
||||
[
|
||||
'number' => $this->credit->number,
|
||||
'account' => $this->credit->company->present()->name(),
|
||||
],
|
||||
null,
|
||||
$this->client->locale()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setTemplate($this->client->getSetting('email_style'))
|
||||
->setContact($this->contact)
|
||||
->setVariables($this->credit->makeValues($this->contact))//move make values into the htmlengine
|
||||
->setSubject($subject_template)
|
||||
->setBody($body_template)
|
||||
->setFooter("<a href='{$this->invitation->getLink()}'>".ctrans('texts.view_credit').'</a>')
|
||||
->setViewLink($this->invitation->getLink())
|
||||
->setViewText(ctrans('texts.view_credit'));
|
||||
|
||||
if ($this->client->getSetting('pdf_email_attachment') !== false) {
|
||||
$this->setAttachments($invitation->pdf_file_path());
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,11 +17,18 @@ use App\Models\Backup;
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Design;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\User;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
||||
|
||||
/**
|
||||
* Class for activity repository.
|
||||
@ -29,7 +36,7 @@ use Illuminate\Support\Facades\Log;
|
||||
class ActivityRepository extends BaseRepository
|
||||
{
|
||||
use MakesInvoiceHtml;
|
||||
|
||||
use MakesHash;
|
||||
/**
|
||||
* Save the Activity.
|
||||
*
|
||||
@ -68,7 +75,7 @@ class ActivityRepository extends BaseRepository
|
||||
|
||||
if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class) {
|
||||
$contact = $entity->client->primary_contact()->first();
|
||||
$backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity, $contact);
|
||||
$backup->html_backup = $this->generateHtml($entity);
|
||||
$backup->amount = $entity->amount;
|
||||
}
|
||||
|
||||
@ -90,4 +97,55 @@ class ActivityRepository extends BaseRepository
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function generateHtml($entity)
|
||||
{
|
||||
$entity_design_id = '';
|
||||
|
||||
if($entity instanceof Invoice || $entity instanceof RecurringInvoice){
|
||||
$entity_design_id = 'invoice_design_id';
|
||||
}
|
||||
elseif($entity instanceof Quote){
|
||||
$entity_design_id = 'quote_design_id';
|
||||
}
|
||||
elseif($entity instanceof Credit){
|
||||
$entity_design_id = 'credit_design_id';
|
||||
}
|
||||
|
||||
$entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id));
|
||||
|
||||
$design = Design::find($entity_design_id);
|
||||
$html = new HtmlEngine($invitation);
|
||||
|
||||
if ($design->is_custom) {
|
||||
$options = [
|
||||
'custom_partials' => json_decode(json_encode($design->design), true)
|
||||
];
|
||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||
} else {
|
||||
$template = new PdfMakerDesign(strtolower($design->name));
|
||||
}
|
||||
|
||||
$state = [
|
||||
'template' => $template->elements([
|
||||
'client' => $entity->client,
|
||||
'entity' => $entity,
|
||||
'pdf_variables' => (array) $entity->company->settings->pdf_variables,
|
||||
'products' => $design->design->product,
|
||||
]),
|
||||
'variables' => $html->generateLabelsAndValues(),
|
||||
'options' => [
|
||||
'all_pages_header' => $entity->client->getSetting('all_pages_header'),
|
||||
'all_pages_footer' => $entity->client->getSetting('all_pages_footer'),
|
||||
],
|
||||
];
|
||||
|
||||
$maker = new PdfMakerService($state);
|
||||
|
||||
return $maker->design($template)
|
||||
->build()
|
||||
->getCompiledHTML(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,8 @@ Route::group(['middleware' => ['auth:contact', 'locale'], 'prefix' => 'client',
|
||||
Route::get('quotes/{quote}', 'ClientPortal\QuoteController@show')->name('quote.show');
|
||||
Route::get('quotes/{quote_invitation}', 'ClientPortal\QuoteController@show')->name('quote.show_invitation');
|
||||
|
||||
Route::resource('credits', 'ClientPortal\CreditController')->only('index', 'show');
|
||||
Route::get('credits', 'ClientPortal\CreditController@index')->name('credits.index');
|
||||
Route::get('credits/{credit}', 'ClientPortal\CreditController@show')->name('credits.show');
|
||||
|
||||
|
||||
Route::get('client/switch_company/{contact}', 'ClientPortal\SwitchCompanyController')->name('switch_company');
|
||||
|
Loading…
Reference in New Issue
Block a user