v2 first commit
This commit is contained in:
63
app/Jobs/Common/DeleteContact.php
Normal file
63
app/Jobs/Common/DeleteContact.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
|
||||
class DeleteContact extends Job
|
||||
{
|
||||
protected $contact;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $contact
|
||||
*/
|
||||
public function __construct($contact)
|
||||
{
|
||||
$this->contact = $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->contact->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->contact->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
if ($this->contact->type == 'customer') {
|
||||
$rels['invoices'] = 'invoices';
|
||||
} else {
|
||||
$rels['bills'] = 'bills';
|
||||
}
|
||||
|
||||
return $this->countRelationships($this->contact, $rels);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user