Aggiunta API per creazione e modifica Articoli
Stile del codice generale.
This commit is contained in:
parent
a07234ec4b
commit
b7a3b3d851
|
@ -97,9 +97,7 @@ elseif (filter('op') == 'download-allegato') {
|
|||
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename')));
|
||||
|
||||
download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']);
|
||||
}
|
||||
|
||||
elseif (filter('op') == 'visualizza-modifica-allegato') {
|
||||
} elseif (filter('op') == 'visualizza-modifica-allegato') {
|
||||
include_once base_dir().'/include/modifica_allegato.php';
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
|
||||
namespace Modules\Articoli\API\v1;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
use API\Interfaces\UpdateInterface;
|
||||
use API\Resource;
|
||||
use Modules\Articoli\Articolo;
|
||||
use Modules\Articoli\Categoria;
|
||||
|
||||
class Articoli extends Resource implements RetrieveInterface
|
||||
class Articoli extends Resource implements RetrieveInterface, UpdateInterface, CreateInterface
|
||||
{
|
||||
public function retrieve($request)
|
||||
{
|
||||
|
@ -35,4 +39,71 @@ class Articoli extends Resource implements RetrieveInterface
|
|||
'query' => $query,
|
||||
];
|
||||
}
|
||||
|
||||
public function create($request)
|
||||
{
|
||||
$data = $request['data'];
|
||||
|
||||
// Gestione categoria
|
||||
list($categoria, $sottocategoria) = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
|
||||
|
||||
$articolo = Articolo::build($data['codice'], $data['descrizione'], $categoria, $sottocategoria);
|
||||
$articolo->setPrezzoVendita($data['prezzo_vendita'], $articolo->idiva_vendita);
|
||||
$articolo->save();
|
||||
|
||||
return [
|
||||
'id' => $articolo->id,
|
||||
];
|
||||
}
|
||||
|
||||
public function update($request)
|
||||
{
|
||||
$data = $request['data'];
|
||||
|
||||
$articolo = Articolo::find($request['id']);
|
||||
list($categoria, $sottocategoria) = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
|
||||
|
||||
// Gestione categoria
|
||||
if (!empty($categoria)) {
|
||||
$articolo->categoria()->associate($categoria);
|
||||
}
|
||||
if (!empty($sottocategoria)) {
|
||||
$articolo->sottocategoria()->associate($sottocategoria);
|
||||
}
|
||||
|
||||
$articolo->descrizione = $data['descrizione'];
|
||||
$articolo->setPrezzoVendita($data['prezzo_vendita'], $articolo->idiva_vendita);
|
||||
|
||||
$articolo->save();
|
||||
}
|
||||
|
||||
protected function gestioneCategorie($nome_categoria, $nome_sottocategoria)
|
||||
{
|
||||
$sottocategoria = null;
|
||||
|
||||
// Gestione categoria
|
||||
$categoria = Categoria::where('nome', '=', $nome_categoria)
|
||||
->first();
|
||||
if (empty($categoria) && !empty($nome_categoria)) {
|
||||
$categoria = Categoria::build($nome_categoria);
|
||||
$categoria->save();
|
||||
}
|
||||
|
||||
// Caso categoria inesistente
|
||||
if (empty($categoria)) {
|
||||
return [$categoria, $sottocategoria];
|
||||
}
|
||||
|
||||
// Gestione sotto-categoria
|
||||
$sottocategoria = Categoria::where('nome', '=', $nome_sottocategoria)
|
||||
->where('parent', '=', $categoria->id)
|
||||
->first();
|
||||
if (empty($sottocategoria) && !empty($nome_sottocategoria)) {
|
||||
$sottocategoria = Categoria::build($nome_sottocategoria);
|
||||
$sottocategoria->parent = $categoria->id;
|
||||
$sottocategoria->save();
|
||||
}
|
||||
|
||||
return [$categoria, $sottocategoria];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,7 @@ class Sync extends Resource implements RetrieveInterface, UpdateInterface
|
|||
|
||||
if ($user->anagrafica->isTipo('Tecnico')) {
|
||||
$query .= ' AND in_interventi_tecnici.idtecnico = '.prepare($user['idanagrafica']);
|
||||
}
|
||||
|
||||
elseif ($user->anagrafica->isTipo('Cliente')) {
|
||||
} elseif ($user->anagrafica->isTipo('Cliente')) {
|
||||
$query .= ' AND in_interventi.idanagrafica = '.prepare($user['idanagrafica']);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ include_once __DIR__.'/../../core.php';
|
|||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "checkbox", "label": "<?php echo tr('Tipo documento predefinito'); ?>", "name": "predefined", "value": "<?php echo intval($record['predefined']); ?>", "help":"<?php echo tr('Impostare questo tipo di documento predefinto per le fatture di '); echo (($record['dir']=='entrata')? tr('Vendita'):tr('Acquisto')); ?>." ]}
|
||||
{[ "type": "checkbox", "label": "<?php echo tr('Tipo documento predefinito'); ?>", "name": "predefined", "value": "<?php echo intval($record['predefined']); ?>", "help":"<?php echo tr('Impostare questo tipo di documento predefinto per le fatture di '); echo ($record['dir'] == 'entrata') ? tr('Vendita') : tr('Acquisto'); ?>." ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "checkbox", "label": "<?php echo tr('Attivo'); ?>", "name": "enabled", "disabled": "<?php echo (($record['predefined'] && $record['enabled']) ? 1 : 0); ?>", "value": "<?php echo intval($record['enabled']); ?>" ]}
|
||||
{[ "type": "checkbox", "label": "<?php echo tr('Attivo'); ?>", "name": "enabled", "disabled": "<?php echo ($record['predefined'] && $record['enabled']) ? 1 : 0; ?>", "value": "<?php echo intval($record['enabled']); ?>" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
namespace Plugins\PianificazioneInterventi\Components;
|
||||
|
||||
use Common\Components\Article;
|
||||
use Modules\Articoli\Articolo as Original;
|
||||
use Modules\Contratti\Contratto;
|
||||
use Plugins\PianificazioneInterventi\Promemoria;
|
||||
|
||||
class Articolo extends Article
|
||||
{
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
namespace Plugins\PianificazioneInterventi\Components;
|
||||
|
||||
use Common\Components\Description;
|
||||
use Modules\Contratti\Contratto;
|
||||
use Plugins\PianificazioneInterventi\Promemoria;
|
||||
|
||||
class Descrizione extends Description
|
||||
{
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
namespace Plugins\PianificazioneInterventi\Components;
|
||||
|
||||
use Common\Components\Row;
|
||||
use Modules\Contratti\Contratto;
|
||||
use Plugins\PianificazioneInterventi\Promemoria;
|
||||
|
||||
class Riga extends Row
|
||||
{
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
namespace Plugins\PianificazioneInterventi\Components;
|
||||
|
||||
use Common\Components\Discount;
|
||||
use Plugins\PianificazioneInterventi\Promemoria;
|
||||
|
||||
class Sconto extends Discount
|
||||
{
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
namespace HTMLBuilder\Manager;
|
||||
|
||||
use Models\Upload;
|
||||
use Models\Setting;
|
||||
use Models\Upload;
|
||||
|
||||
/**
|
||||
* Gestione allegati.
|
||||
|
|
|
@ -59,7 +59,7 @@ class Upload extends Model
|
|||
$value = null;
|
||||
}
|
||||
|
||||
$this->attributes['category'] = $value;;
|
||||
$this->attributes['category'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,18 +226,6 @@ class Upload extends Model
|
|||
return $this->extension == 'pdf';
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se l'estensione è supportata dal sistema di upload.
|
||||
*
|
||||
* @param string $extension
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSupportedType($extension)
|
||||
{
|
||||
return !in_array(strtolower($extension), array_keys(self::$not_allowed_types));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -301,6 +289,18 @@ class Upload extends Model
|
|||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se l'estensione è supportata dal sistema di upload.
|
||||
*
|
||||
* @param string $extension
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSupportedType($extension)
|
||||
{
|
||||
return !in_array(strtolower($extension), array_keys(self::$not_allowed_types));
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera casualmente il nome fisico per il file.
|
||||
*
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
use Models\Upload;
|
||||
use Util\FileSystem;
|
||||
|
||||
/**
|
||||
* Classe per la gestione degli upload del progetto.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
UPDATE `zz_views` SET `query` = '(righe.totale + `co_documenti`.`rivalsainps` + `co_documenti`.`iva_rivalsainps` - `co_documenti`.`ritenutaacconto` - `co_documenti`.`sconto_finale`) * (1 - `co_documenti`.`sconto_finale_percentuale` / 100) * IF(co_tipidocumento.reversed, -1, 1)' WHERE `name` = 'Netto a pagare' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `zz_modules`.`name` = 'Fatture di vendita');
|
||||
UPDATE `zz_views` SET `query` = '(righe.totale + `co_documenti`.`rivalsainps` + `co_documenti`.`iva_rivalsainps` - `co_documenti`.`ritenutaacconto` - `co_documenti`.`sconto_finale`) * (1 - `co_documenti`.`sconto_finale_percentuale` / 100) * IF(co_tipidocumento.reversed, -1, 1)' WHERE `name` = 'Netto a pagare' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `zz_modules`.`name` = 'Fatture di acquisto');
|
||||
|
||||
|
||||
|
||||
-- Fix aggiornamento query Articoli per aggiunta quantità ordinata
|
||||
UPDATE `zz_modules` SET `options` = 'SELECT |select|
|
||||
FROM `mg_articoli`
|
||||
|
@ -35,7 +33,6 @@ WHERE 1=1 AND (`mg_articoli`.`deleted_at`) IS NULL
|
|||
HAVING 2=2
|
||||
ORDER BY `mg_articoli`.`descrizione`' WHERE `zz_modules`.`name`='Articoli';
|
||||
|
||||
|
||||
-- Rimozione flag inutilizzato
|
||||
ALTER TABLE `or_statiordine` DROP `annullato`;
|
||||
|
||||
|
@ -49,3 +46,8 @@ UPDATE `zz_modules` SET `options` = 'SELECT |select|\nFROM `mg_articoli`\n LE
|
|||
-- Fix query widgets Fatturato e Acquisti
|
||||
UPDATE `zz_widgets` SET `query` = 'SELECT\n CONCAT_WS(\' \', REPLACE(REPLACE(REPLACE(FORMAT((\n SELECT SUM(\n (co_righe_documenti.subtotale - co_righe_documenti.sconto) * IF(co_tipidocumento.reversed, -1, 1)\n )\n ), 2), \',\', \'#\'), \'.\', \',\'), \'#\', \'.\'), \'€\') AS dato\nFROM co_righe_documenti\n INNER JOIN co_documenti ON co_righe_documenti.iddocumento = co_documenti.id\n INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento = co_tipidocumento.id\nWHERE co_tipidocumento.dir=\'entrata\' |segment| AND data >= \'|period_start|\' AND data <= \'|period_end|\' AND 1=1' WHERE `zz_widgets`.`name` = 'Fatturato';
|
||||
UPDATE `zz_widgets` SET `query` = 'SELECT\n CONCAT_WS(\' \', REPLACE(REPLACE(REPLACE(FORMAT((\n SELECT SUM(\n (co_righe_documenti.subtotale - co_righe_documenti.sconto) * IF(co_tipidocumento.reversed, -1, 1)\n )\n ), 2), \',\', \'#\'), \'.\', \',\'), \'#\', \'.\'), \'€\') AS dato\nFROM co_righe_documenti\n INNER JOIN co_documenti ON co_righe_documenti.iddocumento = co_documenti.id\n INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento = co_tipidocumento.id\nWHERE co_tipidocumento.dir=\'uscita\' |segment| AND data >= \'|period_start|\' AND data <= \'|period_end|\' AND 1=1' WHERE `zz_widgets`.`name` = 'Acquisti';
|
||||
|
||||
-- Aggiunta risorse API per creazione e modifica Articoli
|
||||
INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `enabled`) VALUES
|
||||
(NULL, 'v1', 'create', 'articolo', 'Modules\\Articoli\\API\\v1\\Articoli', '1'),
|
||||
(NULL, 'v1', 'update', 'articolo', 'Modules\\Articoli\\API\\v1\\Articoli', '1');
|
||||
|
|
Loading…
Reference in New Issue