Skip to content

Commit

Permalink
display unit price in pdf output
Browse files Browse the repository at this point in the history
  • Loading branch information
ole1986 committed Mar 26, 2018
1 parent 451ce10 commit a1d9bc3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Binary file modified lang/wc-invoice-pdf-de_DE.mo
Binary file not shown.
7 changes: 5 additions & 2 deletions lang/wc-invoice-pdf-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ msgstr "Bezeichnung"
msgid "Qty"
msgstr "Menge"

msgid "Net"
msgstr "Netto"
msgid "Unit Price"
msgstr "Einzelpreis"

msgid "Amount"
msgstr "Gesamt"

msgid "Tax"
msgstr "MwSt."
Expand Down
27 changes: 20 additions & 7 deletions model/invoice-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class InvoicePdf {
*/
public function BuildInvoice($invoice, $isOffer = false, $stream = false){
setlocale(LC_ALL, get_locale());

$order = $invoice->Order();

$formatStyle = \NumberFormatter::DECIMAL;
$formatter = new \NumberFormatter(get_locale(), $formatStyle);
$formatter->setPattern("#0.00 " . $order->get_currency());

$items = $order->get_items();

// if its first invoice, use shipping item as one-time fee
Expand Down Expand Up @@ -99,15 +104,16 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false){
$text->SetFont('Helvetica', 15);
$text->AddText("$headlineText");

$table = $pdf->NewTable(array('uy'=>480, 'addlx' => 20, 'addux' => -20,'ly' => 120), 4, null, $ls, Cpdf_Table::DRAWLINE_HEADERROW);
$table = $pdf->NewTable(array('uy'=>480, 'addlx' => 20, 'addux' => -20,'ly' => 120), 5, null, $ls, Cpdf_Table::DRAWLINE_HEADERROW);

$table->SetColumnWidths(30,240);
$table->Fit = true;

$table->AddCell("<strong>". __('No#', 'wc-invoice-pdf') ."</strong>");
$table->AddCell("<strong>". __('Description', 'wc-invoice-pdf') ."</strong>");
$table->AddCell("<strong>". __('Qty', 'wc-invoice-pdf') ."</strong>", 'right');
$table->AddCell("<strong>". __('Net', 'wc-invoice-pdf') ."</strong>", 'right');
$table->AddCell("<strong>". __('Unit Price', 'wc-invoice-pdf') ."</strong>", 'right');
$table->AddCell("<strong>". __('Amount', 'wc-invoice-pdf') ."</strong>", 'right');

$i = 1;
$summary = 0;
Expand Down Expand Up @@ -149,20 +155,23 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false){
}

$total = round($v['total'], 2);
$unitprice = $total / intval($v['qty']);
$tax = round($v['total_tax'], 2);

$table->AddCell("$i", null, [], ['top' => 5]);
$table->AddCell($product_name, null, [], ['top' => 5]);
$table->AddCell($qtyStr, 'right', [], ['top' => 5]);
$table->AddCell(number_format($total, 2, ',',' ') . ' ' . $order->get_currency(), 'right', [], ['top' => 5]);
$table->AddCell($formatter->format($unitprice), 'right', [], ['top' => 5]);
$table->AddCell($formatter->format($total), 'right', [], ['top' => 5]);

// display discount
if(isset($v['subtotal']) && ($subtotal = round($v['subtotal'], 2)) > $total)
{
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell(" - " . __("Discount", 'wc-invoice-pdf'), null, [], ['top' => 5]);
$table->AddCell("", 'right', [], ['top' => 5]);
$table->AddCell(number_format($total - $subtotal, 2, ',',' ') . ' ' . $order->get_currency(), 'right', [], ['top' => 5]);
$table->AddCell("", 'right', [], ['top' => 5]);
$table->AddCell($formatter->format($total - $subtotal), 'right', [], ['top' => 5]);
}

$summary += $total;
Expand All @@ -176,26 +185,30 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false){
$table->AddCell($mdcontent);
$table->AddCell('');
$table->AddCell('');
$table->AddCell('');
}
}

$i++;
}

$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("<strong>".__('Summary', 'wc-invoice-pdf')."</strong>", 'right', [], ['top' => 15]);
$table->AddCell("<strong>".number_format($summary, 2,',',' '). ' ' . $order->get_currency()."</strong>", 'right', [], ['top' => 15]);
$table->AddCell("<strong>".$formatter->format($summary)."</strong>", 'right', [], ['top' => 15]);

$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("<strong>+ 19% ".__('Tax', 'wc-invoice-pdf')."</strong>", 'right', [], ['top' => 5]);
$table->AddCell("<strong>".number_format($summaryTax, 2,',',' '). ' ' . $order->get_currency() ."</strong>", 'right', [], ['top' => 5]);
$table->AddCell("<strong>".$formatter->format($summaryTax) ."</strong>", 'right', [], ['top' => 5]);

$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("", null, [], ['top' => 5]);
$table->AddCell("<strong>".__('Total', 'wc-invoice-pdf')."</strong>", 'right', [], ['top' => 15]);
$table->AddCell("<strong>".number_format($summary + $summaryTax, 2,',',' '). ' ' . $order->get_currency()."</strong>", 'right', [], ['top' => 15]);
$table->AddCell("<strong>".$formatter->format($summary + $summaryTax)."</strong>", 'right', [], ['top' => 15]);

$table->EndTable();

Expand Down
4 changes: 2 additions & 2 deletions wc-invoice-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/*
* Plugin Name: WC Recurring Invoice PDF
* Description: WooCommerce invoice pdf plugin with recurring payments (scheduled)
* Version: 1.0.9
* Version: 1.0.10
* Author: ole1986 <[email protected]>
* Author URI: https://github.com/ole1986/wc-invoice-pdf
* Plugin URI: https://github.com/ole1986/wc-invoice-pdf/releases
* Text Domain: wc-invoice-pdf
*
* WC requires at least: 3.0.0
* WC tested up to: 3.3.3
* WC tested up to: 3.3.4
*/

namespace WCInvoicePdf;
Expand Down

0 comments on commit a1d9bc3

Please sign in to comment.