221 lines
8.9 KiB
PHP
221 lines
8.9 KiB
PHP
<?
|
|
// USATO SOLO DA DULCIAR
|
|
session_start();
|
|
require_once("config.php");
|
|
require_once("Zend/Pdf.php");
|
|
|
|
try{
|
|
$db = new Cms;
|
|
$doc_key = sanitize(B64JSON_parse($_GET["key"]));
|
|
|
|
$sql = "SELECT gtb_anag.cod_anag,
|
|
gtb_anag.rag_soc,
|
|
gtb_anag.indirizzo,
|
|
gtb_anag.citta,
|
|
gtb_anag.cap,
|
|
gtb_anag.prov,
|
|
vtb_dest.destinatario,
|
|
vtb_dest.indirizzo AS indirizzo_dest,
|
|
vtb_dest.citta AS citta_dest,
|
|
vtb_dest.cap AS cap_dest,
|
|
vtb_dest.prov AS prov_dest,
|
|
gtb_paga.descrizione AS descr_paga,
|
|
dtb_doct.cod_vage,
|
|
vtb_agen.rag_soc AS rag_soc_agen,
|
|
dtb_doct.rif_ord,
|
|
dtb_doct.num_colli,
|
|
dtb_doct.peso,
|
|
dtb_doct.aspetto_beni,
|
|
dtb_doct.porto,
|
|
dtb_doct.mezzo,
|
|
dtb_doct.causale_trasp,
|
|
vtb_vett_a.rag_soc AS vett_a,
|
|
vtb_vett_b.rag_soc AS vett_b,
|
|
gtb_anag.part_iva,
|
|
gtb_anag.cod_fisc,
|
|
dtb_doct.cod_mdep
|
|
FROM dtb_doct LEFT OUTER JOIN vtb_dest ON dtb_doct.cod_anag = vtb_dest.cod_anag AND
|
|
dtb_doct.cod_vdes = vtb_dest.cod_vdes
|
|
LEFT OUTER JOIN gtb_paga ON dtb_doct.cod_paga = gtb_paga.cod_paga
|
|
LEFT OUTER JOIN vtb_vett vtb_vett_a ON dtb_doct.cod_vvet = vtb_vett_a.cod_vvet
|
|
LEFT OUTER JOIN vtb_vett vtb_vett_b ON dtb_doct.cod_vvet2 = vtb_vett_b.cod_vvet
|
|
LEFT OUTER JOIN vtb_agen ON dtb_doct.cod_vage = vtb_agen.cod_vage,
|
|
gtb_anag
|
|
WHERE dtb_doct.cod_anag = gtb_anag.cod_anag AND
|
|
dtb_doct.cod_anag = '{$doc_key["cod_anag"]}' AND
|
|
dtb_doct.cod_dtip = '{$doc_key["cod_dtip"]}' AND
|
|
dtb_doct.data_doc = '".strftime("%Y-%m-%d", $doc_key["data_doc"])."' AND
|
|
dtb_doct.ser_doc = '{$doc_key["ser_doc"]}' AND
|
|
dtb_doct.num_doc = {$doc_key["num_doc"]}";
|
|
|
|
$orderHead = sql2array($sql);
|
|
if(count($orderHead)>0){
|
|
$orderHead = $orderHead[0];
|
|
|
|
$pdf = Zend_Pdf::load("config_aziende/custom_dulciar/ddt.pdf");
|
|
|
|
$sql = "SELECT cod_mart,
|
|
descrizione,
|
|
descrizione_estesa,
|
|
unt_doc,
|
|
qta_doc,
|
|
qta_cnf
|
|
FROM dtb_docr
|
|
WHERE cod_anag = '{$doc_key["cod_anag"]}' AND
|
|
cod_dtip = '{$doc_key["cod_dtip"]}' AND
|
|
data_doc = '".strftime("%Y-%m-%d", $doc_key["data_doc"])."' AND
|
|
ser_doc = '{$doc_key["ser_doc"]}' AND
|
|
num_doc = {$doc_key["num_doc"]}";
|
|
|
|
$orderRows = sql2array($sql);
|
|
|
|
$pdf = Zend_Pdf::load("config_aziende/custom_dulciar/ddt.pdf");
|
|
|
|
$page = $pdf->pages[0];
|
|
|
|
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
|
|
$page->setFont($font, 11);
|
|
|
|
// ***** INIZIO CASELLA CLIENTE *** //
|
|
$page->drawText($orderHead["rag_soc"], 325, 775);
|
|
$page->drawText($orderHead["indirizzo"], 325, 760);
|
|
$page->drawText("{$orderHead["cap"]} {$orderHead["citta"]} ({$orderHead["prov"]})", 325, 745);
|
|
// ***** FINE CASELLA CLIENTE *** //
|
|
|
|
// ***** INIZIO CASELLA DESTINATARIO *** //
|
|
if(strlen($orderHead["destinatario"])==0){
|
|
$orderHead["destinatario"] = "IDEM";
|
|
}
|
|
$page->drawText($orderHead["destinatario"], 325, 708);
|
|
$page->drawText($orderHead["indirizzo_dest"], 325, 693);
|
|
|
|
if(strlen($orderHead["prov_dest"])>0){
|
|
$orderHead["prov_dest"] = "({$orderHead["prov_dest"]})";
|
|
}
|
|
$page->drawText("{$orderHead["cap_dest"]} {$orderHead["citta_dest"]} {$orderHead["prov_dest"]}", 325, 678);
|
|
|
|
// ***** FINE CASELLA DESTINATARIO *** //
|
|
|
|
// ***** INIZIO CASELLA TESTATA DOCUMENTO *** //
|
|
$page->setFont($font, 9);
|
|
$tipo_documento = "DOCUMENTO DI TRASPORTO";
|
|
$page->drawText($tipo_documento, 55, 628);
|
|
$page->drawText($doc_key["ser_doc"], 355, 628);
|
|
$page->drawText($doc_key["num_doc"], 400, 628);
|
|
$page->drawText(strftime("%d/%m/%Y", $doc_key["data_doc"]), 455, 628);
|
|
$page->drawText($orderHead["cod_anag"], 55, 605);
|
|
$page->drawText($orderHead["cod_mdep"], 223, 605);
|
|
$page->drawText($orderHead["descr_paga"], 275, 605);
|
|
$page->drawText($orderHead["cod_vage"], 223, 582);
|
|
$page->drawText($orderHead["rag_soc_agen"], 275, 582);
|
|
$page->drawText($orderHead["rif_ord"], 55, 559);
|
|
$page->drawText("EURO", 520, 559);
|
|
|
|
if(strlen($orderHead["part_iva"])==0){
|
|
$page->drawText($orderHead["cod_fisc"], 105, 605);
|
|
} else{
|
|
$page->drawText($orderHead["part_iva"], 105, 605);
|
|
}
|
|
|
|
// ***** FINE CASELLA TESTATA DOCUMENTO *** //
|
|
|
|
|
|
// ***** INIZIO DATI TRASPORTO *** //
|
|
$page->setFont($font, 9);
|
|
$page->drawText($orderHead["num_colli"], 55, 210);
|
|
$page->drawText($orderHead["peso"], 120, 210);
|
|
$page->drawText($orderHead["aspetto_beni"], 185, 210);
|
|
$page->drawText($orderHead["causale_trasp"], 395, 210);
|
|
$page->drawText($orderHead["porto"], 55, 187);
|
|
$page->drawText($orderHead["mezzo"], 185, 187);
|
|
|
|
$page->setFont($font, 7);
|
|
$page->drawText($orderHead["vett_a"], 55, 167);
|
|
$page->drawText($orderHead["vett_b"], 55, 134);
|
|
// ***** FINE DATI TRASPORTO *** //
|
|
|
|
$n_righe = count($orderRows);
|
|
$passo = 26;
|
|
$n_pag = ceil($n_righe/$passo);
|
|
|
|
// ***** INIZIO ELENCO ARTICOLI DOCUMENTO *** //
|
|
|
|
$template = clone $pdf->pages[0];
|
|
|
|
$i = 0;
|
|
$interlinea = 12;
|
|
$riga_su_pag = 0;
|
|
$pag_corr = 0;
|
|
|
|
$page = $pdf->pages[0];
|
|
$page->setFont($font, 9);
|
|
$page->drawText(($pag_corr+1)."/".$n_pag, 530, 628);
|
|
$page->setFont($font, 8);
|
|
|
|
foreach($orderRows as $row){
|
|
if($riga_su_pag==$passo-1){
|
|
$pag_corr++;
|
|
$pdf->pages[$pag_corr] = clone $template;
|
|
$page = $pdf->pages[$pag_corr];
|
|
$riga_su_pag = 0;
|
|
$page->setFont($font, 9);
|
|
$page->drawText(($pag_corr+1)."/".$n_pag, 530, 628);
|
|
$page->setFont($font, 8);
|
|
}
|
|
|
|
$y = 537-$interlinea * $riga_su_pag;
|
|
|
|
$page->drawText($row["cod_mart"], 55, $y);
|
|
$page->drawText((strlen($row["descrizione_estesa"])>0)?$row["descrizione_estesa"]:$row["descrizione"], 110, $y);
|
|
$page->drawText($row["unt_doc"], 397, $y);
|
|
if($row["qta_doc"]>0){
|
|
$page->drawText(number_format($row["qta_doc"], 2), 458 - word_width(number_format($row["qta_doc"], 2), $font, 8), $y);
|
|
if($row["qta_cnf"]!=0){
|
|
$cartoni = number_format($row["qta_doc"] / $row["qta_cnf"], 0);
|
|
$page->drawText($cartoni, getX4DX(435, $cartoni, $font, 8), $y);
|
|
}
|
|
}
|
|
$i++;
|
|
$riga_su_pag++;
|
|
}
|
|
// ***** FINE ELENCO ARTICOLI DOCUMENTO *** //
|
|
|
|
$output_filename = $doc_key["cod_dtip"]."_".$doc_key["cod_anag"]."_".strftime("%Y%m%d", $doc_key["data_doc"])."-".$doc_key["num_doc"];
|
|
|
|
|
|
ob_start();
|
|
echo $pdf->render();
|
|
$byteArray = ob_get_contents();
|
|
ob_end_clean();
|
|
$filesize = strlen($byteArray);
|
|
|
|
header("Content-Disposition: inline; filename=$output_filename.pdf");
|
|
header("Content-type: application/x-pdf");
|
|
header("Content-length: $filesize");
|
|
|
|
echo $byteArray;
|
|
//echo $pdf->render();
|
|
} else{
|
|
echo "Documento non trovato";
|
|
}
|
|
} catch(SoapFault $e){
|
|
print_r($e);
|
|
}
|
|
|
|
//funzione per calcolare la lunghezza in px della stringa (utile per allineamenti)
|
|
function word_width($string, $font, $fontSize){
|
|
$drawingString = iconv("", "UTF-16BE", $string);
|
|
$characters = array();
|
|
for($i=0; $i < strlen($drawingString); $i++){
|
|
$characters[] = (ord($drawingString[$i++]) << 8) | ord ($drawingString[$i]);
|
|
}
|
|
$glyphs = $font->glyphNumbersForCharacters($characters);
|
|
$widths = $font->widthsForGlyphs($glyphs);
|
|
$stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
|
|
return $stringWidth;
|
|
}
|
|
function getX4DX($x1, $string, $font, $fontSize){
|
|
$text_width=word_width($string,$font,$fontSize);
|
|
$left = $x1 + (100 - $text_width) / 2;
|
|
return $left;
|
|
} |