* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file preview.php * \ingroup exportzugferd * \brief Preview ZUGFeRD XML values for an invoice */ // Load Dolibarr environment $res = 0; if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } if (!$res && file_exists("../main.inc.php")) { $res = @include "../main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; require_once __DIR__ . '/class/zugferdgenerator.class.php'; // Security check $id = GETPOSTINT('id'); if (!$user->hasRight('exportzugferd', 'export') && !$user->hasRight('facture', 'lire')) { accessforbidden(); } $langs->loadLangs(array('exportzugferd@exportzugferd', 'bills')); // Load invoice $invoice = new Facture($db); $result = $invoice->fetch($id); if ($result <= 0) { setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); header('Location: ' . DOL_URL_ROOT . '/compta/facture/list.php'); exit; } // Security check on third party $socid = $invoice->socid; if ($user->socid > 0 && $socid != $user->socid) { accessforbidden(); } // Fetch related data $invoice->fetch_thirdparty(); if (empty($invoice->lines)) { $invoice->fetch_lines(); } /* * View */ $title = $langs->trans('PreviewZugferdXML') . ' - ' . $invoice->ref; llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-exportzugferd page-preview'); $head = array(); $head[0][0] = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $invoice->id; $head[0][1] = $langs->trans('Invoice'); $head[0][2] = 'card'; $head[1][0] = dol_buildpath('/exportzugferd/preview.php', 1) . '?id=' . $invoice->id; $head[1][1] = $langs->trans('ZugferdPreview'); $head[1][2] = 'zugferd'; print dol_get_fiche_head($head, 'zugferd', $langs->trans('Invoice'), -1, 'bill'); // Invoice info print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans('Ref') . '' . $invoice->getNomUrl(1) . '
' . $langs->trans('Customer') . '' . $invoice->thirdparty->getNomUrl(1) . '
' . $langs->trans('DateInvoice') . '' . dol_print_date($invoice->date, 'day') . '
' . $langs->trans('AmountTTC') . '' . price($invoice->total_ttc) . ' ' . $conf->currency . '
'; print '
'; print dol_get_fiche_end(); // ZUGFeRD XML Preview print '
'; print ''; print ''; print ''; print ''; // Document Info print ''; print ''; print ''; print ''; print ''; print ''; print ''; $typeCode = '380'; // Standard invoice if ($invoice->type == Facture::TYPE_CREDIT_NOTE) { $typeCode = '381'; } elseif ($invoice->type == Facture::TYPE_DEPOSIT) { $typeCode = '386'; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (!empty($invoice->date_lim_reglement)) { print ''; print ''; print ''; print ''; } // Seller Info print ''; print ''; print ''; global $mysoc; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (!empty($mysoc->tva_intra)) { print ''; print ''; print ''; print ''; } // Buyer Info print ''; print ''; print ''; $buyer = $invoice->thirdparty; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (!empty($buyer->tva_intra)) { print ''; print ''; print ''; print ''; } // Leitweg-ID (for XRechnung) if (!empty($buyer->array_options['options_leitweg_id'])) { print ''; print ''; print ''; print ''; } // Payment Info print ''; print ''; print ''; // Bank Account Info if (!empty($invoice->fk_account)) { require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; $bankAccount = new Account($db); if ($bankAccount->fetch($invoice->fk_account) > 0) { if (!empty($bankAccount->iban)) { print ''; print ''; print ''; print ''; } if (!empty($bankAccount->bic)) { print ''; print ''; print ''; print ''; } } } // Line Items print ''; print ''; print ''; $lineNo = 0; foreach ($invoice->lines as $line) { // Skip title/subtotal lines if (!empty($line->special_code) && in_array($line->special_code, array(104777, 104778, 104779))) { continue; } if ($line->qty == 0 && $line->total_ht == 0 && empty($line->fk_product)) { continue; } $lineNo++; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (!empty($line->fk_product)) { $product = new Product($db); $product->fetch($line->fk_product); print ''; print ''; print ''; print ''; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $vatRate = $line->tva_tx; $categoryCode = ($vatRate > 0) ? 'S' : 'Z'; print ''; print ''; print ''; print ''; } // Totals print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans('ZugferdXMLValues') . '
' . $langs->trans('DocumentInfo') . '
' . $langs->trans('InvoiceNumber') . '' . htmlspecialchars($invoice->ref) . '
' . $langs->trans('TypeCode') . '' . $typeCode . ' (' . ($typeCode == '380' ? 'Commercial Invoice' : ($typeCode == '381' ? 'Credit Note' : 'Deposit')) . ')
' . $langs->trans('IssueDate') . '' . dol_print_date($invoice->date, '%Y%m%d') . '
' . $langs->trans('DueDate') . '' . dol_print_date($invoice->date_lim_reglement, '%Y%m%d') . '
' . $langs->trans('Seller') . ' (SellerTradeParty)
' . $langs->trans('Name') . '' . htmlspecialchars($mysoc->name) . '
' . $langs->trans('Address') . '' . htmlspecialchars($mysoc->address) . '
' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '' . htmlspecialchars($mysoc->zip) . ' / ' . htmlspecialchars($mysoc->town) . '
' . $langs->trans('Country') . '' . htmlspecialchars($mysoc->country_code) . '
' . $langs->trans('VATIntra') . '' . htmlspecialchars($mysoc->tva_intra) . '
' . $langs->trans('Customer') . ' (BuyerTradeParty)
' . $langs->trans('Name') . '' . htmlspecialchars($buyer->name) . '
' . $langs->trans('Address') . '' . htmlspecialchars($buyer->address) . '
' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '' . htmlspecialchars($buyer->zip) . ' / ' . htmlspecialchars($buyer->town) . '
' . $langs->trans('Country') . '' . htmlspecialchars($buyer->country_code) . '
' . $langs->trans('VATIntra') . '' . htmlspecialchars($buyer->tva_intra) . '
' . $langs->trans('LeitwegID') . ' (BuyerReference)' . htmlspecialchars($buyer->array_options['options_leitweg_id']) . '
' . $langs->trans('Payment') . '
IBAN' . htmlspecialchars($bankAccount->iban) . '
BIC' . htmlspecialchars($bankAccount->bic) . '
' . $langs->trans('Lines') . ' (IncludedSupplyChainTradeLineItem)
' . $langs->trans('Line') . ' ' . $lineNo . '
  LineID' . $lineNo . '
  SellerAssignedID' . htmlspecialchars($product->ref) . '
  Name' . htmlspecialchars($line->product_label ?: $line->desc) . '
  BilledQuantity' . number_format($line->qty, 4, '.', '') . '
  NetPriceAmount (ChargeAmount)' . number_format($line->subprice, 2, '.', '') . '
  LineTotalAmount' . number_format($line->total_ht, 2, '.', '') . '
  VAT (CategoryCode / Rate)' . $categoryCode . ' / ' . number_format($vatRate, 2, '.', '') . '%
' . $langs->trans('Totals') . ' (SpecifiedTradeSettlementHeaderMonetarySummation)
LineTotalAmount' . number_format($invoice->total_ht, 2, '.', '') . '
TaxBasisTotalAmount' . number_format($invoice->total_ht, 2, '.', '') . '
TaxTotalAmount' . number_format($invoice->total_tva, 2, '.', '') . ' (currencyID="' . $conf->currency . '")
GrandTotalAmount' . number_format($invoice->total_ttc, 2, '.', '') . '
DuePayableAmount' . number_format($invoice->total_ttc - $invoice->getSommePaiement(), 2, '.', '') . '
'; print '
'; // Check if XML exists and show it $dir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($invoice->ref); $zugferdFile = $dir . '/factur-x.xml'; $xrechnungFile = $dir . '/xrechnung-' . $invoice->ref . '.xml'; $xmlFile = null; if (file_exists($zugferdFile)) { $xmlFile = $zugferdFile; } elseif (file_exists($xrechnungFile)) { $xmlFile = $xrechnungFile; } if ($xmlFile) { print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans('GeneratedXML') . ' (' . basename($xmlFile) . ')
'; print '
';
	print htmlspecialchars(file_get_contents($xmlFile));
	print '
'; print '
'; print '
'; } // Actions print '
'; print ''; print ''; print $langs->trans('RegenerateZugferdXML'); print ''; print ''; print ''; print $langs->trans('DownloadZugferdXML'); print ''; print ''; print ''; print $langs->trans('BackToInvoice'); print ''; print '
'; llxFooter(); $db->close();