removed invoice/bill status tables

This commit is contained in:
denisdulici
2020-01-11 16:57:32 +03:00
parent b5519004a0
commit 08eb8e75fc
69 changed files with 250 additions and 470 deletions

View File

@ -63,11 +63,6 @@ class Company extends Eloquent
return $this->hasMany('App\Models\Purchase\BillItemTax');
}
public function bill_statuses()
{
return $this->hasMany('App\Models\Purchase\BillStatus');
}
public function bill_totals()
{
return $this->hasMany('App\Models\Purchase\BillTotal');
@ -133,11 +128,6 @@ class Company extends Eloquent
return $this->hasMany('App\Models\Sale\InvoiceItemTax');
}
public function invoice_statuses()
{
return $this->hasMany('App\Models\Sale\InvoiceStatus');
}
public function invoice_totals()
{
return $this->hasMany('App\Models\Sale\InvoiceTotal');

View File

@ -23,7 +23,7 @@ class Bill extends Model
*
* @var array
*/
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'status_label'];
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
@ -32,14 +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', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id'];
protected $fillable = ['company_id', 'bill_number', 'order_number', 'status', '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', 'contact_name', 'amount', 'status.name', 'billed_at', 'due_at', 'bill_status_code'];
public $sortable = ['bill_number', 'contact_name', 'amount', 'status', 'billed_at', 'due_at'];
/**
* Clonable relationships.
@ -83,11 +83,6 @@ class Bill extends Model
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
}
public function status()
{
return $this->belongsTo('App\Models\Purchase\BillStatus', 'bill_status_code', 'code');
}
public function totals()
{
return $this->hasMany('App\Models\Purchase\BillTotal');
@ -110,22 +105,22 @@ class Bill extends Model
public function scopeAccrued($query)
{
return $query->where('bill_status_code', '<>', 'draft');
return $query->where('status', '<>', 'draft');
}
public function scopePaid($query)
{
return $query->where('bill_status_code', '=', 'paid');
return $query->where('status', '=', 'paid');
}
public function scopeNotPaid($query)
{
return $query->where('bill_status_code', '<>', 'paid');
return $query->where('status', '<>', 'paid');
}
public function onCloning($src, $child = null)
{
$this->bill_status_code = 'draft';
$this->status = 'draft';
}
/**
@ -256,4 +251,30 @@ class Bill extends Model
return $paid;
}
/**
* Get the status label.
*
* @return string
*/
public function getLabelAttribute()
{
switch ($this->code) {
case 'paid':
$label = 'success';
break;
case 'delete':
$label = 'danger';
break;
case 'partial':
case 'received':
$label = 'warning';
break;
default:
$label = 'info';
break;
}
return $label;
}
}

View File

@ -17,15 +17,10 @@ class BillHistory extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'bill_id', 'status_code', 'notify', 'description'];
protected $fillable = ['company_id', 'bill_id', 'status', 'notify', 'description'];
public function bill()
{
return $this->belongsTo('App\Models\Purchase\Bill');
}
public function status()
{
return $this->belongsTo('App\Models\Purchase\BillStatus', 'status_code', 'code');
}
}

View File

@ -1,51 +0,0 @@
<?php
namespace App\Models\Purchase;
use App\Abstracts\Model;
class BillStatus extends Model
{
protected $table = 'bill_statuses';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['label'];
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'code'];
/**
* Get the status label.
*
* @return string
*/
public function getLabelAttribute()
{
switch ($this->code) {
case 'paid':
$label = 'success';
break;
case 'delete':
$label = 'danger';
break;
case 'partial':
case 'received':
$label = 'warning';
break;
default:
$label = 'info';
break;
}
return $label;
}
}

View File

@ -23,7 +23,7 @@ class Invoice extends Model
*
* @var array
*/
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'status_label'];
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
@ -32,14 +32,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', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id', 'footer'];
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'status', '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', 'contact_name', 'amount', 'status' , 'invoiced_at', 'due_at', 'invoice_status_code'];
public $sortable = ['invoice_number', 'contact_name', 'amount', 'status' , 'invoiced_at', 'due_at'];
protected $reconciled_amount = [];
@ -90,11 +90,6 @@ class Invoice extends Model
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
}
public function status()
{
return $this->belongsTo('App\Models\Sale\InvoiceStatus', 'invoice_status_code', 'code');
}
public function totals()
{
return $this->hasMany('App\Models\Sale\InvoiceTotal');
@ -117,22 +112,22 @@ class Invoice extends Model
public function scopeAccrued($query)
{
return $query->where('invoice_status_code', '<>', 'draft');
return $query->where('status', '<>', 'draft');
}
public function scopePaid($query)
{
return $query->where('invoice_status_code', '=', 'paid');
return $query->where('status', '=', 'paid');
}
public function scopeNotPaid($query)
{
return $query->where('invoice_status_code', '<>', 'paid');
return $query->where('status', '<>', 'paid');
}
public function onCloning($src, $child = null)
{
$this->invoice_status_code = 'draft';
$this->status = 'draft';
$this->invoice_number = $this->getNextInvoiceNumber();
}
@ -264,4 +259,30 @@ class Invoice extends Model
return $paid;
}
/**
* Get the status label.
*
* @return string
*/
public function getStatusLabelAttribute()
{
switch ($this->status) {
case 'paid':
$label = 'success';
break;
case 'delete':
$label = 'danger';
break;
case 'partial':
case 'sent':
$label = 'warning';
break;
default:
$label = 'info';
break;
}
return $label;
}
}

View File

@ -7,7 +7,6 @@ use App\Traits\Currencies;
class InvoiceHistory extends Model
{
use Currencies;
protected $table = 'invoice_histories';
@ -17,15 +16,10 @@ class InvoiceHistory extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'invoice_id', 'status_code', 'notify', 'description'];
protected $fillable = ['company_id', 'invoice_id', 'status', 'notify', 'description'];
public function invoice()
{
return $this->belongsTo('App\Models\Sale\Invoice');
}
public function status()
{
return $this->belongsTo('App\Models\Sale\InvoiceStatus', 'status_code', 'code');
}
}

View File

@ -1,51 +0,0 @@
<?php
namespace App\Models\Sale;
use App\Abstracts\Model;
class InvoiceStatus extends Model
{
protected $table = 'invoice_statuses';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['label'];
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'code'];
/**
* Get the status label.
*
* @return string
*/
public function getLabelAttribute()
{
switch ($this->code) {
case 'paid':
$label = 'success';
break;
case 'delete':
$label = 'danger';
break;
case 'partial':
case 'sent':
$label = 'warning';
break;
default:
$label = 'info';
break;
}
return $label;
}
}