1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Jobs/Invoice/InjectSignature.php

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Jobs\Invoice;
2023-07-26 04:18:00 +02:00
use App\Models\PurchaseOrder;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2023-10-26 04:57:44 +02:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class InjectSignature implements ShouldQueue
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/**
* Create a new job instance.
*
* @param \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity
* @param int $contact_id
2020-10-28 11:10:49 +01:00
* @param string $signature
* @param string $ip
*/
public function __construct(public \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder $entity, private int $contact_id, private string $signature, private ?string $ip)
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
2023-07-26 04:18:00 +02:00
$invitation = false;
2023-10-26 04:57:44 +02:00
if($this->entity instanceof PurchaseOrder) {
2023-07-26 04:18:00 +02:00
$invitation = $this->entity->invitations()->where('vendor_contact_id', $this->contact_id)->first();
2023-10-26 04:57:44 +02:00
if(!$invitation) {
2023-07-26 04:18:00 +02:00
$invitation = $this->entity->invitations->first();
2023-10-26 04:57:44 +02:00
}
2023-07-26 04:18:00 +02:00
2023-10-26 04:57:44 +02:00
} else {
2024-01-14 05:05:00 +01:00
2023-07-26 04:18:00 +02:00
$invitation = $this->entity->invitations()->where('client_contact_id', $this->contact_id)->first();
2023-10-26 04:57:44 +02:00
if(!$invitation) {
2023-07-26 04:18:00 +02:00
$invitation = $this->entity->invitations->first();
2023-10-26 04:57:44 +02:00
}
2023-07-26 04:18:00 +02:00
}
2024-01-14 05:05:00 +01:00
if (! $invitation) {
return;
}
$invitation->signature_base64 = $this->signature;
2023-07-26 04:04:32 +02:00
$invitation->signature_date = now();
$invitation->signature_ip = $this->ip;
$invitation->save();
}
}