Skip to content

Commit

Permalink
Provide option for B2C #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ole committed Jul 13, 2020
1 parent 6e2a5a2 commit a8939a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Binary file modified lang/wc-invoice-pdf-de_DE.mo
Binary file not shown.
15 changes: 14 additions & 1 deletion lang/wc-invoice-pdf-de_DE.po
Expand Up @@ -222,6 +222,12 @@ msgstr "Gesamt"
msgid "Tax"
msgstr "MwSt."

msgid "includes %s %s"
msgstr "enthält %s %s"

msgid "plus %s %s"
msgstr "zzgl. %s %s"

msgid "Summary"
msgstr "Summe"

Expand Down Expand Up @@ -277,4 +283,11 @@ msgid "Customer choose"
msgstr "Kunde entscheidet"

msgid "Allow the customer to choose between the subscriptions during checkout or fix a value"
msgstr "Erlaube dem Kunden die Auswahl eines Abonnement oder setze den Wert fest"
msgstr "Erlaube dem Kunden die Auswahl eines Abonnement oder setze den Wert fest"

msgid "Enable B2C"
msgstr "Aktiviere B2C"

msgid "Create invoice compatible for Business to Customer (B2C) relationship"
msgstr "Erstelle Business to Customer (B2C) kompatible Rechnungen"

3 changes: 3 additions & 0 deletions menu/invoice-menu.php
Expand Up @@ -193,6 +193,9 @@ public function DisplaySettings()
</h2>
<form method="post" action="">
<div id="wcinvoicepdf-order" class="inside tabs-panel" style="display: none;">
<?php
WCInvoicePdf::addField('wc_pdf_b2c', '<strong>' . __('Enable B2C', 'wc-invoice-pdf') . '</strong><br />' . __('Create invoice compatible for Business to Customer (B2C) relationship', 'wc-invoice-pdf'), 'checkbox');
?>
<p>
<label style="width: 220px; display:inline-block;vertical-align:top;">
<strong><?php _e('Subscription option', 'wc-invoice-pdf') ?></strong><br />
Expand Down
23 changes: 17 additions & 6 deletions model/invoice-pdf.php
Expand Up @@ -149,9 +149,14 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false)
}

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

if (\WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_b2c']) {
$total += $tax;
}

$unitprice = $total / intval($v['qty']);

$mdcontent = '';
if ($v instanceof \WC_Order_Item_Product) {
$meta = $v->get_meta_data();
Expand Down Expand Up @@ -196,13 +201,19 @@ public function BuildInvoice($invoice, $isOffer = false, $stream = false)
foreach ($order->get_tax_totals() as $tax) {
$summaryTax += $tax->amount;
$tax_rate = \WC_Tax::get_rate_percent($tax->rate_id);
$summaryData[] = ['<strong>+ ' . $tax_rate . ' '. $tax->label . '</strong>', '<strong>' . $formatter->format($tax->amount) . '</strong>'];

if (\WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_b2c']) {
$taxStr = __(sprintf("includes %s %s", $tax_rate, $tax->label), 'wc-invice-pdf');
} else {
$taxStr = __(sprintf("plus %s %s", $tax_rate, $tax->label), 'wc-invice-pdf');
}

$summaryData[] = ['<strong>' . $taxStr . '</strong>', '<strong>' . $formatter->format($tax->amount) . '</strong>'];
}

$summaryData[] = [
"<strong>".__('Total', 'wc-invoice-pdf')."</strong>",
"<strong>".$formatter->format($summary + $summaryTax)."</strong>"
];
if (empty(\WCInvoicePdf\WCInvoicePdf::$OPTIONS['wc_pdf_b2c'])) {
$summaryData[] = ["<strong>".__('Total', 'wc-invoice-pdf')."</strong>", "<strong>".$formatter->format($summary + $summaryTax)."</strong>"];
}

$pdf->ezSetDy(-20);

Expand Down

0 comments on commit a8939a0

Please sign in to comment.