70 lines
3.6 KiB
PHP
70 lines
3.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class CreateWarehouseStocktakeTables extends AbstractMigration
|
|
{
|
|
public function up(): void
|
|
{
|
|
if ($this->getEnvironment() == "thetool") {
|
|
// 1. Main Stocktake Session Table
|
|
$stocktake = $this->table('WarehouseStocktake');
|
|
$stocktake->addColumn('stocktakeNumber', 'string', ['limit' => 50, 'null' => true])
|
|
->addColumn('title', 'string', ['limit' => 255])
|
|
->addColumn('description', 'text', ['null' => true])
|
|
->addColumn('warehouseLocationId', 'integer', ['signed' => true])
|
|
->addColumn('status', 'enum', ['values' => ['planned', 'in_progress', 'completed', 'cancelled'], 'default' => 'planned'])
|
|
->addColumn('startedAt', 'integer', ['null' => true])
|
|
->addColumn('completedAt', 'integer', ['null' => true])
|
|
->addColumn('startedBy', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('completedBy', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('totalItems', 'integer', ['default' => 0])
|
|
->addColumn('totalScannedItems', 'integer', ['default' => 0])
|
|
->addColumn('notes', 'text', ['null' => true])
|
|
->addColumn('createBy', 'integer', ['signed' => false])
|
|
->addColumn('create', 'integer')
|
|
->addIndex(['stocktakeNumber'], ['unique' => true])
|
|
->addIndex(['status'])
|
|
->addIndex(['warehouseLocationId'])
|
|
->create();
|
|
|
|
// 2. Individual Stocktake Items
|
|
$stocktakeItem = $this->table('WarehouseStocktakeItem');
|
|
$stocktakeItem->addColumn('stocktakeId', 'integer', ['signed' => true])
|
|
->addColumn('articleId', 'integer', ['signed' => false])
|
|
->addColumn('warehouseItemId', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('countedQuantity', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0])
|
|
->addColumn('rack', 'string', ['limit' => 50, 'null' => true])
|
|
->addColumn('shelf', 'string', ['limit' => 50, 'null' => true])
|
|
->addColumn('note', 'text', ['null' => true])
|
|
->addColumn('scannedAt', 'integer', ['null' => true])
|
|
->addColumn('scannedBy', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('createBy', 'integer', ['signed' => false])
|
|
->addColumn('create', 'integer')
|
|
->addIndex(['stocktakeId'])
|
|
->addIndex(['articleId'])
|
|
->create();
|
|
|
|
// 3. Activity Log
|
|
$stocktakeLog = $this->table('WarehouseStocktakeLog');
|
|
$stocktakeLog->addColumn('stocktakeId', 'integer', ['signed' => true])
|
|
->addColumn('stocktakeItemId', 'integer', ['null' => true, 'signed' => true])
|
|
->addColumn('action', 'string', ['limit' => 50])
|
|
->addColumn('details', 'text', ['null' => true])
|
|
->addColumn('userId', 'integer', ['signed' => false])
|
|
->addColumn('create', 'integer')
|
|
->addIndex(['stocktakeId'])
|
|
->create();
|
|
}
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
if ($this->getEnvironment() == "thetool") {
|
|
$this->table('WarehouseStocktakeLog')->drop()->save();
|
|
$this->table('WarehouseStocktakeItem')->drop()->save();
|
|
$this->table('WarehouseStocktake')->drop()->save();
|
|
}
|
|
}
|
|
} |