Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Fpdf e pagina nuova automatica

    Salve a tutti,
    sto strutturando la fatturazione e il ddt in php e per fare ciò mi sono scritto un codice che eseguo con FPDF. La strutturazione della pagina va benissimo, i valori li prende ed il ddt/fattura vengono stampati correttamente... Il problema che ho ora è che non riesco a far si che dopo tot righe nel corpo del documento, il documento vada a pagina nuova continuando... Credo sia una cosa abbastanza facile ma ci sto uscendo pazzo.. Vi posto il php dei due file:

    ddt.php :

    Codice PHP:
    <?php
    session_start
    ();
    define('FPDF_FONTPATH','font/');
    require (
    'ddt_pdf.php');
    include(
    'connect.php');
        
    // $_SESSION['causale']=$causale;
        // $_SESSION['colli']=$colli;
        // $_SESSION['porto']=$porto;
        // $_SESSION['note']=$note;
    if(isset($_POST['creapdf'])){
        
    $barcode=$_POST['barcodeart_vecchi'];
        
    $descrizione $_POST['descrizione'];
        
    $quantita=$_POST['quantita'];
        
    $fornitore=$_POST['fornitore'];
        
    $codice=$_POST['codice'];
        
    $um=$_POST['UM'];
        
    $reparto=$_POST['reparto'];
        
    $prezzo $_POST['prezzo'];
        
    $scontoperc=$_POST['scontoperc'];
        
    $scontoval=$_POST['scontoval'];
        
    $prezzosconto=$_POST['prezzosconto'];
        
    $causale=$_POST['causale'];
        
    $colli=$_POST['colli'];
        
    $porto=$_POST['porto'];
        
    $note=$_POST['note'];
        
    $vettore=$_POST['vettore'];
        
    $_SESSION['vettore']=$vettore;
        
    $_SESSION['causale']=$causale;
        
    $_SESSION['colli']=$colli;
        
    $_SESSION['porto']=$porto;
        
    $_SESSION['note']=$note;
    $message "";
    $border "0";
    $telefono="00000000";
        
    //provo in pfd
        
    $pdf = new INVOICE'P''mm''A4' );
        
    $pdf->Open();
        
    $pdf->AddPage();
        if( 
    file_exists "$image_dir/esteso.txt" ))
            
    $pdf->SetLogo('images/logo.png',1);
        else {
            
    $pdf->SetLogo('images/logo.png');
        }
        
    $pdf->addSociete"html.it",
                      
    "Via roma, 10\n" .
                      
    "00100 - ROMA\n".
                      
    "P.Iva 12345678901\n".
                      
    "C.F. aaaaaaaaaaa\n" .
                      
    "Tel/Fax 00.0000000\n" .
                      
    "Email: [email]html@html.html[/email]\n"
                      
    );
        
    $query mysql_query("SELECT * FROM ddt ");
        
    $rows mysql_fetch_array($query);
        
    $_SESSION['numero']=$rows['numero_doc'];
        
    //$_SESSION['anno']=$rows['anno'];
        
    $numero=$_SESSION['numero']+1;
        
    $anno=2013;
        
    $pdf->fact_dev"DDT ",$numero,$anno); // // Label and number of invoice/estimate
        
    $pdf->addDate(date("d/m/Y"));
        
    $pdf->addPageNumber("1");
        
    $pdf->addClient($ref);
        
    $querydestinatario mysql_query("SELECT * FROM clienti WHERE id='4' ");
        
    $righe mysql_fetch_array($querydestinatario);
        
    $ragione=$righe['ragione'];
        
    $ragione2=$righe['ragione2'];
        
    $indirizzo=$righe['indirizzo'];
        
    $cap=$righe['cap'];
        
    $citta=$righe['citta'];
        
    $pr=$righe['provincia'];
        
    $piva=$righe['piva'];
        if (
    $ragione2 == ""){
        
    $pdf->addClientAdresse
                      
    $ragione."\n".
                      
    $indirizzo."\n" .
                      
    $cap."-".$citta." (".$pr.")\n".
                      
    "P.Iva ".$piva."\n"
                      
    );    
        }else{
        
    $pdf->addClientAdresse
                      
    $ragione."\n".
                      
    $ragione2."\n".
                      
    $indirizzo."\n" .
                      
    $cap."-".$citta." (".$pr.")\n".
                      
    "P.Iva ".$piva."\n"
                      
    );    
        }    
        
    $pdf->addClientDest($re1);
        
    $pdf->addClientAdresseDest(
        
    $indirizzo."\n" .
        
    $cap."-".$citta." (".$pr.")\n".
        
    $telefono."\n"
        
    );  
        
    $pdf->addReglement($causale);
        
    $cols=array( REFERENCE    => 30,
                     
    DESCRIPTION  => 130
                     
    TOT_ART      => 15,
                     
    QUANTITY     => 15);
        
    $pdf->addCols$cols);
        
    $cols=array( REFERENCE    => "L",
                     
    DESCRIPTION  => "L",
                     
    TOT_ART      => "C",
                     
    QUANTITY     => "C");
        
    $pdf->addLineFormat($cols);
        
    $y    100;
        
    $size=0// dummy value
        
    $tot_prods = array();
        
    $conta=count($barcode);
        for(
    $i=0;$i<$conta;$i++){
            
    $line = array(  REFERENCE    => $codice[$i],
                            
    DESCRIPTION  => $descrizione[$i],
                            
    TOT_ART      => $um[$i],
                            
    QUANTITY     => $quantita[$i]); //codice IVA 
            
    $size $pdf->addLine$y$line );
            
    $y   += $size;
        
    $y   += $size;
        }
        
    $pdf->addCadreTVAs();
        
    $params  = array();
        
    $pdf->addTVAs$params$tab_tva$tot_prods);
        
    $pdf->addCadreEurosFrancs(); //conversione euro-franchi
        
    $footerMsg="NOTE: Qui ci vanno tutte le note che vogliamo";
        
    $pdf->SetFooterMsg($note);
        
    //$pdf->Output('doc.pdf','F');
        //header("Location: doc.pdf");
        
    $pdf->Output();
    }
    ?>
    In questa maniera, funziona tutto, ma nel corpo mi va fuori dalla tabella e le apgine successive sono tutte di una riga soltanto... fino all'ultima che include il footer...

  2. #2
    ddt_pdf.php :

    Codice PHP:
    <?php
    session_start
    ();
    require(
    '../fpdf/fpdf.php');
    require(
    'ddt_pdf.inc.php');

    define('EURO'chr(128) );
    define('EURO_VAL'6.55957 );

    define('X_VAT_COL_FIRST'10 );
    define('X_VAT_COL_1'    20 );
    define('X_VAT_COL_2'    50 );
    define('X_VAT_COL_3'    65 );
    define('X_VAT_COL_4'    105 );
    //define('X_VAT_COL_5'    , 130);
    define('X_VAT_COL_LAST' 180 );

    class 
    INVOICE extends FPDF
    {
    var 
    $colonnes;
    var 
    $format;
    var 
    $angle=0;
    var 
    $logo="";
    var 
    $footerMsg="";
    var 
    $formatoInv;

    function 
    SetLogo($path,$pfInv=0)
    {
      global 
    $logo,$formatoInv;
      
    $logo=$path;
      
    $formatoInv=$pfInv;
    }


    function 
    SetFooterMsg($msg)
    {
      global 
    $footerMsg;
      
    $footerMsg=$msg;
    }
    function 
    RoundedRect($x$y$w$h$r$style '')
    {
        
    $k $this->k;
        
    $hp $this->h;
        if(
    $style=='F')
            
    $op='f';
        elseif(
    $style=='FD' or $style=='DF')
            
    $op='B';
        else
            
    $op='S';
        
    $MyArc 4/* (sqrt(2) - 1);
        
    $this->_out(sprintf('%.2f %.2f m',($x+$r)*$k,($hp-$y)*$k ));
        
    $xc $x+$w-$r ;
        
    $yc $y+$r;
        
    $this->_out(sprintf('%.2f %.2f l'$xc*$k,($hp-$y)*$k ));

        
    $this->_Arc($xc $r*$MyArc$yc $r$xc $r$yc $r*$MyArc$xc $r$yc);
        
    $xc $x+$w-$r ;
        
    $yc $y+$h-$r;
        
    $this->_out(sprintf('%.2f %.2f l',($x+$w)*$k,($hp-$yc)*$k));
        
    $this->_Arc($xc $r$yc $r*$MyArc$xc $r*$MyArc$yc $r$xc$yc $r);
        
    $xc $x+$r ;
        
    $yc $y+$h-$r;
        
    $this->_out(sprintf('%.2f %.2f l',$xc*$k,($hp-($y+$h))*$k));
        
    $this->_Arc($xc $r*$MyArc$yc $r$xc $r$yc $r*$MyArc$xc $r$yc);
        
    $xc $x+$r ;
        
    $yc $y+$r;
        
    $this->_out(sprintf('%.2f %.2f l',($x)*$k,($hp-$yc)*$k ));
        
    $this->_Arc($xc $r$yc $r*$MyArc$xc $r*$MyArc$yc $r$xc$yc $r);
        
    $this->_out($op);
    }
    function 
    _Arc($x1$y1$x2$y2$x3$y3)
    {
        
    $h $this->h;
        
    $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c '$x1*$this->k, ($h-$y1)*$this->k,
                            
    $x2*$this->k, ($h-$y2)*$this->k$x3*$this->k, ($h-$y3)*$this->k));
    }
    function 
    Rotate($angle,$x=-1,$y=-1)
    {
        if(
    $x==-1)
            
    $x=$this->x;
        if(
    $y==-1)
            
    $y=$this->y;
        if(
    $this->angle!=0)
            
    $this->_out('Q');
        
    $this->angle=$angle;
        if(
    $angle!=0)
        {
            
    $angle*=M_PI/180;
            
    $c=cos($angle);
            
    $s=sin($angle);
            
    $cx=$x*$this->k;
            
    $cy=($this->h-$y)*$this->k;
            
    $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
        }
    }
    function 
    _endpage()
    {
        if(
    $this->angle!=0)
        {
            
    $this->angle=0;
            
    $this->_out('Q');
        }
        
    parent::_endpage();
    }
    function 
    sizeOfText$texte$largeur )
    {
        
    $index    0;
        
    $nb_lines 0;
        
    $loop     TRUE;
        while ( 
    $loop )
        {
            
    $pos strpos($texte"\n");
            if (!
    $pos)
            {
                
    $loop  FALSE;
                
    $ligne $texte;
            }
            else
            {
                
    $ligne  substr$texte$index$pos);
                
    $texte substr$texte$pos+);
            }
            
    $length floor$this->GetStringWidth$ligne ) );
            
    $res floor ;
            
    $nb_lines += $res;
        }
        return 
    $nb_lines;
    }
    function 
    addSociete$nom$adresse )
    {
        global 
    $logo,$formatoInv;
        
    $x1 10;
        
    $y1 6;
        if (
    $formatoInv==&& !empty($logo)) {
            
    $this->Image($logo,$x1,$y1,100,60);
            return;
        }
        if (!empty(
    $logo))  {
          
    $this->Image($logo,$x1,$y1,60,20);
          
    $x1 10;
          
    $y1 29;
        }
        
    $this->SetXY$x1$y1+);
        
    $this->SetFont('Helvetica','IB',10);
        
    $length $this->GetStringWidth$nom );
        
    $this->Cell$length2$nom);
        
    $this->SetXY$x1$y1 );
        
    $this->SetFont('Helvetica','I',10);
        
    $length $this->GetStringWidth$adresse );
        
    $lignes $this->sizeOfText$adresse$length) ;
        
    $this->MultiCell($length4$adresse);
    }
    function 
    fact_dev$libelle$anno$numero )
    {
        
    $r1  $this->80;
        
    $r2  $r1 68;
        
    $y1  6;
        
    $y2  $y1 2;
        
    $mid = ($r1 $r2 ) / 2;
        
    $texte  $libelle" N°  " $anno"/" $numero;
        
    $szfont 12;
        
    $loop   0;
        while ( 
    $loop == )
        {
           
    $this->SetFont"Helvetica""B"$szfont );
           
    $sz $this->GetStringWidth$texte );
           if ( (
    $r1+$sz) > $r2 )
              
    $szfont --;
           else
              
    $loop ++;
        }
        
    $this->SetLineWidth(0.1);
        
    $this->SetFillColor(255);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), $y22.5'DF');
        
    $this->SetXY$r1+1$y1+2);
        
    $this->Cell($r2-$r1 -1,5$texte00"C" );
    }
    function 
    addDevis$numdev )
    {
        
    $string sprintf("DEV%04d",$numdev);
        
    $this->fact_dev"Devis"$string );
    }
    function 
    addFacture$numfact )
    {
        
    $string sprintf("FA%04d",$numfact);
        
    $this->fact_dev"Fattura"$string );
    }
    function 
    addDate$date )
    {
        
    $r1  $this->42;
        
    $r2  $r1 30;
        
    $y1  17;
        
    $y2  $y1+10;
        
    $mid $y1 + (($y2-$y1) / 2);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'D');
        
    $this->Line$r1$mid$r2$mid);
        
    $this->SetXY$r1 + ($r2 $r1)/$y1+);
        
    $this->SetFont"Helvetica""B"10);
        
    $this->Cell(10,4"Data"00"C");
        
    $this->SetXY$r1 + ($r2-$r1)/$y1 );
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(10,5,$date0,0"C");
    }
    function 
    addPageNumber$page )
    {
        
    $r1  $this->80;
        
    $r2  $r1 30;
        
    $y1  17;
        
    $y2  $y1+10;
        
    $mid $y1 + (($y2-$y1) / 2);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'D');
        
    $this->Line$r1$mid$r2$mid);
        
    $this->SetXY$r1 + ($r2 $r1)/$y1+);
        
    $this->SetFont"Helvetica""B"10);
        
    $this->Cell(10,4"Pagina"00"C");
        
    $this->SetXY$r1 + ($r2-$r1)/$y1 );
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(10,5,$page0,0"C");
    }
    function 
    addClient$ref )
    {
        
    $r1  $this->80;
        
    $r2  $r1 68;
        
    $y1  30;
        
    $y2  $y1+8;
        
    $mid $y1 + (($y2-$y1) / 2);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'DF');
        
    $this->SetXY$r1+1$y1+2);
        
    $this->Cell($r2-$r1 -1,5"Destinatario"00"C" );
    }
    function 
    addClientAdresse$adresse )
    {
        
    $r1     $this->80;
        
    $r2     $r1 68;
        
    $y1     40;
        
    $this->SetXY$r1$y1);
        
    $this->MultiCell604$adresse);
    }
    function 
    addClientDest$ref1 )
    {
        
    $r1  $this->80;
        
    $r2  $r1 68;
        
    $y1  58;
        
    $y2  $y1+8;
        
    $mid $y1 + (($y2-$y1) / 2);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'DF');
        
    $this->SetXY$r1+1$y1+2);
        
    $this->Cell($r2-$r1 -1,5"Destinazione"00"C" );
    }
    function 
    addClientAdresseDest$adresse1 )
    {
        
    $r1     $this->80;
        
    $r2     $r1 68;
        
    $y1     68;
        
    $this->SetXY$r1$y1);
        
    $this->MultiCell604$adresse1);
    }
    function 
    addReglement($causale)
    {
        
    $r1  10;
        
    $r2  $r1 60;
        
    $y1  71;
        
    $y2  $y1+10;
        
    $mid $y1 + (($y2-$y1) / 2);
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2+5-$y1), 2.5'D');
        
    $this->Line$r1$mid$r2$mid);
        
    $this->SetXY$r1 + ($r2-$r1)/-$y1+);
        
    $this->SetFont"Helvetica""B"10);
        
    $this->Cell(10,4"Causale Trasporto"00"C");
        
    $this->SetXY$r1 + ($r2-$r1)/-$y1 );
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(10,5,$_SESSION['causale'], 0,0"C");
        
    }
    function 
    addReference($ref,$r1=10,$y1=92,$pf=10)
    {
        
    $this->SetFont"Helvetica"""$pf);
        
    $length $this->GetStringWidth"" $ref );
        
    $this->SetXY$r1 $y1 );
        
    $this->Cell($length,4"" $ref);
    }
    function 
    addCols$tab )
    {
        global 
    $colonnes;
        
    $r1  10;
        
    $r2  $this->- ($r1 2) ;
        
    $y1  90;
        
    $y2  $this->50 $y1;
        
    $this->SetXY$r1$y1 );
        
    $this->Rect$r1$y1$r2$y2"D");
        
    $this->Line$r1$y1+6$r1+$r2$y1+6);
        
    $colX $r1;
        
    $colonnes $tab;
        while ( list( 
    $lib$pos ) = each ($tab) )
        {
            
    $this->SetXY$colX$y1+);
            
    $this->Cell$pos1$lib00"C");
            
    $colX += $pos;
            
    $this->Line$colX$y1$colX$y1+$y2);
        }
    }
    function 
    addLineFormat$tab )
    {
        global 
    $format$colonnes;
        while ( list( 
    $lib$pos ) = each ($colonnes) )
        {
            if ( isset( 
    $tab["$lib"] ) )
                
    $format$lib ] = $tab["$lib"];
        }
    }
    function 
    lineVert$tab )
    {
        global 
    $colonnes;
        
    reset$colonnes );
        
    $maxSize=0;
        while ( list( 
    $lib$pos ) = each ($colonnes) )
        {
            
    $texte $tab$lib ];
            
    $longCell  $pos -2;
            
    $size $this->sizeOfText$texte$longCell );
            if (
    $size $maxSize)
                
    $maxSize $size;
        }
        return 
    $maxSize;
    }

    function 
    addLine$ligne$tab )
    {
        global 
    $colonnes$format;
        
    $ordonnee     10;
        
    $maxSize      $ligne;
        
    reset$colonnes );
        while ( list( 
    $lib$pos ) = each ($colonnes) )
        {
            
    $longCell  $pos -2;
            
    $texte     $tab$lib ];
            
    $length    $this->GetStringWidth$texte );
            
    $tailleTexte $this->sizeOfText$texte$length );
            
    $formText  $format$lib ];
            
    $this->SetXY$ordonnee$ligne-1);
            
    $this->MultiCell$longCell$texte0$formText);
            if ( 
    $maxSize < ($this->GetY()  ) )
                
    $maxSize $this->GetY() ;
            
    $ordonnee += $pos;
        }
        return ( 
    $maxSize $ligne );
    }
    function 
    addRemarque($remarque)
    {
        
    $this->SetFont"Helvetica"""10);
        
    $length $this->GetStringWidth"Remarque : " $remarque );
        
    $r1  10;
        
    $r2  $r1 $length;
        
    $y1  $this->45.5;
        
    $y2  $y1+5;
        
    $this->SetXY$r1 $y1 );
        
    $this->Cell($length,4"Remarque : " $remarque);
    }
    function 
    addCadreTVAs()
    {
        
    $this->SetFont"Helvetica""B"10);
        
    $r1  10;
        
    $r2  $r1 120;
        
    $y1  $this->40;
        
    $y2  $y1+29;
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'D');
        
    $this->Line$r1$y1+5$r2$y1+5);
        
    $this->Line$r1$y1+5$r2$y1+5); // avant BASES HT
        
    $this->Line$r1+27$y1$r1+27$y2-5);  // avant REMISE
        
    $this->Line$r1+52$y1$r1+52$y2-5);  // avant MT TVA
        
    $this->Line$r1$y1+24$r2$y1+24);
        
    $this->SetFont"Helvetica"""10);
        
    $this->SetXY$r1+7$y1);
        
    $this->Cell(10,4BASES_HT);
        
    $this->SetXY$r1+11$y1);
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(2,15,$_SESSION['colli'], 0,0"C");
        
    $this->SetX$r1+32 );
        
    $this->Cell(10,4REMISE);
        
    $this->SetX$r1+39 );
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(1,15,$_SESSION['porto'], 0,0"C");
        
    $this->SetX$r1+72 );
        
    $this->Cell(10,4MT_TVA);
        
    $this->SetX$r1+75 );
        
    $this->SetFont"Helvetica"""10);
        
    $this->Cell(2,15,$_SESSION['vettore'], 0,0"C");
    }
    function 
    addCadreEurosFrancs()
    {
        
    $r1  $this->55;
        
    $r2  $r1 45;
        
    $y1  $this->40;
        
    $y2  $y1+29;
        
    $this->RoundedRect($r1$y1, ($r2 $r1), ($y2-$y1), 2.5'D');
        
    $this->Line$r1$y1+14.5$r2$y1+14.5);
        
    $this->SetFont"Helvetica"""6);
        
    $this->SetFont"Helvetica"""6);
        
    $this->SetFont"Helvetica"""6);
        
    $this->SetXY$r1+13$y1 );
        
    $this->Cell(22,4TOTAUX00"C");
        
    $this->SetXY$r1+13$y1+);
        
    $this->Cell(22,4ACOMPTE00"C");
        
    $this->SetFont"Helvetica"""6);
        
    $this->SetXY$r1+13$y1+14.5 );
        
    $this->Cell(22,4NET00"C");
        
    $this->SetXY$r1+13$y1+18);
        
    $this->Cell(22,1A_PAYER00,'C');
    }
    function 
    addTVAs$params$tab_tva$invoice )
    {
        
    $this->SetFont('Helvetica','',8);
        
    reset ($invoice);
        
    $px = array();
        while ( list( 
    $k$prod) = each$invoice ) )
        {
            
    $tva $prod["tva"];
        
    $ra $prod["rit"];
            @ 
    $px[$tva."_".$ra] += $prod["qte"] * $prod["px_unit"];
        }
        
    $prix     = array();
        
    $totalHT  0;
        
    $totalTTC 0;
        
    $totalTVA 0;
        
    $totalRIT 0;
        
    $y 261;
        
    reset ($px);
        
    natsort$px );
        while ( list(
    $code_tva$articleHT) = each$px ) )
        {
        
    $rit=substr($code_tva,strpos($code_tva,'_')+1,strlen($code_tva));
        
    $code_tva=substr($code_tva,0,strpos($code_tva,'_'));
            
    $tva $tab_tva[$code_tva];
            }
            }
    function 
    temporaire$texte )
    {
        
    $this->SetFont('Helvetica','B',50);
        
    $this->SetTextColor(203,203,203);
        
    $this->Rotate(45,55,190);
        
    $this->Text(55,190,$texte);
        
    $this->Rotate(0);
        
    $this->SetTextColor(0,0,0);
    }
    function 
    Footer() {
        global 
    $footerMsg;
        
    $this->SetY(-15);
        
    $this->SetFont('Helvetica','IB',8);
        
    $this->Write(3,$_SESSION['note']);
    }
        }
    ?>

  3. #3
    up.... aiutatemi pls...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.