Merge pull request #1892 from SevanNerse/model-extras

this makes possible adding extra attributes to models
This commit is contained in:
Denis Duliçi 2021-02-26 17:29:15 +03:00 committed by GitHub
commit d824cb2ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 31 deletions

View File

@ -21,6 +21,23 @@ abstract class Model extends Eloquent
'enabled' => 'boolean',
];
public $allAttributes = [
//
];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public static function observe($classes)
{
parent::observe($classes);

View File

@ -49,19 +49,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 +81,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;
}

View File

@ -3,8 +3,8 @@
namespace App\Imports\Purchases;
use App\Abstracts\Import;
use App\Models\Banking\Transaction as Model;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
class Payments extends Import
{

View File

@ -3,8 +3,8 @@
namespace App\Imports\Purchases;
use App\Abstracts\Import;
use App\Models\Common\Contact as Model;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact as Model;
class Vendors extends Import
{

View File

@ -3,8 +3,8 @@
namespace App\Imports\Sales;
use App\Abstracts\Import;
use App\Models\Common\Contact as Model;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact as Model;
class Customers extends Import
{

View File

@ -28,6 +28,10 @@ class Company extends Eloquent
'enabled' => 'boolean',
];
public $allAttributes = [
//
];
/**
* Sortable columns.
*
@ -35,6 +39,19 @@ class Company extends Eloquent
*/
public $sortable = ['name', 'domain', 'email', 'enabled', 'created_at'];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public static function boot()
{
parent::boot();

View File

@ -13,8 +13,6 @@ class Setting extends Eloquent
protected $tenantable = true;
public $timestamps = false;
/**
* Attributes that should be mass-assignable.
*
@ -22,6 +20,25 @@ class Setting extends Eloquent
*/
protected $fillable = ['company_id', 'key', 'value'];
public $allAttributes = [
//
];
public $timestamps = false;
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public function company()
{
return $this->belongsTo('App\Models\Common\Company');