Add stock items, groups and movements at a moving average cost
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Inventory\Infrastructure\Persistence\Eloquent;
|
||||
|
||||
use Database\Factories\StockItemGroupFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||
use Illuminate\Database\Eloquent\Attributes\UseFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* Persistence model, used only inside the Inventory Infrastructure layer.
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property int $sort_order
|
||||
* @property bool $is_active
|
||||
*/
|
||||
#[Table('stock_item_groups')]
|
||||
#[Fillable(['name', 'sort_order', 'is_active'])]
|
||||
#[UseFactory(StockItemGroupFactory::class)]
|
||||
class StockItemGroupModel extends Model
|
||||
{
|
||||
/** @use HasFactory<StockItemGroupFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return HasMany<StockItemModel, $this>
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(StockItemModel::class, 'stock_item_group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'sort_order' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Inventory\Infrastructure\Persistence\Eloquent;
|
||||
|
||||
use App\Modules\Inventory\Domain\Enums\StockUnit;
|
||||
use Database\Factories\StockItemFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||
use Illuminate\Database\Eloquent\Attributes\UseFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Persistence model, used only inside the Inventory Infrastructure layer.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $stock_item_group_id
|
||||
* @property string $name
|
||||
* @property StockUnit $unit
|
||||
* @property string|null $code
|
||||
* @property string|null $supplier
|
||||
* @property int|null $reorder_level_milli
|
||||
* @property int $average_cost_hundredths
|
||||
* @property string|null $image_path
|
||||
* @property string|null $thumbnail_path
|
||||
* @property bool $is_active
|
||||
* @property int|null $balance_milli Selected sum of the movements.
|
||||
*/
|
||||
#[Table('stock_items')]
|
||||
#[Fillable(['stock_item_group_id', 'name', 'unit', 'code', 'supplier', 'reorder_level_milli', 'average_cost_hundredths', 'image_path', 'thumbnail_path', 'is_active'])]
|
||||
#[UseFactory(StockItemFactory::class)]
|
||||
class StockItemModel extends Model
|
||||
{
|
||||
/** @use HasFactory<StockItemFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return BelongsTo<StockItemGroupModel, $this>
|
||||
*/
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StockItemGroupModel::class, 'stock_item_group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'stock_item_group_id' => 'integer',
|
||||
'unit' => StockUnit::class,
|
||||
'reorder_level_milli' => 'integer',
|
||||
'average_cost_hundredths' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'balance_milli' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Inventory\Infrastructure\Persistence\Eloquent;
|
||||
|
||||
use App\Modules\Inventory\Domain\Enums\StockMovementKind;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Persistence model, used only inside the Inventory Infrastructure layer.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $stock_item_id
|
||||
* @property StockMovementKind $kind
|
||||
* @property int $quantity_milli
|
||||
* @property int $unit_cost_hundredths
|
||||
* @property int $value_cents
|
||||
* @property Carbon $occurred_on
|
||||
* @property Carbon $recorded_at
|
||||
* @property int $user_id
|
||||
* @property int|null $task_id
|
||||
* @property int|null $customer_job_id
|
||||
* @property int|null $machine_id
|
||||
* @property int|null $quick_sale_order_line_id
|
||||
* @property int|null $maintenance_record_id
|
||||
* @property int|null $inventory_count_id
|
||||
* @property int|null $reverses_movement_id
|
||||
* @property string|null $reason
|
||||
* @property string|null $supplier
|
||||
* @property string|null $document_number
|
||||
*/
|
||||
#[Table('stock_movements')]
|
||||
#[Fillable([
|
||||
'stock_item_id', 'kind', 'quantity_milli', 'unit_cost_hundredths', 'value_cents', 'occurred_on', 'recorded_at', 'user_id',
|
||||
'task_id', 'customer_job_id', 'machine_id', 'quick_sale_order_line_id', 'maintenance_record_id', 'inventory_count_id',
|
||||
'reverses_movement_id', 'reason', 'supplier', 'document_number',
|
||||
])]
|
||||
class StockMovementModel extends Model
|
||||
{
|
||||
/**
|
||||
* @return HasOne<StockMovementModel, $this>
|
||||
*/
|
||||
public function reversal(): HasOne
|
||||
{
|
||||
return $this->hasOne(StockMovementModel::class, 'reverses_movement_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'stock_item_id' => 'integer',
|
||||
'kind' => StockMovementKind::class,
|
||||
'quantity_milli' => 'integer',
|
||||
'unit_cost_hundredths' => 'integer',
|
||||
'value_cents' => 'integer',
|
||||
'occurred_on' => 'immutable_date',
|
||||
'recorded_at' => 'immutable_datetime',
|
||||
'user_id' => 'integer',
|
||||
'task_id' => 'integer',
|
||||
'customer_job_id' => 'integer',
|
||||
'machine_id' => 'integer',
|
||||
'quick_sale_order_line_id' => 'integer',
|
||||
'maintenance_record_id' => 'integer',
|
||||
'inventory_count_id' => 'integer',
|
||||
'reverses_movement_id' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user