Skip to content

Commit

Permalink
added source feature
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Sep 7, 2021
1 parent 0a4e066 commit c59c71b
Show file tree
Hide file tree
Showing 80 changed files with 475 additions and 63 deletions.
2 changes: 2 additions & 0 deletions app/Abstracts/Commands/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ protected function createHistory($action)
'module_id' => $this->model->id,
'version' => $this->module->get('version'),
'description' => trans('modules.' . $action, ['module' => $this->alias]),
'created_from' => source_name(),
'created_by' => user_id(),
]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Abstracts/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function map($row): array
{
$row['company_id'] = company_id();
$row['created_by'] = $this->user->id;
$row['created_from'] = 'import';

// Make enabled field integer
if (isset($row['enabled'])) {
Expand Down
21 changes: 20 additions & 1 deletion app/Abstracts/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

use App\Abstracts\Http\FormRequest;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Interfaces\Job\ShouldDelete;
use App\Interfaces\Job\ShouldUpdate;
use App\Traits\Jobs;
use App\Traits\Relationships;
use App\Traits\Sources;
use App\Traits\Uploads;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

abstract class Job
{
use Jobs, Relationships, Uploads;
use Jobs, Relationships, Sources, Uploads;

protected $model;

Expand Down Expand Up @@ -49,6 +51,10 @@ public function bootCreate(...$arguments): void
if ($this instanceof HasOwner) {
$this->setOwner();
}

if ($this instanceof HasSource) {
$this->setSource();
}
}

public function bootUpdate(...$arguments): void
Expand Down Expand Up @@ -106,4 +112,17 @@ public function setOwner(): void

$this->request->merge(['created_by' => user_id()]);
}

public function setSource(): void
{
if (! $this->request instanceof Request) {
return;
}

if ($this->request->has('created_from')) {
return;
}

$this->request->merge(['created_from' => $this->getSourceName($this->request)]);
}
}
8 changes: 7 additions & 1 deletion app/Abstracts/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Traits\DateTime;
use App\Traits\Owners;
use App\Traits\Sources;
use App\Traits\Tenants;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\Model as Eloquent;
Expand All @@ -14,7 +15,7 @@

abstract class Model extends Eloquent implements Ownable
{
use Cachable, DateTime, Owners, SearchString, SoftDeletes, Sortable, Tenants;
use Cachable, DateTime, Owners, SearchString, SoftDeletes, Sortable, Sources, Tenants;

protected $tenantable = true;

Expand Down Expand Up @@ -211,6 +212,11 @@ public function scopeContact($query, $contacts)
return $query->whereIn($this->table . '.contact_id', (array) $contacts);
}

public function scopeSource($query, $source)
{
return $query->where($this->table . '.created_from', $source);
}

public function scopeIsOwner($query)
{
return $query->where($this->table . '.created_by', user_id());
Expand Down
8 changes: 8 additions & 0 deletions app/Interfaces/Job/HasSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Interfaces\Job;

interface HasSource
{
//
}
4 changes: 3 additions & 1 deletion app/Jobs/Auth/CreateRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace App\Jobs\Auth;

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Auth\Role;

class CreateRole extends Job implements ShouldCreate
class CreateRole extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Role
{
Expand Down
4 changes: 3 additions & 1 deletion app/Jobs/Auth/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace App\Jobs\Auth;

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Events\Auth\UserCreated;
use App\Events\Auth\UserCreating;
use App\Models\Auth\User;
use Illuminate\Support\Facades\Artisan;

class CreateUser extends Job implements ShouldCreate
class CreateUser extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): User
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Banking/CreateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Banking\Account;

class CreateAccount extends Job implements HasOwner, ShouldCreate
class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Account
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Banking/CreateReconciliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Banking\Reconciliation;
use App\Models\Banking\Transaction;

class CreateReconciliation extends Job implements HasOwner, ShouldCreate
class CreateReconciliation extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Reconciliation
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Banking/CreateTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use App\Events\Banking\TransactionCreated;
use App\Events\Banking\TransactionCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Banking\Transaction;

class CreateTransaction extends Job implements HasOwner, ShouldCreate
class CreateTransaction extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Transaction
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Banking/CreateTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Jobs\Banking\CreateTransaction;
use App\Models\Banking\Account;
use App\Models\Banking\Transfer;
use App\Models\Setting\Category;
use App\Traits\Currencies;

class CreateTransfer extends Job implements HasOwner, ShouldCreate
class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate
{
use Currencies;

Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use App\Events\Common\CompanyCreated;
use App\Events\Common\CompanyCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Common\Company;
use Illuminate\Support\Facades\Artisan;

class CreateCompany extends Job implements HasOwner, ShouldCreate
class CreateCompany extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Company
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Auth\User;
use App\Models\Auth\Role;
use App\Models\Common\Contact;
use Illuminate\Support\Str;

class CreateContact extends Job implements HasOwner, ShouldCreate
class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Contact
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Jobs\Common\CreateWidget;
use App\Models\Auth\User;
Expand All @@ -13,7 +14,7 @@
use App\Utilities\Widgets;
use Illuminate\Support\Arr;

class CreateDashboard extends Job implements HasOwner, ShouldCreate
class CreateDashboard extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Dashboard
{
Expand Down
21 changes: 21 additions & 0 deletions app/Jobs/Common/CreateEmailTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Jobs\Common;

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Common\EmailTemplate;

class CreateEmailTemplate extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): EmailTemplate
{
\DB::transaction(function () {
$this->model = EmailTemplate::create($this->request->all());
});

return $this->model;
}
}
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Jobs\Common\CreateItemTaxes;
use App\Models\Common\Item;

class CreateItem extends Job implements HasOwner, ShouldCreate
class CreateItem extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Item
{
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Common/CreateItemTaxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace App\Jobs\Common;

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Common\Item;
use App\Models\Common\ItemTax;

class CreateItemTaxes extends Job implements ShouldCreate
class CreateItemTaxes extends Job implements HasOwner, HasSource, ShouldCreate
{
protected $item;

Expand Down Expand Up @@ -44,6 +46,8 @@ public function handle()
'company_id' => $this->item->company_id,
'item_id' => $this->item->id,
'tax_id' => $tax_id,
'created_from' => $this->request['created_from'],
'created_by' => $this->request['created_by'],
]);
}
});
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Common\Report;

class CreateReport extends Job implements HasOwner, ShouldCreate
class CreateReport extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Report
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Common/CreateWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Common\Widget;

class CreateWidget extends Job implements HasOwner, ShouldCreate
class CreateWidget extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Widget
{
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/Document/CreateDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
use App\Events\Document\DocumentCreated;
use App\Events\Document\DocumentCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Jobs\Document\CreateDocumentItemsAndTotals;
use App\Models\Document\Document;
use Illuminate\Support\Str;

class CreateDocument extends Job implements HasOwner, ShouldCreate
class CreateDocument extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Document
{
Expand Down
6 changes: 5 additions & 1 deletion app/Jobs/Document/CreateDocumentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace App\Jobs\Document;

use App\Abstracts\Job;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
use App\Models\Document\Document;
use App\Models\Document\DocumentHistory;

class CreateDocumentHistory extends Job implements ShouldCreate
class CreateDocumentHistory extends Job implements HasOwner, HasSource, ShouldCreate
{
protected $document;

Expand Down Expand Up @@ -35,6 +37,8 @@ public function handle(): DocumentHistory
'status' => $this->document->status,
'notify' => $this->notify,
'description' => $description,
'created_from' => source_name(),
'created_by' => user_id(),
]);

return $document_history;
Expand Down

0 comments on commit c59c71b

Please sign in to comment.