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

@ -2,19 +2,19 @@
namespace App\Models\Expense;
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;
use App\Traits\Media;
use App\Traits\Recurring;
use Bkwld\Cloner\Cloneable;
use Sofa\Eloquence\Eloquence;
use Date;
class Bill extends Model
{
use Cloneable, Currencies, DateTime, Eloquence, Media, Recurring;
use Cloneable, Currencies, DateTime, Media, Recurring;
protected $table = 'bills';
@ -32,29 +32,14 @@ class Bill extends Model
*
* @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', 'category_id', 'parent_id'];
protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_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'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['bill_number', 'vendor_name', 'amount', 'status.name', 'billed_at', 'due_at', 'bill_status_code'];
/**
* 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 $sortable = ['bill_number', 'contact_name', 'amount', 'status.name', 'billed_at', 'due_at', 'bill_status_code'];
/**
* Clonable relationships.
@ -65,7 +50,12 @@ class Bill 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()
@ -88,11 +78,6 @@ class Bill extends Model
return $this->hasMany('App\Models\Expense\BillItemTax');
}
public function payments()
{
return $this->hasMany('App\Models\Expense\BillPayment');
}
public function recurring()
{
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
@ -108,9 +93,9 @@ class Bill extends Model
return $this->hasMany('App\Models\Expense\BillTotal');
}
public function vendor()
public function transactions()
{
return $this->belongsTo('App\Models\Expense\Vendor');
return $this->hasMany('App\Models\Banking\Transaction', 'document_id');
}
public function scopeDue($query, $date)
@ -120,7 +105,7 @@ class Bill extends Model
public function scopeLatest($query)
{
return $query->orderBy('paid_at', 'desc');
return $query->orderBy('billed_at', 'desc');
}
public function scopeAccrued($query)
@ -238,7 +223,7 @@ class Bill extends Model
if ($this->currency_code == $item->currency_code) {
$amount = (double) $item->amount;
} else {
$default_model = new BillPayment();
$default_model = new Transaction();
$default_model->default_currency_code = $this->currency_code;
$default_model->amount = $item->amount;
$default_model->currency_code = $item->currency_code;
@ -246,13 +231,13 @@ class Bill extends Model
$default_amount = (double) $default_model->getDivideConvertedAmount();
$convert_model = new BillPayment();
$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;