1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-01 16:36:45 +01:00

Bugfix nella procedura di backup

Miglioramento della procedura di backup, ora utilizzante la libreria ifsnop/mysqldump-php per ottimizzare la creazione del dump del database.
Miglioramento della creazione dello zip e della copia delle cartelle.
This commit is contained in:
Thomas Zilio 2017-09-08 13:24:48 +02:00
parent f25677ef33
commit def49a5659
24 changed files with 178 additions and 934 deletions

View File

@ -78,11 +78,7 @@ if (filter('op') == 'send') {
// Se ho scelto di inoltrare copia del db
if (!empty($post['sql'])) {
$dump = "SET foreign_key_checks = 0;\n";
$dump .= backup_tables();
$dump .= "SET foreign_key_checks = 1;\n";
$backup_file = 'Backup OSM '.date('Y-m-d').' '.date('H_i_s').'.sql';
backup_tables('Backup OSM '.date('Y-m-d').' '.date('H_i_s').'.sql');
if (file_put_contents($docroot.'/'.$backup_file, $dump)) {
$mail->AddAttachment($docroot.'/'.$backup_file);

View File

@ -25,6 +25,7 @@
"php": ">=5.4",
"ezyang/htmlpurifier": "^4.8",
"filp/whoops": "^2.1",
"ifsnop/mysqldump-php": "^2.3",
"intervention/image": "^2.3",
"ircmaxell/password-compat": "^1.0",
"maximebf/debugbar": "^1.13",
@ -32,7 +33,8 @@
"mpdf/mpdf": "^6.1",
"paragonie/random_compat": "^2.0",
"phpmailer/phpmailer": "^5.2",
"spipu/html2pdf": "^4.6",
"spipu/html2pdf": "^5.0",
"symfony/finder": "^3.3",
"symfony/translation": "^3.2"
},
"autoload": {

View File

@ -81,7 +81,7 @@ echo '
</div>
</div>';
redirectOperation();
redirectOperation($id_module, $id_record);
/**
* Widget laterali.

View File

@ -118,7 +118,7 @@ if (file_exists($docroot.'/modules/'.$module_dir.'/add.php') && $module['permess
</div>';
}
redirectOperation();
redirectOperation($id_module, $id_record);
echo '
<hr>

View File

@ -236,16 +236,19 @@ gulp.task('release', function () {
del([
'./vendor/tecnickcom/tcpdf/fonts/*',
'!./vendor/tecnickcom/tcpdf/fonts/*helvetica*',
'./vendor/mpdf/mpdf/iccprofiles/*',
'./vendor/mpdf/mpdf/qrcode/*',
'./vendor/mpdf/mpdf/ttfonts/*',
]);
var output = fs.createWriteStream('./release.zip');
var archive = archiver('zip');
output.on('close', function() {
output.on('close', function () {
console.log('ZIP completato!');
});
archive.on('error', function(err) {
archive.on('error', function (err) {
throw err;
});

View File

@ -42,7 +42,6 @@ if (post('db_host') !== null) {
'CREATE',
'ALTER',
'DROP',
'CREATE VIEW',
];
$db_host = str_replace('_', '\_', $db_name);

View File

@ -30,19 +30,15 @@ switch ($op) {
if ($found) {
$_SESSION['infos'][] = tr('Backup saltato perché già esistente!');
} elseif (do_backup()) {
$_SESSION['infos'][] = tr('Backup automatico eseguito correttamente!');
} elseif (empty($backup_dir)) {
$_SESSION['errors'][] = tr('Non è possibile eseguire i backup poichè la cartella di backup non esiste!!!');
} elseif (!file_exists($backup_dir)) {
if (create_dir($backup_dir)) {
$_SESSION['infos'][] = tr('La cartella di backup è stata creata correttamente.');
if (do_backup()) {
$_SESSION['infos'][] = tr('Backup automatico eseguito correttamente!');
}
} else {
$_SESSION['errors'][] = tr('Non è stato possibile creare la cartella di backup!');
$_SESSION['errors'][] = tr('Non è possibile eseguire i backup poichè la cartella di backup non è stata impostata!!!');
} elseif (file_exists($backup_dir) || create_dir($backup_dir)) {
$_SESSION['infos'][] = tr('La cartella di backup è stata creata correttamente.');
if (do_backup()) {
$_SESSION['infos'][] = tr('Backup automatico eseguito correttamente!');
}
} else {
$_SESSION['errors'][] = tr('Non è stato possibile creare la cartella di backup!');
}
}
}

View File

@ -1,5 +1,6 @@
<?php
/**
* Esegue il redirect.
*
@ -82,100 +83,76 @@ function deltree($path)
*
* @return bool Returns TRUE on success, FALSE on failure
*/
function copyr($source, $dest, $ignores = [])
function copyr($source, $destination, $ignores = [])
{
$ignores = (array) $ignores;
foreach ($ignores as $key => $value) {
$ignores[$key] = slashes($value);
$finder = Symfony\Component\Finder\Finder::create()
->files()
->exclude((array) $ignores['dirs'])
->ignoreDotFiles(true)
->ignoreVCS(true)
->in($source);
foreach ((array) $ignores['files'] as $value) {
$finder->notName($value);
}
$path = realpath($source);
$exclude = !empty(array_intersect($ignores, [slashes($path), slashes($path.'/'), $entry]));
foreach ($finder as $file) {
$filename = rtrim($destination, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getRelativePathname();
if ($exclude) {
return;
}
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
create_dir($dest);
}
// If the source is a symlink
if (is_link($source)) {
$link_dest = readlink($source);
return symlink($link_dest, $dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
// Creazione della cartella di base
if (!file_exists(dirname($filename))) {
create_dir(dirname($filename));
}
$path = realpath($source.'/'.$entry.'/');
$exclude = !empty(array_intersect($ignores, [slashes($path), slashes($path.'/'), $entry]));
// Simple copy for a file
if (is_file($file)) {
copy($file, $filename);
}
// Deep copy directories
if (slashes($dest) !== slashes($source.'/'.$entry) && !$exclude) {
copyr($source.'/'.$entry, $dest.'/'.$entry, $ignores);
// If the source is a symlink
if (is_link($file)) {
$link_dest = readlink($file);
symlink($link_dest, $filename);
}
}
// Clean up
$dir->close();
return true;
}
/**
* Crea un file zip comprimendo ricorsivamente tutte le sottocartelle a partire da una cartella specificata.
* *.
*
* @see http://stackoverflow.com/questions/1334613/how-to-recursively-zip-a-directory-in-php
*
* @param unknown $source
* @param unknown $destination
* @param string $source
* @param string $destination
* @param array $ignores
*/
function create_zip($source, $destination)
function create_zip($source, $destination, $ignores = [])
{
if (!extension_loaded('zip') || !file_exists($source)) {
if (!extension_loaded('zip')) {
$_SESSION['errors'][] = tr('Estensione zip non supportata!');
return false;
}
$destination = slashes($destination);
$zip = new ZipArchive();
$result = $zip->open($destination, ZIPARCHIVE::CREATE);
if ($result === true && is_writable(dirname($destination))) {
$source = slashes(realpath($source));
$finder = Symfony\Component\Finder\Finder::create()
->files()
->exclude((array) $ignores['dirs'])
->ignoreDotFiles(true)
->ignoreVCS(true)
->in($source);
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = slashes(realpath($file));
$filename = str_replace($source.DIRECTORY_SEPARATOR, '', $file);
if (is_dir($file) === true) {
$zip->addEmptyDir($filename);
} elseif (is_file($file) === true && $destination != $file) {
$zip->addFromString($filename, file_get_contents($file));
}
}
} elseif (is_file($source) === true && $destination != $source) {
$zip->addFromString(basename($source), file_get_contents($source));
foreach ((array) $ignores['files'] as $value) {
$finder->notName($value);
}
foreach ($finder as $file) {
$zip->addFile($file, $file->getRelativePathname());
}
$zip->close();
} else {
$_SESSION['errors'][] = tr("Errore durante la creazione dell'archivio!");
@ -239,49 +216,51 @@ function checkZip($zip_file)
*
* @return bool
*/
function do_backup()
function do_backup($path = null)
{
global $backup_dir;
set_time_limit(0);
if (extension_loaded('zip')) {
$tmp_backup_dir = '/tmp/';
} else {
$tmp_backup_dir = '/OSM backup '.date('Y-m-d').' '.date('H_i_s').'/';
}
$path = !empty($path) ? $path : DOCROOT;
// Creazione cartella temporanea
if (file_exists($backup_dir.$tmp_backup_dir) || create_dir($backup_dir.$tmp_backup_dir)) {
$do_backup = true;
} else {
$do_backup = false;
}
$backup_name = 'OSM backup '.date('Y-m-d').' '.date('H_i_s');
if (
(extension_loaded('zip') && (file_exists($backup_dir.'tmp') || create_dir($backup_dir.'tmp'))) ||
(!extension_loaded('zip') && (file_exists($backup_dir.$backup_name) || create_dir($backup_dir.$backup_name)))
) {
// Backup del database
$database_file = $backup_dir.(extension_loaded('zip') ? 'tmp' : $backup_name).'/database.sql';
backup_tables($database_file);
if ($do_backup) {
$database_file = 'database.sql';
$backup_file = 'OSM backup '.date('Y-m-d').' '.date('H_i_s').'.zip';
// Percorsi da ignorare di default
$ignores = [
'files' => [
'config.inc.php',
],
'dirs' => [
basename($backup_dir),
'.couscous',
'node_modules',
'tests',
],
];
// Dump database
$dump = "SET foreign_key_checks = 0;\n";
$dump .= backup_tables();
$dump .= "SET foreign_key_checks = 1;\n";
file_put_contents($backup_dir.$tmp_backup_dir.$database_file, $dump);
// Copia file di OSM (escludendo la cartella di backup)
copyr(DOCROOT, $backup_dir.$tmp_backup_dir, [slashes($backup_dir), '.svn', '.git', 'config.inc.php', 'node_modules']);
// Creazione zip
// Creazione dello zip
if (extension_loaded('zip')) {
if (create_zip($backup_dir.$tmp_backup_dir, $backup_dir.$backup_file)) {
if (create_zip([$path, dirname($database_file)], $backup_dir.$backup_name.'.zip', $ignores)) {
$_SESSION['infos'][] = tr('Nuovo backup creato!');
} else {
$_SESSION['errors'][] = tr('Errore durante la creazione del backup!');
}
// Rimozione cartella temporanea
deltree($backup_dir.$tmp_backup_dir);
} else {
unlink($database_file);
}
// Copia dei file di OSM
else {
copyr($path, $backup_dir.$backup_name, $ignores);
$_SESSION['infos'][] = tr('Nuovo backup creato!');
}
@ -315,9 +294,11 @@ function do_backup()
}
}
}
return true;
}
return $do_backup;
return false;
}
/**
@ -329,63 +310,16 @@ function do_backup()
*
* @return string
*/
function backup_tables($tables = '*')
function backup_tables($file)
{
$dbo = Database::getConnection();
global $backup_dir;
global $db_host;
global $db_name;
global $db_username;
global $db_password;
if ($tables == '*') {
$tables = [];
$result = $dbo->fetchArray('SHOW TABLES', true);
if ($result != null) {
foreach ($result as $res) {
$tables[] = $res[0];
}
}
} else {
$tables = is_array($tables) ? $tables : explode(',', $tables);
}
// Eliminazione di tutte le tabelle
foreach ($tables as $table) {
$return .= "DROP TABLE IF EXISTS `$table`;\n";
}
// Ricreazione della struttura di ogni tabella e ri-popolazione database
foreach ($tables as $table) {
$result = $dbo->fetchArray('SELECT * FROM '.$table, true);
$num_fields = count($result[0]);
$row2 = $dbo->fetchArray('SHOW CREATE TABLE '.$table);
$return .= "\n".$row2[1].";\n";
for ($i = 0; $i < $num_fields; ++$i) {
foreach ($result as $row) {
$return .= 'INSERT INTO '.$table.' VALUES(';
for ($j = 0; $j < $num_fields; ++$j) {
$row[$j] = addslashes($row[$j]);
$row[$j] = str_replace("\r\n", '\\n', $row[$j]);
$row[$j] = str_replace("\n", '\\n', $row[$j]);
if (isset($row[$j])) {
$return .= '"'.$row[$j].'"';
} else {
$return .= '""';
}
if ($j < ($num_fields - 1)) {
$return .= ',';
}
}
$return .= ");\n";
}
}
$return .= "\n";
}
return $return;
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$db_host.';dbname='.$db_name, $db_username, $db_password, ['add-drop-table' => true]);
$dump->start($file);
}
/**
@ -878,11 +812,8 @@ function sum($first, $second = null, $decimals = null)
return $result;
}
function redirectOperation()
function redirectOperation($id_module, $id_record)
{
$id_module = filter('id_module');
$id_record = filter('id_record');
$backto = filter('backto');
// Scelta del redirect dopo un submit
if (!empty($backto)) {

View File

@ -12,8 +12,9 @@ switch (filter('op')) {
case 'del':
$file = filter('file');
deltree($backup_dir.$file);
if (deltree($backup_dir.$file)) {
if (!file_exists($backup_dir.$file)) {
$_SESSION['infos'][] = str_replace('_FILE_', '"'.$file.'"', tr('Backup _FILE_ eliminato!'));
} else {
$_SESSION['errors'][] = str_replace('_FILE_', '"'.$file.'"', tr("Errore durante l'eliminazione del backup _FILE_!"));

View File

@ -93,7 +93,8 @@ if (file_exists($backup_dir)) {
foreach ($backups_file as $backup) {
$name = basename($backup);
preg_match('/^OSM backup ([0-9\-]{10}) ([0-9_]{8})$/', basename($file), $m);
preg_match('/^OSM backup ([0-9\-]{10}) ([0-9_]{8})$/', $name, $m);
echo '
<div class="callout callout-warning">
<h4>'.str_replace(['_DATE_', '_TIME_'], [Translator::dateToLocale($m[1]), date('H:i', strtotime(str_replace('_', ':', $m[2])))], tr('Backup del _DATE_ alle _TIME_')).'</h4>

View File

@ -4,11 +4,6 @@ include_once __DIR__.'/core.php';
ob_end_clean();
$orientation = 'P';
$body_table_params = "style='width:210mm;'";
$table = 'margin-left:1.7mm';
$font_size = '10pt';
// Assegnazione di tutte le variabile GET
foreach ($get as $key => $value) {
${$key} = !empty(${$key}) ? ${$key} : $value;
@ -19,21 +14,26 @@ $visualizza_costi = get_var('Visualizza i costi sulle stampe degli interventi');
// Nuovo sistema di generazione stampe
if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
// Impostazioni della stampa
// Impostazioni di default
if (file_exists($docroot.'/templates/base/custom/settings.php')) {
$default = include $docroot.'/templates/base/custom/settings.php';
} else {
$default = include $docroot.'/templates/base/settings.php';
}
// Impostazioni personalizzate della stampa
if (file_exists($docroot.'/templates/'.$ptype.'/custom/settings.php')) {
$custom = include $docroot.'/templates/'.$ptype.'/custom/settings.php';
} elseif (file_exists($docroot.'/templates/'.$ptype.'/settings.php')) {
$custom = include $docroot.'/templates/'.$ptype.'/settings.php';
}
// Individuazione delle impostazioni finali
$settings = array_merge($default, (array) $custom);
// Fix per l'altezza minima del margine in alto
$settings['header-height'] = ($settings['header-height'] < $settings['margins']['top']) ? $settings['margins']['top'] : $settings['header-height'];
// Individuazione delle variabili fondamentali per la sostituzione dei contenuti
if (file_exists($docroot.'/templates/'.$ptype.'/custom/init.php')) {
include $docroot.'/templates/'.$ptype.'/custom/init.php';
@ -73,10 +73,14 @@ if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
}
$foot = ob_get_clean();
if (empty($foot)) {
$foot = '$pagination$';
}
// Footer di default
$foot = !empty($foot) ? $foot : '$pagination$';
} else {
$orientation = 'P';
$body_table_params = "style='width:210mm;'";
$table = 'margin-left:1.7mm';
$font_size = '10pt';
// Decido se usare la stampa personalizzata (se esiste) oppure quella standard
if (file_exists($ptype.'/custom/pdfgen.'.$ptype.'.php')) {
include $docroot.'/templates/'.$ptype.'/custom/pdfgen.'.$ptype.'.php';
@ -96,9 +100,6 @@ if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
// Operazioni di sostituzione
include $docroot.'/templates/pdfgen_variables.php';
$report = str_replace('$docroot$', $docroot, $report);
$report = str_replace('$rootdir$', $rootdir, $report);
// Individuazione dellla configurazione
$directory = dirname($filename);
if (!empty($filename) && ((is_dir($directory) && !is_writable($directory)) || (!is_dir($directory) && !create_dir($directory)))) {
@ -123,7 +124,19 @@ if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
'templates/base/style.css',
];
$mpdf = new mPDF('utf-8', $settings['dimension'], $settings['font-size'], '', 12, 12, $settings['header'], $settings['footer'], 9, 9, $settings['orientation']);
$mpdf = new mPDF(
'c',
$settings['dimension'],
$settings['font-size'],
'helvetica',
$settings['margins']['left'],
$settings['margins']['right'],
$settings['header-height'],
$settings['footer-height'],
$settings['margins']['top'],
$settings['margins']['bottom'],
strtolower($settings['orientation']) == 'l' ? 'l' : 'p'
);
$mpdf->SetHTMLFooter($foot);
$mpdf->SetHTMLHeader($head);
@ -137,19 +150,10 @@ if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
$mpdf->Output($filename, $mode);
} else {
// HTML
$html = (get_var('Formato report') == 'html');
$html2pdf = new Spipu\Html2Pdf\Html2Pdf($orientation, 'A4', 'it', true, 'UTF-8');
try {
ob_end_clean();
$html2pdf = new HTML2PDF($orientation, 'A4', 'it', true, 'UTF-8');
$html2pdf->writeHTML($report);
$html2pdf->pdf->setTitle($title);
$html2pdf->writeHTML($report, $html);
$html2pdf->pdf->setTitle($title);
$html2pdf->output($filename, $mode);
} catch (HTML2PDF_exception $e) {
echo $e;
exit();
}
$html2pdf->output($filename, $mode);
}

View File

@ -56,7 +56,7 @@ if (!empty($info['script'])) {
}
}
redirectOperation();
redirectOperation($id_module, $id_parent);
$module = Modules::getModule($info['idmodule_to']);

View File

@ -1,9 +1,15 @@
<?php
return [
'orientation' => 'portrait',
'orientation' => 'p',
'dimension' => 'A4',
'font-size' => '11pt',
'header' => '40',
'footer' => '5',
'margins' => [
'top' => 9,
'bottom' => 9,
'left' => 12,
'right' => 12,
],
'header-height' => 40,
'footer-height' => 5,
];

View File

@ -1,11 +1,11 @@
body {
background-color: white;
color: black;
font-family: 'FreeSans', sans-serif, monospace;
}
.small-bold {
font-weight: bold;
p {
padding: 0px;
margin: 0px;
}
small,
@ -14,64 +14,46 @@ small,
font-size: 70%;
}
.small-bold {
font-weight: bold;
}
table {
width: 100%;
overflow: wrap
}
table td {
vertical-align: top;
padding: 4px;
}
table.table-striped tbody tr:nth-child(2n) td {
background-color: #eee;
}
table.table-striped tbody tr:nth-child(2n+1) td {
background-color: #fff;
}
.row,
.col-xs-1,
.col-sm-1,
.col-md-1,
.col-lg-1,
.col-xs-2,
.col-sm-2,
.col-md-2,
.col-lg-2,
.col-xs-3,
.col-sm-3,
.col-md-3,
.col-lg-3,
.col-xs-4,
.col-sm-4,
.col-md-4,
.col-lg-4,
.col-xs-5,
.col-sm-5,
.col-md-5,
.col-lg-5,
.col-xs-6,
.col-sm-6,
.col-md-6,
.col-lg-6,
.col-xs-7,
.col-sm-7,
.col-md-7,
.col-lg-7,
.col-xs-8,
.col-sm-8,
.col-md-8,
.col-lg-8,
.col-xs-9,
.col-sm-9,
.col-md-9,
.col-lg-9,
.col-xs-10,
.col-sm-10,
.col-md-10,
.col-lg-10,
.col-xs-11,
.col-sm-11,
.col-md-11,
.col-lg-11,
.col-xs-12,
.col-sm-12,
.col-md-12,
.col-lg-12 {
margin: 0px !important;
padding: 0px !important;
}
p {
padding: 0px;
margin: 0px;
}
.border-left {
border-left: 1px solid #aaa;
}
@ -92,13 +74,7 @@ p {
border: 1px solid #aaa;
}
table {
width: 100%;
overflow: wrap
}
table td {
vertical-align: top;
.cell-padded {
padding: 4px;
}
@ -114,11 +90,3 @@ table td {
padding: 3px;
font-size: 90%;
}
.cell-padded {
padding: 4px;
}
.bg-default {
background-color: #eee;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

View File

@ -1,54 +0,0 @@
<style>
<!--
.table_values td{
padding: 4px;
white-space: normal;
}
.table_values th{
background: #ddd;
padding: 3px;
}
.first_cell{
border-left: 1px solid #aaa;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
.table_cell{
border-bottom: 1px solid #aaa;
border-right: 1px solid #aaa;
}
.full_cell1{
border: 1px solid #aaa;
}
.full_cell{
border-top: 1px solid #aaa;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
}
.center{
text-align: center;
}
.b-right{ border-right:1px solid #aaa; }
.b-left{ border-left:1px solid #aaa; }
.b-top{ border-top:1px solid #aaa; }
.b-bottom{ border-bottom:1px solid #aaa; }
.cell-padded{
padding: 4px;
}
#contents td{
font-size: 11px;
}
-->
</style>
<page backimg="$docroot$/templates/ddt/$img_sfondo$" backtop="90mm" backbottom="75mm" backleft="3mm" backright="5mm" footer="" style="font-size: $font_size$">
$body$
</page>

View File

@ -1,227 +0,0 @@
<page_header>
<br/>
<table align="left">
<tr>
<td style="width:110mm;">
<img src="$docroot$/templates/ddt/logo_azienda.jpg" alt="Logo" style="width:80mm;" border="0">
</td>
<td style="width:110mm;">
<p align='left' style='margin:15px 9px;'>
<b>$f_ragionesociale$</b><br/>
$f_indirizzo$
$f_citta$
$f_piva$
$f_codicefiscale$
$f_capsoc$
$f_telefono$
</p>
</td>
</tr>
</table>
<br/><br/>
<table align="center" style="font-size:11px;">
<tr>
<!-- Dati Fattura -->
<td cellspacing="0" cellpadding="0" valign="top">
<div style="text-align:center; width:105mm; height:5mm; font-size:14px;">
<b>$tipo_doc$</b><br>
</div>
<table cellspacing="0" style="table-layout:fixed;">
<col width="27"><col width="35"><col width="21.3"><col width="12">
<tr>
<td valign="top" class="full_cell1" align="center" style="width:27mm;">
<small><small><b>NR. DOCUMENTO</b></small></small><br>
$numero_doc$
</td>
<td class="full_cell" align="center" style="width:35mm;">
<small><small><b>DATA DOCUMENTO</b></small></small><br>
$data$
</td>
<td class="full_cell" align="center" style="width:21.3mm;">
<small><small><b>CLIENTE</b></small></small><br>
$c_codice$
</td>
<td class="full_cell" align="center" style="width:12mm;">
<small><small><b>FOGLIO</b></small></small><br>
&nbsp;&nbsp;&nbsp;&nbsp;[[page_cu]]/[[page_nb]]
</td>
</tr>
<tr>
<tr><td class="first_cell" colspan="4">
<div style="height:8mm; overflow:hidden;">
<table style="width:100%;" cellspacing="0" cellpadding="0">
<tr><td style="width:50%;">
<small><small><b>PARTITA IVA</b></small></small><br>
$c_piva$
</td>
<td style="width:50%;">
<small><small><b>CODICE FISCALE</b></small></small><br>
$c_codicefiscale$
</td></tr>
</table>
</div>
</td></tr>
<tr>
<td class="first_cell" colspan="4">
<div style="height:8.5mm; overflow:hidden;">
<small><small><b>PAGAMENTO</b></small></small><br>
$pagamento$
</div>
</td>
</tr>
<tr>
<td class="first_cell" colspan="4">
<div style="height:8.5mm; overflow:hidden;">
<small><small><b>&nbsp;</b></small></small><br>
&nbsp;
</div>
</td>
</tr>
</tr>
</table>
</td>
<td style="width:2mm;"></td>
<td style="width:83mm;" valign="top">
<div style="height:5mm;">
&nbsp;<br>
</div>
<!-- Intestazione cliente -->
<table cellspacing="0">
<tr>
<!-- cliente -->
<td style="width:80mm; height:16mm; font-size:9pt; border:1px solid #aaa;" valign="top">
<small><small><b>SPETT.LE</b></small></small><br/>
<div style="padding:1mm;">
$c_ragionesociale$
$c_indirizzo$
$c_citta$
</div>
</td>
</tr>
<tr>
<!-- Destinazione cliente -->
<td style="height:15mm; font-size:9pt; border-left:1px solid #aaa; border-right:1px solid #aaa; border-bottom:1px solid #aaa;" valign="top">
<small><small><b>DESTINAZIONE DIVERSA</b></small></small><br/>
<div style="padding:1mm;">
$c_destinazione$
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
</page_header>
<!-- Footer -->
<page_footer>
<table style='margin-left:3mm; border:1px solid #aaa; border-bottom:none;' cellspacing='0'>
$footer$
</table>
<table style='margin-left:3mm; border:1px solid #aaa; border-bottom:none;' class='table_values' cellspacing='0'>
<col width="227.5"><col width="228"><col width="228">
<tr>
<th class="b-bottom b-right" valign="top">
<small><small><b>ASPETTO BENI</b></small></small>
</th>
<th class="b-bottom b-right" valign="top">
<small><small><b>CAUSALE TRASPORTO</b></small></small>
</th>
<th class="b-bottom" valign="top">
<small><small><b>PORTO</b></small></small>
</th>
</tr>
<tr>
<td valign="top" class="cell-padded b-right">
$aspettobeni$&nbsp;
</td>
<td valign="top" class="cell-padded b-right">
$causalet$&nbsp;
</td>
<td valign="top" class="cell-padded">
$porto$&nbsp;
</td>
</tr>
</table>
<table style='margin-left:3mm; border:1px solid #aaa; border-bottom:none;' class='table_values' cellspacing='0'>
<col width="227.5"><col width="228"><col width="228">
<tr>
<th class="b-bottom b-right" valign="top">
<small><small><b>N<sup>o</sup> COLLI</b></small></small>
</th>
<th class="b-bottom b-right" valign="top">
<small><small><b>TIPO DI SPEDIZIONE</b></small></small>
</th>
<th class="b-bottom" valign="top">
<small><small><b>VETTORE</b></small></small>
</th>
</tr>
<tr>
<td valign="top" class="cell-padded b-right">
$n_colli$&nbsp;
</td>
<td valign="top" class="cell-padded b-right">
$spedizione$&nbsp;
</td>
<td valign="top" class="cell-padded">
$vettore$&nbsp;
</td>
</tr>
</table>
<table style='margin-left:3mm; border:1px solid #aaa;' class='table_values' cellspacing='0'>
<col width="227.5"><col width="228"><col width="228">
<tr>
<th class="b-bottom b-right" valign="top">
<small><small><b>FIRMA CONDUCENTE</b></small></small>
</th>
<th class="b-bottom b-right" valign="top">
<small><small><b>FIRMA VETTORE</b></small></small>
</th>
<th class="b-bottom" valign="top">
<small><small><b>FIRMA DESTINATARIO</b></small></small>
</th>
</tr>
<tr>
<td valign="top" class="cell-padded b-right">
&nbsp;<br>&nbsp;<br>&nbsp;
</td>
<td valign="top" class="cell-padded b-right">
&nbsp;<br>&nbsp;<br>&nbsp;
</td>
<td valign="top" class="cell-padded">
&nbsp;<br>&nbsp;<br>&nbsp;
</td>
</tr>
</table>
</page_footer>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,385 +0,0 @@
<?php
$idddt = save($_GET['idddt']);
$iva_generica = '';
$n_rows = 0;
$words4row = 45;
//Lettura tipo ddt
$q = "SELECT n_colli, (SELECT dir FROM dt_tipiddt WHERE id=idtipoddt) AS dir, (SELECT descrizione FROM dt_causalet WHERE id=idcausalet) AS causalet, (SELECT descrizione FROM dt_porto WHERE id=idporto) AS porto, (SELECT descrizione FROM dt_aspettobeni WHERE id=idaspettobeni) AS aspettobeni, (SELECT descrizione FROM dt_spedizione WHERE id=idspedizione) AS spedizione, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idvettore) AS vettore FROM dt_ddt WHERE id=\"".$idddt."\"";
$rs = $dbo->fetchArray($q);
$aspettobeni = $rs[0]['aspettobeni'];
$causalet = $rs[0]['causalet'];
$porto = $rs[0]['porto'];
$n_colli = $rs[0]['n_colli'];
if($n_colli=="0") $n_colli = "";
$spedizione = $rs[0]['spedizione'];
$vettore = $rs[0]['vettore'];
if( $rs[0]['dir']=='entrata' )
$nome_modulo = "Ddt di vendita";
else
$nome_modulo = "Ddt di acquisto";
include_once( $docroot."/lib/permissions_check.php" );
include_once( $docroot."/modules/ddt/modutil.php" );
$additional_where[$nome_modulo] = str_replace( "|idanagrafica|", "'".$user_idanagrafica."'", $additional_where[$nome_modulo] );
$mostra_prezzi = get_var("Stampa i prezzi sui ddt");
//Lettura info fattura
$q = "SELECT *, (SELECT descrizione FROM dt_tipiddt WHERE id=idtipoddt) AS tipo_doc, (SELECT dir FROM dt_tipiddt WHERE id=idtipoddt) AS dir FROM dt_ddt WHERE id=\"".$idddt."\" ".$additional_where[$nome_modulo];
$rs = $dbo->fetchArray($q);
$tipo_doc = $rs[0]['tipo_doc'];
$idcliente = $rs[0]['idanagrafica'];
//$idsede = $rs[0]['idsede'];
( $rs[0]['numero_esterno']!='' ) ? $numero=$rs[0]['numero_esterno'] : $numero=$rs[0]['numero'];
if( $rs[0]['numero_esterno']=='' ){
$numero = "pro-forma ".$numero;
$tipo_doc = "DDT PRO-FORMA";
}
//Lettura righe ddt
$q2 = "SELECT * FROM dt_righe_ddt INNER JOIN dt_ddt ON dt_righe_ddt.idddt=dt_ddt.id WHERE idddt='$idddt' ".$additional_where[$nome_modulo];
$righe = $dbo->fetchArray( $q2 );
//carica report html
$report = file_get_contents ($docroot."/templates/ddt/ddt.html");
$body = file_get_contents ($docroot."/templates/ddt/ddt_body.html");
if( !($idcliente == $user_idanagrafica || $_SESSION['is_admin']) )
die("Non hai i permessi per questa stampa!");
include_once( "pdfgen_variables.php" );
// $body = str_replace( "P.Iva: ".$c_piva, $c_piva, $body );
// $body = str_replace( "P.Iva/C.F.: ".$c_piva, $c_piva, $body );
$body = str_replace( '$tipo_doc$', strtoupper($tipo_doc), $body );
$body = str_replace( '$numero_doc$', $numero, $body );
$body = str_replace( '$data$', date( "d/m/Y", strtotime($rs[0]['data']) ), $body );
$body = str_replace( '$pagamento$', $rs[0]['tipo_pagamento'], $body );
$body = str_replace( '$c_banca_appoggio$', "&nbsp;", $body );
if($mostra_prezzi):
$report = str_replace( '$img_sfondo$', "bg_ddt.jpg", $report );
else:
$report = str_replace( '$img_sfondo$', "bg_ddt_noprezzi.jpg", $report );
endif;
//Leggo i dati della destinazione (se 0=sede legale, se!=altra sede da leggere da tabella an_sedi)
$destinazione = '';
if( $rs[0]['idsede']==0 ){
$destinazione = '';
} else {
$queryd = "SELECT (SELECT codice FROM an_anagrafiche WHERE idanagrafica=an_sedi.idanagrafica) AS codice, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=an_sedi.idanagrafica) AS ragione_sociale, indirizzo, indirizzo2, cap, citta, provincia, piva, codice_fiscale FROM an_sedi WHERE idanagrafica='".$idcliente."' AND id='".$rs[0]['idsede']."'";
$rsd = $dbo->fetchArray($queryd);
if( $rsd[0]['indirizzo']!='' )
$destinazione .= $rsd[0]['indirizzo']."<br/>\n";
if( $rsd[0]['indirizzo2']!='' )
$destinazione .= $rsd[0]['indirizzo2']."<br/>\n";
if( $rsd[0]['cap']!='' )
$destinazione .= $rsd[0]['cap']." ";
if( $rsd[0]['citta']!='' )
$destinazione .= $rsd[0]['citta'];
if( $rsd[0]['provincia']!='' )
$destinazione .= " (".$rsd[0]['provincia'].")\n";
}
$body = str_replace( '$c_destinazione$', $destinazione, $body );
//Campi finali
$body = str_replace( '$aspettobeni$', $aspettobeni, $body );
$body = str_replace( '$causalet$', $causalet, $body );
$body = str_replace( '$porto$', $porto, $body );
$body = str_replace( '$n_colli$', $n_colli, $body );
$body = str_replace( '$spedizione$', $spedizione, $body );
$body = str_replace( '$vettore$', $vettore, $body );
$v_iva = '';
$v_totale = '';
//Intestazione tabella per righe
$body .= "<table class='table_values' cellspacing='0' style='table-layout:fixed;' id='contents'>\n";
if($mostra_prezzi):
$body .= "<col width='298'><col width='57'><col width='81'><col width='81'><col width='81'><col width='43'>\n";
else:
$body .= "<col width='635'><col width='70'>\n";
endif;
$body .= "<thead>\n";
$body .= "<tr>\n";
$body .= "<th class='b-top b-right b-bottom b-left'><small>DESCRIZIONE</small></th>\n";
$body .= "<th align='center' class='b-top b-right b-bottom'><small>Q.T&Agrave;</small></th>\n";
if($mostra_prezzi):
$body .= "<th align='center' class='b-top b-right b-bottom'><small>PREZZO U.</small></th>\n";
$body .= "<th align='center' class='b-top b-right b-bottom'><small>IMPORTO</small></th>\n";
$body .= "<th align='center' class='b-top b-right b-bottom'><small>SCONTO</small></th>\n";
$body .= "<th align='center' class='b-top b-right b-bottom'><small>IVA</small></th>\n";
endif;
$body .= "</tr>\n";
$body .= "</thead>\n";
$body .= "<tbody>\n";
//Mostro le righe del ddt
$totale_ddt = 0.00;
$totale_imponibile = 0.00;
$totale_iva = 0.00;
$sconto = 0.00;
$sconto_generico = 0.00;
/*
Righe
*/
$q_gen = "SELECT *, (SELECT percentuale FROM co_iva WHERE id=idiva) AS perc_iva FROM `dt_righe_ddt` WHERE idddt='$idddt'";
$rs_gen = $dbo->fetchArray( $q_gen );
$tot_gen = sizeof($rs_gen);
$imponibile_gen = 0.0;
$iva_gen = 0.0;
if( $tot_gen>0 ){
for( $i=0; $i<sizeof($rs_gen); $i++ ){
$descrizione = $rs_gen[$i]['descrizione'];
$qta = $rs_gen[$i]['qta'];
$subtot = $rs_gen[$i]['subtotale']/$rs_gen[$i]['qta'];
$subtotale = $rs_gen[$i]['subtotale'];
$sconto = $rs_gen[$i]['sconto'];
$iva = $rs_gen[$i]['iva'];
//Se c'è un barcode provo a proseguire il loop per accorpare eventuali barcode dello stesso articolo
if( $rs_gen[$i]['barcode'] != '' ){
$descrizione .= "\n".$rs_gen[$i]['barcode'];
while( $rs_gen[$i+1]['idarticolo'] == $rs_gen[$i]['idarticolo'] && $rs_gen[$i+1]['barcode'] != '' ){
$i++;
if( $rs_gen[$i]['barcode'] != '' ){
$descrizione .= ", ".$rs_gen[$i]['barcode'];
}
$qta += $rs_gen[$i]['qta'];
$subtot += $rs_gen[$i]['subtotale']/$rs_gen[$i]['qta'];
$subtotale += $rs_gen[$i]['subtotale'];
$sconto += $rs_gen[$i]['sconto'];
$iva += $rs_gen[$i]['iva'];
}
}
$descrizione = rtrim( $descrizione, "," );
//Calcolo quanti a capo ci sono
$righe = explode( "\n", $descrizione );
for( $r=0; $r<sizeof($righe); $r++ ){
if( $r == 0 ){
$n_rows += ceil( ceil( strlen($righe[$r])/$words4row )*4.1 );
} else {
$n_rows += ceil( ceil( strlen($righe[$r])/$words4row )*2.9 );
}
$n++;
}
if( $rs_gen[$i]['descrizione'] == 'SCONTO' ){
$sconto_generico = $rs_gen[$i]['subtotale'];
$iva_gen += $rs_gen[$i]['iva'];
}
else{
$body .= "<tr><td class='' valign='top'>\n";
$body .= nl2br( $descrizione );
//Aggiunta riferimento a ordine
if( $rs_gen[$i]['idordine']!='0' ){
$rso = $dbo->fetchArray("SELECT numero, numero_esterno, data FROM or_ordini WHERE id=\"".$rs_gen[$i]['idordine']."\"");
( $rso[0]['numero_esterno']!='' ) ? $numero=$rso[0]['numero_esterno'] : $numero=$rso[0]['numero'];
$body .= "<br/><small>Rif. ordine n<sup>o</sup>".$numero." del ".date("d/m/Y", strtotime($rso[0]['data']) )."</small>";
}
$body .= "</td>\n";
$body .= "<td class='center' valign='top'>\n";
$body .= number_format($qta, 2, ",", "")."\n";
$body .= "</td>\n";
/*
$body .= "<td class='center b-right' valign='top'>\n";
$body .= $rs_gen[$i]['um']."\n";
$body .= "</td>\n";
*/
if($mostra_prezzi):
$body .= "<td align='right' class='' valign='top'>\n";
$body .= number_format( $subtotale/$qta, 2, ",", "" )." &euro;\n";
$body .= "</td>\n";
//Imponibile
$body .= "<td align='right' class='' valign='top'>\n";
$subtot = $subtotale;
$body .= number_format( $subtot, 2, ",", "." )." &euro;\n";
/*
if( $rs_gen[$i]['sconto']>0 ){
$body .= "<br/>\n<small style='color:#555;'>- sconto ".number_format( $rs_gen[$i]['sconto'], 2, ",", "." )." &euro;</small>\n";
$tot_gen++;
}*/
$body .= "</td>\n";
//Sconto
$body .= "<td align='right' class='' valign='top'>\n";
if( $rs_gen[$i]['scontoperc'] > 0 ){
$body .= "(".$rs_gen[$i]['scontoperc']."%) ";
}
if( $rs_gen[$i]['sconto'] > 0 ){
$body .= " ".number_format( $rs_gen[$i]['sconto'], 2, ",", "." )." &euro;\n";
}
$body .= "</td>\n";
//Iva
$body .= "<td align='center' valign='top'>\n";
if( $rs_gen[$i]['perc_iva'] > 0 ){
$body .= " ".intval($rs_gen[$i]['perc_iva'])."%\n";
}
$body .= "</td>\n";
endif;
$body .= "</tr>\n";
$imponibile_gen += $subtotale;
$iva_gen += $iva;
$sconto += $sconto;
if( $rs_gen[$i]['perc_iva'] > 0 ){
$iva_generica = $rs_gen[$i]['perc_iva'];
}
}
}
$imponibile_ddt += $imponibile_gen;
$totale_iva += $iva_gen;
$totale_ddt += $imponibile_gen;
}
$body .= "</tbody>\n";
$body .= "</table><br/>\n";
/*
NOTE
*/
/*
$body .= "<table style='margin-left:-0.5mm;'>\n";
$body .= " <tr><td style='width:193.5mm; height:20mm; border:1px solid #aaa;' valign='top'>\n";
$body .= " <small><b>NOTE</b></small><br/>\n";
$body .= " <div style='padding:3mm;'>\n";
$body .= " ".nl2br( $rs[0]['note'] )."\n";
$body .= " </div>\n";
$body .= " </td></tr>\n";
$body .= "</table>\n";
*/
$imponibile_ddt -= $sconto;
$totale_ddt = $totale_ddt - $sconto + $totale_iva;
/*
SCADENZE | TOTALI
*/
//TABELLA PRINCIPALE
if($mostra_prezzi):
//Riga 1
$footer = " <tr><td rowspan='7' style='width:159mm;' valign='top' class='b-right'>\n";
$footer .= " <small><b>NOTE</b></small><br/>\n";
$footer .= " ".nl2br( $rs[0]['note'] )."\n";
$footer .= " </td>\n";
$footer .= " <td style='width:33mm;' valign='top' class='b-bottom'>\n";
$footer .= " <small><small><b>TOTALE IMPONIBILE</b></small></small>\n";
$footer .= " </td></tr>\n";
//Dati riga 1
$footer .= " <tr>\n";
$footer .= " <td valign='top' style='text-align:right;' class='b-bottom cell-padded'>\n";
$footer .= " ".number_format( $imponibile_ddt, 2, ",", "." )." &euro;\n";
$footer .= " </td></tr>\n";
//Riga 2
$footer .= " <tr><td style='width:33mm;' valign='top' class='b-bottom'>\n";
$footer .= " <small><small><b>TOTALE IMPOSTE</b></small></small>\n";
$footer .= " </td></tr>\n";
$footer .= " <tr><td valign='top' style='text-align:right;' class='b-bottom cell-padded'>\n";
$footer .= " ".number_format( $totale_iva, 2, ",", "." )." &euro;\n";
$footer .= " </td></tr>\n";
//Riga 3
$footer .= " <tr><td valign='top' class='b-bottom'>\n";
$footer .= " <small><small><b>TOTALE DOCUMENTO</b></small></small>\n";
$footer .= " </td></tr>\n";
$footer .= " <tr><td valign='top' class='b-bottom cell-padded' style='border-bottom:none;text-align:right;'>\n";
$footer .= " ".number_format( $totale_ddt, 2, ",", "." )." &euro;\n";
$footer .= " </td></tr>\n";
//Riga 4 (opzionale, solo se c'è la ritenuta d'acconto)
if( $rs[0]['ritenutaacconto'] > 0 ):
$rs2 = $dbo->fetchArray("SELECT percentuale FROM co_ritenutaacconto WHERE id='".$rs[0]['idritenutaacconto']."'");
$footer .= " <tr><td valign='top' class='b-bottom'>\n";
$footer .= " <small><small><b>RITENUTA D'ACCONTO ".intval( $rs2[0]['percentuale'] )."%</b></small></small>\n";
$footer .= " </td></tr>\n";
$footer .= " <tr><td valign='top' style='text-align:right;' class='b-bottom cell-padded'>\n";
$footer .= " ".number_format( $rs[0]['ritenutaacconto'], 2, ",", "." )." &euro;\n";
$footer .= " </td></tr>\n";
$footer .= " <tr><td valign='top' class='b-bottom'>\n";
$footer .= " <small><small><b>NETTO A PAGARE</b></small></small>\n";
$footer .= " </td></tr>\n";
$footer .= " <tr><td valign='top' style='text-align:right;' class='cell-padded'>\n";
$footer .= " ".number_format( $totale_ddt - $rs[0]['ritenutaacconto'], 2, ",", "." )." &euro;\n";
$footer .= " </td></tr>\n";
endif;
else:
//Riga 1
$footer = " <tr><td style='width:193.5mm;height:30mm;' valign='top' class=''>\n";
$footer .= " <small><b>NOTE</b></small><br/>\n";
$footer .= " ".nl2br( $rs[0]['note'] )."\n";
$footer .= " </td></tr>\n";
endif;
$report_name = "ddt_".$numero.".pdf";
?>

View File

@ -41,7 +41,7 @@ foreach ($righe as $i => $riga) {
$n_rows += substr_count($riga['descrizione'], PHP_EOL);
echo "
<tr class='".($i % 2 != 0 ? 'bg-default' : '')."'>
<tr>
<td class='border-right'>
".nl2br($riga['descrizione']);

View File

@ -1,6 +1,6 @@
<?php
return [
'header' => '90',
'footer' => '70',
'header-height' => '90',
'footer-height' => '70',
];

View File

@ -7,6 +7,8 @@ include_once __DIR__.'/../core.php';
// Valori aggiuntivi per la sostituzione
$values = [
'docroot' => DOCROOT,
'rootdir' => ROOTDIR,
'footer' => !empty($footer) ? $footer : '',
'dicitura_fissa_fattura' => get_var('Dicitura fissa fattura'),
'pagination' => '

View File

@ -418,6 +418,7 @@ INSERT INTO `zz_group_view` (`id_gruppo`, `id_vista`) VALUES
-- Eliminazione impostazioni inutilizzata
DELETE FROM `zz_settings` WHERE `zz_settings`.`nome` = 'Usa tabelle avanzate';
DELETE FROM `zz_settings` WHERE `zz_settings`.`nome` = 'Righe per pagina';
DELETE FROM `zz_settings` WHERE `zz_settings`.`nome` = 'Formato report';
-- Aggiunta tabelle per la gestione dei campi "minori""
INSERT INTO `zz_modules` (`id`, `name`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Tabelle', '', '', '', 'fa fa-table', '2.3', '2.3', '1', 1, '1', '1');