Add an example for hook integration in pdf

This commit is contained in:
Regis Houssin 2010-09-09 07:26:17 +00:00
parent 91d8da54f1
commit ff17dfd9c0
5 changed files with 37 additions and 22 deletions

View File

@ -164,7 +164,7 @@ if ($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes'
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$propal->id);
exit;
@ -194,7 +194,7 @@ if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' &
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
}
else
{
@ -342,7 +342,7 @@ if ($_POST['action'] == 'add' && $user->rights->propale->creer)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $id, $_REQUEST['model'], $outputlangs);
propale_pdf_create($db, $propal, $_REQUEST['model'], $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
@ -602,7 +602,7 @@ if ($_GET['action'] == 'modif' && $user->rights->propale->creer)
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
}
if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer)
@ -751,7 +751,7 @@ if ($_POST['action'] == "addline" && $user->rights->propale->creer)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
unset($_POST['qty']);
unset($_POST['type']);
@ -823,7 +823,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
}
}
@ -850,7 +850,7 @@ if ($_REQUEST['action'] == 'builddoc' && $user->rights->propale->creer)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result=propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
$result=propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
if ($result <= 0)
{
dol_print_error($db,$result);
@ -920,7 +920,7 @@ if ($_GET['action'] == 'up' && $user->rights->propale->creer)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
exit;
@ -942,7 +942,7 @@ if ($_GET['action'] == 'down' && $user->rights->propale->creer)
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
propale_pdf_create($db, $propal, $propal->modelpdf, $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
exit;
@ -1372,7 +1372,7 @@ if ($id > 0 || ! empty($ref))
print '<table class="noborder" width="100%">';
$result = $propal->getLinesArray();
if (!empty($propal->lines))
{
$propal->print_title_list();

View File

@ -928,7 +928,7 @@ class Propal extends CommonObject
/*
* Lignes propales liees a un produit ou non
*/
$sql = "SELECT d.rowid, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql = "SELECT d.rowid, d.fk_propal, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.marge_tx, d.marque_tx, d.special_code, d.rang, d.product_type,";
$sql.= " p.ref, p.label, p.description as product_desc";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
@ -949,6 +949,7 @@ class Propal extends CommonObject
$line = new PropaleLigne($this->db);
$line->rowid = $objp->rowid;
$line->fk_propal = $objp->fk_propal;
$line->product_type = $objp->product_type;
$line->desc = $objp->description; // Description ligne
$line->qty = $objp->qty;

View File

@ -138,7 +138,7 @@ class ModeleNumRefPropales
* @param outputlangs objet lang a utiliser pour traduction
* @return int 0 si KO, 1 si OK
*/
function propale_pdf_create($db, $id, $modele, $outputlangs)
function propale_pdf_create($db, $object, $modele, $outputlangs)
{
global $langs;
$langs->load("propale");
@ -181,11 +181,11 @@ function propale_pdf_create($db, $id, $modele, $outputlangs)
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output=$outputlangs->charset_output;
if ($obj->write_file($id, $outputlangs) > 0)
if ($obj->write_file($object, $outputlangs) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// on supprime l'image correspondant au preview
propale_delete_preview($db, $id);
propale_delete_preview($db, $object->id);
return 1;
}
else

View File

@ -123,13 +123,6 @@ class pdf_propale_azur extends ModelePDFPropales
if ($conf->propale->dir_output)
{
// Definition de l'objet $object (pour compatibilite ascendante)
if (! is_object($object))
{
$id = $object;
$object = new Propal($this->db);
$ret=$object->fetch($id);
}
$object->fetch_thirdparty();
$deja_regle = "";
@ -264,8 +257,10 @@ class pdf_propale_azur extends ModelePDFPropales
// TVA
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
{
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs);
$pdf->SetXY ($this->posxtva, $curY);
$pdf->MultiCell($this->posxup-$this->posxtva-1, 4, vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits), 0, 'R');
$pdf->MultiCell($this->posxup-$this->posxtva-1, 4, $vat_rate, 0, 'R');
}
// Prix unitaire HT avant remise

View File

@ -501,4 +501,23 @@ function pdf_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli
}
return $libelleproduitservice;
}
/**
* Return line vat rate
* @param object Object
* @param $i Current line number
* @param outputlang Object lang for output
*/
function pdf_getlinevatrate($object,$i,$outputlangs)
{
if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
{
// TODO add hook function
}
else
{
return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits);
}
}
?>