table('mago_prod_queue', [ 'comment' => 'Righe ordine Mago da portare in programmazione produzione', ]) // --- riga Mago --- ->addColumn('sale_ord_id', 'integer', ['signed' => false]) ->addColumn('sub_id', 'integer') ->addColumn('internal_ord_no', 'string', ['limit' => 30, 'default' => '']) ->addColumn('line_no', 'integer', ['default' => 0]) ->addColumn('order_date', 'date', ['null' => true]) ->addColumn('customer', 'string', ['limit' => 20, 'default' => '']) ->addColumn('company_name', 'string', ['limit' => 200, 'default' => '']) ->addColumn('item', 'string', ['limit' => 30, 'default' => '']) ->addColumn('description', 'string', ['limit' => 255, 'default' => '']) ->addColumn('cod_art_cli', 'string', ['limit' => 60, 'default' => '']) ->addColumn('uom', 'string', ['limit' => 10, 'default' => '']) ->addColumn('qty', 'decimal', ['precision' => 15, 'scale' => 3, 'default' => 0]) ->addColumn('delivered_qty', 'decimal', ['precision' => 15, 'scale' => 3, 'default' => 0]) ->addColumn('residual_qty', 'decimal', ['precision' => 15, 'scale' => 3, 'default' => 0]) ->addColumn('zibo_date', 'date', ['null' => true]) ->addColumn('client_date', 'date', ['null' => true]) ->addColumn('mago_notes', 'text', ['null' => true]) // --- matrice --- ->addColumn('matrice_misura', 'string', ['limit' => 30, 'default' => '', 'comment' => 'Valore originale di Mago']) ->addColumn('mm_tipo', 'string', ['limit' => 2, 'default' => '', 'comment' => 'M matrice, D diametro, R rettangolo, T tubo, Q quadrato, S, ? altro']) ->addColumn('mm_codice', 'string', ['limit' => 40, 'default' => '', 'comment' => 'Codice matrice estratto (es. 00786S-1)']) ->addColumn('mm_misura', 'string', ['limit' => 40, 'default' => '', 'comment' => 'Misura (es. 3,3 / 17X12)']) ->addColumn('idmatrice', 'integer', ['null' => true]) ->addColumn('match_status', 'string', ['limit' => 20, 'default' => '', 'comment' => 'esatta, revisione, mappa, manuale, da_creare, profilo, anomalia']) ->addColumn('match_info', 'string', ['limit' => 255, 'default' => '']) // --- percorso --- ->addColumn('queue_status', 'string', ['limit' => 20, 'default' => 'nuovo', 'comment' => 'nuovo, importato, scartato, chiuso_mago']) ->addColumn('discard_reason', 'string', ['limit' => 255, 'default' => '']) ->addColumn('productiondata_id', 'integer', ['null' => true]) ->addColumn('mago_changed', 'boolean', ['default' => false, 'comment' => 'Riga cambiata in Mago dopo l\'import']) ->addColumn('mago_changes', 'string', ['limit' => 500, 'default' => '']) ->addColumn('first_seen_at', 'datetime', ['null' => true]) ->addColumn('updated_at', 'datetime', ['null' => true]) ->addColumn('imported_at', 'datetime', ['null' => true]) ->addColumn('imported_by', 'string', ['limit' => 100, 'default' => '']) ->addIndex(['sale_ord_id', 'sub_id'], ['unique' => true, 'name' => 'uk_mpq_line']) ->addIndex(['queue_status']) ->addIndex(['productiondata_id']) ->addIndex(['idmatrice']) ->create(); $this->table('matrice_mago_map', [ 'comment' => 'Corrispondenze manuali: valore Matrice/Misura di Mago → matrice', ]) ->addColumn('codice_mago', 'string', ['limit' => 60]) ->addColumn('idmatrice', 'integer') ->addColumn('note', 'string', ['limit' => 255, 'default' => '']) ->addColumn('created_by', 'string', ['limit' => 100, 'default' => '']) ->addColumn('created_at', 'datetime', ['null' => true]) ->addIndex(['codice_mago'], ['unique' => true]) ->addForeignKey('idmatrice', 'matrice', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) ->create(); $this->table('clients') ->addColumn('mago_code', 'string', ['limit' => 20, 'null' => true, 'after' => 'nome', 'comment' => 'Codice cliente Mago']) ->addIndex(['mago_code']) ->update(); } }