wip
This commit is contained in:
89
app/Models/Ecommerce/Product/Inventory/Inventory.php
Normal file
89
app/Models/Ecommerce/Product/Inventory/Inventory.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
|
||||
class Inventory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'description',
|
||||
'email',
|
||||
'phone_number',
|
||||
'street_address',
|
||||
'zipcode',
|
||||
'region',
|
||||
'province_id',
|
||||
'longitude',
|
||||
'latitude',
|
||||
'is_default',
|
||||
'channel_id',
|
||||
'shareable',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the options for generating the slug.
|
||||
*/
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom('name')
|
||||
->saveSlugsTo('code')
|
||||
->doNotGenerateSlugsOnUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* User Channel
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Products
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class)->withPivot('stock');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tmpost default inventory
|
||||
*/
|
||||
public static function tmpostDefault(): Inventory
|
||||
{
|
||||
return static::where('code', 'tmpost')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* History
|
||||
*/
|
||||
public function history(): HasMany
|
||||
{
|
||||
return $this->hasMany(InventoryHistory::class, 'inventory_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* History removed
|
||||
*/
|
||||
public function historyRemoved(): HasMany
|
||||
{
|
||||
return $this->hasMany(InventoryHistoryRemoved::class, 'inventory_id');
|
||||
}
|
||||
}
|
||||
61
app/Models/Ecommerce/Product/Inventory/InventoryHistory.php
Normal file
61
app/Models/Ecommerce/Product/Inventory/InventoryHistory.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Concerns\HasSchemalessAttributes;
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class InventoryHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasSchemalessAttributes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'date',
|
||||
'inventory_id',
|
||||
'channel_id',
|
||||
'notes',
|
||||
'total',
|
||||
'options',
|
||||
];
|
||||
|
||||
/**
|
||||
* Attributes that are casted
|
||||
*/
|
||||
protected $casts = [
|
||||
'date' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Channel
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inventory
|
||||
*/
|
||||
public function inventory(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Inventory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Items
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(InventoryHistoryItem::class, 'inventory_history_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class InventoryHistoryItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'inventory_history_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
'total',
|
||||
'cost_amount',
|
||||
];
|
||||
|
||||
/**
|
||||
* Inventory history
|
||||
*/
|
||||
public function inventoryHistory(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(InventoryHistory::class, 'inventory_history_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Product
|
||||
*/
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Concerns\HasSchemalessAttributes;
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class InventoryHistoryRemoved extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasSchemalessAttributes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'date',
|
||||
'inventory_id',
|
||||
'channel_id',
|
||||
'notes',
|
||||
'total',
|
||||
'options',
|
||||
];
|
||||
|
||||
/**
|
||||
* Attributes that are casted
|
||||
*/
|
||||
protected $casts = [
|
||||
'date' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Channel
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inventory
|
||||
*/
|
||||
public function inventory(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Inventory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Items
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(InventoryHistoryRemovedItem::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class InventoryHistoryRemovedItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'inventory_history_removed_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
'total',
|
||||
'cost_amount',
|
||||
];
|
||||
|
||||
/**
|
||||
* Inventory history
|
||||
*/
|
||||
public function inventoryHistoryRemoved(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(InventoryHistoryRemoved::class, 'inventory_history_removed_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Product
|
||||
*/
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user