Gestito update per modulo import anagrafiche

This commit is contained in:
Luca 2018-03-01 01:56:57 +01:00
parent f1b0c2e2be
commit 320d53ad54
2 changed files with 59 additions and 21 deletions

View File

@ -8,22 +8,45 @@ switch (post('op')) {
foreach ($data as $key => $value) {
if (!empty($value)){
$i++;
(array) $idtipoanagrafica = $data[$key]['tipologia'];
unset($data[$key]['tipologia']);
$dbo->insert('an_anagrafiche', $data[$key]);
//update
if (post('primary_key')!=''){
$primary_key = post('primary_key');
$rs = $dbo->select('an_anagrafiche', $primary_key, [$primary_key => $data[$key][$primary_key]]);
if (!in_array($data[$key][$primary_key], $rs[0])) {
//insert
$dbo->insert('an_anagrafiche', $data[$key]);
//campi extra
if (count($idtipoanagrafica)>0){
// Aggiornamento della tipologia di anagrafiche
$dbo->sync('an_tipianagrafiche_anagrafiche', [
'idanagrafica' => $dbo->lastInsertedID(),
], [
'idtipoanagrafica' => (array) $idtipoanagrafica,
]);
}
}else{
//update
$dbo->update('an_anagrafiche', $data[$key], [$primary_key => $data[$key][$primary_key]]);
}
}
unset($data[$key]);
//campi extra
if (count($idtipoanagrafica)>0){
// Aggiornamento della tipologia di anagrafiche
$dbo->sync('an_tipianagrafiche_anagrafiche', [
'idanagrafica' => $dbo->lastInsertedID(),
], [
'idtipoanagrafica' => (array) $idtipoanagrafica,
]);
}
}
@ -39,6 +62,7 @@ return [
[
'field' => 'codice',
'label' => 'Codice',
'primary_key' => '1',
],
[
'field' => 'ragione_sociale',

View File

@ -5,16 +5,6 @@ include_once __DIR__.'/../../core.php';
if (empty($id_record)) {
require $docroot.'/add.php';
} else {
echo '
<form action="" method="post" id="edit-form">
<input type="hidden" name="backto" value="record-list">
<input type="hidden" name="op" value="import">
<div class="row">
<div class="col-md-12">
{[ "type": "checkbox", "label": "'.tr('Importa prima riga').'", "name": "first_row", "extra":"", "value": "1" ]}
</div>
</div>';
// Inclusione del file del modulo per eventuale HTML personalizzato
include $imports[$id_record]['import'];
@ -22,13 +12,37 @@ if (empty($id_record)) {
$fields = Import::getFields($id_record);
$select = [];
$select2 = [];
foreach ($fields as $key => $value) {
$select[] = [
'id' => $key,
'text' => $value['label'],
];
$select2[] = [
'id' => $value['field'],
'text' => $value['label'],
];
if ($value['primary_key']){
$primary_key = $value['field'];
}
}
echo '
<form action="" method="post" id="edit-form">
<input type="hidden" name="backto" value="record-list">
<input type="hidden" name="op" value="import">
<div class="row">
<div class="col-md-8">
{[ "type": "checkbox", "label": "'.tr('Importa prima riga').'", "name": "first_row", "extra":"", "value": "1" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Chiave primaria').'", "name": "primary_key", "values": '.json_encode($select2).', "value": "'.$primary_key.'" ]}
</div>
</div>';
$rows = Import::getFile($id_record, $records[0]['id'], [
'limit' => 10,
]);