v2 first commit

This commit is contained in:
denisdulici
2019-11-16 10:21:14 +03:00
parent 5b23e9c2c4
commit 6d50fa8442
3075 changed files with 3451681 additions and 65594 deletions

View 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);
}
}