* * 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. */ /** * \file idsconnect/cart_review.php * \ingroup idsconnect * \brief Empfangenen Warenkorb prüfen und als Lieferantenbestellung übernehmen */ // Dolibarr laden $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.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; dol_include_once('/idsconnect/class/idslog.class.php'); dol_include_once('/idsconnect/class/idssupplier.class.php'); dol_include_once('/idsconnect/class/idsconnect.class.php'); dol_include_once('/idsconnect/lib/idsconnect.lib.php'); /** * @var Conf $conf * @var DoliDB $db * @var Translate $langs * @var User $user */ $langs->loadLangs(array("idsconnect@idsconnect", "orders", "bills")); if (!$user->hasRight('idsconnect', 'use')) { accessforbidden(); } $log_id = GETPOSTINT('log_id'); $action = GETPOST('action', 'aZ09'); // Log laden $log = new IdsLog($db); if ($log_id > 0) { $log->fetch($log_id); } // Großhändler laden $supplier = new IdsSupplier($db); if ($log->fk_supplier > 0) { $supplier->fetch($log->fk_supplier); } // Artikel aus dem Log parsen $items = array(); if (!empty($log->response_data)) { $response = json_decode($log->response_data, true); if (!empty($response['items'])) { $items = $response['items']; } } // Falls keine Artikel im Response, aus dem XML parsen if (empty($items) && !empty($log->cart_xml)) { $idsconnect = new IdsConnect($db); $items = $idsconnect->parseCartXml($log->cart_xml); if ($items === false) { $items = array(); } } /* * Actions */ // Lieferantenbestellung erstellen if ($action == 'create_order' && $user->hasRight('fournisseur', 'commande', 'creer')) { if (!verifCond(GETPOST('token', 'alpha') == newToken())) { accessforbidden('Bad CSRF token'); } if ($supplier->fk_soc > 0 && !empty($items)) { $order = new CommandeFournisseur($db); $order->socid = $supplier->fk_soc; $order->note_private = 'Erstellt via IDS Connect aus Warenkorb vom '.dol_print_date($log->date_creation, 'dayhour').' ('.$supplier->label.')'; $db->begin(); $order_id = $order->create($user); if ($order_id > 0) { $line_errors = 0; foreach ($items as $item) { $vat_rate = !empty($item['mwst_satz']) ? $item['mwst_satz'] : 19; $result = $order->addline( $item['bezeichnung'], // desc $item['einzelpreis'], // pu_ht (Stückpreis, schon durch PE geteilt) $item['menge'], // qty $vat_rate, // txtva 0, // txlocaltax1 0, // txlocaltax2 0, // fk_product 0, // fk_prod_fourn_price $item['artikelnr'], // ref_supplier 0, // remise_percent 'HT' // price_base_type ); if ($result < 0) { $line_errors++; } } if ($line_errors == 0) { $db->commit(); // Log aktualisieren $log->updateStatus('success', $log->response_data); $log->updateCart($log->cart_xml, $order_id); setEventMessages($langs->trans("IdsconnectCartImported"), null, 'mesgs'); header('Location: '.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$order_id); exit; } else { $db->rollback(); setEventMessages('Fehler beim Erstellen der Bestellpositionen', null, 'errors'); } } else { $db->rollback(); setEventMessages('Fehler beim Erstellen der Bestellung: '.$order->error, null, 'errors'); } } else { if ($supplier->fk_soc <= 0) { setEventMessages('Großhändler hat keinen verknüpften Dolibarr-Lieferanten. Bitte zuerst in der Großhändler-Konfiguration zuweisen.', null, 'errors'); } } } /* * View */ $form = new Form($db); llxHeader('', $langs->trans("IdsconnectCartReview"), '', '', 0, 0, '', '', '', 'mod-idsconnect page-cart_review'); print load_fiche_titre($langs->trans("IdsconnectCartReviewTitle"), '', 'fa-shopping-cart'); idsconnectShowTestModeBanner(); if (empty($items)) { print '
'.$langs->trans("IdsconnectCartEmpty").'
'; print '
'.$langs->trans("Back").''; llxFooter(); $db->close(); exit; } // Info-Banner print '
'; print ''.$langs->trans("IdsconnectCartReviewInfo").'
'; print 'Großhändler: '.htmlspecialchars($supplier->label ?: '-').''; print ' | Empfangen: '.dol_print_date($log->date_creation, 'dayhour'); print ' | Artikel: '.count($items).''; print '
'; // Artikel-Tabelle print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $total = 0; foreach ($items as $item) { $line_total = $item['gesamtpreis'] ?: ($item['menge'] * $item['einzelpreis']); $total += $line_total; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } // Summe print ''; print ''; print ''; print ''; print '
'.$langs->trans("IdsconnectCartArticleNr").''.$langs->trans("IdsconnectCartDescription").''.$langs->trans("IdsconnectCartManufacturer").''.$langs->trans("IdsconnectCartQty").''.$langs->trans("IdsconnectCartUnit").''.$langs->trans("IdsconnectCartUnitPrice").''.$langs->trans("IdsconnectCartTotalPrice").'
'.htmlspecialchars($item['artikelnr']).''.htmlspecialchars($item['bezeichnung']).''.htmlspecialchars($item['hersteller'] ?: '-').''.($item['menge']).''.htmlspecialchars($item['einheit']).''.price($item['einzelpreis']); // Preiseinheit-Info anzeigen wenn vorhanden (z.B. "Preis/100") if (!empty($item['preiseinheit']) && $item['preiseinheit'] > 1) { print '
'.price($item['raw_netprice']).' / '.$item['preiseinheit'].' Stk'; } print '
'.price($line_total).'
'.$langs->trans("Total").''.price($total).'
'; // Aktionsbuttons print '
'; if ($user->hasRight('fournisseur', 'commande', 'creer') && $supplier->fk_soc > 0) { print ''.$langs->trans("IdsconnectCartCreateOrder").''; } elseif ($supplier->fk_soc <= 0) { print ''.$langs->trans("IdsconnectCartCreateOrder").''; } print ''.$langs->trans("Back").''; print '
'; // XML-Details (aufklappbar) if (!empty($log->cart_xml)) { print '
'; print '
'; print 'XML-Rohdaten anzeigen'; print '
'; print htmlspecialchars($log->cart_xml); print '
'; print '
'; } llxFooter(); $db->close();