Xinon mobile/improve
This commit is contained in:
50
db/migrations/20260117120000_add_shipping_note_number.php
Normal file
50
db/migrations/20260117120000_add_shipping_note_number.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddShippingNoteNumber extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table('WarehouseShippingNote');
|
||||
$table
|
||||
->addColumn('shippingNoteNumber', 'string', ['limit' => 20, 'null' => true, 'after' => 'id'])
|
||||
->addIndex(['shippingNoteNumber'], ['unique' => true])
|
||||
->update();
|
||||
|
||||
// Get all shipping notes ordered by create timestamp to assign numbers in chronological order
|
||||
$rows = $this->fetchAll(
|
||||
"SELECT id, YEAR(FROM_UNIXTIME(`create`)) as year
|
||||
FROM WarehouseShippingNote
|
||||
ORDER BY `create` ASC, id ASC"
|
||||
);
|
||||
|
||||
// Group by year and assign sequential numbers
|
||||
$yearCounters = [];
|
||||
foreach ($rows as $row) {
|
||||
$year = $row['year'];
|
||||
if (!isset($yearCounters[$year])) {
|
||||
$yearCounters[$year] = 0;
|
||||
}
|
||||
$yearCounters[$year]++;
|
||||
|
||||
$shippingNoteNumber = 'LS' . $year . '-X' . str_pad((string)$yearCounters[$year], 4, '0', STR_PAD_LEFT);
|
||||
|
||||
$this->execute(
|
||||
"UPDATE WarehouseShippingNote SET shippingNoteNumber = '{$shippingNoteNumber}' WHERE id = {$row['id']}"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table('WarehouseShippingNote');
|
||||
$table->removeColumn('shippingNoteNumber')->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
43
db/migrations/20260117150000_add_order_movement_linking.php
Normal file
43
db/migrations/20260117150000_add_order_movement_linking.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddOrderMovementLinking extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
// Add columns to WarehouseOrder for linking to movements and delivery note files
|
||||
$orderTable = $this->table('WarehouseOrder');
|
||||
$orderTable
|
||||
->addColumn('linkedMovementIds', 'text', ['null' => true, 'after' => 'note'])
|
||||
->addColumn('deliveryNoteFileIds', 'text', ['null' => true, 'after' => 'linkedMovementIds'])
|
||||
->update();
|
||||
|
||||
// Add column to WarehouseMovement for linking back to orders
|
||||
$movementTable = $this->table('WarehouseMovement');
|
||||
$movementTable
|
||||
->addColumn('linkedOrderId', 'integer', ['null' => true, 'signed' => false, 'after' => 'note'])
|
||||
->addIndex(['linkedOrderId'], ['name' => 'idx_linkedOrderId'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if ($this->getEnvironment() == "thetool") {
|
||||
$orderTable = $this->table('WarehouseOrder');
|
||||
$orderTable
|
||||
->removeColumn('linkedMovementIds')
|
||||
->removeColumn('deliveryNoteFileIds')
|
||||
->update();
|
||||
|
||||
$movementTable = $this->table('WarehouseMovement');
|
||||
$movementTable
|
||||
->removeIndex(['linkedOrderId'])
|
||||
->removeColumn('linkedOrderId')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user