1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-01-23 20:30:51 +01:00

Introdotto build per referenti

This commit is contained in:
Luca 2022-10-08 17:28:43 +02:00
parent 508ab0c7e9
commit 0bdadffd2a
2 changed files with 41 additions and 12 deletions

View File

@ -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.

View File

@ -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!'));