fetchArray($q); if ($rs[0]['dir'] == 'entrata') { $module_name = 'Fatture di vendita'; } else { $module_name = 'Fatture di acquisto'; } $additional_where[$module_name] = str_replace('|idanagrafica|', "'".$user['idanagrafica']."'", $additional_where[$module_name]); // Lettura info fattura $q = 'SELECT *, (SELECT descrizione FROM co_tipidocumento WHERE id=idtipodocumento) AS tipo_doc, (SELECT descrizione FROM co_pagamenti WHERE id=idpagamento) AS tipo_pagamento, (SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id="'.$iddocumento.'" '.$additional_where[$module_name]; $rs = $dbo->fetchArray($q); $numero_doc = $rs[0]['numero']; $idcliente = $rs[0]['idanagrafica']; (!empty($rs[0]['numero_esterno'])) ? $numero = $rs[0]['numero_esterno'] : $numero = $rs[0]['numero']; // carica report html $report = file_get_contents($docroot.'/templates/fatture_accompagnatorie/fattura.html'); $body = file_get_contents($docroot.'/templates/fatture_accompagnatorie/fattura_body.html'); if (!($idcliente == $user['idanagrafica'] || Auth::admin())) { die('Non hai i permessi per questa stampa!'); } include_once $docroot.'/templates/pdfgen_variables.php'; // Leggo i dati della destinazione (se 0=sede legale, se!=altra sede da leggere da tabella an_sedi) $destinazione = ''; if ($rs[0]['idsede'] == 0) { $queryd = "SELECT ragione_sociale, indirizzo, indirizzo2, cap, citta, provincia, piva, codice_fiscale FROM an_anagrafiche WHERE idanagrafica='".$idcliente."'"; $rsd = $dbo->fetchArray($queryd); if ($rsd[0]['ragione_sociale'] != '') { $destinazione .= $rsd[0]['ragione_sociale']."
\n"; } if ($rsd[0]['indirizzo'] != '') { $destinazione .= $rsd[0]['indirizzo']."
\n"; } if ($rsd[0]['indirizzo2'] != '') { $destinazione .= $rsd[0]['indirizzo2']."
\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"; } if ($rsd[0]['piva'] != '') { $destinazione .= 'P.IVA: '.$rsd[0]['piva']."
\n"; } if ($rsd[0]['piva'] == '') { $destinazione .= 'C.F.: '.$rsd[0]['codice_fiscale']."
\n"; } } else { $queryd = "SELECT (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]['ragione_sociale'] != '') { $destinazione .= $rsd[0]['ragione_sociale']."
\n"; } if ($rsd[0]['indirizzo'] != '') { $destinazione .= $rsd[0]['indirizzo']."
\n"; } if ($rsd[0]['indirizzo2'] != '') { $destinazione .= $rsd[0]['indirizzo2']."
\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"; } if ($rsd[0]['piva'] != '') { $destinazione .= 'P.IVA: '.$rsd[0]['piva']."
\n"; } if ($rsd[0]['codice_fiscale'] != '') { $destinazione .= 'C.F.: '.$rsd[0]['codice_fiscale']."
\n"; } } $body = str_replace('$c_destinazione$', $destinazione, $body); // Dati generici fattura if ($rs[0]['buono_ordine'] != '') { $width = '165'; } else { $width = '228'; } $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; if ($rs[0]['buono_ordine']) { $body .= "\n"; } $body .= "\n"; $body .= "
".$rs[0]['tipo_doc']."
num. $numero
Data:
".Translator::dateToLocale($rs[0]['data'])."
Pagamento:
".$rs[0]['tipo_pagamento']."
Buono d'ordine:
".$rs[0]['buono_ordine']."


\n"; // Intestazione tabella per righe $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; // Mostro le righe del documento $totale_documento = 0.00; $totale_imponibile = 0.00; $totale_iva = 0.00; $sconto = 0.00; /* Righe fattura */ $qr = "SELECT * FROM `co_righe_documenti` WHERE iddocumento='$iddocumento'"; $rsr = $dbo->fetchArray($qr); $tot = sizeof($rsr); $imponibile_int = 0.00; $iva_int = 0.00; if ($tot > 0) { for ($i = 0; $i < $tot; ++$i) { // Intervento if (!empty($rsr[$i]['idintervento']) && empty($rsr[$i]['idarticolo'])) { $body .= "\n"; $qta = $rsr[$i]['qta']; ($qta == 0) ? $qta = '-' : $qta = Translator::numberToLocale($qta); $body .= "\n"; ($qta == 0) ? $um = '-' : $um = $rsr[$i]['um']; $body .= "\n"; // costo unitario $subtotale = $rsr[$i]['subtotale'] / $rsr[$i]['qta']; ($subtotale == 0) ? $subtotale = '-' : $subtotale = Translator::numberToLocale($subtotale).' €'; $body .= "\n"; $body .= "\n"; $body .= "\n"; $imponibile_int += $rsr[$i]['subtotale']; $iva_int += $iva; $sconto += $rsr[$i]['sconto']; } // Preventivi elseif ($rsr[$i]['idpreventivo'] != 0) { $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; // Iva $body .= "\n"; // Imponibile $body .= "\n"; $imponibile_pre += $rsr[$i]['subtotale']; $iva_pre += $iva; $sconto += $rsr[$i]['sconto']; } // Contratti elseif ($rsr[$i]['idcontratto'] != 0) { $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; // Iva $body .= "\n"; // Imponibile $body .= "\n"; $imponibile_con += $rsr[$i]['subtotale']; $iva_con += $iva; $sconto += $rsr[$i]['sconto']; } // Articoli elseif ($rsr[$i]['idarticolo'] != 0) { $body .= "\n"; $body .= "\n"; $body .= "\n"; // costo unitario $body .= "\n"; $body .= "\n"; $body .= "\n"; $imponibile_art += $rsr[$i]['subtotale']; $iva_art += $iva; $sconto += $rsr[$i]['sconto']; } // Righe generiche else { $body .= "\n"; $body .= "\n"; $body .= "\n"; $body .= "\n"; // Iva $body .= "\n"; // Imponibile $body .= "\n"; $imponibile_gen += $rsr[$i]['subtotale']; $iva_gen += $iva; $sconto += $rsr[$i]['sconto']; } } $imponibile_documento += $imponibile_int; $totale_iva += $iva_int; $totale_documento += $imponibile_int; $imponibile_documento += $imponibile_pre; $totale_iva += $iva_pre; $totale_documento += $imponibile_pre; $imponibile_documento += $imponibile_con; $totale_iva += $iva_con; $totale_documento += $imponibile_con; $imponibile_documento += $imponibile_art; $totale_iva += $iva_art; $totale_documento += $imponibile_art; $imponibile_documento += $imponibile_gen; $totale_iva += $iva_gen; $totale_documento += $imponibile_gen; } // Totale documento $body .= "\n"; // Imponibile $body .= "\n"; // Mostra sconto se c'è if (abs($sconto) > 0) { $body .= "\n"; // Sconto $body .= "'; // Totale scontato $body .= "\n"; // Sconto $body .= "\n"; } // Mostra INPS se c'è if (abs($rs[0]['rivalsainps']) > 0) { $body .= "\n"; // Rivalsa INPS $body .= "\n"; $totale_documento += $rs[0]['rivalsainps']; } // Mostra iva se c'è $totale_iva += $rs[0]['iva_rivalsainps']; if (abs($totale_iva) > 0) { $body .= "\n"; // Iva $body .= "\n"; $totale_documento += $totale_iva; } /* Totale documento */ $body .= "\n"; $body .= "\n"; $netto_a_pagare = $totale_documento; // Mostra marca da bollo se c'è if (abs($rs[0]['bollo']) > 0) { $body .= "\n"; // Marca da bollo $body .= "\n"; $netto_a_pagare += $marca_da_bollo; } // Mostra ritenuta d'acconto se c'è if (abs($rs[0]['ritenutaacconto']) > 0) { $body .= "\n"; // Ritenuta d'acconto $body .= "\n"; $netto_a_pagare -= $rs[0]['ritenutaacconto']; } /* Netto a pagare (se diverso dal totale) */ if ($totale_documento != $netto_a_pagare) { $body .= "\n"; $body .= "\n"; } $body .= "\n"; $body .= "
DescrizioneQ.tàu.m.Costo unitarioIvaImponibile
\n"; $body .= nl2br($rsr[$i]['descrizione'])."\n"; $body .= "\n"; $body .= $qta; $body .= "\n"; $body .= $um; $body .= "\n"; $body .= $subtotale."\n"; $body .= "\n"; $iva = $rsr[$i]['iva']; $body .= '
'.Translator::numberToLocale($iva)." €
".$rsr[$i]['desc_iva']."\n"; $body .= "
\n"; $subtot = $rsr[$i]['subtotale']; $body .= Translator::numberToLocale($subtot)." €\n"; if ($rsr[$i]['sconto'] > 0) { $body .= "
\n- sconto ".Translator::numberToLocale($rsr[$i]['sconto'])." €\n"; } $body .= "
\n"; $body .= nl2br($rsr[$i]['descrizione'])."\n"; $body .= "\n"; $body .= "1\n"; $body .= "\n"; $body .= '-'; $body .= "\n"; $body .= "-\n"; $body .= "\n"; $iva = $rsr[$i]['iva']; $body .= '
'.Translator::numberToLocale($iva)." €
".$rsr[$i]['desc_iva']."\n"; $body .= "
\n"; $subtot = $rsr[$i]['subtotale']; $body .= Translator::numberToLocale($subtot)." €\n"; if ($rsr[$i]['sconto'] > 0) { $body .= "
\n- sconto ".Translator::numberToLocale($rsr[$i]['sconto'])." €\n"; } $body .= "
\n"; $body .= nl2br($rsr[$i]['descrizione'])."\n"; $body .= "\n"; $body .= "1\n"; $body .= "\n"; $body .= '-'; $body .= "\n"; $body .= "-\n"; $body .= "\n"; $iva = $rsr[$i]['iva']; $body .= '
'.Translator::numberToLocale($iva)." €
".$rsr[$i]['desc_iva']."\n"; $body .= "
\n"; $subtot = $rsr[$i]['subtotale']; $body .= Translator::numberToLocale($subtot)." €\n"; if ($rsr[$i]['sconto'] > 0) { $body .= "
\n- sconto ".Translator::numberToLocale($rsr[$i]['sconto'])." €\n"; } $body .= "
\n"; // Immagine articolo $f = pathinfo($rsr[$i]['immagine01']); $img = $docroot.'/modules/magazzino/articoli/images/'.$f['filename'].'_thumb100.'.$f['extension']; if (file_exists($img)) { $body .= '\"\"\n"; } $body .= nl2br($rsr[$i]['descrizione']); // Aggiunta riferimento a ordine if (!empty($rsr[$i]['idordine'])) { $rso = $dbo->fetchArray('SELECT numero, numero_esterno, data FROM or_ordini WHERE id="'.$rsr[$i]['idordine'].'"'); ($rso[0]['numero_esterno'] != '') ? $numero = $rso[0]['numero_esterno'] : $numero = $rso[0]['numero']; $body .= '
Rif. ordine '.$numero.' del '.Translator::dateToLocale($rso[0]['data']).''; } // Aggiunta riferimento a ddt elseif (!empty($rsr[$i]['idddt'])) { $rso = $dbo->fetchArray('SELECT numero, numero_esterno, data FROM dt_ddt WHERE id="'.$rsr[$i]['idddt'].'"'); ($rso[0]['numero_esterno'] != '') ? $numero = $rso[0]['numero_esterno'] : $numero = $rso[0]['numero']; $body .= '
Rif. ddt '.$numero.' del '.Translator::dateToLocale($rso[0]['data']).''; } $body .= "
\n"; $body .= Translator::numberToLocale($rsr[$i]['qta']); $body .= "\n"; $body .= $rsr[$i]['um']; $body .= "\n"; $body .= Translator::numberToLocale($rsr[$i]['subtotale'] / $rsr[$i]['sumqta'])." €\n"; $body .= "\n"; $iva = $rsr[$i]['iva']; $body .= '
'.Translator::numberToLocale($iva)." €
".$rsr[$i]['desc_iva']."\n"; $body .= "
\n"; $subtot = $rsr[$i]['subtotale']; $body .= Translator::numberToLocale($subtot)." €\n"; if ($rsr[$i]['sconto'] > 0) { $body .= "
\n- sconto ".Translator::numberToLocale($rsr[$i]['sconto'])." €\n"; } $body .= "
\n"; $body .= nl2br($rsr[$i]['descrizione']); // Aggiunta riferimento a ordine if (!empty($rsr[$i]['idordine'])) { $rso = $dbo->fetchArray('SELECT numero, numero_esterno, data FROM or_ordini WHERE id="'.$rsr[$i]['idordine'].'"'); ($rso[0]['numero_esterno'] != '') ? $numero = $rso[0]['numero_esterno'] : $numero = $rso[0]['numero']; $body .= '
Rif. ordine num.'.$numero.' del '.Translator::dateToLocale($rso[0]['data']).''; } // Aggiunta riferimento a ddt elseif (!empty($rsr[$i]['idddt'])) { $rso = $dbo->fetchArray('SELECT numero, numero_esterno, data FROM dt_ddt WHERE id="'.$rsr[$i]['idddt'].'"'); ($rso[0]['numero_esterno'] != '') ? $numero = $rso[0]['numero_esterno'] : $numero = $rso[0]['numero']; $body .= '
Rif. ddt num.'.$numero.' del '.Translator::dateToLocale($rso[0]['data']).''; } $body .= "
\n"; $body .= Translator::numberToLocale($rsr[$i]['qta'])."\n"; $body .= "\n"; $body .= $rsr[$i]['um']."\n"; $body .= "\n"; $body .= Translator::numberToLocale($rsr[$i]['subtotale'] / $rsr[$i]['qta'])." €\n"; $body .= "\n"; $iva = $rsr[$i]['iva']; $body .= '
'.Translator::numberToLocale($iva)." €
".$rsr[$i]['desc_iva']."\n"; $body .= "
\n"; $subtot = $rsr[$i]['subtotale']; $body .= Translator::numberToLocale($subtot)." €\n"; if ($rsr[$i]['sconto'] > 0) { $body .= "
\n- sconto ".Translator::numberToLocale($rsr[$i]['sconto'])." €\n"; } $body .= "
\n"; $body .= 'Subtot.:'; $body .= "\n"; $totale_documento = $imponibile_documento; $body .= Translator::numberToLocale($totale_documento)." €\n"; $body .= "
\n"; $body .= 'Sconto:'; $body .= "\n"; $body .= Translator::numberToLocale($sconto)." €\n"; $body .= '
\n"; $body .= 'Totale scontato:'; $body .= "\n"; $totale_documento -= $sconto; $body .= Translator::numberToLocale($totale_documento)." €\n"; $body .= "
\n"; $body .= 'Rivalsa INPS:'; $body .= "\n"; $body .= Translator::numberToLocale($rs[0]['rivalsainps'])." €\n"; $body .= "
\n"; $body .= 'Iva:'; $body .= "\n"; $body .= Translator::numberToLocale($totale_iva)." €\n"; $body .= "
\n"; $body .= 'Totale documento:'; $body .= "\n"; $body .= ''.Translator::numberToLocale($totale_documento)." €\n"; $body .= "
\n"; $body .= 'Marca da bollo:'; $body .= "\n"; $marca_da_bollo = str_replace(',', '.', $rs[0]['bollo']); $body .= Translator::numberToLocale($marca_da_bollo).' €'; $body .= "
\n"; $body .= "Ritenuta d'acconto:"; $body .= "\n"; $body .= Translator::numberToLocale($rs[0]['ritenutaacconto']).' €'; $body .= "
\n"; $body .= 'Netto a pagare:'; $body .= "\n"; $body .= ''.Translator::numberToLocale($netto_a_pagare)." €\n"; $body .= "
\n"; $body .= '

'.nl2br($rs[0]['note'])."

\n"; if ($rs[0]['vettore'] != '') { $vettore = ' ('.$rs[0]['vettore'].')'; } else { $vettore = ''; } // Dati footer ddt $footer = "

\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "
Colli:
".$rs[0]['n_colli']." 
Aspetto beni:
".$rs[0]['aspettobeni']." 
Causale trasporto:
".$rs[0]['causalet']." 
Porto:
".$rs[0]['porto']." 
\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "\n"; $footer .= "
Tipo di spedizione:
".$rs[0]['spedizione'].$vettore." 
Conducente:
______________________
Destinatario:
______________________
\n"; $body = str_replace('|footer|', $footer, $body); $report_name = 'fattura_'.$numero_doc.'.pdf';