diff --git a/app/Jobs/Ninja/SendReminders.php b/app/Jobs/Ninja/SendReminders.php index 299dd1e0f607..934c42c10d7f 100644 --- a/app/Jobs/Ninja/SendReminders.php +++ b/app/Jobs/Ninja/SendReminders.php @@ -16,6 +16,7 @@ use App\Events\Invoice\InvoiceWasEmailed; use App\Jobs\Entity\EmailEntity; use App\Libraries\MultiDB; use App\Models\Invoice; +use App\Models\Webhook; use App\Utils\Ninja; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesReminders; @@ -25,6 +26,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Carbon; +use App\Jobs\Util\WebHookHandler; class SendReminders implements ShouldQueue { @@ -81,6 +83,7 @@ class SendReminders implements ShouldQueue if (in_array($reminder_template, ['reminder1', 'reminder2', 'reminder3', 'endless_reminder'])) { $this->sendReminder($invoice, $reminder_template); + WebHookHandler::dispatch(Webhook::EVENT_REMIND_INVOICE, $invoice, $invoice->company); } }); } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 9cc71214d1be..61c535345f86 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -81,4 +81,9 @@ class Expense extends BaseModel { return $this->belongsTo(Company::class); } + + public function vendor() + { + return $this->belongsTo(Vendor::class); + } } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 66d37d7257d5..7ea3ff929556 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -601,22 +601,37 @@ trait GeneratesCounter $replace[] = str_replace($format, $date, $matches[1]); } - if ($entity instanceof Client || $entity instanceof Vendor) { - $search[] = '{$client_custom1}'; - $replace[] = $entity->custom_value1; + if ($entity instanceof Vendor) { - $search[] = '{$client_custom2}'; - $replace[] = $entity->custom_value2; - - $search[] = '{$client_custom3}'; - $replace[] = $entity->custom_value3; - - $search[] = '{$client_custom4}'; - $replace[] = $entity->custom_value4; - - $search[] = '{$id_number}'; + $search[] = '{$vendor_id_number}'; $replace[] = $entity->id_number; - } else { + + } + + if ($entity instanceof Expense) { + + if($entity->vendor){ + $search[] = '{$vendor_id_number}'; + $replace[] = $entity->vendor->id_number; + + $search[] = '{$vendor_custom1}'; + $replace[] = $entity->vendor->custom_value1; + + $search[] = '{$vendor_custom2}'; + $replace[] = $entity->vendor->custom_value2; + + $search[] = '{$vendor_custom3}'; + $replace[] = $entity->vendor->custom_value3; + + $search[] = '{$vendor_custom4}'; + $replace[] = $entity->vendor->custom_value4; + } + + $search[] = '{$expense_id_number}'; + $replace[] = $entity->id_number; + } + + if ($entity->client) { $search[] = '{$client_custom1}'; $replace[] = $entity->client->custom_value1; @@ -629,7 +644,7 @@ trait GeneratesCounter $search[] = '{$client_custom4}'; $replace[] = $entity->client->custom_value4; - $search[] = '{$id_number}'; + $search[] = '{$client_id_number}'; $replace[] = $entity->client->id_number; }