Merge pull request #6830 from turbo124/v5-develop

Triggered actions for recurring objects
This commit is contained in:
David Bomba 2021-10-13 16:43:16 +11:00 committed by GitHub
commit 2106c9fe8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 43 additions and 17 deletions

View File

@ -53,6 +53,9 @@ class InvoiceSum
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
// if(!$this->invoice->relationLoaded('client'))
// $this->invoice->load('client');
$this->tax_map = new Collection; $this->tax_map = new Collection;
} }

View File

@ -210,6 +210,10 @@ class RecurringInvoiceController extends BaseController
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->service()
->triggeredActions($request)
->save();
return $this->itemResponse($recurring_invoice); return $this->itemResponse($recurring_invoice);
} }

View File

@ -36,9 +36,9 @@ class QueryLogging
{ {
// Enable query logging for development // Enable query logging for development
if (!Ninja::isHosted() || !config('beacon.enabled')) { // if (!Ninja::isHosted() || !config('beacon.enabled')) {
return $next($request); // return $next($request);
} // }
$timeStart = microtime(true); $timeStart = microtime(true);
DB::enableQueryLog(); DB::enableQueryLog();
@ -52,7 +52,7 @@ class QueryLogging
$timeEnd = microtime(true); $timeEnd = microtime(true);
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
// info("Query count = {$count}"); info("Query count = {$count}");
if($count > 175){ if($count > 175){
nlog("Query count = {$count}"); nlog("Query count = {$count}");

View File

@ -105,7 +105,7 @@ class StoreRecurringInvoiceRequest extends Request
if (isset($input['auto_bill'])) { if (isset($input['auto_bill'])) {
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else { } else {
if ($client = Client::find($input['client_id'])) { if (array_key_exists('client_id', $input) && $client = Client::find($input['client_id'])) {
$input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} }

View File

@ -93,6 +93,7 @@ class CreateEntityPdf implements ShouldQueue
$this->contact = $invitation->contact; $this->contact = $invitation->contact;
$this->client = $invitation->contact->client; $this->client = $invitation->contact->client;
$this->client->load('company');
$this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk; $this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk;
@ -107,7 +108,7 @@ class CreateEntityPdf implements ShouldQueue
/* Init a new copy of the translator*/ /* Init a new copy of the translator*/
$t = app('translator'); $t = app('translator');
/* Set the locale*/ /* Set the locale*/
App::setLocale($this->contact->preferredLocale()); App::setLocale($this->client->locale());
/* Set customized translations _NOW_ */ /* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings())); $t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));

View File

@ -49,6 +49,7 @@ class EntityCreatedObject
/* Set customized translations _NOW_ */ /* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->entity->company->settings)); $t->replace(Ninja::transformTranslations($this->entity->company->settings));
$this->entity->load('client.country', 'client.company');
$this->client = $this->entity->client; $this->client = $this->entity->client;
$this->company = $this->entity->company; $this->company = $this->entity->company;

View File

@ -87,7 +87,7 @@ class TemplateEmail extends Mailable
$this->from(config('mail.from.address'), $email_from_name); $this->from(config('mail.from.address'), $email_from_name);
if (strlen($settings->bcc_email) > 1) if (strlen($settings->bcc_email) > 1)
$this->bcc(explode(",",$settings->bcc_email)); $this->bcc(explode(",",str_replace(" ", "", $settings->bcc_email)));//remove whitespace if any has been inserted.
$this->subject($this->build_email->getSubject()) $this->subject($this->build_email->getSubject())
->text('email.template.plain', [ ->text('email.template.plain', [

View File

@ -81,7 +81,8 @@ class ActivityRepository extends BaseRepository
|| get_class($entity) == Credit::class || get_class($entity) == Credit::class
|| get_class($entity) == RecurringInvoice::class || get_class($entity) == RecurringInvoice::class
) { ) {
$entity->load('company', 'client');
$entity->load('client');
$contact = $entity->client->primary_contact()->first(); $contact = $entity->client->primary_contact()->first();
$backup->html_backup = $this->generateHtml($entity); $backup->html_backup = $this->generateHtml($entity);
$backup->amount = $entity->amount; $backup->amount = $entity->amount;
@ -95,7 +96,7 @@ class ActivityRepository extends BaseRepository
public function getTokenId(array $event_vars) public function getTokenId(array $event_vars)
{ {
if ($event_vars['token']) { if ($event_vars['token']) {
$company_token = CompanyToken::whereRaw('BINARY `token`= ?', [$event_vars['token']])->first(); $company_token = CompanyToken::where('token', $event_vars['token'])->first();
if ($company_token) { if ($company_token) {
return $company_token->id; return $company_token->id;
@ -117,7 +118,7 @@ class ActivityRepository extends BaseRepository
$entity_design_id = 'credit_design_id'; $entity_design_id = 'credit_design_id';
} }
$entity->load('client','client.company'); // $entity->load('client.company');
$entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id)); $entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id));
@ -128,6 +129,8 @@ class ActivityRepository extends BaseRepository
return; return;
} }
$entity->load('client.company', 'invitations');
$html = new HtmlEngine($entity->invitations->first()); $html = new HtmlEngine($entity->invitations->first());
if ($design->is_custom) { if ($design->is_custom) {

View File

@ -64,7 +64,6 @@ class TriggeredActions extends AbstractService
{ {
$reminder_template = $this->invoice->calculateTemplate('invoice'); $reminder_template = $this->invoice->calculateTemplate('invoice');
//$reminder_template = 'payment';
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) { $this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) {
EmailEntity::dispatch($invitation, $this->invoice->company, $reminder_template); EmailEntity::dispatch($invitation, $this->invoice->company, $reminder_template);

View File

@ -97,6 +97,20 @@ class RecurringService
return $this; return $this;
} }
public function triggeredActions($request)
{
if ($request->has('start') && $request->input('start') == 'true') {
$this->start();
}
if ($request->has('stop') && $request->input('stop') == 'true') {
$this->stop();
}
return $this;
}
public function fillDefaults() public function fillDefaults()
{ {

View File

@ -49,7 +49,6 @@ class HtmlEngine
public function __construct($invitation) public function __construct($invitation)
{ {
$this->invitation = $invitation; $this->invitation = $invitation;
// $invitation->load('contact.client.company', 'company');
$this->entity_string = $this->resolveEntityString(); $this->entity_string = $this->resolveEntityString();
@ -59,8 +58,8 @@ class HtmlEngine
$this->contact = $invitation->contact; $this->contact = $invitation->contact;
$this->client = $invitation->contact->client; $this->client = $this->contact->client->load('company','country');
$this->client->load('country','company');
$this->entity->load('client'); $this->entity->load('client');
$this->settings = $this->client->getMergedSettings(); $this->settings = $this->client->getMergedSettings();

View File

@ -2479,6 +2479,8 @@ $LANG = array(
'currency_cambodian_riel' => 'Cambodian Riel', 'currency_cambodian_riel' => 'Cambodian Riel',
'currency_vanuatu_vatu' => 'Vanuatu Vatu', 'currency_vanuatu_vatu' => 'Vanuatu Vatu',
'currency_cuban_peso' => 'Cuban Peso',
'review_app_help' => 'We hope you\'re enjoying using the app.<br/>If you\'d consider :link we\'d greatly appreciate it!', 'review_app_help' => 'We hope you\'re enjoying using the app.<br/>If you\'d consider :link we\'d greatly appreciate it!',
'writing_a_review' => 'writing a review', 'writing_a_review' => 'writing a review',