v2 first commit

This commit is contained in:
denisdulici
2019-11-16 10:21:14 +03:00
parent 5b23e9c2c4
commit 6d50fa8442
3075 changed files with 3451681 additions and 65594 deletions

View File

@ -1,83 +0,0 @@
<?php
namespace App\Models\Income;
use App\Models\Model;
use Bkwld\Cloner\Cloneable;
use App\Traits\Currencies;
use Illuminate\Notifications\Notifiable;
use Sofa\Eloquence\Eloquence;
class Customer extends Model
{
use Cloneable, Currencies, Eloquence, 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', 'reference', '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', 'user_id', 'id');
}
public function onCloning($src, $child = null)
{
$this->user_id = null;
}
public function getUnpaidAttribute()
{
$amount = 0;
$invoices = $this->invoices()->accrued()->notPaid()->get();
foreach ($invoices as $invoice) {
$invoice_amount = $invoice->amount - $invoice->paid;
$amount += $this->dynamicConvert(setting('general.default_currency'), $invoice_amount, $invoice->currency_code, $invoice->currency_rate, false);
}
return $amount;
}
}

View File

@ -2,7 +2,8 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
use App\Models\Banking\Transaction;
use App\Models\Setting\Currency;
use App\Traits\Currencies;
use App\Traits\DateTime;
@ -10,12 +11,11 @@ use App\Traits\Incomes;
use App\Traits\Media;
use App\Traits\Recurring;
use Bkwld\Cloner\Cloneable;
use Sofa\Eloquence\Eloquence;
use Date;
class Invoice extends Model
{
use Cloneable, Currencies, DateTime, Eloquence, Incomes, Media, Recurring;
use Cloneable, Currencies, DateTime, Incomes, Media, Recurring;
protected $table = 'invoices';
@ -33,29 +33,14 @@ class Invoice extends Model
*
* @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', 'category_id', 'parent_id'];
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id', 'footer'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['invoice_number', 'customer_name', 'amount', 'status' , 'invoiced_at', 'due_at', 'invoice_status_code'];
/**
* 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 $sortable = ['invoice_number', 'contact_name', 'amount', 'status' , 'invoiced_at', 'due_at', 'invoice_status_code'];
protected $reconciled_amount = [];
@ -68,7 +53,12 @@ class Invoice extends Model
public function category()
{
return $this->belongsTo('App\Models\Setting\Category');
return $this->belongsTo('App\Models\Setting\Category')->withDefault(['name' => trans('general.na')]);
}
public function contact()
{
return $this->belongsTo('App\Models\Common\Contact')->withDefault(['name' => trans('general.na')]);
}
public function currency()
@ -76,11 +66,6 @@ class Invoice extends Model
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function customer()
{
return $this->belongsTo('App\Models\Income\Customer');
}
public function items()
{
return $this->hasMany('App\Models\Income\InvoiceItem');
@ -98,7 +83,7 @@ class Invoice extends Model
public function payments()
{
return $this->hasMany('App\Models\Income\InvoicePayment');
return $this->transactions();
}
public function recurring()
@ -116,6 +101,11 @@ class Invoice extends Model
return $this->hasMany('App\Models\Income\InvoiceTotal');
}
public function transactions()
{
return $this->hasMany('App\Models\Banking\Transaction', 'document_id');
}
public function scopeDue($query, $date)
{
return $query->whereDate('due_at', '=', $date);
@ -123,7 +113,7 @@ class Invoice extends Model
public function scopeLatest($query)
{
return $query->orderBy('paid_at', 'desc');
return $query->orderBy('invoiced_at', 'desc');
}
public function scopeAccrued($query)
@ -242,7 +232,7 @@ class Invoice extends Model
if ($this->currency_code == $item->currency_code) {
$amount = (double) $item->amount;
} else {
$default_model = new InvoicePayment();
$default_model = new Transaction();
$default_model->default_currency_code = $this->currency_code;
$default_model->amount = $item->amount;
$default_model->currency_code = $item->currency_code;
@ -250,13 +240,13 @@ class Invoice extends Model
$default_amount = (double) $default_model->getDivideConvertedAmount();
$convert_model = new InvoicePayment();
$convert_model = new Transaction();
$convert_model->default_currency_code = $item->currency_code;
$convert_model->amount = $default_amount;
$convert_model->currency_code = $this->currency_code;
$convert_model->currency_rate = $currencies[$this->currency_code];
$amount = (double) $convert_model->getDynamicConvertedAmount();
$amount = (double) $convert_model->getAmountConvertedFromCustomDefault();
}
$paid += $amount;

View File

@ -2,7 +2,7 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
use App\Traits\Currencies;
class InvoiceHistory extends Model
@ -24,28 +24,8 @@ class InvoiceHistory extends Model
return $this->belongsTo('App\Models\Income\Invoice');
}
public function item()
{
return $this->belongsTo('App\Models\Common\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

@ -2,13 +2,14 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
use App\Traits\Currencies;
use Bkwld\Cloner\Cloneable;
class InvoiceItem extends Model
{
use Currencies;
use Cloneable, Currencies;
protected $table = 'invoice_items';
@ -17,7 +18,14 @@ class InvoiceItem extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
/**
* Clonable relationships.
*
* @var array
*/
public $cloneable_relations = ['taxes'];
public function invoice()
{

View File

@ -2,7 +2,7 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
use App\Traits\Currencies;
class InvoiceItemTax extends Model

View File

@ -1,109 +0,0 @@
<?php
namespace App\Models\Income;
use App\Models\Model;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Media;
use Date;
class InvoicePayment extends Model
{
use Currencies, DateTime, Media;
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'];
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 invoice()
{
return $this->belongsTo('App\Models\Income\Invoice');
}
public function item()
{
return $this->belongsTo('App\Models\Common\Item');
}
public function tax()
{
return $this->belongsTo('App\Models\Setting\Tax');
}
public function scopeLatest($query)
{
return $query->orderBy('paid_at', 'desc');
}
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = (double) $value;
}
/**
* Convert currency rate to double.
*
* @param string $value
* @return void
*/
public function setCurrencyRateAttribute($value)
{
$this->attributes['currency_rate'] = (double) $value;
}
/**
* Scope paid invoice.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePaid($query)
{
return $query->sum('amount');
}
/**
* Get the current balance.
*
* @return string
*/
public function getAttachmentAttribute($value)
{
if (!empty($value) && !$this->hasMedia('attachment')) {
return $value;
} elseif (!$this->hasMedia('attachment')) {
return false;
}
return $this->getMedia('attachment')->last();
}
public function getDivideConvertedAmount($format = false)
{
return $this->divide($this->amount, $this->currency_code, $this->currency_rate, $format);
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
class InvoiceStatus extends Model
{
@ -32,17 +32,17 @@ class InvoiceStatus extends Model
{
switch ($this->code) {
case 'paid':
$label = 'label-success';
$label = 'success';
break;
case 'delete':
$label = 'label-danger';
$label = 'danger';
break;
case 'partial':
case 'sent':
$label = 'label-warning';
$label = 'warning';
break;
default:
$label = 'bg-aqua';
$label = 'info';
break;
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Income;
use App\Models\Model;
use App\Abstracts\Model;
use App\Models\Setting\Tax;
use App\Traits\DateTime;
@ -34,12 +34,12 @@ class InvoiceTotal extends Model
/**
* Convert amount to double.
*
* @param string $value
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = (double) $value;
$this->attributes['amount'] = (double)$value;
}
/**
@ -53,6 +53,8 @@ class InvoiceTotal extends Model
$percent = 0;
$tax = null;
switch ($this->code) {
case 'discount':
$title = trans($title);
@ -60,22 +62,23 @@ class InvoiceTotal extends Model
break;
case 'tax':
$rate = Tax::where('name', $title)->value('rate');
$tax = Tax::where('name', $title)->first();
if (!empty($rate)) {
$percent = $rate;
if (!empty($tax->rate)) {
$percent = $tax->rate;
}
break;
}
if (!empty($percent)) {
$title .= ' (';
if (setting('general.percent_position', 'after') == 'after') {
$title .= $percent . '%';
if (setting('localisation.percent_position', 'after') == 'after') {
$title .= $this->code == 'discount' ? false : $tax->type == 'fixed' ? $percent : $percent . '%';
} else {
$title .= '%' . $percent;
$title .= $this->code == 'discount' ? false : $tax->type == 'fixed' ? $percent : '%' . $percent;
}
$title .= ')';

View File

@ -1,156 +0,0 @@
<?php
namespace App\Models\Income;
use App\Models\Model;
use App\Models\Setting\Category;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Media;
use App\Traits\Recurring;
use Bkwld\Cloner\Cloneable;
use Sofa\Eloquence\Eloquence;
use Date;
class Revenue extends Model
{
use Cloneable, Currencies, DateTime, Eloquence, Media, Recurring;
protected $table = 'revenues';
protected $dates = ['deleted_at', 'paid_at'];
/**
* 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', 'parent_id'];
/**
* 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,
];
/**
* Clonable relationships.
*
* @var array
*/
public $cloneable_relations = ['recurring'];
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 recurring()
{
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
}
public function transfers()
{
return $this->hasMany('App\Models\Banking\Transfer');
}
/**
* Get only transfers.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsTransfer($query)
{
return $query->where('category_id', '=', Category::transfer());
}
/**
* Skip transfers.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsNotTransfer($query)
{
return $query->where('category_id', '<>', Category::transfer());
}
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = (double) $value;
}
/**
* Convert currency rate to double.
*
* @param string $value
* @return void
*/
public function setCurrencyRateAttribute($value)
{
$this->attributes['currency_rate'] = (double) $value;
}
public function scopeLatest($query)
{
return $query->orderBy('paid_at', 'desc');
}
/**
* Get the current balance.
*
* @return string
*/
public function getAttachmentAttribute($value)
{
if (!empty($value) && !$this->hasMedia('attachment')) {
return $value;
} elseif (!$this->hasMedia('attachment')) {
return false;
}
return $this->getMedia('attachment')->last();
}
}