diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index 1a296623994..ce9490cf4e5 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; $langs->load("products"); $langs->load("stocks"); @@ -84,6 +85,56 @@ if (! empty($_POST["button_removefilter_x"])) /* * Actions */ + +if($action == 'order'){ + $linecount = GETPOST('linecount', 'int'); + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $supplierpriceid = GETPOST('fourn'.$i, 'int'); + //get all the parameters needed to create a line + $qty = GETPOST('tobuy'.$i, 'int'); + $desc = GETPOST('desc'.$i, 'alpha'); + $sql = 'Select fk_product, fk_soc, ref_fourn'; + $sql .= ', tva_tx, unitprice'; + $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; + $sql .= ' where rowid = '.$supplierpriceid; + $resql = $db->query($sql); + if($resql) { + //might need some value checks + $obj = $db->fetch_object($resql); + $line = new CommandeFournisseurLigne($db); + $line->qty = $qty; + $line->desc = $desc; + $line->fk_product = $obj->fk_product; + $line->tva_tx = $obj->tva_tx; + $line->subprice = $obj->unitprice; + $line->total_ht = $obj->unitprice * $qty; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $line->total_ttc = $line->total_ht + $line->total_tva; + $line->ref_fourn = $obj->ref_fourn; + $suppliers[$obj->fk_soc]['lines'][] = $line; + } + } + } + //At this point we know how many orders we need and what lines they have + $i = 0; + $orders = array(); + $suppliersid = array_keys($suppliers); + foreach($suppliers as $supplier){ + $order = new CommandeFournisseur($db); + $order->socid = $suppliersid[$i]; + $order->source = 42; + $i++; + foreach($supplier['lines'] as $line){ + $order->lines[] = $line; + } + $id = $order->create($user); + if($id) { + //emulate what fourn/commande/liste.php does + } + } +} // None @@ -207,6 +258,8 @@ if ($resql) print ''; print ''; print ''; + print ''; + print ''; print '
| '; print "\n"; @@ -263,8 +314,6 @@ if ($resql) print ' | '; print ' | '; print ' | '; - //print ' | '; - // print ' | '; print ' | '; print ''; print ''; @@ -297,7 +346,7 @@ if ($resql) $var=!$var; print ' | |||||
| '; + print ' | '; print ' | '; $product_static->ref=$objp->ref; $product_static->id=$objp->rowid; @@ -306,6 +355,7 @@ if ($resql) //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ' | '; print ''.$objp->label.' | '; + print ''; if (! empty($conf->service->enabled) && $type == 1) { @@ -316,8 +366,6 @@ if ($resql) else print $objp->duration; print ''; } - //print ''.$objp->stock_theorique.' | '; - //print ''.$objp->seuil_stock_alerte.' | '; print ''.$objp->desiredstock.' | '; print ''; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; @@ -328,8 +376,9 @@ if ($resql) ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); $stocktobuy = $objp->desiredstock - $stock; print ' | '.$stocktobuy.' | '; + print ''; $form = new Form($db); - print ''.$form->select_product_fourn_price($product_static->id).' | '; + print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' | '; print '  | '; print "