diff --git a/modules/anagrafiche/src/Referente.php b/modules/anagrafiche/src/Referente.php index 5bb83c7b7..22fec8706 100644 --- a/modules/anagrafiche/src/Referente.php +++ b/modules/anagrafiche/src/Referente.php @@ -27,6 +27,31 @@ class Referente extends Model use SimpleModelTrait; protected $table = 'an_referenti'; + + /** + * Crea un nuovo referente. + * + * @param string $nome + * + * @return self + */ + public static function build($idanagrafica, $nome, $idmansione, $idsede) + { + $model = new static(); + + + $model->idanagrafica = $idanagrafica; + + $model->nome = $nome; + + $model->idmansione = $idmansione; + $model->idsede = $idsede; + + $model->save(); + + return $model; + } + /** * The attributes that aren't mass assignable. diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index 5b5f0dbc3..6d21d9d19 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -135,7 +135,7 @@ if (!empty($note_accredito)) { ]); echo ' -
'.Modules::link('Fatture di vendita', $nota['id'], $text, $text); +
'.Modules::link( ($dir == 'entrata' ? 'Fatture di vendita' : 'Fatture di acquisto' ), $nota['id'], $text, $text); } echo ' '; diff --git a/modules/scadenzario/actions.php b/modules/scadenzario/actions.php index c09857e4c..71f8571ef 100755 --- a/modules/scadenzario/actions.php +++ b/modules/scadenzario/actions.php @@ -34,6 +34,7 @@ switch (post('op')) { break; case 'update': + $idanagrafica = post('idanagrafica'); $tipo = post('tipo'); $descrizione = post('descrizione'); $iddocumento = post('iddocumento') ?: 0; @@ -79,6 +80,7 @@ switch (post('op')) { $id_scadenza = post('id_scadenza')[$id]; if (!empty($id_scadenza)) { $database->update('co_scadenziario', [ + 'idanagrafica' => $idanagrafica, 'descrizione' => $descrizione, 'da_pagare' => $da_pagare, 'pagato' => $pagato, diff --git a/modules/scadenzario/edit.php b/modules/scadenzario/edit.php index edfd4122c..93dda4598 100755 --- a/modules/scadenzario/edit.php +++ b/modules/scadenzario/edit.php @@ -31,6 +31,7 @@ echo ' +
diff --git a/modules/statistiche/edit.php b/modules/statistiche/edit.php index 4d0533cd2..3e3ee0627 100755 --- a/modules/statistiche/edit.php +++ b/modules/statistiche/edit.php @@ -474,7 +474,7 @@ $(document).ready(function() { data: { labels: months, datasets: [ - '.$dataset.' + '.($dataset? :'{ label: "", backgroundColor: "transparent", data: [ 0,0,0,0,0,0,0,0,0,0,0,0 ] }').' ] }, options: { @@ -549,7 +549,6 @@ INNER JOIN an_tipianagrafiche_anagrafiche ON an_anagrafiche.idanagrafica=an_tipi INNER JOIN an_tipianagrafiche ON an_tipianagrafiche_anagrafiche.idtipoanagrafica=an_tipianagrafiche.idtipoanagrafica WHERE an_tipianagrafiche.descrizione = "Cliente" AND co_tipidocumento.dir = "entrata" AND an_anagrafiche.created_at BETWEEN '.prepare($start).' AND '.prepare($end).' GROUP BY YEAR(an_anagrafiche.created_at), MONTH(an_anagrafiche.created_at) ORDER BY YEAR(an_anagrafiche.created_at) ASC, MONTH(an_anagrafiche.created_at) ASC'); -$clienti = Stats::monthly($clienti, $start, $end); //Random color $background = '#'.dechex(rand(256, 16777215)); diff --git a/plugins/referenti/actions.php b/plugins/referenti/actions.php index 17befdf59..5736c9cf0 100755 --- a/plugins/referenti/actions.php +++ b/plugins/referenti/actions.php @@ -19,26 +19,30 @@ include_once __DIR__.'/../../core.php'; +use Modules\Anagrafiche\Referente; + $operazione = filter('op'); switch ($operazione) { case 'addreferente': if (!empty(post('nome'))) { - $opt_out_newsletter = post('disable_newsletter'); - $dbo->insert('an_referenti', [ - 'idanagrafica' => $id_parent, - 'nome' => post('nome'), - 'idmansione' => post('idmansione'), - 'telefono' => post('telefono'), - 'email' => post('email'), - 'idsede' => post('idsede'), - 'enable_newsletter' => empty($opt_out_newsletter), - ]); - $id_record = $dbo->lastInsertedID(); + $nome = post('nome'); + $idmansione = post('idmansione'); + $idsede = post('idsede'); + $opt_out_newsletter = post('disable_newsletter'); + + $referente = Referente::build($id_parent, $nome, $idmansione, $idsede); + $id_record = $referente->id; + + $referente->telefono = post('telefono'); + $referente->email = post('email'); + $referente->enable_newsletter = empty($opt_out_newsletter); + + $referente->save(); if (isAjaxRequest() && !empty($id_record)) { - echo json_encode(['id' => $id_record, 'text' => post('nome')]); + echo json_encode(['id' => $id_record, 'text' => $referente->nome]); } flash()->info(tr('Aggiunto nuovo referente!'));