Merge branch '3.6' of git@github.com:Dolibarr/dolibarr.git into 3.6
This commit is contained in:
commit
7d519fdfe6
@ -1680,17 +1680,19 @@ class Product extends CommonObject
|
||||
$sql.= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."commande as c";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."expedition as e";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE e.rowid = ed.fk_expedition";
|
||||
$sql.= " AND c.rowid = cd.fk_commande";
|
||||
$sql.= " AND e.fk_soc = s.rowid";
|
||||
$sql.= " AND e.entity = ".$conf->entity;
|
||||
$sql.= " AND ed.fk_origin_line = cd.rowid";
|
||||
$sql.= " AND cd.fk_product = ".$this->id;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid > 0) $sql.= " AND e.fk_soc = ".$socid;
|
||||
if ($filtrestatut <> '') $sql.= " AND e.fk_statut in (".$filtrestatut.")";
|
||||
if ($filtrestatut <> '') $sql.= " AND c.fk_statut in (".$filtrestatut.")";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ( $result )
|
||||
@ -1709,6 +1711,48 @@ class Product extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge tableau des stats réception fournisseur pour le produit/service
|
||||
*
|
||||
* @param int $socid Id societe pour filtrer sur une societe
|
||||
* @param int $filtrestatut Id statut pour filtrer sur un statut
|
||||
* @return array Tableau des stats
|
||||
*/
|
||||
function load_stats_reception($socid=0,$filtrestatut='')
|
||||
{
|
||||
global $conf,$user;
|
||||
|
||||
$sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
|
||||
$sql.= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE cf.rowid = fd.fk_commande";
|
||||
$sql.= " AND cf.fk_soc = s.rowid";
|
||||
$sql.= " AND cf.entity = ".$conf->entity;
|
||||
$sql.= " AND fd.fk_product = ".$this->id;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid > 0) $sql.= " AND cf.fk_soc = ".$socid;
|
||||
if ($filtrestatut <> '') $sql.= " AND cf.fk_statut in (".$filtrestatut.")";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ( $result )
|
||||
{
|
||||
$obj=$this->db->fetch_object($result);
|
||||
$this->stats_reception['suppliers']=$obj->nb_customers;
|
||||
$this->stats_reception['nb']=$obj->nb;
|
||||
$this->stats_reception['rows']=$obj->nb_rows;
|
||||
$this->stats_reception['qty']=$obj->qty?$obj->qty:0;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge tableau des stats contrat pour le produit/service
|
||||
*
|
||||
@ -2872,6 +2916,7 @@ class Product extends CommonObject
|
||||
}
|
||||
}
|
||||
$this->db->free($result);
|
||||
$this->load_virtual_stock();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -2881,6 +2926,47 @@ class Product extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load information about virtual stock of a product
|
||||
*
|
||||
* @return int < 0 if KO, > 0 if OK
|
||||
*/
|
||||
function load_virtual_stock()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
|
||||
{
|
||||
$stock_commande_client=$stock_commande_fournisseur=0;
|
||||
$stock_sending_client=$stock_reception_fournisseur=0;
|
||||
|
||||
if (! empty($conf->commande->enabled))
|
||||
{
|
||||
$result=$this->load_stats_commande(0,'1,2');
|
||||
if ($result < 0) dol_print_error($db,$this->error);
|
||||
$stock_commande_client=$this->stats_commande['qty'];
|
||||
}
|
||||
if (! empty($conf->expedition->enabled))
|
||||
{
|
||||
$result=$this->load_stats_sending(0,'1,2');
|
||||
if ($result < 0) dol_print_error($db,$this->error);
|
||||
$stock_sending_client=$this->stats_expedition['qty'];
|
||||
}
|
||||
if (! empty($conf->fournisseur->enabled))
|
||||
{
|
||||
$result=$this->load_stats_commande_fournisseur(0,'3');
|
||||
if ($result < 0) dol_print_error($db,$this->error);
|
||||
$stock_commande_fournisseur=$this->stats_commande_fournisseur['qty'];
|
||||
|
||||
$result=$this->load_stats_reception(0,'3');
|
||||
if ($result < 0) dol_print_error($db,$this->error);
|
||||
$stock_reception_fournisseur=$this->stats_reception['qty'];
|
||||
}
|
||||
|
||||
$this->stock_theorique=$this->stock_reel-($stock_commande_client-$stock_sending_client)+($stock_commande_fournisseur-$stock_reception_fournisseur);
|
||||
//echo $this->stock_theorique.' = '.$this->stock_reel.' - ('.$stock_commande_client.' - '.$stock_sending_client.') + ('.$stock_commande_fournisseur.' - '.$stock_reception_fournisseur.')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deplace fichier uploade sous le nom $files dans le repertoire sdir
|
||||
|
||||
@ -118,7 +118,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
|
||||
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,";
|
||||
$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid";
|
||||
$sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."commande as c";
|
||||
@ -148,6 +148,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
@ -170,6 +171,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print "<td>".$objp->code_client."</td>\n";
|
||||
print "<td align=\"center\">";
|
||||
print dol_print_date($db->jdate($objp->date_commande))."</td>";
|
||||
print "<td align=\"center\">".$objp->qty."</td>\n";
|
||||
print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
|
||||
print '<td align="right">'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
@ -111,7 +111,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
|
||||
$sql.= " c.rowid, c.total_ht as total_ht, c.ref,";
|
||||
$sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid";
|
||||
$sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
@ -141,6 +141,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
@ -165,6 +166,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->nom,44).'</a></td>';
|
||||
print "<td>".$objp->code_client."</td>\n";
|
||||
print '<td align="center">'.dol_print_date($db->jdate($objp->date_commande))."</td>";
|
||||
print "<td align=\"center\">".$objp->qty."</td>\n";
|
||||
print '<td align="right">'.price($objp->total_ht)."</td>\n";
|
||||
print '<td align="right">'.$commandestatic->getLibStatut(4).'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
@ -122,7 +122,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
|
||||
$sql.= " f.facnumber, f.total as total_ht,";
|
||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
||||
@ -152,6 +152,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
@ -174,6 +175,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print "<td>".$objp->code_client."</td>\n";
|
||||
print "<td align=\"center\">";
|
||||
print dol_print_date($db->jdate($objp->datef),'day')."</td>";
|
||||
print "<td align=\"center\">".$objp->qty."</td>\n";
|
||||
print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
|
||||
print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
@ -123,7 +123,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
|
||||
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,";
|
||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
|
||||
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
@ -153,6 +153,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
@ -175,6 +176,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print "<td>".$objp->code_client."</td>\n";
|
||||
print "<td align=\"center\">";
|
||||
print dol_print_date($db->jdate($objp->datef))."</td>";
|
||||
print "<td align=\"center\">".$objp->qty."</td>\n";
|
||||
print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
|
||||
print '<td align="right">'.$supplierinvoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
@ -113,7 +113,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
|
||||
$sql = "SELECT DISTINCT s.nom, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
|
||||
$sql.= "p.datep, p.fk_statut as statut";
|
||||
$sql.= "p.datep, p.fk_statut as statut, d.qty";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ",".MAIN_DB_PREFIX."propal as p";
|
||||
@ -141,6 +141,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.rowid","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("DatePropal"),$_SERVER["PHP_SELF"],"p.datep","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"p.total","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
@ -162,6 +163,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->nom,44).'</a></td>';
|
||||
print '<td align="center">';
|
||||
print dol_print_date($db->jdate($objp->datep))."</td>";
|
||||
print "<td align=\"center\">".$objp->qty."</td>\n";
|
||||
print '<td align="right">'.price($objp->amount).'</td>'."\n";
|
||||
print '<td align="right">'.$propalstatic->LibStatut($objp->statut,5).'</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
@ -321,23 +321,6 @@ if ($id > 0 || $ref)
|
||||
// If stock if stock increment is done on real sending
|
||||
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
|
||||
{
|
||||
$stock_commande_client=$stock_commande_fournisseur=0;
|
||||
|
||||
if (! empty($conf->commande->enabled))
|
||||
{
|
||||
$result=$product->load_stats_commande(0,'1,2');
|
||||
if ($result < 0) dol_print_error($db,$product->error);
|
||||
$stock_commande_client=$product->stats_commande['qty'];
|
||||
}
|
||||
if (! empty($conf->fournisseur->enabled))
|
||||
{
|
||||
$result=$product->load_stats_commande_fournisseur(0,'3');
|
||||
if ($result < 0) dol_print_error($db,$product->error);
|
||||
$stock_commande_fournisseur=$product->stats_commande_fournisseur['qty'];
|
||||
}
|
||||
|
||||
$product->stock_theorique=$product->stock_reel-($stock_commande_client+$stock_sending_client)+$stock_commande_fournisseur;
|
||||
|
||||
// Stock theorique
|
||||
print '<tr><td>'.$langs->trans("VirtualStock").'</td>';
|
||||
print "<td>".$product->stock_theorique;
|
||||
@ -360,7 +343,7 @@ if ($id > 0 || $ref)
|
||||
if (! empty($conf->commande->enabled))
|
||||
{
|
||||
if ($found) print '<br>'; else $found=1;
|
||||
print $langs->trans("CustomersOrdersRunning").': '.($stock_commande_client+$stock_sending_client);
|
||||
print $langs->trans("CustomersOrdersRunning").': '.($product->stats_commande['qty']-$product->stats_sendings['qty']);
|
||||
$result=$product->load_stats_commande(0,'0');
|
||||
if ($result < 0) dol_print_error($db,$product->error);
|
||||
print ' ('.$langs->trans("Draft").': '.$product->stats_commande['qty'].')';
|
||||
@ -372,7 +355,7 @@ if ($id > 0 || $ref)
|
||||
if (! empty($conf->fournisseur->enabled))
|
||||
{
|
||||
if ($found) print '<br>'; else $found=1;
|
||||
print $langs->trans("SuppliersOrdersRunning").': '.$stock_commande_fournisseur;
|
||||
print $langs->trans("SuppliersOrdersRunning").': '.($product->stats_commande_fournisseur['qty']-$product->stats_reception['qty']);
|
||||
$result=$product->load_stats_commande_fournisseur(0,'0,1,2');
|
||||
if ($result < 0) dol_print_error($db,$product->error);
|
||||
print ' ('.$langs->trans("DraftOrWaitingApproved").': '.$product->stats_commande_fournisseur['qty'].')';
|
||||
|
||||
@ -252,36 +252,59 @@ $sql.= ', s.fk_product';
|
||||
|
||||
if ($usevirtualstock)
|
||||
{
|
||||
$sqlCommandesCli = "(SELECT SUM(cd.qty) as qty";
|
||||
$sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty";
|
||||
$sqlCommandesCli.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sqlCommandesCli.= ", ".MAIN_DB_PREFIX."commande as c";
|
||||
$sqlCommandesCli.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sqlCommandesCli.= " AND c.entity = ".$conf->entity;
|
||||
$sqlCommandesCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)";
|
||||
$sqlCommandesCli.= " WHERE c.entity = ".$conf->entity;
|
||||
$sqlCommandesCli.= " AND cd.fk_product = p.rowid";
|
||||
$sqlCommandesCli.= " AND c.fk_statut in (1,2))";
|
||||
|
||||
$sqlCommandesFourn = "(SELECT SUM(cd.qty) as qty";
|
||||
$sqlCommandesCli.= " AND c.fk_statut IN (1,2))";
|
||||
|
||||
$sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed.qty) IS NULL", "0", "SUM(ed.qty)")." as qty";
|
||||
$sqlExpeditionsCli.= " FROM ".MAIN_DB_PREFIX."expedition as e";
|
||||
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet as ed ON (ed.fk_expedition = e.rowid)";
|
||||
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd ON (cd.rowid = ed.fk_origin_line)";
|
||||
$sqlExpeditionsCli.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON (c.rowid = cd.fk_commande)";
|
||||
$sqlExpeditionsCli.= " WHERE e.entity = ".$conf->entity;
|
||||
$sqlExpeditionsCli.= " AND cd.fk_product = p.rowid";
|
||||
$sqlExpeditionsCli.= " AND c.fk_statut IN (1,2))";
|
||||
|
||||
$sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd.qty) IS NULL", "0", "SUM(cd.qty)")." as qty";
|
||||
$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
|
||||
$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
$sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sqlCommandesFourn.= " AND c.entity = ".$conf->entity;
|
||||
$sqlCommandesFourn.= " AND cd.fk_product = p.rowid";
|
||||
$sqlCommandesFourn.= " AND c.fk_statut in (3))";
|
||||
|
||||
$sql.= ' HAVING ((p.desiredstock > 0 AND p.desiredstock > (SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn).'))';
|
||||
|
||||
$sql.= ' OR (p.seuil_stock_alerte > 0 AND p.seuil_stock_alerte > (SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn).'))';
|
||||
$sql.= " )";
|
||||
$sqlCommandesFourn.= " AND c.fk_statut IN (3,4))";
|
||||
|
||||
$sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty";
|
||||
$sqlReceptionFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
|
||||
$sqlReceptionFourn.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)";
|
||||
$sqlReceptionFourn.= " WHERE cf.entity = ".$conf->entity;
|
||||
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
|
||||
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
|
||||
|
||||
$sql.= ' HAVING ((('.$db->ifsql("p.desiredstock IS NULL", "0", "p.desiredstock").' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
|
||||
$sql.= ' OR (p.seuil_stock_alerte >= 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
|
||||
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql.= ' AND (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
|
||||
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
|
||||
$alertchecked = 'checked="checked"';
|
||||
}
|
||||
} else {
|
||||
$sql.= ' HAVING ((p.desiredstock > 0 AND (p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))) OR (p.seuil_stock_alerte > 0 AND (seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
|
||||
}
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql .= ' AND SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') < p.seuil_stock_alerte AND p.seuil_stock_alerte is not NULL';
|
||||
$alertchecked = 'checked="checked"';
|
||||
$sql.= ' HAVING ((p.desiredstock > 0 AND (p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$sql.= ' OR (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
|
||||
|
||||
if ($salert == 'on') // Option to see when stock is lower than alert
|
||||
{
|
||||
$sql.= ' AND (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
|
||||
$alertchecked = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$sql.= $db->plimit($limit, $offset);
|
||||
|
||||
@ -368,6 +391,7 @@ print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">'
|
||||
'<input type="hidden" name="type" value="' . $type . '">'.
|
||||
'<input type="hidden" name="linecount" value="' . $num . '">'.
|
||||
'<input type="hidden" name="action" value="order">'.
|
||||
'<input type="hidden" name="mode" value="' . $mode . '">'.
|
||||
|
||||
'<table class="liste" width="100%">';
|
||||
|
||||
@ -422,6 +446,9 @@ while ($i < ($limit ? min($num, $limit) : $num))
|
||||
|
||||
if (! empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0)
|
||||
{
|
||||
$prod->fetch($objp->rowid);
|
||||
$prod->load_stock();
|
||||
|
||||
// Multilangs
|
||||
if (! empty($conf->global->MAIN_MULTILANGS))
|
||||
{
|
||||
@ -438,36 +465,21 @@ while ($i < ($limit ? min($num, $limit) : $num))
|
||||
if (!empty($objtp->label)) $objp->label = $objtp->label;
|
||||
}
|
||||
}
|
||||
$form = new Form($db);
|
||||
$var =! $var;
|
||||
$prod->ref = $objp->ref;
|
||||
$prod->id = $objp->rowid;
|
||||
$prod->type = $objp->fk_product_type;
|
||||
|
||||
// Get number already ordered.
|
||||
$ordered = ordered($prod->id);
|
||||
|
||||
// Defined current stock number and warning if required
|
||||
if ($usevirtualstock)
|
||||
{
|
||||
// If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock.
|
||||
$prod->fetch($prod->id);
|
||||
$result=$prod->load_stats_commande(0, '1,2');
|
||||
if ($result < 0) {
|
||||
dol_print_error($db, $prod->error);
|
||||
}
|
||||
$stock_commande_client = $prod->stats_commande['qty'];
|
||||
$result=$prod->load_stats_commande_fournisseur(0, '3');
|
||||
if ($result < 0) {
|
||||
dol_print_error($db,$prod->error);
|
||||
}
|
||||
$stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty'];
|
||||
$stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur;
|
||||
var_dump($stock_commande_fournisseur);
|
||||
$stock = $prod->stock_theorique;
|
||||
}
|
||||
else
|
||||
{
|
||||
$stock = $objp->stock_physique;
|
||||
$stock = $prod->stock_reel;
|
||||
}
|
||||
|
||||
$ordered = $prod->stats_commande_fournisseur['qty']-$prod->stats_reception['qty'];
|
||||
|
||||
$warning='';
|
||||
if ($objp->alertstock && ($stock < $objp->alertstock))
|
||||
{
|
||||
@ -477,6 +489,19 @@ while ($i < ($limit ? min($num, $limit) : $num))
|
||||
//depending on conf, use either physical stock or
|
||||
//virtual stock to compute the stock to buy value
|
||||
$stocktobuy = max(max($objp->desiredstock, $objp->alertstock) - $stock - $ordered, 0);
|
||||
$disabled = '';
|
||||
if($ordered > 0) {
|
||||
$compare = $usevirtualstock ? $stock : $stock + $ordered;
|
||||
if($compare >= $objp->desiredstock) {
|
||||
$picto = img_picto('', './img/yes', '', 1);
|
||||
$disabled = 'disabled="disabled"';
|
||||
}
|
||||
else {
|
||||
$picto = img_picto('', './img/no', '', 1);
|
||||
}
|
||||
} else {
|
||||
$picto = img_picto('', './img/no', '', 1);
|
||||
}
|
||||
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user