2018-02-23 19:04:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
switch (post('op')) {
|
2018-06-22 17:04:37 +02:00
|
|
|
case 'example':
|
|
|
|
|
|
|
|
$module = filter('module');
|
|
|
|
|
|
|
|
$list = [
|
|
|
|
['Codice', 'Ragione sociale', 'Partita IVA', 'Nazione', 'Indirizzo', 'CAP', 'Città', 'Provincia', 'Telefono', 'Fax', 'Cellulare', 'Email', 'IBAN', 'Note', 'Tipologia'],
|
|
|
|
['00001', 'Cliente', '12345678910', 'ITALIA', 'Via Giuseppe Mazzini, 123', '12345', 'Este', 'PD', '786 543 21', '123 456 78', '321 123 456 78', 'email@cliente.it', 'IT60 X054 2811 1010 0000 0123 456', 'Anagrafica di esempio', 'Cliente'],
|
|
|
|
];
|
|
|
|
|
|
|
|
directory('../../files/'.$module);
|
|
|
|
|
|
|
|
$fp = fopen('../../files/'.$module.'/'.$module.'.csv', 'w');
|
2018-08-11 15:49:46 +02:00
|
|
|
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
|
|
|
|
|
2018-06-22 17:04:37 +02:00
|
|
|
foreach ($list as $fields) {
|
|
|
|
fputcsv($fp, $fields, ';');
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
exit;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'import':
|
2018-02-23 19:04:05 +01:00
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
if (!empty($value)) {
|
|
|
|
$idtipoanagrafica = (array) $data[$key]['tipologia'];
|
|
|
|
unset($data[$key]['tipologia']);
|
2018-03-01 01:56:57 +01:00
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
// Insert o update
|
|
|
|
$insert = true;
|
|
|
|
if (!empty($primary_key)) {
|
|
|
|
$rs = $dbo->select('an_anagrafiche', $primary_key, [
|
|
|
|
$primary_key => $data[$key][$primary_key],
|
|
|
|
]);
|
2018-03-01 01:56:57 +01:00
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
$insert = !in_array($data[$key][$primary_key], $rs[0]);
|
|
|
|
}
|
2018-03-01 01:56:57 +01:00
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
// Insert
|
|
|
|
if ($insert) {
|
|
|
|
$dbo->insert('an_anagrafiche', $data[$key]);
|
2018-03-01 01:56:57 +01:00
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
// Campi extra
|
|
|
|
if (count($idtipoanagrafica) > 0) {
|
|
|
|
// Aggiornamento della tipologia di anagrafiche
|
|
|
|
$dbo->sync('an_tipianagrafiche_anagrafiche', [
|
|
|
|
'idanagrafica' => $dbo->lastInsertedID(),
|
|
|
|
], [
|
|
|
|
'idtipoanagrafica' => (array) $idtipoanagrafica,
|
|
|
|
]);
|
2018-03-01 01:56:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:39:19 +01:00
|
|
|
// Update
|
|
|
|
else {
|
|
|
|
$dbo->update('an_anagrafiche', $data[$key], [$primary_key => $data[$key][$primary_key]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($data[$key]);
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 01:56:57 +01:00
|
|
|
|
2018-02-23 19:04:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'field' => 'codice',
|
|
|
|
'label' => 'Codice',
|
2018-03-15 17:39:19 +01:00
|
|
|
'primary_key' => true,
|
2018-02-23 19:04:05 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'ragione_sociale',
|
|
|
|
'label' => 'Ragione sociale',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'provincia',
|
|
|
|
'label' => 'Provincia',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'citta',
|
|
|
|
'label' => 'Città',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'telefono',
|
|
|
|
'label' => 'Telefono',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'indirizzo',
|
|
|
|
'label' => 'Indirizzo',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'cap',
|
|
|
|
'label' => 'CAP',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'cellulare',
|
|
|
|
'label' => 'Cellulare',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'fax',
|
|
|
|
'label' => 'Fax',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'email',
|
|
|
|
'label' => 'Email',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'codice_fiscale',
|
|
|
|
'label' => 'Codice Fiscale',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'piva',
|
|
|
|
'label' => 'Partita IVA',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'codiceiban',
|
|
|
|
'label' => 'IBAN',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'note',
|
|
|
|
'label' => 'Note',
|
|
|
|
],
|
2018-02-28 21:40:16 +01:00
|
|
|
[
|
2018-02-23 19:04:05 +01:00
|
|
|
'field' => 'id_nazione',
|
|
|
|
'label' => 'Nazione',
|
2018-03-15 17:39:19 +01:00
|
|
|
'names' => [
|
|
|
|
'Nazione',
|
|
|
|
'id_nazione',
|
|
|
|
'idnazione',
|
|
|
|
'nazione',
|
|
|
|
],
|
2018-02-23 19:04:05 +01:00
|
|
|
'query' => 'SELECT id as result FROM an_nazioni WHERE LOWER(nome) = LOWER(|value|)',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'idagente',
|
|
|
|
'label' => 'ID Agente',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'idpagamento_vendite',
|
|
|
|
'label' => 'ID Pagamento',
|
2018-03-15 17:39:19 +01:00
|
|
|
'names' => [
|
|
|
|
'Pagamento',
|
|
|
|
'ID Pagamento',
|
|
|
|
'id_pagamento',
|
|
|
|
'idpagamento_vendite',
|
|
|
|
'idpagamento',
|
|
|
|
],
|
2018-02-23 19:04:05 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'field' => 'tipologia',
|
|
|
|
'label' => 'Tipologia',
|
2018-03-15 17:39:19 +01:00
|
|
|
'names' => [
|
|
|
|
'Tipologia',
|
|
|
|
'tipologia',
|
|
|
|
'idtipo',
|
|
|
|
],
|
2018-02-23 19:04:05 +01:00
|
|
|
'query' => 'SELECT idtipoanagrafica as result FROM an_tipianagrafiche WHERE descrizione = |value|',
|
|
|
|
],
|
|
|
|
];
|