From 08ad75940e504c75863d1ff87f975193738844bd Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Thu, 9 Sep 2010 08:33:30 +0000 Subject: [PATCH] Add an example for hook integration in pdf --- .../propale/pdf_propale_azur.modules.php | 24 ++---- htdocs/lib/pdf.lib.php | 85 +++++++++++++++++++ 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php index 91a5bb867b2..5aba1f71281 100644 --- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php +++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php @@ -258,38 +258,32 @@ class pdf_propale_azur extends ModelePDFPropales 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, $vat_rate, 0, 'R'); } // Prix unitaire HT avant remise + $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs); $pdf->SetXY ($this->posxup, $curY); - $pdf->MultiCell($this->posxqty-$this->posxup-1, 4, price($object->lines[$i]->subprice), 0, 'R', 0); + $pdf->MultiCell($this->posxqty-$this->posxup-1, 4, $up_excl_tax, 0, 'R', 0); // Quantity + $qty = pdf_getlineqty($object, $i, $outputlangs); $pdf->SetXY ($this->posxqty, $curY); - if ($object->lines[$i]->special_code != 3) $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 4, $object->lines[$i]->qty, 0, 'R'); + $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 4, $qty, 0, 'R'); // Remise sur ligne $pdf->SetXY ($this->posxdiscount, $curY); - if ($object->lines[$i]->remise_percent && $object->lines[$i]->special_code != 3) + if ($object->lines[$i]->remise_percent) { - $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs), 0, 'R'); + $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs); + $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, $remise_percent, 0, 'R'); } // Total HT ligne + $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs); $pdf->SetXY ($this->postotalht, $curY); - if ($object->lines[$i]->special_code == 3) - { - // Ligne produit en option - $pdf->MultiCell(26, 4, $outputlangs->transnoentities("Option"), 0, 'R', 0); - } - else - { - $total = price($object->lines[$i]->total_ht); - $pdf->MultiCell(26, 4, $total, 0, 'R', 0); - } + $pdf->MultiCell(26, 4, $total_excl_tax, 0, 'R', 0); // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva $tvaligne=$object->lines[$i]->total_tva; diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php index dcc59562132..83100a00314 100644 --- a/htdocs/lib/pdf.lib.php +++ b/htdocs/lib/pdf.lib.php @@ -520,4 +520,89 @@ function pdf_getlinevatrate($object,$i,$outputlangs) } } +/** + * Return line unit price excluding tax + * @param object Object + * @param $i Current line number + * @param outputlang Object lang for output + */ +function pdf_getlineupexcltax($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 price($object->lines[$i]->subprice); + } +} + +/** + * Return line quantity + * @param object Object + * @param $i Current line number + * @param outputlang Object lang for output + */ +function pdf_getlineqty($object,$i,$outputlangs) +{ + if ($object->lines[$i]->special_code != 3) + { + if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) + { + // TODO add hook function + } + else + { + return $object->lines[$i]->qty; + } + } +} + +/** + * Return line remise percent + * @param object Object + * @param $i Current line number + * @param outputlang Object lang for output + */ +function pdf_getlineremisepercent($object,$i,$outputlangs) +{ + if ($object->lines[$i]->special_code != 3) + { + if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) + { + // TODO add hook function + } + else + { + return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs); + } + } +} + +/** + * Return line total excluding tax + * @param object Object + * @param $i Current line number + * @param outputlang Object lang for output + */ +function pdf_getlinetotalexcltax($object,$i,$outputlangs) +{ + if ($object->lines[$i]->special_code == 3) + { + return $outputlangs->transnoentities("Option"); + } + else + { + if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) + { + // TODO add hook function + } + else + { + return price($object->lines[$i]->total_ht); + } + } +} + ?> \ No newline at end of file -- GitLab