fixes on invoices relations and revisions
This commit is contained in:
@@ -13,6 +13,7 @@ class InvoicesDataTable extends DataTable
|
|||||||
|
|
||||||
public function query(Invoice $model)
|
public function query(Invoice $model)
|
||||||
{
|
{
|
||||||
|
$model = $model->with('customer');
|
||||||
return $this->buildQuery($model);
|
return $this->buildQuery($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ class InvoicesDataTable extends DataTable
|
|||||||
return $invoice->created_at->toDateTimeString();
|
return $invoice->created_at->toDateTimeString();
|
||||||
})
|
})
|
||||||
->editColumn('customer.last_name', function (Invoice $invoice) {
|
->editColumn('customer.last_name', function (Invoice $invoice) {
|
||||||
return $invoice->customer->last_name . ' ' . $invoice->customer->first_name;
|
return ($invoice->customer ?? false) ? $invoice->customer->last_name . ' ' . $invoice->customer->first_name : '';
|
||||||
})
|
})
|
||||||
->rawColumns(['action']);
|
->rawColumns(['action']);
|
||||||
return parent::modifier($datatables);
|
return parent::modifier($datatables);
|
||||||
@@ -38,7 +39,7 @@ class InvoicesDataTable extends DataTable
|
|||||||
|
|
||||||
Column::make('status'),
|
Column::make('status'),
|
||||||
Column::make('created_at')->title('Date'),
|
Column::make('created_at')->title('Date'),
|
||||||
Column::make('customer.last_name'),
|
Column::make('customer.last_name')->default(''),
|
||||||
Column::make('total'),
|
Column::make('total'),
|
||||||
$this->makeColumnButtons(),
|
$this->makeColumnButtons(),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -3,19 +3,32 @@
|
|||||||
namespace App\Models\Shop;
|
namespace App\Models\Shop;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
use Venturecraft\Revisionable\RevisionableTrait;
|
||||||
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||||
|
|
||||||
class Invoice extends Model
|
class Invoice extends Model
|
||||||
{
|
{
|
||||||
|
use BelongsToThrough, RevisionableTrait, SoftDeletes;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
protected $table = 'shop_invoices';
|
protected $table = 'shop_invoices';
|
||||||
|
protected $revisionCreationsEnabled = false;
|
||||||
|
protected $keepRevisionOf = ['status', 'total_taxed', 'shipping', 'total_shipped'];
|
||||||
|
|
||||||
public function InvoiceItems()
|
public function payments()
|
||||||
{
|
{
|
||||||
return $this->hasMany(InvoiceItem::class);
|
return $this->hasMany(InvoicePayment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Customer()
|
public function order()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Customer::class);
|
return $this->belongsTo(Order::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function customer()
|
||||||
|
{
|
||||||
|
return $this->belongsToThrough(Customer::class, Order::class, null, '', [Customer::class => 'customer_id', Order::class => 'order_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ class Invoices
|
|||||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getStatus($id)
|
||||||
|
{
|
||||||
|
return self::statuses()[$id] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function statuses()
|
public static function statuses()
|
||||||
{
|
{
|
||||||
return ['En attente', 'Non soldée', 'Soldée'];
|
return ['En attente', 'Non soldée', 'Soldée'];
|
||||||
|
|||||||
Reference in New Issue
Block a user