this makes possible adding extra attributes to models
This commit is contained in:
parent
19093668ec
commit
962e626c9e
@ -21,6 +21,10 @@ abstract class Model extends Eloquent
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
|
||||
public $extras = [
|
||||
//
|
||||
];
|
||||
|
||||
public static function observe($classes)
|
||||
{
|
||||
parent::observe($classes);
|
||||
|
24
app/Events/Common/ModelCreated.php
Normal file
24
app/Events/Common/ModelCreated.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ModelCreated extends Event
|
||||
{
|
||||
public $model;
|
||||
|
||||
public $attributes;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $model
|
||||
* @param $attributes
|
||||
*/
|
||||
public function __construct($model, $attributes)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Banking;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
|
||||
@ -10,7 +11,11 @@ class Transactions extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Banking;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer as Model;
|
||||
use App\Models\Setting\Category;
|
||||
@ -15,7 +16,11 @@ class Transfers extends Import
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
@ -49,19 +54,19 @@ class Transfers extends Import
|
||||
private function getExpenseTransactionId($row)
|
||||
{
|
||||
$expense_transaction = Transaction::create([
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'expense',
|
||||
'account_id' => $row['from_account_id'],
|
||||
'paid_at' => $row['transferred_at'],
|
||||
'currency_code' => $row['from_currency_code'],
|
||||
'currency_rate' => $row['from_currency_rate'],
|
||||
'amount' => $row['amount'],
|
||||
'contact_id' => 0,
|
||||
'description' => $row['description'],
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $row['payment_method'],
|
||||
'reference' => $row['reference'],
|
||||
]);
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'expense',
|
||||
'account_id' => $row['from_account_id'],
|
||||
'paid_at' => $row['transferred_at'],
|
||||
'currency_code' => $row['from_currency_code'],
|
||||
'currency_rate' => $row['from_currency_rate'],
|
||||
'amount' => $row['amount'],
|
||||
'contact_id' => 0,
|
||||
'description' => $row['description'],
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $row['payment_method'],
|
||||
'reference' => $row['reference'],
|
||||
]);
|
||||
|
||||
return $expense_transaction->id;
|
||||
}
|
||||
@ -81,19 +86,19 @@ class Transfers extends Import
|
||||
}
|
||||
|
||||
$income_transaction = Transaction::create([
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'income',
|
||||
'account_id' => $row['to_account_id'],
|
||||
'paid_at' => $row['transferred_at'],
|
||||
'currency_code' => $row['to_currency_code'],
|
||||
'currency_rate' => $row['to_currency_rate'],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $row['description'],
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $row['payment_method'],
|
||||
'reference' => $row['reference'],
|
||||
]);
|
||||
'company_id' => session('company_id'),
|
||||
'type' => 'income',
|
||||
'account_id' => $row['to_account_id'],
|
||||
'paid_at' => $row['transferred_at'],
|
||||
'currency_code' => $row['to_currency_code'],
|
||||
'currency_rate' => $row['to_currency_rate'],
|
||||
'amount' => $amount,
|
||||
'contact_id' => 0,
|
||||
'description' => $row['description'],
|
||||
'category_id' => Category::transfer(), // Transfer Category ID
|
||||
'payment_method' => $row['payment_method'],
|
||||
'reference' => $row['reference'],
|
||||
]);
|
||||
|
||||
return $income_transaction->id;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Common\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Common\Item as Request;
|
||||
use App\Models\Common\Item as Model;
|
||||
|
||||
@ -10,7 +11,11 @@ class Items extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,14 +3,19 @@
|
||||
namespace App\Imports\Purchases;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
|
||||
class Payments extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Document\DocumentItem as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
@ -11,7 +12,11 @@ class BillItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Document\Document as Request;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Illuminate\Support\Str;
|
||||
@ -11,7 +12,11 @@ class Bills extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,14 +3,19 @@
|
||||
namespace App\Imports\Purchases;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Common\Contact as Model;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Common\Contact as Request;
|
||||
use App\Models\Common\Contact as Model;
|
||||
|
||||
class Vendors extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,14 +3,19 @@
|
||||
namespace App\Imports\Sales;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Common\Contact as Model;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Common\Contact as Request;
|
||||
use App\Models\Common\Contact as Model;
|
||||
|
||||
class Customers extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Sales;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Models\Banking\Transaction as Model;
|
||||
|
||||
@ -10,7 +11,11 @@ class Revenues extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Document\DocumentItem as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
@ -11,7 +12,11 @@ class InvoiceItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Sales\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Document\Document as Request;
|
||||
use App\Models\Document\Document as Model;
|
||||
use Illuminate\Support\Str;
|
||||
@ -11,7 +12,11 @@ class Invoices extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Imports\Settings;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Events\Common\ModelCreated;
|
||||
use App\Http\Requests\Setting\Category as Request;
|
||||
use App\Models\Setting\Category as Model;
|
||||
|
||||
@ -10,7 +11,11 @@ class Categories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
$model = new Model($row);
|
||||
|
||||
event(new ModelCreated($model, $row));
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
|
@ -28,6 +28,10 @@ class Company extends Eloquent
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
|
||||
public $extras = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
|
@ -13,8 +13,6 @@ class Setting extends Eloquent
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
@ -22,6 +20,12 @@ class Setting extends Eloquent
|
||||
*/
|
||||
protected $fillable = ['company_id', 'key', 'value'];
|
||||
|
||||
public $extras = [
|
||||
//
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Company');
|
||||
|
Loading…
x
Reference in New Issue
Block a user