Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into d…
Browse files Browse the repository at this point in the history
…evelop-api
  • Loading branch information
Neil Orley committed Nov 2, 2017
2 parents 5febdf7 + 1f33c25 commit be36a79
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 222 deletions.
55 changes: 44 additions & 11 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -1906,6 +1906,40 @@ function getNbOfServicesLines()
return $nb;
}

/**
* Count numbe rof shipments for this order
*
* @return int <0 if KO, Nb of shipment found if OK
*/
function getNbOfShipments()
{
$nb = 0;

$sql = 'SELECT COUNT(DISTINCT ed.fk_expedition) as nb';
$sql.= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed,';
$sql.= ' '.MAIN_DB_PREFIX.'commandedet as cd';
$sql.= ' WHERE';
$sql.= ' ed.fk_origin_line = cd.rowid';
$sql.= ' AND cd.fk_commande =' .$this->id;
//print $sql;

dol_syslog(get_class($this)."::getNbOfShipments", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
if ($obj) $nb = $obj->nb;

$this->db->free($resql);
return $nb;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}

/**
* Load array this->expeditions of lines of shipments with nb of products sent for each order line
* Note: For a dedicated shipment, the fetch_lines can be used to load the qty_asked and qty_shipped. This function is use to return qty_shipped cumulated for the order
Expand All @@ -1932,26 +1966,25 @@ function loadExpeditions($filtre_statut=-1)
//print $sql;

dol_syslog(get_class($this)."::loadExpeditions", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$obj = $this->db->fetch_object($resql);
$this->expeditions[$obj->rowid] = $obj->qty;
$i++;
}
$this->db->free();
$this->db->free($resql);
return $num;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}

}

/**
Expand Down Expand Up @@ -2002,18 +2035,18 @@ function stock_array($filtre_statut=self::STATUS_CANCELED)
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " WHERE ps.fk_product IN (".join(',',$array_of_product).")";
$sql.= ' GROUP BY fk_product ';
$result = $this->db->query($sql);
if ($result)
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$obj = $this->db->fetch_object($resql);
$this->stocks[$obj->fk_product] = $obj->total;
$i++;
}
$this->db->free();
$this->db->free($resql);
}
}
return 0;
Expand Down
2 changes: 2 additions & 0 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -2564,6 +2564,8 @@ function select_produits_fournisseurs_list($socid,$selected='',$htmlname='produc

$this->db->free($result);

$out.=ajax_combobox($htmlname);

if (empty($outputmode)) return $out;
return $outarray;
}
Expand Down
3 changes: 3 additions & 0 deletions htdocs/core/lib/order.lib.php
Expand Up @@ -61,10 +61,13 @@ function commande_prepare_head(Commande $object)
if (($conf->expedition_bon->enabled && $user->rights->expedition->lire)
|| ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire))
{
$nbShipments=$object->getNbOfShipments(); $nbReceiption=0;
$head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id;
if ($conf->expedition_bon->enabled) $text=$langs->trans("Shipments");
if ($nbShipments > 0) $text.= ' <span class="badge">'.$nbShipments.'</span>';
if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/';
if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings");
if ($nbReceiption > 0) $text.= ' <span class="badge">'.$nbReceiption.'</span>';
$head[$h][1] = $text;
$head[$h][2] = 'shipping';
$h++;
Expand Down

0 comments on commit be36a79

Please sign in to comment.