From 47a1ffd58c684057b78ed550afd958798a4b2be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 12:27:09 +0200 Subject: [PATCH] order creation wizard --- htdocs/product/replenish.php | 196 +++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 8 deletions(-) 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 ''; @@ -239,8 +292,6 @@ if ($resql) print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - // TODO Add info of running suppliers/customers orders - //print_liste_field_titre($langs->trans("TheoreticalStock"),"replenish.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); print ''; print "\n"; @@ -263,8 +314,6 @@ if ($resql) print ''; print ''; print ''; - //print ''; - // print ''; print ''; - print ''; + print ''; print ''; print ''; + print ''; if (! empty($conf->service->enabled) && $type == 1) { @@ -316,8 +366,6 @@ if ($resql) else print $objp->duration; print ''; } - //print ''; - //print ''; print ''; print ''; + print ''; $form = new Form($db); - print ''; + print ''; print ''; print "\n"; $i++; @@ -360,6 +409,137 @@ else dol_print_error($db); } +$commandestatic=new CommandeFournisseur($db); + +$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha'); +if($sortorder == '') $sortorder="DESC"; +if($sortfield == '') $sortfield="cf.date_creation"; +$offset = $conf->liste_limit * $page ; +$sql = "SELECT s.rowid as socid, s.nom, cf.date_creation as dc,"; +$sql.= " cf.rowid,cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,"; +$sql.= " u.login"; +$sql.= " FROM (".MAIN_DB_PREFIX."societe as s,"; +$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as cf"; +if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +$sql.= ")"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; +$sql.= " WHERE cf.fk_soc = s.rowid "; +$sql.= " AND cf.entity = ".$conf->entity; +$sql.= " AND cf.source = 42"; +$sql.= " AND cf.fk_statut < 5"; +if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; +if ($sref) +{ + $sql.= " AND cf.ref LIKE '%".$db->escape($sref)."%'"; +} +if ($snom) +{ + $sql.= " AND s.nom LIKE '%".$db->escape($snom)."%'"; +} +if ($suser) +{ + $sql.= " AND u.login LIKE '%".$db->escape($suser)."%'"; +} +if ($sttc) +{ + $sql .= " AND total_ttc = ".price2num($sttc); +} +if ($sall) +{ + $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +} +if ($socid) $sql.= " AND s.rowid = ".$socid; + +if (GETPOST('statut')) +{ + $sql .= " AND fk_statut =".GETPOST('statut'); +} + +$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); +$resql = $db->query($sql); +if ($resql) +{ + + $num = $db->num_rows($resql); + $i = 0; + + + print_barre_liste($title, $page, "replenishment.php", "", $sortfield, $sortorder, '', $num); + print ''; + print '
 
     '; print ''; print ''; @@ -297,7 +346,7 @@ if ($resql) $var=!$var; 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 ''.$objp->label.''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; 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.''.$form->select_product_fourn_price($product_static->id).''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
'; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","","",'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=true; + + $userstatic = new User($db); + + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($resql); + $var=!$var; + + print ""; + + // Ref + print ''."\n"; + + // Company + print ''."\n"; + + // Author + $userstatic->id=$obj->fk_user_author; + $userstatic->login=$obj->login; + print ""; + + // Amount + print '"; + + // Date + print "'; + + // Statut + print ''; + + print "\n"; + $i++; + } + print "
'; + print ''; + print '
'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; + print $obj->nom.'"; + if ($userstatic->id) print $userstatic->getLoginUrl(1); + else print " "; + print "'.price($obj->total_ttc).""; + if ($obj->dc) + { + print dol_print_date($db->jdate($obj->dc),"day"); + } + else + { + print "-"; + } + print ''.$commandestatic->LibStatut($obj->fk_statut, 5).'
\n"; + print "\n"; + + $db->free($resql); +} llxFooter(); $db->close();