This commit is contained in:
Beppe 2021-06-18 09:38:35 +02:00
commit dca9ac12bc
13 changed files with 466 additions and 28 deletions

View File

@ -40,7 +40,9 @@ Il formato utilizzato è basato sulle linee guida di [Keep a Changelog](http://k
### Aggiunto (Added)
- Aggiunta nel calendario della Dashboard visualizzazione dei preventivi pianificabili in corrispondenza alla data di accettazione e conclusione.
- Aggiunta impostazione per la visualizzazione delle ore nella stampa intervento (Decimale, Sessantesimi).
- Aggiunta possibilità di selezionare la sede di partenza della merce in fase di aggiunta articolo da un'attività
- Sostituito plugin **Componenti** nel modulo Impianti con la possibilità di inserire gli articoli di magazzino
### Fixed
-

View File

@ -22,6 +22,15 @@ $qta_minima = 0;
// Articolo
if (empty($result['idarticolo'])) {
// Sede partenza
if ($module['name'] == 'Interventi') {
echo '
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Partenza merce').'", "required": "1", "id":"idsede", "name": "idsede_partenza", "ajax-source": "sedi_azienda", "value": "'.($result['idsede_partenza'] ?: $options['idsede_partenza']).'" ]}
</div>
</div>';
}
echo '
<div class="row">
<div class="col-md-12">
@ -179,6 +188,12 @@ $("#idarticolo").on("change", function() {
});
$("#idsede").on("change", function() {
updateSelectOption("idsede_partenza", $(this).val());
session_set("superselect,idsede_partenza", $(this).val(), 0);
$("#idarticolo").selectReset();
});
$(document).on("change", "input[name^=qta], input[name^=prezzo_unitario], input[name^=sconto]", function() {
verificaPrezzoArticolo();
verificaScontoArticolo();

View File

@ -68,8 +68,6 @@ foreach ($ddt as $elemento) {
$tipo_ordini = $direzione_richiesta == 'entrata' ? 'cliente' : 'fornitore';
$ordini = Ordine::whereHas('stato', function ($query) {
$query->where('descrizione', '!=', 'Bozza');
})->whereHas('tipo', function ($query) use ($direzione_richiesta) {
$query->where('dir', '=', $direzione_richiesta);
})->get();
foreach ($ordini as $elemento) {
$documenti_disponibili->push([

View File

@ -175,7 +175,7 @@ include_once __DIR__.'/../../core.php';
<div class="row">
<div class="col-md-12">
{[ "type": "select", "label": "<?php echo tr('Fornitore predefinito'); ?>", "name": "id_fornitore", "ajax-source": "fornitori-articolo", "select-options": <?php echo json_encode(['id_articolo' => $id_record]); ?>, "value":"$id_fornitore$", "help": "<?php echo tr('Fornitore predefinito, utilizzato dal gestionale per funzioni più avanzate della gestione magazzino'); ?>." ]}
{[ "type": "select", "label": "<?php echo tr('Fornitore predefinito'); ?>", "name": "id_fornitore", "ajax-source": "fornitori-articolo", "select-options": <?php echo json_encode(['id_articolo' => $id_record]); ?>, "value":"$id_fornitore$", "help": "<?php echo tr('Fornitore predefinito selezionabile tra i fornitori presenti nel plugin "Prezzi di listino"'); ?>." ]}
</div>
</div>

View File

@ -111,7 +111,7 @@ switch (post('op')) {
}
}
}
aggiorna_sedi_movimenti('interventi', $id_record);
flash()->info(tr('Attività modificata correttamente!'));
break;
@ -131,8 +131,6 @@ switch (post('op')) {
$intervento = Intervento::build($anagrafica, $tipo, $stato, $data_richiesta);
$id_record = $intervento->id;
aggiorna_sedi_movimenti('interventi', $id_record);
flash()->info(tr('Aggiunto nuovo intervento!'));
// Informazioni di base
@ -219,7 +217,6 @@ switch (post('op')) {
flash()->clearMessage('warning');
}
aggiorna_sedi_movimenti('interventi', $id_record);
break;
// Eliminazione intervento
@ -267,8 +264,6 @@ switch (post('op')) {
}
}
aggiorna_sedi_movimenti('interventi', $id_record);
break;
case 'manage_barcode':
@ -313,7 +308,8 @@ switch (post('op')) {
}
$qta = post('qta');
$articolo->idsede_partenza = post('idsede_partenza');
$articolo->descrizione = post('descrizione');
$articolo->um = post('um') ?: null;
@ -394,7 +390,6 @@ switch (post('op')) {
$serials = (array) post('serial');
$articolo->serials = $serials;
aggiorna_sedi_movimenti('interventi', $id_record);
break;
// Aggiunta di un documento in ordine

View File

@ -33,6 +33,7 @@ $options = [
'totale_imponibile_documento' => $documento->totale_imponibile,
'totale_documento' => $documento->totale,
'nascondi_prezzi' => !$show_prezzi,
'idsede_partenza' => $documento->idsede_partenza,
'select-options' => [
'articoli' => [
'idanagrafica' => $documento->idanagrafica,

View File

@ -0,0 +1,125 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Carbon\Carbon;
$operazione = filter('op');
switch ($operazione) {
case 'update':
$articolo = (array)post('id_articolo');
$data_installazione = (array)post('data_installazione');
$data_disinstallazione = (array)post('data_disinstallazione');
$data_registrazione = (array)post('data_registrazione');
$note = (array)post('note');
$key = key($articolo);
if(post('sostituito')){
$field_articolo = 'pre_id_articolo';
} else{
$field_articolo = 'id_articolo';
}
$dbo->update('my_componenti_articoli', [
$field_articolo => $articolo[$key],
'data_installazione' => $data_installazione[$key] ?: null,
'data_disinstallazione' => $data_disinstallazione[$key] ?: null,
'data_registrazione' => $data_registrazione[$key] ?: null,
'note' => $note[$key],
], ['id' => $key]);
flash()->info(tr('Salvataggio completato!'));
$dbo->commitTransaction();
header('Location: '.$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
exit;
break;
case 'add':
$dbo->insert('my_componenti_articoli', [
'id_impianto' => $id_record,
'data_registrazione' => Carbon::now(),
'id_articolo' => post('id_articolo'),
]);
flash()->info(tr('Salvataggio completato!'));
break;
case 'sostituisci':
$old_id = get('id_old');
$old = $dbo->selectOne('my_componenti_articoli', '*', ['id' => $old_id]);
if(!empty($old['id_articolo'])){
if(empty($old['data_disinstallazione'])){
$data = Carbon::now();
} else{
$data = $old['data_disinstallazione'];
}
$dbo->update('my_componenti_articoli', [
'pre_id_articolo' => $old['id_articolo'],
'id_articolo' => 0,
'data_disinstallazione' => $data,
],[
'id' => $old_id,
]);
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM my_componenti_articoli WHERE id= '.prepare($old_id));
$dbo->query('ALTER TABLE tmp DROP id');
$dbo->query('INSERT INTO my_componenti_articoli SELECT NULL,tmp. * FROM tmp');
$new_id = $dbo->lastInsertedID();
$dbo->query('DROP TEMPORARY TABLE tmp');
$dbo->update('my_componenti_articoli', [
'id_articolo' => $old['id_articolo'],
'pre_id_articolo' => 0,
'data_registrazione' => Carbon::now(),
'data_installazione' => $data,
'data_disinstallazione' => null,
], [
'id' => $new_id,
]);
flash()->info(tr('Informazioni salvate correttamente!'));
} else{
flash()->warning(tr('Inserire un articolo prima di effettuare la sostituzione!'));
}
$dbo->commitTransaction();
header('Location: '.$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
exit;
break;
case 'delete':
$dbo->query('DELETE FROM my_componenti_articoli WHERE id='.prepare(get('id')));
flash()->info(tr('Componente eliminato!'));
$dbo->commitTransaction();
header('Location: '.$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'#tab_'.$id_plugin);
exit;
break;
}

View File

@ -0,0 +1,40 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '
<form action="" method="post" role="form">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="add">
<div class="row">
<div class="col-md-6">
{["type": "select", "label": "'.tr('Articolo').'", "name": "id_articolo", "ajax-source": "articoli", "value": "", "required": 1, "select-options": {"permetti_movimento_a_zero": 1} ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
</div>
</div>
</form>';

View File

@ -0,0 +1,22 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '{( "name": "filelist_and_upload", "id":"'.rand(1,999).'", "id_record": "'.get('id').'", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'" )}';

194
plugins/componenti/edit.php Normal file
View File

@ -0,0 +1,194 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '<hr>';
$componenti = $dbo->fetchArray('SELECT my_componenti_articoli.*, my_impianti.idanagrafica, CONCAT(a.codice, " - ", a.descrizione) AS art_sostituito, CONCAT(b.codice, " - ", b.descrizione) AS art_installato, a.codice FROM my_componenti_articoli LEFT JOIN my_impianti ON my_componenti_articoli.id_impianto=my_impianti.id LEFT JOIN mg_articoli AS a ON my_componenti_articoli.pre_id_articolo=a.id LEFT JOIN mg_articoli AS b ON my_componenti_articoli.id_articolo=b.id WHERE id_impianto='.prepare($id_record).' ORDER BY data_registrazione, id_articolo DESC');
$installati = 0;
$disinstallati = 0;
foreach($componenti as $componente){
if(!empty($componente['pre_id_articolo'])){
$id_articolo = $componente['pre_id_articolo'];
$check_value = 1;
$box = 'danger';
$articolo = $componente['art_sostituito'];
$data = dateFormat($componente['data_disinstallazione']);
$text = 'DISINSTALLATO';
$class = 'danger';
$title = ''.tr('Storico').'';
$table ='default';
if($disinstallati==0){
echo '
<div class="row">
<div class="col-md-12 text-center">
<h4 class="text-danger">ARTICOLI DISINSTALLATI</h4>
</div>
</div>
<hr>';
$disinstallati++;
}
} else{
$id_articolo = $componente['id_articolo'];
$check_value = 0;
$box = 'primary';
$articolo = $componente['art_installato'];
$data = dateFormat($componente['data_installazione']);
$text = 'INSTALLATO';
$class = 'primary';
$title = ''.tr('Dati').'';
$table ='primary';
if($installati==0){
echo '
<div class="row">
<div class="col-md-12 text-center">
<h4 class="text-blue">ARTICOLI INSTALLATI</h4>
</div>
</div>
<hr>';
$installati++;
}
}
$allegati = $dbo->fetchOne('SELECT COUNT(id) AS num FROM zz_files WHERE id_plugin='.prepare($id_plugin).' AND id_record='.$componente['id'].' GROUP BY id_record')['num'];
if($allegati){
$icon = 'fa fa-check text-success';
} else{
$icon = 'fa fa-times text-danger';
}
echo '
<form action="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'" method="post" role="form">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
<input type="hidden" name="sostituito" value="'.$check_value.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="update">
<div class="panel-group" id="accordion">
<div class="box collapsed-box box-'.$box.'">
<div class="box-header with-border mini">
<small class="text-'.$class.'">
<table class="table" style="margin:0; padding:0;">
<thead>
<tr>
<th class="text-center">'.tr('ARTICOLO').'</td>
<th class="text-center" width="20%">'.$text.'</th>
<th class="text-center" width="20%">'.tr('REGISTRAZIONE').'</th>
<th class="text-center" width="10%">'.tr('ALLEGATI').'</th>
</tr>
<tr>
<td class="text-center">'.$articolo.'</td>
<td class="text-center">'.$data.'</td>
<td class="text-center">'.dateFormat($componente['data_registrazione']).'</td>
<td class="text-center"><i class="'.$icon.' fa-lg"></i></td>
</tr>
</thead>
</table>
</small>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
<div id="collapse_'.$j.'" class="box-body">
<div class="panel panel-'.$table.'">
<div class="panel-heading">
<h3 class="panel-title">'.$title.'</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
{[ "type":"select","label":"'.tr('Articolo').'","name":"id_articolo['.$componente['id'].']", "required":"1","value":"'.$id_articolo.'", "ajax-source": "articoli", "select-options": {"permetti_movimento_a_zero": 1} ]}
</div>
<div class="col-md-2">
{[ "type":"date","label":"'.tr('Data registrazione').'","name":"data_registrazione['.$componente['id'].']", "value":"'.$componente['data_registrazione'].'" ]}
</div>
<div class="col-md-2">
{[ "type":"date","label":"'.tr('Data installazione').'","name":"data_installazione['.$componente['id'].']", "value":"'.$componente['data_installazione'].'" ]}
</div>
<div class="col-md-2">
{[ "type":"date","label":"'.tr('Data disinstallazione').'","name":"data_disinstallazione['.$componente['id'].']", "value":"'.$componente['data_disinstallazione'].'" ]}
</div>
</div>
<div class="row">
<div class="col-md-12">
{[ "type":"textarea","label":"'.tr('Note').'","name":"note['.$componente['id'].']", "value":"'.$componente['note'].'" ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-1">
<button type="button" class="btn btn-danger" onclick="elimina('.$componente['id'].')"><i class="fa fa-trash"></i> '.tr('Elimina').'</button>
</div>
<div class="col-md-1">
<a onclick="openModal(\'Aggiungi file\', \''.$structure->fileurl('allegati.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'id_record='.$id_record.'&id='.$componente['id'].'\');" class="btn btn-default">
<i class="fa fa-file-text-o"></i> '.tr('Allegati _NUM_', [
'_NUM_' => $allegati,
]).'
</a>
</div>';
if(!empty($componente['id_articolo'])){
echo '
<div class="col-md-9">
<button type="button" class="btn btn-warning pull-right" onclick="sostituisci('.$componente['id'].')"><i class="fa fa-cog"></i> '.tr('Sostituisci').'</button>
</div>';
}
echo '
<div class="col-md-1 pull-right">
<button type="submit" class="btn btn-success pull-right"><i class="fa fa-check"></i> '.tr('Salva').'</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>';
}
echo '
<script>
function sostituisci(id) {
if(confirm("'.tr('Vuoi sostituire questo componente?').'")){
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=sostituisci&backto=record-edit&id_plugin='.$id_plugin.'&id_old="+id);
}
}
function elimina(id) {
if(confirm("'.tr('Vuoi eliminare questo componente?').'")){
redirect("'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=delete&backto=record-edit&id_plugin='.$id_plugin.'&id="+id);
}
}
</script>';

View File

@ -1026,25 +1026,55 @@ class FatturaElettronica
$result = [];
// Se imposto il vettore deve essere indicata anche la p.iva nella sua anagrafica
if ($documento['idvettore']) {
$vettore = Anagrafica::find($documento['idvettore']);
$result['DatiAnagraficiVettore'] = static::getDatiAnagrafici($vettore);
if ($documento->tipo->descrizione == 'Fattura accompagnatoria di vendita') {
if ($documento['idvettore']) {
$vettore = Anagrafica::find($documento['idvettore']);
$result['DatiAnagraficiVettore'] = static::getDatiAnagrafici($vettore);
}
if (!empty($causale)) {
$result['CausaleTrasporto'] = $causale;
}
if (!empty($documento['n_colli'])) {
$result['NumeroColli'] = $documento['n_colli'];
}
if (!empty($aspetto)) {
$result['Descrizione'] = $aspetto;
}
if ($documento['tipo_resa']) {
$result['TipoResa'] = $documento['tipo_resa'];
}
}
if (!empty($causale)) {
$result['CausaleTrasporto'] = $causale;
}
if (!empty($documento['idsede_destinazione'])){
$sede = $database->fetchOne('SELECT * FROM an_sedi WHERE id='.prepare($documento['idsede_destinazione']));
if (!empty($documento['n_colli'])) {
$result['NumeroColli'] = $documento['n_colli'];
}
if (!empty($sede['indirizzo'])){
$result['IndirizzoResa']['Indirizzo'] = $sede['indirizzo'];
}
if (!empty($aspetto)) {
$result['Descrizione'] = $aspetto;
}
if (!empty($sede['cap'])){
$result['IndirizzoResa']['CAP'] = $sede['cap'];
}
if ($documento['tipo_resa']) {
$result['TipoResa'] = $documento['tipo_resa'];
if (!empty($sede['citta'])){
$result['IndirizzoResa']['Comune'] = $sede['citta'];
}
if (!empty($sede['provincia'])){
$result['IndirizzoResa']['Provincia'] = $sede['provincia'];
}
if (!empty($sede['id_nazione'])){
$rs_nazione = $database->fetchOne('SELECT * FROM an_nazioni WHERE id='.prepare($sede['id_nazione']));
$result['IndirizzoResa']['Nazione'] = $rs_nazione['iso2'];
}
}
return $result;
@ -1273,7 +1303,7 @@ class FatturaElettronica
}
}
if ($documento->tipo->descrizione == 'Fattura accompagnatoria di vendita') {
if ($documento->tipo->descrizione == 'Fattura accompagnatoria di vendita' || !empty($documento['idsede_destinazione'])) {
$result['DatiTrasporto'] = static::getDatiTrasporto($fattura);
}

View File

@ -292,7 +292,11 @@ abstract class Article extends Accounting
$qta_movimento = $documento->direzione == 'uscita' ? $qta : -$qta;
$movimento = Movimento::descrizioneMovimento($qta_movimento, $documento->direzione).' - '.$documento->getReference();
$id_sede = $documento->direzione == 'uscita' ? $documento->idsede_destinazione : $documento->idsede_partenza;
if ($documento instanceof \Modules\Interventi\Intervento) {
$id_sede = $this->idsede_partenza;
} else{
$id_sede = $documento->direzione == 'uscita' ? $documento->idsede_destinazione : $documento->idsede_partenza;
}
// Fix per valori di sede a NULL
$id_sede = $id_sede ?: 0;

View File

@ -28,3 +28,15 @@ INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`
-- Aggiunta plugin allegati dell'anagrafica
INSERT INTO `zz_plugins` (`name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`) VALUES ('Allegati', 'Allegati', (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name`='Anagrafiche'), (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name`='Anagrafiche'), 'tab', 'allegati.php', '1', '0', '0', '', '', NULL, NULL, '', '');
-- Aggiunta idsede nelle righe dell'intervento
ALTER TABLE `in_righe_interventi` ADD `idsede_partenza` INT NOT NULL AFTER `id_dettaglio_fornitore`;
-- Aggiunto nuovo plugin Componenti e disabilitato quello precedente
UPDATE `zz_plugins` SET `name`='Componenti ini', `title`='Componenti ini' WHERE `name`='Componenti';
UPDATE `zz_plugins` SET `enabled`=0 WHERE `name`='Componenti ini';
INSERT INTO `zz_plugins` ( `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`, `created_at`, `updated_at`) VALUES ('Componenti', 'Componenti', (SELECT `id` FROM `zz_modules` WHERE name='Impianti'), (SELECT `id` FROM `zz_modules` WHERE name='Impianti'), 'tab', '', '1', '0', '0', '', '', NULL, 'custom', 'componenti', '', NOW(), NOW());
CREATE TABLE `my_componenti_articoli` ( `id` INT NOT NULL AUTO_INCREMENT, `id_impianto` INT NOT NULL , `id_articolo` INT NOT NULL , `pre_id_articolo` INT NOT NULL, `note` TEXT NOT NULL , `data_registrazione` DATE NULL , `data_installazione` DATE NULL , `data_disinstallazione` DATE NULL , `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`));