mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Ridistribuzione funzioni generiche
This commit is contained in:
@@ -59,6 +59,7 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/functions.php",
|
"lib/functions.php",
|
||||||
|
"lib/common.php",
|
||||||
"lib/helpers.php",
|
"lib/helpers.php",
|
||||||
"lib/util.php",
|
"lib/util.php",
|
||||||
"lib/deprecated.php"
|
"lib/deprecated.php"
|
||||||
|
277
lib/common.php
Normal file
277
lib/common.php
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Funzioni globali utilizzate per il funzionamento dei componenti indipendenti del progetto (moduli, plugin, stampe, ...).
|
||||||
|
*
|
||||||
|
* @since 2.4.2
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Esegue una somma precisa tra due interi/array.
|
||||||
|
*
|
||||||
|
* @param array|float $first
|
||||||
|
* @param array|float $second
|
||||||
|
* @param int $decimals
|
||||||
|
*
|
||||||
|
* @since 2.3
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
function sum($first, $second = null, $decimals = 4)
|
||||||
|
{
|
||||||
|
$first = (array) $first;
|
||||||
|
$second = (array) $second;
|
||||||
|
|
||||||
|
$array = array_merge($first, $second);
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
$decimals = is_numeric($decimals) ? $decimals : Translator::getFormatter()->getPrecision();
|
||||||
|
|
||||||
|
$bcadd = function_exists('bcadd');
|
||||||
|
|
||||||
|
foreach ($array as $value) {
|
||||||
|
$value = round($value, $decimals);
|
||||||
|
|
||||||
|
if ($bcadd) {
|
||||||
|
$result = bcadd($result, $value, $decimals);
|
||||||
|
} else {
|
||||||
|
$result += $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return floatval($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function aggiorna_sconto($tables, $fields, $id_record, $options = [])
|
||||||
|
{
|
||||||
|
$dbo = Database::getConnection();
|
||||||
|
|
||||||
|
$descrizione = tr('Sconto', [], ['upper' => true]);
|
||||||
|
|
||||||
|
// Rimozione dello sconto precedente
|
||||||
|
$dbo->query('DELETE FROM '.$tables['row'].' WHERE sconto_globale = 1 AND '.$fields['row'].'='.prepare($id_record));
|
||||||
|
|
||||||
|
// Individuazione del nuovo sconto
|
||||||
|
$sconto = $dbo->select($tables['parent'], ['sconto_globale', 'tipo_sconto_globale'], [$fields['parent'] => $id_record]);
|
||||||
|
$sconto[0]['sconto_globale'] = floatval($sconto[0]['sconto_globale']);
|
||||||
|
|
||||||
|
// Aggiorno l'eventuale sconto gestendolo con le righe in fattura
|
||||||
|
$iva = 0;
|
||||||
|
|
||||||
|
if (!empty($sconto[0]['sconto_globale'])) {
|
||||||
|
if ($sconto[0]['tipo_sconto_globale'] == 'PRC') {
|
||||||
|
$rs = $dbo->fetchArray('SELECT SUM(subtotale - sconto) AS imponibile, SUM(iva) AS iva FROM (SELECT '.$tables['row'].'.subtotale, '.$tables['row'].'.sconto, '.$tables['row'].'.iva FROM '.$tables['row'].' WHERE '.$fields['row'].'='.prepare($id_record).') AS t');
|
||||||
|
$subtotale = $rs[0]['imponibile'];
|
||||||
|
$iva += $rs[0]['iva'] / 100 * $sconto[0]['sconto_globale'];
|
||||||
|
$subtotale = -$subtotale / 100 * $sconto[0]['sconto_globale'];
|
||||||
|
|
||||||
|
$descrizione = $descrizione.' '.Translator::numberToLocale($sconto[0]['sconto_globale']).'%';
|
||||||
|
} else {
|
||||||
|
$rs = $dbo->fetchArray('SELECT SUM(subtotale - sconto) AS imponibile, SUM(iva) AS iva FROM (SELECT '.$tables['row'].'.subtotale, '.$tables['row'].'.sconto, '.$tables['row'].'.iva FROM '.$tables['row'].' WHERE '.$fields['row'].'='.prepare($id_record).') AS t');
|
||||||
|
$subtotale = $rs[0]['imponibile'];
|
||||||
|
$iva += $sconto[0]['sconto_globale'] * $rs[0]['iva'] / $subtotale;
|
||||||
|
|
||||||
|
$subtotale = -$sconto[0]['sconto_globale'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcolo dell'IVA da scontare
|
||||||
|
$idiva = setting('Iva predefinita');
|
||||||
|
$rsi = $dbo->select('co_iva', ['descrizione', 'percentuale'], ['id' => $idiva]);
|
||||||
|
|
||||||
|
$values = [
|
||||||
|
$fields['row'] => $id_record,
|
||||||
|
'descrizione' => $descrizione,
|
||||||
|
'subtotale' => $subtotale,
|
||||||
|
'qta' => 1,
|
||||||
|
'idiva' => $idiva,
|
||||||
|
'desc_iva' => $rsi[0]['descrizione'],
|
||||||
|
'iva' => -$iva,
|
||||||
|
'sconto_globale' => 1,
|
||||||
|
'#order' => '(SELECT IFNULL(MAX(`order`) + 1, 0) FROM '.$tables['row'].' AS t WHERE '.$fields['row'].'='.prepare($id_record).')',
|
||||||
|
];
|
||||||
|
|
||||||
|
$dbo->insert($tables['row'], $values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function controlla_seriali($field, $id_riga, $old_qta, $new_qta, $dir)
|
||||||
|
{
|
||||||
|
$dbo = Database::getConnection();
|
||||||
|
|
||||||
|
$new_qta = abs($new_qta);
|
||||||
|
$old_qta = abs($old_qta);
|
||||||
|
|
||||||
|
if ($old_qta >= $new_qta) {
|
||||||
|
// Controllo sulla possibilità di rimuovere i seriali (se non utilizzati da documenti di vendita)
|
||||||
|
if ($dir == 'uscita' && $new_qta < count(seriali_non_rimuovibili($field, $id_riga, $dir))) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
// Controllo sul numero di seriali effettivi da rimuovere
|
||||||
|
$count = $dbo->fetchArray('SELECT COUNT(*) AS tot FROM mg_prodotti WHERE '.$field.'='.prepare($id_riga))[0]['tot'];
|
||||||
|
if ($new_qta < $count) {
|
||||||
|
$deletes = $dbo->fetchArray("SELECT id FROM mg_prodotti WHERE serial NOT IN (SELECT serial FROM mg_prodotti WHERE dir = 'entrata' AND ".$field.'!='.prepare($id_riga).') AND '.$field.'='.prepare($id_riga).' ORDER BY serial DESC LIMIT '.abs($count - $new_qta));
|
||||||
|
|
||||||
|
// Rimozione
|
||||||
|
foreach ($deletes as $delete) {
|
||||||
|
$dbo->query('DELETE FROM mg_prodotti WHERE id = '.prepare($delete['id']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Individua i seriali non rimuovibili poichè utilizzati in documenti rilasciati.
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param int $id_riga
|
||||||
|
* @param string $dir
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function seriali_non_rimuovibili($field, $id_riga, $dir)
|
||||||
|
{
|
||||||
|
$dbo = Database::getConnection();
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
if ($dir == 'uscita') {
|
||||||
|
$results = $dbo->fetchArray("SELECT serial FROM mg_prodotti WHERE serial IN (SELECT serial FROM mg_prodotti WHERE dir = 'entrata') AND ".$field.'='.prepare($id_riga));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calcola gli sconti in modo automatico.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
function calcola_sconto($data)
|
||||||
|
{
|
||||||
|
if ($data['tipo'] == 'PRC') {
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
$price = floatval($data['prezzo']);
|
||||||
|
|
||||||
|
$percentages = explode('+', $data['sconto']);
|
||||||
|
foreach ($percentages as $percentage) {
|
||||||
|
$discount = $price / 100 * floatval($percentage);
|
||||||
|
|
||||||
|
$result += $discount;
|
||||||
|
$price -= $discount;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = floatval($data['sconto']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['qta'])) {
|
||||||
|
$result = $result * $data['qta'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restistuisce le informazioni sull'eventuale riferimento ai documenti.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param string $dir
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function doc_references($info, $dir, $ignore = [])
|
||||||
|
{
|
||||||
|
$dbo = Database::getConnection();
|
||||||
|
|
||||||
|
// Rimozione valori da non controllare
|
||||||
|
foreach ($ignore as $field) {
|
||||||
|
if (isset($info[$field])) {
|
||||||
|
unset($info[$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$module = null;
|
||||||
|
$id = null;
|
||||||
|
|
||||||
|
// Ordine
|
||||||
|
if (!empty($info['idordine'])) {
|
||||||
|
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM or_ordini WHERE id=".prepare($info['idordine']));
|
||||||
|
|
||||||
|
$module = ($dir == 'entrata') ? 'Ordini cliente' : 'Ordini fornitore';
|
||||||
|
$id = $info['idordine'];
|
||||||
|
|
||||||
|
$document = tr('Ordine');
|
||||||
|
}
|
||||||
|
|
||||||
|
// DDT
|
||||||
|
elseif (!empty($info['idddt'])) {
|
||||||
|
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM dt_ddt WHERE id=".prepare($info['idddt']));
|
||||||
|
|
||||||
|
$module = ($dir == 'entrata') ? 'Ddt di vendita' : 'Ddt di acquisto';
|
||||||
|
$id = $info['idddt'];
|
||||||
|
|
||||||
|
$document = tr('Ddt');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preventivo
|
||||||
|
elseif (!empty($info['idpreventivo'])) {
|
||||||
|
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_preventivi WHERE id='.prepare($info['idpreventivo']));
|
||||||
|
|
||||||
|
$module = 'Preventivi';
|
||||||
|
$id = $info['idpreventivo'];
|
||||||
|
|
||||||
|
$document = tr('Preventivo');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contratto
|
||||||
|
elseif (!empty($info['idcontratto'])) {
|
||||||
|
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_contratti WHERE id='.prepare($info['idcontratto']));
|
||||||
|
|
||||||
|
$module = 'Contratti';
|
||||||
|
$id = $info['idcontratto'];
|
||||||
|
|
||||||
|
$document = tr('Contratto');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intervento
|
||||||
|
elseif (!empty($info['idintervento'])) {
|
||||||
|
$data = $dbo->fetchArray('SELECT codice AS numero, IFNULL( (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE in_interventi_tecnici.idintervento=in_interventi.id), data_richiesta) AS data FROM in_interventi WHERE id='.prepare($info['idintervento']));
|
||||||
|
|
||||||
|
$module = 'Interventi';
|
||||||
|
$id = $info['idintervento'];
|
||||||
|
|
||||||
|
$document = tr('Intervento');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testo relativo
|
||||||
|
if (!empty($module) && !empty($id)) {
|
||||||
|
$document = Stringy\Stringy::create($document)->toLowerCase();
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
$description = tr('Rif. _DOC_ num. _NUM_ del _DATE_', [
|
||||||
|
'_DOC_' => $document,
|
||||||
|
'_NUM_' => $data[0]['numero'],
|
||||||
|
'_DATE_' => Translator::dateToLocale($data[0]['data']),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$description = tr('_DOC_ di riferimento _ID_ eliminato', [
|
||||||
|
'_DOC_' => $document->upperCaseFirst(),
|
||||||
|
'_ID_' => $id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'module' => $module,
|
||||||
|
'id' => $id,
|
||||||
|
'description' => $description,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
@@ -35,3 +35,156 @@ function get_var($nome, $sezione = null, $descrizione = false, $again = false)
|
|||||||
{
|
{
|
||||||
return setting($nome, $again);
|
return setting($nome, $again);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crea le thumbnails di $filename da dentro $dir e le salva in $dir.
|
||||||
|
*
|
||||||
|
* @param string $tmp
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $dir
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function create_thumbnails($tmp, $filename, $dir)
|
||||||
|
{
|
||||||
|
$infos = pathinfo($filename);
|
||||||
|
$name = $infos['filename'];
|
||||||
|
$extension = strtolower($infos['extension']);
|
||||||
|
|
||||||
|
if (!directory($dir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
|
||||||
|
Intervention\Image\ImageManagerStatic::configure(['driver' => $driver]);
|
||||||
|
|
||||||
|
$img = Intervention\Image\ImageManagerStatic::make($tmp);
|
||||||
|
|
||||||
|
$img->resize(600, null, function ($constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
});
|
||||||
|
$img->save(slashes($dir.'/'.$name.'.'.$extension));
|
||||||
|
|
||||||
|
$img->resize(250, null, function ($constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
});
|
||||||
|
$img->save(slashes($dir.'/'.$name.'_thumb250.'.$extension));
|
||||||
|
|
||||||
|
$img->resize(100, null, function ($constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
});
|
||||||
|
$img->save(slashes($dir.'/'.$name.'_thumb100.'.$extension));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifica che il nome del file non sia già usato nella cartella inserita, nel qual caso aggiungo un suffisso.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $dir
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function unique_filename($filename, $dir)
|
||||||
|
{
|
||||||
|
$f = pathinfo($filename);
|
||||||
|
$suffix = 1;
|
||||||
|
while (file_exists($dir.'/'.$filename)) {
|
||||||
|
$filename = $f['filename'].'_'.$suffix.'.'.$f['extension'];
|
||||||
|
++$suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Individua la differenza tra le date indicate.
|
||||||
|
* $interval può essere:
|
||||||
|
* yyyy - Number of full years
|
||||||
|
* q - Number of full quarters
|
||||||
|
* m - Number of full months
|
||||||
|
* y - Difference between day numbers
|
||||||
|
* (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
|
||||||
|
* d - Number of full days
|
||||||
|
* w - Number of full weekdays
|
||||||
|
* ww - Number of full weeks
|
||||||
|
* h - Number of full hours
|
||||||
|
* n - Number of full minutes
|
||||||
|
* s - Number of full seconds (default).
|
||||||
|
*
|
||||||
|
* @param unknown $interval
|
||||||
|
* @param unknown $datefrom
|
||||||
|
* @param unknown $dateto
|
||||||
|
* @param string $using_timestamps
|
||||||
|
*/
|
||||||
|
function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
|
||||||
|
{
|
||||||
|
if (!$using_timestamps) {
|
||||||
|
$datefrom = strtotime($datefrom, 0);
|
||||||
|
$dateto = strtotime($dateto, 0);
|
||||||
|
}
|
||||||
|
$difference = $dateto - $datefrom; // Difference in seconds
|
||||||
|
switch ($interval) {
|
||||||
|
case 'yyyy': // Number of full years
|
||||||
|
$years_difference = floor($difference / 31536000);
|
||||||
|
if (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom), date('j', $datefrom), date('Y', $datefrom) + $years_difference) > $dateto) {
|
||||||
|
--$years_difference;
|
||||||
|
}
|
||||||
|
if (mktime(date('H', $dateto), date('i', $dateto), date('s', $dateto), date('n', $dateto), date('j', $dateto), date('Y', $dateto) - ($years_difference + 1)) > $datefrom) {
|
||||||
|
++$years_difference;
|
||||||
|
}
|
||||||
|
$datediff = $years_difference;
|
||||||
|
break;
|
||||||
|
case 'q': // Number of full quarters
|
||||||
|
$quarters_difference = floor($difference / 8035200);
|
||||||
|
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($quarters_difference * 3), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
||||||
|
++$months_difference;
|
||||||
|
}
|
||||||
|
--$quarters_difference;
|
||||||
|
$datediff = $quarters_difference;
|
||||||
|
break;
|
||||||
|
case 'm': // Number of full months
|
||||||
|
$months_difference = floor($difference / 2678400);
|
||||||
|
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($months_difference), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
||||||
|
++$months_difference;
|
||||||
|
}
|
||||||
|
--$months_difference;
|
||||||
|
$datediff = $months_difference;
|
||||||
|
break;
|
||||||
|
case 'y': // Difference between day numbers
|
||||||
|
$datediff = date('z', $dateto) - date('z', $datefrom);
|
||||||
|
break;
|
||||||
|
case 'd': // Number of full days
|
||||||
|
$datediff = floor($difference / 86400);
|
||||||
|
break;
|
||||||
|
case 'w': // Number of full weekdays
|
||||||
|
$days_difference = floor($difference / 86400);
|
||||||
|
$weeks_difference = floor($days_difference / 7); // Complete weeks
|
||||||
|
$first_day = date('w', $datefrom);
|
||||||
|
$days_remainder = floor($days_difference % 7);
|
||||||
|
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
|
||||||
|
if ($odd_days > 7) { // Sunday
|
||||||
|
--$days_remainder;
|
||||||
|
}
|
||||||
|
if ($odd_days > 6) { // Saturday
|
||||||
|
--$days_remainder;
|
||||||
|
}
|
||||||
|
$datediff = ($weeks_difference * 5) + $days_remainder;
|
||||||
|
break;
|
||||||
|
case 'ww': // Number of full weeks
|
||||||
|
$datediff = floor($difference / 604800);
|
||||||
|
break;
|
||||||
|
case 'h': // Number of full hours
|
||||||
|
$datediff = floor($difference / 3600);
|
||||||
|
break;
|
||||||
|
case 'n': // Number of full minutes
|
||||||
|
$datediff = floor($difference / 60);
|
||||||
|
break;
|
||||||
|
default: // Number of full seconds (default)
|
||||||
|
$datediff = $difference;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $datediff;
|
||||||
|
}
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Funzioni fondamentali per il corretto funzionamento del nucleo del progetto.
|
||||||
|
*
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Esegue il redirect.
|
* Esegue il redirect.
|
||||||
@@ -36,6 +41,13 @@ function sanitizeFilename($filename)
|
|||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elimina i file indicati.
|
||||||
|
*
|
||||||
|
* @param array $files
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function delete($files)
|
function delete($files)
|
||||||
{
|
{
|
||||||
// Filesystem Symfony
|
// Filesystem Symfony
|
||||||
@@ -51,6 +63,13 @@ function delete($files)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla l'esistenza e i permessi di scrittura sul percorso indicato.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function directory($path)
|
function directory($path)
|
||||||
{
|
{
|
||||||
if (is_dir($path) && is_writable($path)) {
|
if (is_dir($path) && is_writable($path)) {
|
||||||
@@ -74,18 +93,9 @@ function directory($path)
|
|||||||
/**
|
/**
|
||||||
* Copy a file, or recursively copy a folder and its contents.
|
* Copy a file, or recursively copy a folder and its contents.
|
||||||
*
|
*
|
||||||
* @author Aidan Lister <aidan@php.net>
|
* @param string $source Source path
|
||||||
*
|
* @param string $dest Destination path
|
||||||
* @version 1.0.1
|
* @param array|string $ignores Paths to ingore
|
||||||
*
|
|
||||||
* @see http://aidanlister.com/repos/v/function.copyr.php
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
* Source path
|
|
||||||
* @param string $dest
|
|
||||||
* Destination path
|
|
||||||
* @param array|string $ignores
|
|
||||||
* Paths to ingore
|
|
||||||
*
|
*
|
||||||
* @return bool Returns TRUE on success, FALSE on failure
|
* @return bool Returns TRUE on success, FALSE on failure
|
||||||
*/
|
*/
|
||||||
@@ -209,97 +219,6 @@ function checkZip($zip_file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Individua la differenza tra le date indicate.
|
|
||||||
* $interval può essere:
|
|
||||||
* yyyy - Number of full years
|
|
||||||
* q - Number of full quarters
|
|
||||||
* m - Number of full months
|
|
||||||
* y - Difference between day numbers
|
|
||||||
* (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
|
|
||||||
* d - Number of full days
|
|
||||||
* w - Number of full weekdays
|
|
||||||
* ww - Number of full weeks
|
|
||||||
* h - Number of full hours
|
|
||||||
* n - Number of full minutes
|
|
||||||
* s - Number of full seconds (default).
|
|
||||||
*
|
|
||||||
* @param unknown $interval
|
|
||||||
* @param unknown $datefrom
|
|
||||||
* @param unknown $dateto
|
|
||||||
* @param string $using_timestamps
|
|
||||||
*/
|
|
||||||
function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
|
|
||||||
{
|
|
||||||
if (!$using_timestamps) {
|
|
||||||
$datefrom = strtotime($datefrom, 0);
|
|
||||||
$dateto = strtotime($dateto, 0);
|
|
||||||
}
|
|
||||||
$difference = $dateto - $datefrom; // Difference in seconds
|
|
||||||
switch ($interval) {
|
|
||||||
case 'yyyy': // Number of full years
|
|
||||||
$years_difference = floor($difference / 31536000);
|
|
||||||
if (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom), date('j', $datefrom), date('Y', $datefrom) + $years_difference) > $dateto) {
|
|
||||||
--$years_difference;
|
|
||||||
}
|
|
||||||
if (mktime(date('H', $dateto), date('i', $dateto), date('s', $dateto), date('n', $dateto), date('j', $dateto), date('Y', $dateto) - ($years_difference + 1)) > $datefrom) {
|
|
||||||
++$years_difference;
|
|
||||||
}
|
|
||||||
$datediff = $years_difference;
|
|
||||||
break;
|
|
||||||
case 'q': // Number of full quarters
|
|
||||||
$quarters_difference = floor($difference / 8035200);
|
|
||||||
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($quarters_difference * 3), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
|
||||||
++$months_difference;
|
|
||||||
}
|
|
||||||
--$quarters_difference;
|
|
||||||
$datediff = $quarters_difference;
|
|
||||||
break;
|
|
||||||
case 'm': // Number of full months
|
|
||||||
$months_difference = floor($difference / 2678400);
|
|
||||||
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($months_difference), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
|
||||||
++$months_difference;
|
|
||||||
}
|
|
||||||
--$months_difference;
|
|
||||||
$datediff = $months_difference;
|
|
||||||
break;
|
|
||||||
case 'y': // Difference between day numbers
|
|
||||||
$datediff = date('z', $dateto) - date('z', $datefrom);
|
|
||||||
break;
|
|
||||||
case 'd': // Number of full days
|
|
||||||
$datediff = floor($difference / 86400);
|
|
||||||
break;
|
|
||||||
case 'w': // Number of full weekdays
|
|
||||||
$days_difference = floor($difference / 86400);
|
|
||||||
$weeks_difference = floor($days_difference / 7); // Complete weeks
|
|
||||||
$first_day = date('w', $datefrom);
|
|
||||||
$days_remainder = floor($days_difference % 7);
|
|
||||||
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
|
|
||||||
if ($odd_days > 7) { // Sunday
|
|
||||||
--$days_remainder;
|
|
||||||
}
|
|
||||||
if ($odd_days > 6) { // Saturday
|
|
||||||
--$days_remainder;
|
|
||||||
}
|
|
||||||
$datediff = ($weeks_difference * 5) + $days_remainder;
|
|
||||||
break;
|
|
||||||
case 'ww': // Number of full weeks
|
|
||||||
$datediff = floor($difference / 604800);
|
|
||||||
break;
|
|
||||||
case 'h': // Number of full hours
|
|
||||||
$datediff = floor($difference / 3600);
|
|
||||||
break;
|
|
||||||
case 'n': // Number of full minutes
|
|
||||||
$datediff = floor($difference / 60);
|
|
||||||
break;
|
|
||||||
default: // Number of full seconds (default)
|
|
||||||
$datediff = $difference;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $datediff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recupera informazioni sistema operativo dell'utente.
|
* Recupera informazioni sistema operativo dell'utente.
|
||||||
*
|
*
|
||||||
@@ -337,68 +256,6 @@ function getOS()
|
|||||||
return tr('Altro');
|
return tr('Altro');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifica che il nome del file non sia già usato nella cartella inserita, nel qual caso aggiungo un suffisso.
|
|
||||||
*
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $dir
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function unique_filename($filename, $dir)
|
|
||||||
{
|
|
||||||
$f = pathinfo($filename);
|
|
||||||
$suffix = 1;
|
|
||||||
while (file_exists($dir.'/'.$filename)) {
|
|
||||||
$filename = $f['filename'].'_'.$suffix.'.'.$f['extension'];
|
|
||||||
++$suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crea le thumbnails di $filename da dentro $dir e le salva in $dir.
|
|
||||||
*
|
|
||||||
* @param string $tmp
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $dir
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function create_thumbnails($tmp, $filename, $dir)
|
|
||||||
{
|
|
||||||
$infos = pathinfo($filename);
|
|
||||||
$name = $infos['filename'];
|
|
||||||
$extension = strtolower($infos['extension']);
|
|
||||||
|
|
||||||
if (!directory($dir)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
|
|
||||||
Intervention\Image\ImageManagerStatic::configure(['driver' => $driver]);
|
|
||||||
|
|
||||||
$img = Intervention\Image\ImageManagerStatic::make($tmp);
|
|
||||||
|
|
||||||
$img->resize(600, null, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
});
|
|
||||||
$img->save(slashes($dir.'/'.$name.'.'.$extension));
|
|
||||||
|
|
||||||
$img->resize(250, null, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
});
|
|
||||||
$img->save(slashes($dir.'/'.$name.'_thumb250.'.$extension));
|
|
||||||
|
|
||||||
$img->resize(100, null, function ($constraint) {
|
|
||||||
$constraint->aspectRatio();
|
|
||||||
});
|
|
||||||
$img->save(slashes($dir.'/'.$name.'_thumb100.'.$extension));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ottiene l'indirizzo IP del client.
|
* Ottiene l'indirizzo IP del client.
|
||||||
*
|
*
|
||||||
@@ -483,28 +340,6 @@ function translateTemplate()
|
|||||||
echo $template;
|
echo $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sostituisce la prima occorenza di una determinata stringa.
|
|
||||||
*
|
|
||||||
* @param string $str_pattern
|
|
||||||
* @param string $str_replacement
|
|
||||||
* @param string $string
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function str_replace_once($str_pattern, $str_replacement, $string)
|
|
||||||
{
|
|
||||||
if (strpos($string, $str_pattern) !== false) {
|
|
||||||
$occurrence = strpos($string, $str_pattern);
|
|
||||||
|
|
||||||
return substr_replace($string, $str_replacement, strpos($string, $str_pattern), strlen($str_pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restituisce il percorso del filesystem in modo indipendente dal sistema operativo.
|
* Restituisce il percorso del filesystem in modo indipendente dal sistema operativo.
|
||||||
*
|
*
|
||||||
@@ -531,43 +366,6 @@ function isAjaxRequest()
|
|||||||
return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null;
|
return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Esegue una somma precisa tra due interi/array.
|
|
||||||
*
|
|
||||||
* @param array|float $first
|
|
||||||
* @param array|float $second
|
|
||||||
* @param int $decimals
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
function sum($first, $second = null, $decimals = 4)
|
|
||||||
{
|
|
||||||
$first = (array) $first;
|
|
||||||
$second = (array) $second;
|
|
||||||
|
|
||||||
$array = array_merge($first, $second);
|
|
||||||
|
|
||||||
$result = 0;
|
|
||||||
|
|
||||||
$decimals = is_numeric($decimals) ? $decimals : Translator::getFormatter()->getPrecision();
|
|
||||||
|
|
||||||
$bcadd = function_exists('bcadd');
|
|
||||||
|
|
||||||
foreach ($array as $value) {
|
|
||||||
$value = round($value, $decimals);
|
|
||||||
|
|
||||||
if ($bcadd) {
|
|
||||||
$result = bcadd($result, $value, $decimals);
|
|
||||||
} else {
|
|
||||||
$result += $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return floatval($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effettua le operazioni automatiche di redirect tra le pagine.
|
* Effettua le operazioni automatiche di redirect tra le pagine.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Funzioni di aiuto per la semplificazione del codice.
|
||||||
|
*
|
||||||
|
* @since 2.4.2
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restituisce l'oggetto dedicato alla gestione della connessione con il database.
|
* Restituisce l'oggetto dedicato alla gestione della connessione con il database.
|
||||||
*
|
*
|
||||||
|
30
lib/util.php
30
lib/util.php
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
use Stringy\Stringy as S;
|
use Stringy\Stringy as S;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Funzioni esterne di utilità per il progetto.
|
||||||
|
*
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
|
||||||
if (!function_exists('array_column')) {
|
if (!function_exists('array_column')) {
|
||||||
/**
|
/**
|
||||||
* Pluck an array of values from an array.
|
* Pluck an array of values from an array.
|
||||||
@@ -53,6 +59,30 @@ if (!function_exists('ends_with')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('str_replace_once')) {
|
||||||
|
/**
|
||||||
|
* Sostituisce la prima occorenza di una determinata stringa.
|
||||||
|
*
|
||||||
|
* @param string $str_pattern
|
||||||
|
* @param string $str_replacement
|
||||||
|
* @param string $string
|
||||||
|
*
|
||||||
|
* @since 2.3
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function str_replace_once($str_pattern, $str_replacement, $string)
|
||||||
|
{
|
||||||
|
if (strpos($string, $str_pattern) !== false) {
|
||||||
|
$occurrence = strpos($string, $str_pattern);
|
||||||
|
|
||||||
|
return substr_replace($string, $str_replacement, strpos($string, $str_pattern), strlen($str_pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('str_contains')) {
|
if (!function_exists('str_contains')) {
|
||||||
/**
|
/**
|
||||||
* Check if a string contains the given string.
|
* Check if a string contains the given string.
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
include_once Modules::filepath('Interventi', 'modutil.php');
|
||||||
|
|
||||||
if (!isset($user['idanagrafica'])) {
|
if (!isset($user['idanagrafica'])) {
|
||||||
$user['idanagrafica'] = '';
|
$user['idanagrafica'] = '';
|
||||||
}
|
}
|
||||||
@@ -44,8 +46,8 @@ switch (get('op')) {
|
|||||||
case 'update_intervento':
|
case 'update_intervento':
|
||||||
$sessione = get('id');
|
$sessione = get('id');
|
||||||
$idintervento = get('idintervento');
|
$idintervento = get('idintervento');
|
||||||
$timeStart = get('timeStart');
|
$orario_inizio = get('timeStart');
|
||||||
$timeEnd = get('timeEnd');
|
$orario_fine = get('timeEnd');
|
||||||
|
|
||||||
// Aggiornamento prezzo totale
|
// Aggiornamento prezzo totale
|
||||||
$q = 'SELECT in_interventi_tecnici.prezzo_ore_unitario, idtecnico, in_statiintervento.completato FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento = in_statiintervento.idstatointervento WHERE in_interventi.id='.prepare($idintervento).' AND in_statiintervento.completato = 0 '.Modules::getAdditionalsQuery('Interventi');
|
$q = 'SELECT in_interventi_tecnici.prezzo_ore_unitario, idtecnico, in_statiintervento.completato FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento = in_statiintervento.idstatointervento WHERE in_interventi.id='.prepare($idintervento).' AND in_statiintervento.completato = 0 '.Modules::getAdditionalsQuery('Interventi');
|
||||||
@@ -54,15 +56,14 @@ switch (get('op')) {
|
|||||||
|
|
||||||
for ($i = 0; $i < count($rs); ++$i) {
|
for ($i = 0; $i < count($rs); ++$i) {
|
||||||
$prezzo_ore_unitario = $rs[$i]['prezzo_ore_unitario'];
|
$prezzo_ore_unitario = $rs[$i]['prezzo_ore_unitario'];
|
||||||
|
$ore = calcola_ore_intervento($orario_inizio, $orario_fine);
|
||||||
|
|
||||||
$t = datediff('n', $timeStart, $timeEnd);
|
$prezzo_ore += $ore * $prezzo_ore_unitario;
|
||||||
$t = floatval(round($t / 60, 1));
|
|
||||||
$prezzo_ore += $t * $prezzo_ore_unitario;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($rs) > 0) {
|
if (count($rs) > 0) {
|
||||||
// Aggiornamento orario tecnico
|
// Aggiornamento orario tecnico
|
||||||
$dbo->query('UPDATE in_interventi_tecnici SET orario_inizio = '.prepare($timeStart).', orario_fine = '.prepare($timeEnd).', ore='.prepare($t).', prezzo_ore_consuntivo='.prepare($t * $prezzo_ore_unitario).' WHERE id='.prepare($sessione));
|
$dbo->query('UPDATE in_interventi_tecnici SET orario_inizio = '.prepare($orario_inizio).', orario_fine = '.prepare($orario_fine).', ore='.prepare($ore).', prezzo_ore_consuntivo='.prepare($t * $prezzo_ore_unitario).' WHERE id='.prepare($sessione));
|
||||||
echo 'ok';
|
echo 'ok';
|
||||||
} else {
|
} else {
|
||||||
echo tr('Attività completata, non è possibile modificarla!');
|
echo tr('Attività completata, non è possibile modificarla!');
|
||||||
|
@@ -799,239 +799,6 @@ function rimuovi_articolo_dafattura($idarticolo, $iddocumento, $idrigadocumento)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggiorna_sconto($tables, $fields, $id_record, $options = [])
|
|
||||||
{
|
|
||||||
$dbo = Database::getConnection();
|
|
||||||
|
|
||||||
$descrizione = tr('Sconto', [], ['upper' => true]);
|
|
||||||
|
|
||||||
// Rimozione dello sconto precedente
|
|
||||||
$dbo->query('DELETE FROM '.$tables['row'].' WHERE sconto_globale = 1 AND '.$fields['row'].'='.prepare($id_record));
|
|
||||||
|
|
||||||
// Individuazione del nuovo sconto
|
|
||||||
$sconto = $dbo->select($tables['parent'], ['sconto_globale', 'tipo_sconto_globale'], [$fields['parent'] => $id_record]);
|
|
||||||
$sconto[0]['sconto_globale'] = floatval($sconto[0]['sconto_globale']);
|
|
||||||
|
|
||||||
// Aggiorno l'eventuale sconto gestendolo con le righe in fattura
|
|
||||||
$iva = 0;
|
|
||||||
|
|
||||||
if (!empty($sconto[0]['sconto_globale'])) {
|
|
||||||
if ($sconto[0]['tipo_sconto_globale'] == 'PRC') {
|
|
||||||
$rs = $dbo->fetchArray('SELECT SUM(subtotale - sconto) AS imponibile, SUM(iva) AS iva FROM (SELECT '.$tables['row'].'.subtotale, '.$tables['row'].'.sconto, '.$tables['row'].'.iva FROM '.$tables['row'].' WHERE '.$fields['row'].'='.prepare($id_record).') AS t');
|
|
||||||
$subtotale = $rs[0]['imponibile'];
|
|
||||||
$iva += $rs[0]['iva'] / 100 * $sconto[0]['sconto_globale'];
|
|
||||||
$subtotale = -$subtotale / 100 * $sconto[0]['sconto_globale'];
|
|
||||||
|
|
||||||
$descrizione = $descrizione.' '.Translator::numberToLocale($sconto[0]['sconto_globale']).'%';
|
|
||||||
} else {
|
|
||||||
$rs = $dbo->fetchArray('SELECT SUM(subtotale - sconto) AS imponibile, SUM(iva) AS iva FROM (SELECT '.$tables['row'].'.subtotale, '.$tables['row'].'.sconto, '.$tables['row'].'.iva FROM '.$tables['row'].' WHERE '.$fields['row'].'='.prepare($id_record).') AS t');
|
|
||||||
$subtotale = $rs[0]['imponibile'];
|
|
||||||
$iva += $sconto[0]['sconto_globale'] * $rs[0]['iva'] / $subtotale;
|
|
||||||
|
|
||||||
$subtotale = -$sconto[0]['sconto_globale'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcolo dell'IVA da scontare
|
|
||||||
$idiva = setting('Iva predefinita');
|
|
||||||
$rsi = $dbo->select('co_iva', ['descrizione', 'percentuale'], ['id' => $idiva]);
|
|
||||||
|
|
||||||
$values = [
|
|
||||||
$fields['row'] => $id_record,
|
|
||||||
'descrizione' => $descrizione,
|
|
||||||
'subtotale' => $subtotale,
|
|
||||||
'qta' => 1,
|
|
||||||
'idiva' => $idiva,
|
|
||||||
'desc_iva' => $rsi[0]['descrizione'],
|
|
||||||
'iva' => -$iva,
|
|
||||||
'sconto_globale' => 1,
|
|
||||||
'#order' => '(SELECT IFNULL(MAX(`order`) + 1, 0) FROM '.$tables['row'].' AS t WHERE '.$fields['row'].'='.prepare($id_record).')',
|
|
||||||
];
|
|
||||||
|
|
||||||
$dbo->insert($tables['row'], $values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function controlla_seriali($field, $id_riga, $old_qta, $new_qta, $dir)
|
|
||||||
{
|
|
||||||
$dbo = Database::getConnection();
|
|
||||||
|
|
||||||
$new_qta = abs($new_qta);
|
|
||||||
$old_qta = abs($old_qta);
|
|
||||||
|
|
||||||
if ($old_qta >= $new_qta) {
|
|
||||||
// Controllo sulla possibilità di rimuovere i seriali (se non utilizzati da documenti di vendita)
|
|
||||||
if ($dir == 'uscita' && $new_qta < count(seriali_non_rimuovibili($field, $id_riga, $dir))) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// Controllo sul numero di seriali effettivi da rimuovere
|
|
||||||
$count = $dbo->fetchArray('SELECT COUNT(*) AS tot FROM mg_prodotti WHERE '.$field.'='.prepare($id_riga))[0]['tot'];
|
|
||||||
if ($new_qta < $count) {
|
|
||||||
$deletes = $dbo->fetchArray("SELECT id FROM mg_prodotti WHERE serial NOT IN (SELECT serial FROM mg_prodotti WHERE dir = 'entrata' AND ".$field.'!='.prepare($id_riga).') AND '.$field.'='.prepare($id_riga).' ORDER BY serial DESC LIMIT '.abs($count - $new_qta));
|
|
||||||
|
|
||||||
// Rimozione
|
|
||||||
foreach ($deletes as $delete) {
|
|
||||||
$dbo->query('DELETE FROM mg_prodotti WHERE id = '.prepare($delete['id']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Individua i seriali non rimuovibili poichè utilizzati in documenti rilasciati.
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param int $id_riga
|
|
||||||
* @param string $dir
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function seriali_non_rimuovibili($field, $id_riga, $dir)
|
|
||||||
{
|
|
||||||
$dbo = Database::getConnection();
|
|
||||||
|
|
||||||
$results = [];
|
|
||||||
|
|
||||||
if ($dir == 'uscita') {
|
|
||||||
$results = $dbo->fetchArray("SELECT serial FROM mg_prodotti WHERE serial IN (SELECT serial FROM mg_prodotti WHERE dir = 'entrata') AND ".$field.'='.prepare($id_riga));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calcola gli sconti in modo automatico.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
function calcola_sconto($data)
|
|
||||||
{
|
|
||||||
if ($data['tipo'] == 'PRC') {
|
|
||||||
$result = 0;
|
|
||||||
|
|
||||||
$price = floatval($data['prezzo']);
|
|
||||||
|
|
||||||
$percentages = explode('+', $data['sconto']);
|
|
||||||
foreach ($percentages as $percentage) {
|
|
||||||
$discount = $price / 100 * floatval($percentage);
|
|
||||||
|
|
||||||
$result += $discount;
|
|
||||||
$price -= $discount;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result = floatval($data['sconto']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($data['qta'])) {
|
|
||||||
$result = $result * $data['qta'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restistuisce le informazioni sull'eventuale riferimento ai documenti.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param string $dir
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function doc_references($info, $dir, $ignore = [])
|
|
||||||
{
|
|
||||||
$dbo = Database::getConnection();
|
|
||||||
|
|
||||||
// Rimozione valori da non controllare
|
|
||||||
foreach ($ignore as $field) {
|
|
||||||
if (isset($info[$field])) {
|
|
||||||
unset($info[$field]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = null;
|
|
||||||
$id = null;
|
|
||||||
|
|
||||||
// Ordine
|
|
||||||
if (!empty($info['idordine'])) {
|
|
||||||
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM or_ordini WHERE id=".prepare($info['idordine']));
|
|
||||||
|
|
||||||
$module = ($dir == 'entrata') ? 'Ordini cliente' : 'Ordini fornitore';
|
|
||||||
$id = $info['idordine'];
|
|
||||||
|
|
||||||
$document = tr('Ordine');
|
|
||||||
}
|
|
||||||
|
|
||||||
// DDT
|
|
||||||
elseif (!empty($info['idddt'])) {
|
|
||||||
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM dt_ddt WHERE id=".prepare($info['idddt']));
|
|
||||||
|
|
||||||
$module = ($dir == 'entrata') ? 'Ddt di vendita' : 'Ddt di acquisto';
|
|
||||||
$id = $info['idddt'];
|
|
||||||
|
|
||||||
$document = tr('Ddt');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preventivo
|
|
||||||
elseif (!empty($info['idpreventivo'])) {
|
|
||||||
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_preventivi WHERE id='.prepare($info['idpreventivo']));
|
|
||||||
|
|
||||||
$module = 'Preventivi';
|
|
||||||
$id = $info['idpreventivo'];
|
|
||||||
|
|
||||||
$document = tr('Preventivo');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Contratto
|
|
||||||
elseif (!empty($info['idcontratto'])) {
|
|
||||||
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_contratti WHERE id='.prepare($info['idcontratto']));
|
|
||||||
|
|
||||||
$module = 'Contratti';
|
|
||||||
$id = $info['idcontratto'];
|
|
||||||
|
|
||||||
$document = tr('Contratto');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intervento
|
|
||||||
elseif (!empty($info['idintervento'])) {
|
|
||||||
$data = $dbo->fetchArray('SELECT codice AS numero, IFNULL( (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE in_interventi_tecnici.idintervento=in_interventi.id), data_richiesta) AS data FROM in_interventi WHERE id='.prepare($info['idintervento']));
|
|
||||||
|
|
||||||
$module = 'Interventi';
|
|
||||||
$id = $info['idintervento'];
|
|
||||||
|
|
||||||
$document = tr('Intervento');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Testo relativo
|
|
||||||
if (!empty($module) && !empty($id)) {
|
|
||||||
$document = Stringy\Stringy::create($document)->toLowerCase();
|
|
||||||
|
|
||||||
if (!empty($data)) {
|
|
||||||
$description = tr('Rif. _DOC_ num. _NUM_ del _DATE_', [
|
|
||||||
'_DOC_' => $document,
|
|
||||||
'_NUM_' => $data[0]['numero'],
|
|
||||||
'_DATE_' => Translator::dateToLocale($data[0]['data']),
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$description = tr('_DOC_ di riferimento _ID_ eliminato', [
|
|
||||||
'_DOC_' => $document->upperCaseFirst(),
|
|
||||||
'_ID_' => $id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'module' => $module,
|
|
||||||
'id' => $id,
|
|
||||||
'description' => $description,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function rimuovi_riga_fattura($id_documento, $id_riga, $dir)
|
function rimuovi_riga_fattura($id_documento, $id_riga, $dir)
|
||||||
{
|
{
|
||||||
$dbo = Database::getConnection();
|
$dbo = Database::getConnection();
|
||||||
|
@@ -79,9 +79,7 @@ switch (post('op')) {
|
|||||||
$orario_fine = post('orario_fine')[$idriga];
|
$orario_fine = post('orario_fine')[$idriga];
|
||||||
|
|
||||||
// Ricalcolo le ore lavorate
|
// Ricalcolo le ore lavorate
|
||||||
$inizio = new DateTime($orario_inizio);
|
$ore = calcola_ore_intervento($orario_inizio, $orario_fine);
|
||||||
$diff = $inizio->diff(new DateTime($orario_fine));
|
|
||||||
$ore = $diff->h + ($diff->days * 24);
|
|
||||||
|
|
||||||
$km = post('km')[$idriga];
|
$km = post('km')[$idriga];
|
||||||
|
|
||||||
|
@@ -315,3 +315,20 @@ function get_costi_intervento($id_intervento)
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calcola le ore presenti tra due date.
|
||||||
|
*
|
||||||
|
* @param string $orario_inizio
|
||||||
|
* @param string $orario_fine
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
function calcola_ore_intervento($orario_inizio, $orario_fine)
|
||||||
|
{
|
||||||
|
$inizio = new DateTime($orario_inizio);
|
||||||
|
$diff = $inizio->diff(new DateTime($orario_fine));
|
||||||
|
$ore = $diff->h + ($diff->days * 24);
|
||||||
|
|
||||||
|
return $ore;
|
||||||
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once $docroot.'/modules/interventi/modutil.php';
|
include_once Modules::filepath('Interventi', 'modutil.php');
|
||||||
|
|
||||||
$report_name = 'contratto_'.$records[0]['numero'].'_cons.pdf';
|
$report_name = 'contratto_'.$records[0]['numero'].'_cons.pdf';
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ if (!empty($interventi)) {
|
|||||||
// Calcolo il totale delle ore lavorate
|
// Calcolo il totale delle ore lavorate
|
||||||
$tecnici = $dbo->fetchArray('SELECT orario_inizio, orario_fine FROM in_interventi_tecnici WHERE idintervento='.prepare($int['id']));
|
$tecnici = $dbo->fetchArray('SELECT orario_inizio, orario_fine FROM in_interventi_tecnici WHERE idintervento='.prepare($int['id']));
|
||||||
foreach ($tecnici as $tecnico) {
|
foreach ($tecnici as $tecnico) {
|
||||||
$totale_ore_impiegate += datediff('n', $tecnico['orario_inizio'], $tecnico['orario_fine']) / 60;
|
$totale_ore_impiegate += calcola_ore_intervento($tecnico['orario_inizio'], $tecnico['orario_fine']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ore[] = $int['ore'];
|
$ore[] = $int['ore'];
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once DOCROOT.'/modules/fatture/modutil.php';
|
include_once Modules::filepath('Fatture di vendita', 'modutil.php');
|
||||||
|
|
||||||
$report_name = 'ddt_'.$numero.'.pdf';
|
$report_name = 'ddt_'.$numero.'.pdf';
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once DOCROOT.'/modules/fatture/modutil.php';
|
include_once Modules::filepath('Fatture di vendita', 'modutil.php');
|
||||||
|
|
||||||
$report_name = 'fattura_'.$numero.'.pdf';
|
$report_name = 'fattura_'.$numero.'.pdf';
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once $docroot.'/modules/interventi/modutil.php';
|
include_once Modules::filepath('Interventi', 'modutil.php');
|
||||||
|
|
||||||
$report_name = 'intervento_'.$records[0]['codice'].'.pdf';
|
$report_name = 'intervento_'.$records[0]['codice'].'.pdf';
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once $docroot.'/modules/interventi/modutil.php';
|
include_once Modules::filepath('Interventi', 'modutil.php');
|
||||||
|
|
||||||
$module_name = 'Interventi';
|
$module_name = 'Interventi';
|
||||||
|
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
include_once $docroot.'/modules/interventi/modutil.php';
|
include_once Modules::filepath('Interventi', 'modutil.php');
|
||||||
include_once $docroot.'/modules/preventivi/modutil.php';
|
include_once Modules::filepath('Preventivi', 'modutil.php');
|
||||||
|
|
||||||
$report_name = 'preventivo_'.$records[0]['numero'].'_cons.pdf';
|
$report_name = 'preventivo_'.$records[0]['numero'].'_cons.pdf';
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
|
Reference in New Issue
Block a user