Introduzione plugin FE

This commit is contained in:
Thomas Zilio 2018-07-09 12:57:55 +02:00
parent 5326df77d6
commit f90cb57c38
18 changed files with 134 additions and 128 deletions

View File

@ -80,7 +80,7 @@ echo '
</div>
</div>';
redirectOperation($id_module, $id_record);
redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record);
// Widget in basso
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "position": "right", "place": "controller" )}';

View File

@ -224,7 +224,7 @@ if (empty($records)) {
</div>';
}
redirectOperation($id_module, $id_record);
redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record);
// Widget in basso
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "right", "place": "editor" )}';

View File

@ -36,6 +36,12 @@ $total = App::readQuery($element);
$module_options = (!empty($element['options2'])) ? $element['options2'] : $element['options'];
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
include_once App::filepath($directory.'|custom|', 'modutil.php');
// Lettura risultato query del modulo
include App::filepath($directory.'|custom|', 'init.php');
// Caricamento file aggiuntivo su elenco record
include App::filepath($directory.'|custom|', 'controller_before.php');

View File

@ -192,6 +192,8 @@ if (!function_exists('download')) {
*/
function download($file, $filename = null)
{
ob_end_clean();
if (!headers_sent()) {
$filename = !empty($filename) ? $filename : basename($file);

View File

@ -11,9 +11,9 @@ $img = null;
if (!empty($records[0]['immagine01'])) {
$fileinfo = Uploads::fileInfo($records[0]['immagine01']);
$default_img = '/'.Uploads::getUploadDirectory($id_module).'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'];
$default_img = '/'.Uploads::getDirectory($id_module).'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'];
$img = file_exists(DOCROOT.$default_img) ? ROOTDIR.$default_img : ROOTDIR.'/'.Uploads::getUploadDirectory($id_module).'/'.$records[0]['immagine01'];
$img = file_exists(DOCROOT.$default_img) ? ROOTDIR.$default_img : ROOTDIR.'/'.Uploads::getDirectory($id_module).'/'.$records[0]['immagine01'];
}
?><form action="" method="post" id="edit-form" enctype="multipart/form-data">

View File

@ -2,8 +2,6 @@
include_once __DIR__.'/../../../core.php';
//<form action="plugin_editor.php?id_plugin=$id_plugin$&id_module=$id_module$&id_parent=$id_parent$" method="post" role="form">
//nuovo promemoria
$data_richiesta = date('d/m/Y');
$disabled = '';

View File

@ -1,95 +0,0 @@
<?php
include_once __DIR__.'/core.php';
// Lettura parametri iniziali
$info = Plugins::get($id_plugin);
if (empty($info) || empty($info['enabled'])) {
die(tr('Accesso negato'));
}
// Inclusione di eventuale plugin personalizzato
if (!empty($info['script'])) {
include App::filepath('modules/'.$info['module_dir'].'/plugins|custom|', $info['script']);
return;
}
// Plugin standard
else {
// Caricamento helper plugin (verifico se ci sono helper personalizzati)
include_once Plugins::filepath($info['id'], 'modutil.php');
// Lettura risultato query del plugin
include_once Plugins::filepath($info['id'], 'init.php');
// Esecuzione delle operazioni del plugin
include $docroot.'/actions.php';
if (empty($records)) {
echo '
<p>'.tr('Record non trovato').'.</p>';
} else {
// Lettura template plugin (verifico se ci sono template personalizzati, altrimenti uso quello base)
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.php')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/edit.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.html')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/edit.html';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/edit.php')) {
include $docroot.'/plugins/'.$info['directory'].'/edit.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/edit.html')) {
include $docroot.'/plugins/'.$info['directory'].'/edit.html';
}
// Campi personalizzati
echo '
<div class="hide" id="custom_fields_top-plugin">
{( "name": "custom_fields", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'", "position": "top" )}
</div>
<div class="hide" id="custom_fields_bottom-plugin">
{( "name": "custom_fields", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'" )}
</div>
<script>
$(document).ready(function(){
var form = $("#custom_fields_top-plugin").parent().find("form").first();
// Campi a inizio form
form.prepend($("#custom_fields_top-plugin").html());
// Campi a fine form
var last = form.find(".panel").last();
if (!last.length) {
last = form.find(".row").eq(-2);
}
last.after($("#custom_fields_bottom-plugin").html());
});
</script>';
}
redirectOperation($id_module, $id_parent);
$module = Modules::get($info['idmodule_to']);
if ($module['permessi'] != 'rw') {
?>
<script>
$(document).ready( function(){
$('input, textarea, select', 'section.content').attr('readonly', 'true');
$('select.chzn-done').prop('disabled', true).trigger('liszt:updated');
$('a.btn, button, input[type=button], input[type=submit]', 'section.content').hide();
$('a.btn-info, button.btn-info, input[type=button].btn-info', 'section.content').show();
});
</script>
<?php
}
}
echo '
<script src="'.$rootdir.'/lib/init.js"></script>';

View File

@ -33,13 +33,12 @@ class FatturaElettronica
$database = \Database::getConnection();
// Documento
$documento = $database->fetchOne('SELECT *, (SELECT `codice_tipo_documento_fe` FROM `co_tipidocumento` WHERE `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento`) AS `tipo_documento`, (SELECT `descrizione` FROM `co_statidocumento` WHERE `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`) AS `stato` FROM `co_documenti` WHERE `id` = '.prepare($id_documento));
$this->documento = $database->fetchOne('SELECT *, (SELECT `codice_tipo_documento_fe` FROM `co_tipidocumento` WHERE `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento`) AS `tipo_documento`, (SELECT `descrizione` FROM `co_statidocumento` WHERE `co_documenti`.`idstatodocumento` = `co_statidocumento`.`id`) AS `stato` FROM `co_documenti` WHERE `id` = '.prepare($id_documento));
// Controllo sulla possibilità di creare la fattura elettronica
if ($documento['stato'] != 'Emessa') {
throw new UnexpectedValueException();
if ($this->documento['stato'] != 'Emessa' || $this->getCliente()['tipo'] == 'Privato') {
throw new \UnexpectedValueException();
}
$this->documento = $documento;
}
/**
@ -497,14 +496,26 @@ class FatturaElettronica
*/
public function save($directory)
{
$documento = $this->getDocumento();
$filename = $documento['codice_xml'];
$azienda = self::getAzienda();
$codice = 'IT'.(empty($azienda['piva']) ? $azienda['codice_fiscale'] : $azienda['piva']);
// Generazione nome XML
if (empty($filename) || !starts_with($filename, $codice)) {
$filename = $this->getFilename();
// Salvataggio del file
$result = directory($directory) && file_put_contents(rtrim($directory, '/').'/'.$filename, $this->__toString());
return ($result === false) ? null : $filename;
}
/**
* Restituisce il nome del file XML per la fattura elettronica.
*
* @return string
*/
public function getFilename()
{
if (empty($this->documento['codice_xml'])) {
$azienda = self::getAzienda();
$codice = 'IT'.(empty($azienda['piva']) ? $azienda['codice_fiscale'] : $azienda['piva']);
$database = \Database::getConnection();
do {
@ -512,15 +523,11 @@ class FatturaElettronica
} while ($database->fetchNum('SELECT `id` FROM `co_documenti` WHERE `codice_xml` = '.prepare($filename)));
// Registrazione
$database->update('co_documenti', ['codice_xml' => $filename], ['id' => $documento['id']]);
$database->update('co_documenti', ['codice_xml' => $filename], ['id' => $this->getDocumento()['id']]);
$this->documento['codice_xml'] = $filename;
}
$filename .= '.xml';
// Salvataggio del file
$result = directory($directory) && file_put_contents(rtrim($directory, '/').'/'.$filename, $this->__toString());
return ($result === false) ? null : $filename;
return $this->documento['codice_xml'].'.xml';
}
/**

View File

@ -0,0 +1,30 @@
<?php
include_once __DIR__.'/../../core.php';
switch (filter('op')) {
case 'generate':
try {
$fattura = new Plugins\Fatturazione\FatturaElettronica($id_record);
$file = $fattura->save($upload_dir);
App::flash()->info(tr('Fattura elettronica generata correttamente!'));
if ($fattura->isValid()) {
App::flash()->warning(tr('La fattura elettronica potrebbe avere delle irregolarità!'));
}
} catch (UnexpectedValueException $e) {
App::flash()->error(tr('Impossibile generare la fattura elettronica'));
}
break;
case 'download':
try {
$fattura = new Plugins\Fatturazione\FatturaElettronica($id_record);
download($upload_dir.'/'.$fattura->getFilename());
} catch (UnexpectedValueException $e) {
}
break;
}

View File

@ -0,0 +1,33 @@
<?php
include_once __DIR__.'/../../core.php';
if ($download) {
echo '
<div class="row">
<div class="col-md-6">';
}
echo '
<form action="" method="post" role="form">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="generate">
<button type="submit" class="btn btn-primary btn-lg btn-block'.($disabled ? ' disabled' : null).'" '.($disabled ? ' disabled' : null).'>
<i class="fa fa-file"></i> '.tr('Genera fattura elettronica').'
</button>
</form>';
if ($download) {
echo '
</div>
<div class="col-md-6">
<a href="'.ROOTDIR.'/editor.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'&id_record='.$id_record.'&op=download" class="btn btn-success btn-lg btn-block" target="_blank">
<i class="fa fa-download "></i> '.tr('Scarica fattura elettronica').'
</a>
</div>
</div>';
}

View File

@ -0,0 +1,15 @@
<?php
include_once __DIR__.'/../../core.php';
$upload_dir = DOCROOT.'/'.Uploads::getDirectory($id_module, $id_plugin);
try {
$fattura = new Plugins\Fatturazione\FatturaElettronica($id_record);
$disabled = false;
$download = file_exists($upload_dir.'/'.$fattura->getFilename());
} catch (UnexpectedValueException $e) {
$disabled = true;
$download = false;
}

View File

@ -3,7 +3,8 @@
include_once __DIR__.'/../../core.php';
echo '
<form action="plugin_editor.php?id_plugin=$id_plugin$&id_module=$id_module$&id_parent=$id_parent$" method="post" role="form">
<form action="" method="post" role="form">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="addreferente">

View File

@ -3,7 +3,10 @@
include_once __DIR__.'/../../core.php';
echo '
<form action="plugin_editor.php?id_plugin=$id_plugin$&id_module=$id_module$&id_record=$id_record$&id_parent=$id_parent$" method="post" role="form" id="form_sedi">
<form action="" method="post" role="form">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="updatereferente">
@ -36,7 +39,7 @@ echo '
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12">
<a class="btn btn-danger ask" data-backto="record-edit" data-href="'.$rootdir.'/plugin_editor.php" data-op="deletereferente" data-id_record="'.$records[0]['id'].'" data-id_plugin="'.$id_plugin.'" data-id_module="'.$id_module.'" data-id_parent="'.$id_parent.'">
<a class="btn btn-danger ask" data-backto="record-edit" data-op="deletereferente" data-id_record="'.$records[0]['id'].'" data-id_plugin="'.$id_plugin.'" data-id_module="'.$id_module.'" data-id_parent="'.$id_parent.'">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</a>

View File

@ -3,7 +3,8 @@
include_once __DIR__.'/../../core.php';
echo '
<form action="plugin_editor.php?id_plugin=$id_plugin$&id_module=$id_module$&id_parent=$id_parent$" method="post" role="form">
<form action="" method="post" role="form">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="addsede">

View File

@ -12,7 +12,10 @@ if (!empty($google)) {
*/
echo '
<form action="plugin_editor.php?id_plugin=$id_plugin$&id_module=$id_module$&id_record=$id_record$&id_parent=$id_parent$" method="post" role="form" id="form_sedi">
<form action="" method="post" role="form" id="form_sedi">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="updatesede">
@ -136,7 +139,7 @@ echo '
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12">
<a class="btn btn-danger ask" data-backto="record-edit" data-href="'.$rootdir.'/plugin_editor.php" data-op="deletesede" data-id_record="'.$records[0]['id'].'" data-id_plugin="'.$id_plugin.'" data-id_module="'.$id_module.'" data-id_parent="'.$id_parent.'">
<a class="btn btn-danger ask" data-backto="record-edit" data-op="deletesede" data-id_record="'.$records[0]['id'].'" data-id_plugin="'.$id_plugin.'" data-id_module="'.$id_module.'" data-id_parent="'.$id_parent.'">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</a>

View File

@ -27,7 +27,7 @@ class FileManager implements ManagerInterface
$attachment_id = 'attachments_'.$options['id_module'].'-'.$options['id_plugin'];
// Cartella delle anteprime
$directory = \Uploads::getUploadDirectory($options['id_module'], $options['id_plugin']);
$directory = \Uploads::getDirectory($options['id_module'], $options['id_plugin']);
$dbo = \Database::getConnection();

View File

@ -120,7 +120,7 @@ class Uploads
'wpd' => 'application/wordperfect',
];
public static function getUploadDirectory($id_module, $id_plugin = null)
public static function getDirectory($id_module, $id_plugin = null)
{
if (empty($id_plugin)) {
$directory = Modules::get($id_module)['directory'];
@ -155,7 +155,7 @@ class Uploads
$extension = strtolower(pathinfo($original)['extension']);
$ok = self::isSupportedType($extension);
$directory = DOCROOT.'/'.self::getUploadDirectory($data['id_module'], $data['id_plugin']);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
do {
$filename = random_string().'.'.$extension;
@ -236,7 +236,7 @@ class Uploads
])['nome'];
$fileinfo = self::fileInfo($filename);
$directory = DOCROOT.'/'.self::getUploadDirectory($data['id_module'], $data['id_plugin']);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
$files = [
$directory.'/'.$fileinfo['basename'],

View File

@ -204,6 +204,8 @@ età svizzere che possiedono i requisiti di cui all''art. 15, c. 2 dellAccord
INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Causale ritenuta d''acconto', '', 'query=SELECT codice AS id, descrizione FROM fe_causali_pagamento_ritenuta', 1, 'Fatturazione', 0);
INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `directory`, `options`) VALUES (NULL, 'Fatturazione Elettronica', 'Fatturazione Elettronica', (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di vendita'), (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di vendita'), 'tab', 'fatturazione', 'custom');
-- Aggiornamento zz_settings
ALTER TABLE `zz_settings` CHANGE `idimpostazione` `id` int(11) NOT NULL AUTO_INCREMENT;
UPDATE `zz_views` SET `query` = REPLACE(`query`, 'idimpostazione', 'id');