[WIP] Working on orders & invoices

This commit is contained in:
Ludovic CANDELLIER
2022-08-19 22:04:44 +02:00
parent c22b10dd10
commit f89acd9399
32 changed files with 440 additions and 323 deletions

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_invoices';
public function InvoiceItems()
{

View File

@@ -1,20 +0,0 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class InvoiceItem extends Model
{
protected $guarded = ['id'];
public function Product()
{
return $this->belongsTo(Product::class);
}
public function Invoice()
{
return $this->belongsTo(Invoice::class);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class InvoicePayment extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_invoice_payments';
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
public function scopeByInvoice($query, $invoice_id)
{
return $query->where('invoice_id', $invoice_id);
}
}

View File

@@ -7,14 +7,55 @@ use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_orders';
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function payments()
public function address()
{
return $this->hasMany(OrderPayment::class);
return $this->belongsTo(CustomerAddress::class, 'customer_address_id');
}
public function delivery()
{
return $this->belongsTo(Delivery::class);
}
public function detail()
{
return $this->hasMany(OrderDetail::class);
}
public function invoice()
{
return $this->hasOne(Invoice::class);
}
public function sale_channel()
{
return $this->belongsTo(SaleChannel::class);
}
public function scopeByCustomer($query, $customer_id)
{
return $query->where('customer_id', $customer_id);
}
public function scopeByDelivery($query, $delivery_id)
{
return $query->where('delivery_id', $delivery_id);
}
public function scopeByStatus($query, $status)
{
return $query->where('status', $status);
}
public function scopeByPaymentType($query, $payment_type)
{
return $query->where('payment_type', $payment_type);
}
}

View File

@@ -7,9 +7,25 @@ use Illuminate\Database\Eloquent\Model;
class OrderDetail extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_order_details';
public function order()
{
return $this->belongsTo(Order::class);
}
public function offer()
{
return $this->belongsTo(Offer::class);
}
public function scopeByOrder($query, $order_id)
{
return $query->where('order_id', $order_id);
}
public function scopeByOffer($query, $offer_id)
{
return $query->where('offer_id', $offer_id);
}
}

View File

@@ -1,15 +0,0 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class OrderPayment extends Model
{
protected $guarded = ['id'];
public function order()
{
return $this->belongsTo(Order::class);
}
}