first commit

This commit is contained in:
denisdulici
2017-09-14 22:21:00 +03:00
commit 515bdaf5cd
598 changed files with 48030 additions and 0 deletions

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

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

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

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

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

View 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'];
}

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