Skip to content

Commit

Permalink
Use native selectWarehouses()
Browse files Browse the repository at this point in the history
Fixes #73
  • Loading branch information
rdoursenaud authored and csalvador committed Aug 8, 2012
1 parent ddf7764 commit 4800b28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 93 deletions.
91 changes: 0 additions & 91 deletions htdocs/detailedstock/class/productstockdet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,97 +481,6 @@ public function selectSerialType($selected, $htmlname)
}
}

//had to copy 2 functions from html.formproduct.class.php to modify because they're terrible and I don't want to modify dolibarr core files.

/**
* Load in cache array list of warehouses
* If fk_product is not 0, we do not use cache
*
* @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0.
* @param string $filter Additional filter option
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
*/
public function loadWarehouses($fk_product = 0, $filter = '')
{
global $conf, $langs;

if (empty($fk_product) && count($this->cache_warehouses))
return 0; // Cache already loaded and we do not want a list with information specific to a product

$sql = "SELECT e.rowid, e.label";
if ($fk_product) $sql.= ", ps.reel";
$sql.= " FROM " . MAIN_DB_PREFIX . "entrepot as e";
if ($fk_product) {
$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.fk_entrepot = e.rowid";
$sql.= " AND ps.fk_product = '" . $fk_product . "'";
}
$sql.= " WHERE e.entity = " . $conf->entity;
$sql.= " AND e.statut = 1";
//if a filter is defined, use it
if ( ! empty($filter)) $sql.= " AND " . $filter;
$sql.= " ORDER BY e.label";

dol_syslog(get_class($this) . '::loadWarehouses sql=' . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $this->db->fetch_object($resql);

$this->cache_warehouses[$obj->rowid]['id'] = $obj->rowid;
$this->cache_warehouses[$obj->rowid]['label'] = $obj->label;
if ($fk_product) $this->cache_warehouses[$obj->rowid]['stock'] = $obj->reel;
$i ++;
}
return $num;
}
else {
dol_print_error($this->db);
return -1;
}
}

/**
* Creates an html select element to choose a warehouse
* @global $langs
* @global User $user
* @param int $selected id of the selected option
* @param string $htmlname html name of the select
* @param string $filter optional filter
* @param int $empty
* @param int $disabled
* @param int $fk_product product id
* @return string html select element
*/
public function selectWarehouses($selected = '', $htmlname = 'idwarehouse', $filter = '', $empty = 0, $disabled = 0,
$fk_product = 0)
{
global $langs, $user;

dol_syslog(get_class($this) . "::selectWarehouses $selected, $htmlname, $filter, $empty, $disabled, $fk_product",
LOG_DEBUG);

$this->loadWarehouses($fk_product, $filter);

$out = '<select class="flat"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . ($htmlname . ($disabled ? '_disabled' : '')) . '">';
if ($empty) $out.='<option value="">&nbsp;</option>';
foreach ($this->cache_warehouses as $id => $arraytypes) {
$out.='<option value="' . $id . '"';
// Si selected est text, on compare avec code, sinon avec id
if ($selected == $id) $out.=' selected="selected"';
$out.='>';
$out.=$arraytypes['label'];
if ($fk_product)
$out.=' (' . $langs->trans("Stock") . ': ' . ($arraytypes['stock'] > 0 ? $arraytypes['stock'] : '?') . ')';
$out.='</option>';
}
$out.='</select>';
if ($disabled) $out.='<input type="hidden" name="' . $htmlname . '" value="' . $selected . '">';

return $out;
}

/**
* Gets the date and author of the action
* @param string $action input or output
Expand Down
4 changes: 3 additions & 1 deletion htdocs/detailedstock/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require_once(DOL_DOCUMENT_ROOT . "/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT . "/core/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php");
require_once(DOL_DOCUMENT_ROOT . "/product/class/html.formproduct.class.php");
require_once(DOL_DOCUMENT_ROOT . "/detailedstock/class/productstockdet.class.php");
require_once(DOL_DOCUMENT_ROOT . "/detailedstock/class/serialtype.class.php");
require_once(DOL_DOCUMENT_ROOT . "/core/lib/functions.lib.php");
Expand Down Expand Up @@ -218,6 +219,7 @@
//add mode
else {
$det = new Productstockdet($db);
$formprod = new Formproduct($db);
print '<br><form action="' . $_SERVER['PHP_SELF'] . '?id=' . $product->id . '" method="post"><table class="noborder" width="100%">';
print '<input type="hidden" name="action" value="create"/>';
print '<tr class="liste_titre"><td>' . $langs->trans("SerialNumber") . '</td>';
Expand All @@ -232,7 +234,7 @@
print '<td>' . $det->selectSerialType($newDet->fk_serial_type, 'serialType') . '</td>';
print '<td>' . $form->select_company($newDet->fk_supplier, 'supplier', 's.fournisseur=1', 1) . '</td>';
print '<td><input type="text" name="buyingPrice" value="' . $newDet->price . '"/></td>';
print '<td>' . $det->selectWarehouses($newDet->fk_entrepot, 'warehouse', 'ps.reel > 0', 1, 0, $product->id) . '</td>';
print '<td>' . $formprod->selectWarehouses($newDet->fk_entrepot, 'warehouse', 'ps.reel > 0', 1, 0, $product->id) . '</td>';
print '<td><input class="button" type="submit" name ="valid" value="' . $langs->trans("Valid") . '"/></td><td><input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"/></td>';
print '</tr>';
print '</table></form>';
Expand Down
4 changes: 3 additions & 1 deletion htdocs/detailedstock/fiche.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require_once(DOL_DOCUMENT_ROOT . "/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT . "/core/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php");
require_once(DOL_DOCUMENT_ROOT . "/product/class/html.formproduct.class.php");
require_once(DOL_DOCUMENT_ROOT . "/detailedstock/class/productstockdet.class.php");
require_once(DOL_DOCUMENT_ROOT . "/detailedstock/class/serialtype.class.php");
require_once(DOL_DOCUMENT_ROOT . "/core/lib/functions.lib.php");
Expand Down Expand Up @@ -204,6 +205,7 @@
$det = new Productstockdet($db);
$det->fetch($id);
$form = new Form($db);
$formprod = new Formproduct($db);
dol_fiche_head('', 'info', $langs->trans('DetailedStock'), 1, 'product');
print '<br><form action="' . $_SERVER['PHP_SELF'] . '?id=' . $det->id . '" method="post"><table class="noborder" width="100%">';
print '<input type="hidden" name="action" value="update"/>';
Expand All @@ -219,7 +221,7 @@
print '<td>' . $det->selectSerialType($det->fk_serial_type, 'serialType') . '</td>';
print '<td>' . $form->select_company($det->fk_supplier, 'supplier', 's.fournisseur=1', 1) . '</td>';
print '<td><input type="text" name="buyingPrice" value="' . $det->price . '"/></td>';
print '<td>' . $det->selectWarehouses($det->fk_entrepot, 'warehouse', 'ps.reel > 0', 1, 0, $det->fk_product) . '</td>';
print '<td>' . $formprod->selectWarehouses($det->fk_entrepot, 'warehouse', '', 1, 0, $det->fk_product) . '</td>';
print '<td><input class="button" type="submit" name ="valid" value="' . $langs->trans("Valid") . '"/></td><td><input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"/></td>';
print '</tr>';
print '</table></form>';
Expand Down

0 comments on commit 4800b28

Please sign in to comment.