first commit
This commit is contained in:
70
app/Models/Auth/Permission.php
Normal file
70
app/Models/Auth/Permission.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use EloquentFilter\Filterable;
|
||||
use Laratrust\LaratrustPermission;
|
||||
use Laratrust\Traits\LaratrustPermissionTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
use Request;
|
||||
use Route;
|
||||
|
||||
class Permission extends LaratrustPermission
|
||||
{
|
||||
use LaratrustPermissionTrait;
|
||||
use Filterable;
|
||||
use Sortable;
|
||||
|
||||
|
||||
protected $table = 'permissions';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name', 'display_name', 'description'];
|
||||
|
||||
/**
|
||||
* Define the filter provider globally.
|
||||
*
|
||||
* @return ModelFilter
|
||||
*/
|
||||
public function modelFilter()
|
||||
{
|
||||
// Check if is api or web
|
||||
if (Request::is('api/*')) {
|
||||
$arr = array_reverse(explode('\\', explode('@', app()['api.router']->currentRouteAction())[0]));
|
||||
$folder = $arr[1];
|
||||
$file = $arr[0];
|
||||
} else {
|
||||
list($folder, $file) = explode('/', Route::current()->uri());
|
||||
}
|
||||
|
||||
if (empty($folder) || empty($file)) {
|
||||
return $this->provideFilter();
|
||||
}
|
||||
|
||||
$class = '\App\Filters\\' . ucfirst($folder) .'\\' . ucfirst($file);
|
||||
|
||||
return $this->provideFilter($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get all rows filtered, sorted and paginated.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $sort
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCollect($query, $sort = 'display_name')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$input = $request->input();
|
||||
$limit = $request->get('limit', setting('general.list_limit', '25'));
|
||||
|
||||
return $this->filter($input)->sortable($sort)->paginate($limit);
|
||||
}
|
||||
}
|
69
app/Models/Auth/Role.php
Normal file
69
app/Models/Auth/Role.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use EloquentFilter\Filterable;
|
||||
use Laratrust\LaratrustRole;
|
||||
use Laratrust\Traits\LaratrustRoleTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
use Request;
|
||||
use Route;
|
||||
|
||||
class Role extends LaratrustRole
|
||||
{
|
||||
use LaratrustRoleTrait;
|
||||
use Filterable;
|
||||
use Sortable;
|
||||
|
||||
protected $table = 'roles';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name', 'display_name', 'description'];
|
||||
|
||||
/**
|
||||
* Define the filter provider globally.
|
||||
*
|
||||
* @return ModelFilter
|
||||
*/
|
||||
public function modelFilter()
|
||||
{
|
||||
// Check if is api or web
|
||||
if (Request::is('api/*')) {
|
||||
$arr = array_reverse(explode('\\', explode('@', app()['api.router']->currentRouteAction())[0]));
|
||||
$folder = $arr[1];
|
||||
$file = $arr[0];
|
||||
} else {
|
||||
list($folder, $file) = explode('/', Route::current()->uri());
|
||||
}
|
||||
|
||||
if (empty($folder) || empty($file)) {
|
||||
return $this->provideFilter();
|
||||
}
|
||||
|
||||
$class = '\App\Filters\\' . ucfirst($folder) .'\\' . ucfirst($file);
|
||||
|
||||
return $this->provideFilter($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get all rows filtered, sorted and paginated.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $sort
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCollect($query, $sort = 'display_name')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$input = $request->input();
|
||||
$limit = $request->get('limit', setting('general.list_limit', '25'));
|
||||
|
||||
return $this->filter($input)->sortable($sort)->paginate($limit);
|
||||
}
|
||||
}
|
184
app/Models/Auth/User.php
Normal file
184
app/Models/Auth/User.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Notifications\Auth\Reset;
|
||||
use Date;
|
||||
use EloquentFilter\Filterable;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Hash;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
use Request;
|
||||
use Route;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
use Filterable;
|
||||
use Sortable;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['name', 'email', 'password', 'locale', 'picture'];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['last_logged_in_at', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
public function companies()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Company\Company', 'user', 'user_companies', 'user_id', 'company_id');
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->hasOne('App\Models\Income\Customer', 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Always capitalize the name when we retrieve it
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
return ucfirst($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always return a valid picture when we retrieve it
|
||||
*/
|
||||
public function getPictureAttribute($value)
|
||||
{
|
||||
$pic = '';
|
||||
|
||||
if (is_file(base_path($value))) {
|
||||
$pic = $value;
|
||||
} elseif (setting('general.use_gravatar', '0') == '1') {
|
||||
// Check for gravatar
|
||||
$url = 'https://www.gravatar.com/avatar/' . md5(strtolower($this->getAttribute('email'))).'?size=90&d=404';
|
||||
|
||||
$client = new \GuzzleHttp\Client(['verify' => false]);
|
||||
|
||||
try {
|
||||
$pic = $client->request('GET', $url)->getBody()->getContents();
|
||||
} catch (RequestException $e) {
|
||||
// 404 Not Found
|
||||
}
|
||||
}
|
||||
|
||||
return $pic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always return a valid picture when we retrieve it
|
||||
*/
|
||||
public function getLastLoggedInAtAttribute($value)
|
||||
{
|
||||
// Date::setLocale('tr');
|
||||
|
||||
if (!empty($value)) {
|
||||
return Date::parse($value)->diffForHumans();
|
||||
} else {
|
||||
return trans('auth.never');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send reset link to user via email
|
||||
*/
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new Reset($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Always capitalize the name when we save it to the database
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = ucfirst($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always hash the password when we save it to the database
|
||||
*/
|
||||
public function setPasswordAttribute($value)
|
||||
{
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the filter provider globally.
|
||||
*
|
||||
* @return ModelFilter
|
||||
*/
|
||||
public function modelFilter()
|
||||
{
|
||||
// Check if is api or web
|
||||
if (Request::is('api/*')) {
|
||||
$arr = array_reverse(explode('\\', explode('@', app()['api.router']->currentRouteAction())[0]));
|
||||
$folder = $arr[1];
|
||||
$file = $arr[0];
|
||||
} else {
|
||||
list($folder, $file) = explode('/', Route::current()->uri());
|
||||
}
|
||||
|
||||
if (empty($folder) || empty($file)) {
|
||||
return $this->provideFilter();
|
||||
}
|
||||
|
||||
//$class = '\App\Filters\Auth\Users';
|
||||
|
||||
$class = '\App\Filters\\' . ucfirst($folder) . '\\' . ucfirst($file);
|
||||
|
||||
return $this->provideFilter($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get all rows filtered, sorted and paginated.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $sort
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCollect($query, $sort = 'name')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$input = $request->input();
|
||||
$limit = $request->get('limit', setting('general.list_limit', '25'));
|
||||
|
||||
return $this->filter($input)->sortable($sort)->paginate($limit);
|
||||
}
|
||||
}
|
136
app/Models/Banking/Account.php
Normal file
136
app/Models/Banking/Account.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Banking;
|
||||
|
||||
use App\Models\Model;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Account extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
|
||||
protected $table = 'accounts';
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['balance'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'number', 'currency_code', 'opening_balance', 'bank_name', 'bank_phone', 'bank_address', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'number', 'opening_balance', 'enabled'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'number' => 10,
|
||||
'bank_name' => 10,
|
||||
'bank_phone' => 5,
|
||||
'bank_address' => 2,
|
||||
];
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function invoice_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoicePayment');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function bill_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$bill_payments = $this->bill_payments();
|
||||
if ($bill_payments->count()) {
|
||||
$error['bills'] = $bill_payments->count();
|
||||
}
|
||||
|
||||
$payments = $this->payments();
|
||||
if ($payments->count()) {
|
||||
$error['payments'] = $payments->count();
|
||||
}
|
||||
|
||||
$invoice_payments = $this->invoice_payments();
|
||||
if ($invoice_payments->count()) {
|
||||
$error['invoices'] = $invoice_payments->count();
|
||||
}
|
||||
|
||||
$revenues = $this->revenues();
|
||||
if ($revenues->count()) {
|
||||
$error['revenues'] = $revenues->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBalanceAttribute()
|
||||
{
|
||||
// Opening Balance
|
||||
$total = $this->opening_balance;
|
||||
|
||||
// Sum invoices
|
||||
foreach ($this->invoice_payments as $item) {
|
||||
$total += $item->amount;
|
||||
}
|
||||
|
||||
// Sum revenues
|
||||
foreach ($this->revenues as $item) {
|
||||
$total += $item->amount;
|
||||
}
|
||||
|
||||
// Subtract bills
|
||||
foreach ($this->bill_payments as $item) {
|
||||
$total -= $item->amount;
|
||||
}
|
||||
|
||||
// Subtract payments
|
||||
foreach ($this->payments as $item) {
|
||||
$total -= $item->amount;
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
92
app/Models/Banking/Transaction.php
Normal file
92
app/Models/Banking/Transaction.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Banking;
|
||||
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\Revenue;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Transaction extends Model
|
||||
{
|
||||
public static function getUserTransactions($user_id, $type)
|
||||
{
|
||||
$transactions = array();
|
||||
|
||||
switch ($type) {
|
||||
case 'payments':
|
||||
$bills = Bill::where('vendor_id', $user_id)->get();
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
$bill_payments = $bill->payments;
|
||||
|
||||
if ($bill_payments) {
|
||||
foreach ($bill_payments as $bill_payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $bill_payment->paid_at,
|
||||
'account' => $bill_payment->account->name,
|
||||
'type' => trans('invoices.status.partial'),
|
||||
'category' => trans_choice('general.invoices', 1),
|
||||
'description' => $bill_payment->description,
|
||||
'amount' => $bill_payment->amount,
|
||||
'currency_code' => $bill_payment->currency_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payments = Payment::where('vendor_id', $user_id)->get();
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $payment->paid_at,
|
||||
'account' => $payment->account->name,
|
||||
'type' => 'Expense',
|
||||
'category' => $payment->category->name,
|
||||
'description' => $payment->description,
|
||||
'amount' => $payment->amount,
|
||||
'currency_code' => $payment->currency_code,
|
||||
];
|
||||
}
|
||||
break;
|
||||
case 'revenues':
|
||||
$invoices = Invoice::where('customer_id', $user_id)->get();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$invoice_payments = $invoice->payments;
|
||||
|
||||
if ($invoice_payments) {
|
||||
foreach ($invoice_payments as $invoice_payment) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $invoice_payment->paid_at,
|
||||
'account' => $invoice_payment->account->name,
|
||||
'type' => trans('invoices.status.partial'),
|
||||
'category' => trans_choice('general.invoices', 1),
|
||||
'description' => $invoice_payment->description,
|
||||
'amount' => $invoice_payment->amount,
|
||||
'currency_code' => $invoice_payment->currency_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$revenues = Revenue::where('customer_id', $user_id)->get();
|
||||
|
||||
foreach ($revenues as $revenue) {
|
||||
$transactions[] = (object) [
|
||||
'date' => $revenue->paid_at,
|
||||
'account' => $revenue->account->name,
|
||||
'type' => trans_choice('general.payments', 1),
|
||||
'category' => $revenue->category->name,
|
||||
'description' => $revenue->description,
|
||||
'amount' => $revenue->amount,
|
||||
'currency_code' => $revenue->currency_code,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
}
|
52
app/Models/Banking/Transfer.php
Normal file
52
app/Models/Banking/Transfer.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Banking;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class Transfer extends Model
|
||||
{
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'transfers';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'payment_id', 'revenue_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['payment.paid_at', 'payment.amount', 'payment.name', 'revenue.name'];
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Payment');
|
||||
}
|
||||
|
||||
public function paymentAccount()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account', 'payment.account_id', 'id');
|
||||
}
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function revenueAccount()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account', 'revenue.account_id', 'id');
|
||||
}
|
||||
|
||||
public function getDynamicConvertedAmount($format = false)
|
||||
{
|
||||
return $this->dynamicConvert($this->default_currency_code, $this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
}
|
199
app/Models/Company/Company.php
Normal file
199
app/Models/Company/Company.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Company;
|
||||
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
|
||||
class Company extends Eloquent
|
||||
{
|
||||
use Filterable, SoftDeletes, Sortable;
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = ['domain'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['domain'];
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function bill_histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillHistory');
|
||||
}
|
||||
|
||||
public function bill_items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItem');
|
||||
}
|
||||
|
||||
public function bill_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
}
|
||||
|
||||
public function bill_statuses()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillStatus');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Category');
|
||||
}
|
||||
|
||||
public function currencies()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Currency');
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Customer');
|
||||
}
|
||||
|
||||
public function invoice_histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceHistory');
|
||||
}
|
||||
|
||||
public function invoice_items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function invoice_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoicePayment');
|
||||
}
|
||||
|
||||
public function invoice_statuses()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceStatus');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function settings()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Setting');
|
||||
}
|
||||
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Transfer');
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->morphedByMany('App\Models\Auth\User', 'user', 'user_companies', 'company_id', 'user_id');
|
||||
}
|
||||
|
||||
public function vendors()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Vendor');
|
||||
}
|
||||
|
||||
public function setSettings()
|
||||
{
|
||||
$settings = $this->settings;
|
||||
|
||||
foreach ($settings as $setting) {
|
||||
list($group, $key) = explode('.', $setting->getAttribute('key'));
|
||||
|
||||
// Load only general settings
|
||||
if ($group != 'general') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $setting->getAttribute('value');
|
||||
|
||||
if (($key == 'company_logo') && empty($value)) {
|
||||
$value = 'public/img/company.png';
|
||||
}
|
||||
|
||||
$this->setAttribute($key, $value);
|
||||
}
|
||||
|
||||
// Set default default company logo if empty
|
||||
if ($this->getAttribute('company_logo') == '') {
|
||||
$this->setAttribute('company_logo', 'public/img/company.png');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the filter provider globally.
|
||||
*
|
||||
* @return ModelFilter
|
||||
*/
|
||||
public function modelFilter()
|
||||
{
|
||||
list($folder, $file) = explode('/', \Route::current()->uri());
|
||||
|
||||
if (empty($folder) || empty($file)) {
|
||||
return $this->provideFilter();
|
||||
}
|
||||
|
||||
$class = '\App\Filters\\' . ucfirst($folder) .'\\' . ucfirst($file);
|
||||
|
||||
return $this->provideFilter($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get all rows filtered, sorted and paginated.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $sort
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCollect($query, $sort = 'name')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$input = $request->input();
|
||||
$limit = $request->get('limit', setting('general.list_limit', '25'));
|
||||
|
||||
return $this->filter($input)->sortable($sort)->paginate($limit);
|
||||
}
|
||||
}
|
91
app/Models/Expense/Bill.php
Normal file
91
app/Models/Expense/Bill.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Bill extends Model
|
||||
{
|
||||
use Currencies, DateTime, Eloquence;
|
||||
|
||||
protected $table = 'bills';
|
||||
|
||||
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'vendor_name', 'vendor_email', 'vendor_tax_number', 'vendor_phone', 'vendor_address', 'notes', 'attachment'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['bill_number', 'vendor_name', 'amount', 'status.name', 'billed_at', 'due_at'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'bill_number' => 10,
|
||||
'order_number' => 10,
|
||||
'vendor_name' => 10,
|
||||
'vendor_email' => 5,
|
||||
'vendor_phone' => 2,
|
||||
'vendor_address' => 1,
|
||||
'notes' => 2,
|
||||
];
|
||||
|
||||
public function vendor()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Vendor');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\BillStatus', 'bill_status_code', 'code');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\BillItem', 'id', 'bill_id');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItem');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\BillPayment', 'id', 'bill_id');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillHistory');
|
||||
}
|
||||
|
||||
public function scopeDue($query, $date)
|
||||
{
|
||||
return $query->where('due_at', '=', $date);
|
||||
}
|
||||
}
|
51
app/Models/Expense/BillHistory.php
Normal file
51
app/Models/Expense/BillHistory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class BillHistory extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'bill_histories';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'status_code', 'notify', 'description'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Payment');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\BillStatus', 'status_code', 'code');
|
||||
}
|
||||
|
||||
public function getConvertedAmount($format = false)
|
||||
{
|
||||
return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
}
|
36
app/Models/Expense/BillItem.php
Normal file
36
app/Models/Expense/BillItem.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class BillItem extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'bill_items';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax', 'tax_id'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
}
|
48
app/Models/Expense/BillPayment.php
Normal file
48
app/Models/Expense/BillPayment.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class BillPayment extends Model
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $table = 'bill_payments';
|
||||
|
||||
protected $dates = ['deleted_at', 'paid_at'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference', 'attachment'];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function scopeLatest($query)
|
||||
{
|
||||
return $query->orderBy('paid_at', 'desc');
|
||||
}
|
||||
}
|
18
app/Models/Expense/BillStatus.php
Normal file
18
app/Models/Expense/BillStatus.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class BillStatus extends Model
|
||||
{
|
||||
|
||||
protected $table = 'bill_statuses';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code'];
|
||||
}
|
71
app/Models/Expense/Payment.php
Normal file
71
app/Models/Expense/Payment.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
use Currencies, DateTime, Eloquence;
|
||||
|
||||
protected $table = 'payments';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'vendor_id', 'description', 'category_id', 'payment_method', 'reference', 'attachment'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['paid_at', 'amount', 'category.name', 'account.name'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'accounts.name',
|
||||
'categories.name',
|
||||
'vendors.name' ,
|
||||
'description' ,
|
||||
];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Category');
|
||||
}
|
||||
|
||||
public function vendor()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Vendor');
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Transfer');
|
||||
}
|
||||
|
||||
public static function scopeLatest($query)
|
||||
{
|
||||
return $query->orderBy('paid_at', 'desc');
|
||||
}
|
||||
}
|
76
app/Models/Expense/Vendor.php
Normal file
76
app/Models/Expense/Vendor.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Vendor extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
|
||||
protected $table = 'vendors';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'email', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'email', 'phone', 'enabled'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'email' => 5,
|
||||
'phone' => 2,
|
||||
'website' => 2,
|
||||
'address' => 1,
|
||||
];
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payments');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$bills = $this->bills();
|
||||
if ($bills->count()) {
|
||||
$error['bills'] = $bills->count();
|
||||
}
|
||||
|
||||
$payments = $this->payments();
|
||||
if ($payments->count()) {
|
||||
$error['payments'] = $payments->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
83
app/Models/Income/Customer.php
Normal file
83
app/Models/Income/Customer.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
use Notifiable;
|
||||
|
||||
protected $table = 'customers';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'user_id', 'name', 'email', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'email', 'phone', 'enabled'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'email' => 5,
|
||||
'phone' => 2,
|
||||
'website' => 2,
|
||||
'address' => 1,
|
||||
];
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$invoices = $this->invoices();
|
||||
if ($invoices->count()) {
|
||||
$error['invoices'] = $invoices->count();
|
||||
}
|
||||
|
||||
$revenues = $this->revenues();
|
||||
if ($revenues->count()) {
|
||||
$error['revenues'] = $revenues->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
96
app/Models/Income/Invoice.php
Normal file
96
app/Models/Income/Invoice.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use Currencies, DateTime, Eloquence;
|
||||
|
||||
protected $table = 'invoices';
|
||||
|
||||
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'customer_name', 'customer_email', 'customer_tax_number', 'customer_phone', 'customer_address', 'notes', 'attachment'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['invoice_number', 'customer_name', 'amount', 'status' , 'invoiced_at', 'due_at'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'invoice_number' => 10,
|
||||
'order_number' => 10,
|
||||
'customer_name' => 10,
|
||||
'customer_email' => 5,
|
||||
'customer_phone' => 2,
|
||||
'customer_address' => 1,
|
||||
'notes' => 2,
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Customer');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\InvoiceStatus', 'invoice_status_code', 'code');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\InvoiceItem', 'id', 'invoice_id');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\InvoicePayment', 'id', 'invoice_id');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoicePayment');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceHistory');
|
||||
}
|
||||
|
||||
public function scopeDue($query, $date)
|
||||
{
|
||||
return $query->where('due_at', '=', $date);
|
||||
}
|
||||
}
|
51
app/Models/Income/InvoiceHistory.php
Normal file
51
app/Models/Income/InvoiceHistory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class InvoiceHistory extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'invoice_histories';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'status_code', 'notify', 'description'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Payment');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\InvoiceStatus', 'status_code', 'code');
|
||||
}
|
||||
|
||||
public function getConvertedAmount($format = false)
|
||||
{
|
||||
return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
}
|
36
app/Models/Income/InvoiceItem.php
Normal file
36
app/Models/Income/InvoiceItem.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class InvoiceItem extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'invoice_items';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax', 'tax_id'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
}
|
48
app/Models/Income/InvoicePayment.php
Normal file
48
app/Models/Income/InvoicePayment.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class InvoicePayment extends Model
|
||||
{
|
||||
use Currencies, DateTime;
|
||||
|
||||
protected $table = 'invoice_payments';
|
||||
|
||||
protected $dates = ['deleted_at', 'paid_at'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'description', 'payment_method', 'reference', 'attachment'];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function scopeLatest($query)
|
||||
{
|
||||
return $query->orderBy('paid_at', 'desc');
|
||||
}
|
||||
}
|
18
app/Models/Income/InvoiceStatus.php
Normal file
18
app/Models/Income/InvoiceStatus.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class InvoiceStatus extends Model
|
||||
{
|
||||
|
||||
protected $table = 'invoice_statuses';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code'];
|
||||
}
|
77
app/Models/Income/Revenue.php
Normal file
77
app/Models/Income/Revenue.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Revenue extends Model
|
||||
{
|
||||
use Currencies, DateTime, Eloquence;
|
||||
|
||||
protected $table = 'revenues';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference', 'attachment'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['paid_at', 'amount','category_id', 'account', 'payment_method'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'invoice_number' => 10,
|
||||
'order_number' => 10,
|
||||
'customer_name' => 10,
|
||||
'customer_email' => 5,
|
||||
'notes' => 2,
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Category');
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Customer');
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Transfer');
|
||||
}
|
||||
|
||||
public function scopeLatest($query)
|
||||
{
|
||||
return $query->orderBy('paid_at', 'desc');
|
||||
}
|
||||
}
|
121
app/Models/Item/Item.php
Normal file
121
app/Models/Item/Item.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Item;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Traits\Currencies;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
use Currencies, Eloquence;
|
||||
|
||||
protected $table = 'items';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'sku', 'description', 'sale_price', 'purchase_price', 'quantity', 'category_id', 'tax_id', 'picture', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sortable = ['name', 'category_id', 'quantity', 'sale_price', 'purchase_price', 'enabled'];
|
||||
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'sku' => 5,
|
||||
'description' => 2,
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Category');
|
||||
}
|
||||
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function getConvertedAmount($format = false)
|
||||
{
|
||||
return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
|
||||
public function getReverseConvertedAmount($format = false)
|
||||
{
|
||||
return $this->reverseConvert($this->amount, $this->currency_code, $this->currency_rate, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always return a valid picture when we retrieve it
|
||||
*/
|
||||
public function getPictureAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return 'public/img/akaunting-logo-green.png';
|
||||
}
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$bills = $this->bills();
|
||||
if ($bills->count()) {
|
||||
$error['bills'] = $bills->count();
|
||||
}
|
||||
|
||||
$invoices = $this->invoices();
|
||||
if ($invoices->count()) {
|
||||
$error['invoices'] = $invoices->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getItems($filter_data = array())
|
||||
{
|
||||
if (empty($filter_data)) {
|
||||
return Item::all();
|
||||
}
|
||||
|
||||
$query = Item::select('id as item_id', 'name', 'sale_price', 'purchase_price', 'tax_id');
|
||||
|
||||
$query->where('quantity', '>', '0');
|
||||
|
||||
foreach ($filter_data as $key => $value) {
|
||||
$query->where($key, 'LIKE', "%" . $value . "%");
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
107
app/Models/Model.php
Normal file
107
app/Models/Model.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
use Request;
|
||||
use Route;
|
||||
|
||||
class Model extends Eloquent
|
||||
{
|
||||
use Filterable, SoftDeletes, Sortable;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* The "booting" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope(new Company);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global company relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Company\Company');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the filter provider globally.
|
||||
*
|
||||
* @return ModelFilter
|
||||
*/
|
||||
public function modelFilter()
|
||||
{
|
||||
// Check if is api or web
|
||||
if (Request::is('api/*')) {
|
||||
$arr = array_reverse(explode('\\', explode('@', app()['api.router']->currentRouteAction())[0]));
|
||||
$folder = $arr[1];
|
||||
$file = $arr[0];
|
||||
} else {
|
||||
list($folder, $file) = explode('/', Route::current()->uri());
|
||||
}
|
||||
|
||||
if (empty($folder) || empty($file)) {
|
||||
return $this->provideFilter();
|
||||
}
|
||||
|
||||
$class = '\App\Filters\\' . ucfirst($folder) . '\\' . ucfirst($file);
|
||||
|
||||
return $this->provideFilter($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include company data.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $company_id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCompanyId($query, $company_id)
|
||||
{
|
||||
return $query->where($this->table . '.company_id', '=', $company_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get all rows filtered, sorted and paginated.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $sort
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCollect($query, $sort = 'name')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$input = $request->input();
|
||||
$limit = $request->get('limit', setting('general.list_limit', '25'));
|
||||
|
||||
return $this->filter($input)->sortable($sort)->paginate($limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include active currencies.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeEnabled($query)
|
||||
{
|
||||
return $query->where('enabled', 1);
|
||||
}
|
||||
}
|
20
app/Models/Module/Module.php
Normal file
20
app/Models/Module/Module.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Module;
|
||||
|
||||
use App\Models\Model;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Module extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
|
||||
protected $table = 'modules';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'alias', 'status'];
|
||||
}
|
18
app/Models/Module/ModuleHistory.php
Normal file
18
app/Models/Module/ModuleHistory.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Module;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class ModuleHistory extends Model
|
||||
{
|
||||
|
||||
protected $table = 'module_histories';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'module_id', 'category', 'version', 'description'];
|
||||
}
|
80
app/Models/Setting/Category.php
Normal file
80
app/Models/Setting/Category.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Item\Item;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Revenue;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $table = 'categories';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'type', 'enabled'];
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment');
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$items = $this->items();
|
||||
if ($items->count()) {
|
||||
$error['items'] = $items->count();
|
||||
}
|
||||
|
||||
$payments = $this->payments();
|
||||
if ($payments->count()) {
|
||||
$error['payments'] = $payments->count();
|
||||
}
|
||||
|
||||
$revenues = $this->revenues();
|
||||
if ($revenues->count()) {
|
||||
$error['revenues'] = $revenues->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include categories of a given type.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param mixed $type
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeType($query, $type)
|
||||
{
|
||||
return $query->where('type', $type);
|
||||
}
|
||||
}
|
55
app/Models/Setting/Currency.php
Normal file
55
app/Models/Setting/Currency.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class Currency extends Model
|
||||
{
|
||||
|
||||
protected $table = 'currencies';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'code', 'rate', 'enabled'];
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany('App\Models\Banking\Account');
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Customer');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill', 'code', 'currency_code');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Payment', 'code', 'currency_code');
|
||||
}
|
||||
}
|
59
app/Models/Setting/Setting.php
Normal file
59
app/Models/Setting/Setting.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Scopes\Company;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'key', 'value'];
|
||||
|
||||
/**
|
||||
* The "booting" method of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope(new Company);
|
||||
}
|
||||
|
||||
public static function all($code = 'general')
|
||||
{
|
||||
return static::where('key', 'like', $code . '.%')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global company relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Company\Company');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include company data.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $company_id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCompanyId($query, $company_id)
|
||||
{
|
||||
return $query->where($this->table . '.company_id', '=', $company_id);
|
||||
}
|
||||
}
|
69
app/Models/Setting/Tax.php
Normal file
69
app/Models/Setting/Tax.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Item\Item;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Income\Invoice;
|
||||
|
||||
class Tax extends Model
|
||||
{
|
||||
|
||||
protected $table = 'taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'rate', 'enabled'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['name', 'rate', 'enabled'];
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$items = $this->items();
|
||||
if ($items->count()) {
|
||||
$error['items'] = $items->count();
|
||||
}
|
||||
|
||||
$bills = $this->bills();
|
||||
if ($bills->count()) {
|
||||
$error['bills'] = $bills->count();
|
||||
}
|
||||
|
||||
$invoices = $this->invoices();
|
||||
if ($invoices->count()) {
|
||||
$error['invoices'] = $invoices->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user