table('suppliers'); if (!$t->hasColumn('mago_code')) { $t->addColumn('mago_code', 'string', ['limit' => 20, 'null' => true, 'after' => 'vat']) ->addIndex(['mago_code'], ['name' => 'idx_suppliers_mago_code']) ->update(); } // codici Mago giĆ  noti dalla prova acquisti (DER-GOM e HEXPOL si collegano da soli al primo sync) foreach (['COMET' => 'C063', 'SIGEA' => 'S022', 'TOVO' => 'T050', 'EVER COMPOUND' => 'E025'] as $name => $code) { $this->execute("UPDATE suppliers SET mago_code = '$code' WHERE supplier_name = '$name' AND (mago_code IS NULL OR mago_code = '')"); } if (!$this->fetchRow("SELECT idsupplier FROM suppliers WHERE supplier_name LIKE 'HEXPOL%'")) { $this->execute("INSERT INTO suppliers (supplier_name) VALUES ('HEXPOL')"); } if (!$this->hasTable('mago_mix_purchases')) { $this->table('mago_mix_purchases', ['id' => false, 'primary_key' => ['purchase_doc_id', 'line'], 'collation' => 'utf8mb4_general_ci']) ->addColumn('purchase_doc_id', 'integer') ->addColumn('line', 'integer') ->addColumn('document_type', 'integer', ['null' => true]) ->addColumn('doc_date', 'date', ['null' => true]) ->addColumn('doc_no', 'string', ['limit' => 40, 'null' => true]) ->addColumn('supplier_code', 'string', ['limit' => 20, 'null' => true]) ->addColumn('supplier_name', 'string', ['limit' => 150, 'null' => true]) ->addColumn('item', 'string', ['limit' => 40, 'null' => true]) ->addColumn('description', 'string', ['limit' => 500, 'null' => true]) ->addColumn('uom', 'string', ['limit' => 10, 'null' => true]) ->addColumn('qty', 'decimal', ['precision' => 14, 'scale' => 3, 'default' => 0]) ->addColumn('unit_value', 'decimal', ['precision' => 14, 'scale' => 5, 'default' => 0]) ->addColumn('taxable_amount', 'decimal', ['precision' => 14, 'scale' => 2, 'default' => 0]) ->addColumn('notes', 'string', ['limit' => 500, 'null' => true]) ->addColumn('purchase_ord_no', 'string', ['limit' => 40, 'null' => true]) ->addColumn('synced_at', 'datetime', ['null' => true]) ->addIndex(['doc_date']) ->addIndex(['supplier_code']) ->create(); } } public function down(): void { if ($this->hasTable('mago_mix_purchases')) $this->table('mago_mix_purchases')->drop()->save(); $t = $this->table('suppliers'); if ($t->hasColumn('mago_code')) $t->removeIndexByName('idx_suppliers_mago_code')->removeColumn('mago_code')->update(); } }