* * 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. */ // Load Dolibarr environment $res = 0; 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 && 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.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; $langs->loadLangs(array('orders', 'sendings', 'companies', 'suppliers')); // Parameter $origin = GETPOST('origin', 'alpha'); $originid = GETPOST('originid', 'int'); $action = GETPOST('action', 'alpha'); // Berechtigungen prüfen if (empty($user->rights->fournisseur->commande->creer)) { accessforbidden(); } // Kundenauftrag laden $objectsrc = new Commande($db); $objectsrc->fetch($originid); $objectsrc->fetch_lines(); // Kunde laden für Lieferantenreferenz $customer = new Societe($db); $customer->fetch($objectsrc->socid); // Lieferantenreferenz Format: "Kundenname - Auftragsnummer / Kundenzeichen" $supplier_ref_default = $customer->name.' - '.$objectsrc->ref; if (!empty($objectsrc->ref_client)) { $supplier_ref_default .= ' / '.$objectsrc->ref_client; } /* * Actions */ if ($action == 'create_supplier_orders') { $toselect = GETPOST('toselect', 'array'); $supplier_id = GETPOST('supplier_id', 'int'); $ref_supplier = GETPOST('ref_supplier', 'alpha'); if (empty($toselect)) { setEventMessages('Bitte wählen Sie mindestens eine Zeile aus.', null, 'errors'); } elseif (empty($supplier_id)) { setEventMessages('Bitte wählen Sie einen Lieferanten aus.', null, 'errors'); } else { // Lieferantenbestellung erstellen $supplierorder = new CommandeFournisseur($db); $supplierorder->socid = $supplier_id; $supplierorder->ref_supplier = !empty($ref_supplier) ? $ref_supplier : $supplier_ref_default; $supplierorder->cond_reglement_id = 0; $supplierorder->mode_reglement_id = 0; $supplierorder->origin = 'commande'; $supplierorder->origin_id = $originid; $db->begin(); $result = $supplierorder->create($user); if ($result > 0) { // Zeilen hinzufügen $errors = 0; foreach ($toselect as $lineid) { // Zeile aus Kundenauftrag finden $srcline = null; foreach ($objectsrc->lines as $line) { if ($line->id == $lineid) { $srcline = $line; break; } } if ($srcline && !empty($srcline->fk_product)) { // Günstigsten Lieferantenpreis für diesen Lieferanten finden $sql = "SELECT pfp.rowid, pfp.ref_fourn, pfp.price, pfp.quantity as min_qty FROM ".MAIN_DB_PREFIX."product_fournisseur_price pfp WHERE pfp.fk_product = ".(int)$srcline->fk_product." AND pfp.fk_soc = ".(int)$supplier_id." ORDER BY pfp.price ASC LIMIT 1"; $resql = $db->query($sql); $fournprice = 0; $fournref = ''; $fournpricerowid = 0; if ($resql && $db->num_rows($resql) > 0) { $objprice = $db->fetch_object($resql); $fournprice = $objprice->price; $fournref = $objprice->ref_fourn; $fournpricerowid = $objprice->rowid; } // Zeile zur Lieferantenbestellung hinzufügen $result_line = $supplierorder->addline( $srcline->desc, // Description $fournprice, // Unit price $srcline->qty, // Quantity $srcline->tva_tx, // VAT rate $srcline->localtax1_tx, // Local tax 1 $srcline->localtax2_tx, // Local tax 2 $srcline->fk_product, // Product ID $fournpricerowid, // Supplier price ID $fournref, // Supplier ref $srcline->remise_percent, // Discount 'HT', // Price base type 0, // pu_ht_devise 0, // type 0, // info_bits false, // notrigger null, // date_start null, // date_end 0, // array_options '', // fk_unit 0, // origin 0, // origin_id 1 // rang ); if ($result_line < 0) { $errors++; } } } if ($errors == 0) { $db->commit(); setEventMessages('Lieferantenbestellung '.$supplierorder->ref.' wurde erstellt.', null, 'mesgs'); header('Location: '.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$supplierorder->id); exit; } else { $db->rollback(); setEventMessages('Fehler beim Hinzufügen der Zeilen.', null, 'errors'); } } else { $db->rollback(); setEventMessages('Fehler beim Erstellen der Lieferantenbestellung: '.$supplierorder->error, null, 'errors'); } } } /* * View */ $title = 'Lieferantenbestellung aus Kundenauftrag erstellen'; llxHeader('', $title); print load_fiche_titre($title, '', 'order'); // Formular für Auswahl print '
'; print ''; print ''; print ''; print ''; // Zwei Boxen nebeneinander print '
'; // Linke Box: Kundenauftrag-Info print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
Kundenauftrag
'.$langs->trans("Ref").''.$objectsrc->getNomUrl(1).'
'.$langs->trans("Customer").''.$customer->getNomUrl(1).'
'.$langs->trans("RefCustomer").''.dol_escape_htmltag($objectsrc->ref_client).'
'.$langs->trans("Status").''.$objectsrc->getLibStatut(4).'
'; print '
'; // Rechte Box: Lieferant und Referenz print '
'; print '
'; print ''; print ''; // Alle Lieferanten mit Shop-URL abrufen, die Produkte aus diesem Auftrag liefern können $sql = "SELECT DISTINCT s.rowid, s.nom FROM ".MAIN_DB_PREFIX."societe s INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price pfp ON pfp.fk_soc = s.rowid WHERE pfp.fk_product IN ( SELECT cd.fk_product FROM ".MAIN_DB_PREFIX."commandedet cd WHERE cd.fk_commande = ".(int)$originid." AND cd.fk_product > 0 ) AND s.fournisseur = 1 ORDER BY s.nom ASC"; $resql = $db->query($sql); $suppliers = array(); if ($resql) { while ($obj = $db->fetch_object($resql)) { $suppliers[$obj->rowid] = $obj->nom; } } print ''; print ''; print ''; print ''; print '
Neue Lieferantenbestellung
Lieferant
Lieferanten-Referenz'; print '
'; print '
'; // Ende fichehalfright print '
'; // Ende fichecenter print '
'; print '
'; // Zeilen-Auswahl mit Checkboxen print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Produkte aus Kundenauftrag auflisten foreach ($objectsrc->lines as $line) { // Nur Produkte, keine Dienstleistungen if (empty($line->fk_product) || $line->product_type != 0) { continue; } // Produkt laden $product = new Product($db); $product->fetch($line->fk_product); // Lagerbestand $qtyStock = $product->stock_reel; // Stock-Badge Farbe $stockClass = 'badge-success'; if ($qtyStock <= 0) { $stockClass = 'badge-danger'; } elseif ($product->seuil_stock_alerte > 0 && $qtyStock < $product->seuil_stock_alerte) { $stockClass = 'badge-warning'; } elseif ($product->desiredstock > 0 && $qtyStock < $product->desiredstock) { $stockClass = 'badge-secondary'; } // Lieferanten für dieses Produkt $sql_suppliers = "SELECT pfp.fk_soc, pfp.price, pfp.ref_fourn, s.nom FROM ".MAIN_DB_PREFIX."product_fournisseur_price pfp INNER JOIN ".MAIN_DB_PREFIX."societe s ON s.rowid = pfp.fk_soc WHERE pfp.fk_product = ".(int)$line->fk_product." ORDER BY pfp.price ASC"; $ressuppliers = $db->query($sql_suppliers); $supplierList = array(); if ($ressuppliers) { while ($objsup = $db->fetch_object($ressuppliers)) { $supplierList[] = dol_escape_htmltag($objsup->nom).' ('.number_format($objsup->price, 2, ',', '.').' EUR)'; } } print ''; // Checkbox print ''; // Produkt print ''; // Menge print ''; // Lagerbestand print ''; // Lieferanten print ''; print ''; } print '
ProduktMengeLagerbestandLieferanten
'; print ''; print ''; print $product->getNomUrl(1); print ' - '.dol_escape_htmltag($product->label); print ''.(int)$line->qty.''; print ''.(int)$qtyStock.''; print ''; if (!empty($supplierList)) { print implode('
', $supplierList); } else { print 'Keine Lieferanten'; } print '
'; print '
'; // Buttons print '
'; print ''; print '   '; print 'Abbrechen'; print '
'; print '
'; // JavaScript für "Alle auswählen" print ''; // Badge-Styles print ''; llxFooter(); $db->close();