PSR coding style

This commit is contained in:
Raphaël Doursenaud 2013-06-13 17:40:18 +02:00 committed by Cédric Salvador
parent f0243646df
commit 2f5f96dc13
2 changed files with 201 additions and 214 deletions

View File

@ -39,7 +39,8 @@ if ($user->societe_id) {
$result=restrictedArea($user,'produit|service'); $result=restrictedArea($user,'produit|service');
//checks if a product has been ordered //checks if a product has been ordered
function ordered($product_id) { function ordered($product_id)
{
global $db; global $db;
$sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from ';
$sql .= MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd '; $sql .= MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
@ -49,20 +50,20 @@ function ordered($product_id) {
$sql .= ' GROUP BY cfd.fk_product'; $sql .= ' GROUP BY cfd.fk_product';
$resql = $db->query($sql); $resql = $db->query($sql);
if($resql) { if ($resql) {
$exists = $db->num_rows($resql); $exists = $db->num_rows($resql);
if($exists) { if ($exists) {
$obj = $db->fetch_array($resql); $obj = $db->fetch_array($resql);
return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick');
} } else {
else {
return img_picto('', 'stcomm-1'); return img_picto('', 'stcomm-1');
} }
} } else {
else {
$error = $db->lasterror(); $error = $db->lasterror();
dol_print_error($db); dol_print_error($db);
dol_syslog('replenish.php: ' . $error, LOG_ERROR); dol_syslog('replenish.php: ' . $error, LOG_ERROR);
return $langs->trans('error'); return $langs->trans('error');
} }
} }
@ -93,12 +94,12 @@ $offset = $limit * $page ;
*/ */
//orders creation //orders creation
if($action == 'order') { if ($action == 'order') {
$linecount = GETPOST('linecount', 'int'); $linecount = GETPOST('linecount', 'int');
unset($_POST['linecount']); unset($_POST['linecount']);
if($linecount > 0) { if ($linecount > 0) {
$suppliers = array(); $suppliers = array();
for($i = 0; $i < $linecount; $i++) { for ($i = 0; $i < $linecount; $i++) {
if(GETPOST($i, 'alpha') === 'on' if(GETPOST($i, 'alpha') === 'on'
&& GETPOST('fourn' . $i, 'int') > 0) { //one line && GETPOST('fourn' . $i, 'int') > 0) { //one line
$supplierpriceid = GETPOST('fourn'.$i, 'int'); $supplierpriceid = GETPOST('fourn'.$i, 'int');
@ -110,7 +111,7 @@ if($action == 'order') {
$sql .= MAIN_DB_PREFIX . 'product_fournisseur_price'; $sql .= MAIN_DB_PREFIX . 'product_fournisseur_price';
$sql .= ' WHERE rowid = ' . $supplierpriceid; $sql .= ' WHERE rowid = ' . $supplierpriceid;
$resql = $db->query($sql); $resql = $db->query($sql);
if($resql && $db->num_rows($resql) > 0) { if ($resql && $db->num_rows($resql) > 0) {
//might need some value checks //might need some value checks
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$line = new CommandeFournisseurLigne($db); $line = new CommandeFournisseurLigne($db);
@ -125,8 +126,7 @@ if($action == 'order') {
$line->total_ttc = $line->total_ht + $line->total_tva; $line->total_ttc = $line->total_ht + $line->total_tva;
$line->ref_fourn = $obj->ref_fourn; $line->ref_fourn = $obj->ref_fourn;
$suppliers[$obj->fk_soc]['lines'][] = $line; $suppliers[$obj->fk_soc]['lines'][] = $line;
} } else {
else {
$error=$db->lasterror(); $error=$db->lasterror();
dol_print_error($db); dol_print_error($db);
dol_syslog('replenish.php: '.$error, LOG_ERROR); dol_syslog('replenish.php: '.$error, LOG_ERROR);
@ -140,22 +140,22 @@ if($action == 'order') {
$i = 0; $i = 0;
$orders = array(); $orders = array();
$suppliersid = array_keys($suppliers); $suppliersid = array_keys($suppliers);
foreach($suppliers as $supplier) { foreach ($suppliers as $supplier) {
$order = new CommandeFournisseur($db); $order = new CommandeFournisseur($db);
$order->socid = $suppliersid[$i]; $order->socid = $suppliersid[$i];
//trick to know which orders have been generated this way //trick to know which orders have been generated this way
$order->source = 42; $order->source = 42;
foreach($supplier['lines'] as $line) { foreach ($supplier['lines'] as $line) {
$order->lines[] = $line; $order->lines[] = $line;
} }
$id = $order->create($user); $id = $order->create($user);
if($id < 0) { if ($id < 0) {
$fail++; $fail++;
setEventMessage($langs->trans('OrderFail'), 'errors'); setEventMessage($langs->trans('OrderFail'), 'errors');
} }
$i++; $i++;
} }
if(!$fail && $id) { if (!$fail && $id) {
setEventMessage($langs->trans('OrderCreated'), 'mesgs'); setEventMessage($langs->trans('OrderCreated'), 'mesgs');
header('Location: replenishorders.php'); header('Location: replenishorders.php');
exit; exit;
@ -190,8 +190,7 @@ if ($sall) {
if (dol_strlen($type)) { if (dol_strlen($type)) {
if ($type == 1) { if ($type == 1) {
$sql .= ' AND p.fk_product_type = 1'; $sql .= ' AND p.fk_product_type = 1';
} } else {
else {
$sql .= ' AND p.fk_product_type != 1'; $sql .= ' AND p.fk_product_type != 1';
} }
} }
@ -251,8 +250,7 @@ if ($resql) {
'', '',
$num $num
); );
} } else {
else {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id; $filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)?'&amp;type=' . $type:''); $filters .= (isset($type)?'&amp;type=' . $type:'');
@ -321,10 +319,9 @@ if ($resql) {
$sortfield, $sortfield,
$sortorder $sortorder
); );
if($conf->global->USE_VIRTUAL_STOCK) { if ($conf->global->USE_VIRTUAL_STOCK) {
$stocklabel = $langs->trans('VirtualStock'); $stocklabel = $langs->trans('VirtualStock');
} } else {
else {
$stocklabel = $langs->trans('PhysicalStock'); $stocklabel = $langs->trans('PhysicalStock');
} }
print_liste_field_titre($stocklabel, print_liste_field_titre($stocklabel,
@ -395,10 +392,10 @@ if ($resql) {
$var = True; $var = True;
while ($i < min($num, $limit)) { while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
if($conf->global->STOCK_SUPPORTS_SERVICES if ($conf->global->STOCK_SUPPORTS_SERVICES
|| $objp->fk_product_type == 0) { || $objp->fk_product_type == 0) {
// Multilangs // Multilangs
if(! empty($conf->global->MAIN_MULTILANGS)) { if (! empty($conf->global->MAIN_MULTILANGS)) {
$sql = 'SELECT label'; $sql = 'SELECT label';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang';
$sql .= ' WHERE fk_product = ' . $objp->rowid; $sql .= ' WHERE fk_product = ' . $objp->rowid;
@ -406,7 +403,7 @@ if ($resql) {
$sql .= ' LIMIT 1'; $sql .= ' LIMIT 1';
$result = $db->query($sql); $result = $db->query($sql);
if($result) { if ($result) {
$objtp = $db->fetch_object($result); $objtp = $db->fetch_object($result);
if (!empty($objtp->label)) { if (!empty($objtp->label)) {
$objp->label = $objtp->label; $objp->label = $objtp->label;
@ -426,28 +423,25 @@ if ($resql) {
print '<td>' . $objp->label . '</td>'; print '<td>' . $objp->label . '</td>';
print '<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" >'; print '<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" >';
if(!empty($conf->service->enabled) && $type == 1) { if (!empty($conf->service->enabled) && $type == 1) {
print '<td align="center">'; print '<td align="center">';
if(preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
print $regs[1] . ' ' . $langs->trans('DurationYear'); print $regs[1] . ' ' . $langs->trans('DurationYear');
} } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
print $regs[1] . ' ' . $langs->trans('DurationMonth'); print $regs[1] . ' ' . $langs->trans('DurationMonth');
} } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
print $regs[1] . ' ' . $langs->trans('DurationDay'); print $regs[1] . ' ' . $langs->trans('DurationDay');
} } else {
else {
print $objp->duration; print $objp->duration;
} }
print '</td>'; print '</td>';
} }
print '<td align="right">' . $objp->desiredstock . '</td>'; print '<td align="right">' . $objp->desiredstock . '</td>';
print '<td align="right">'; print '<td align="right">';
if(!$objp->stock_physique) { if (!$objp->stock_physique) {
$objp->stock_physique = 0; $objp->stock_physique = 0;
} }
if($conf->global->USE_VIRTUAL_STOCK) { if ($conf->global->USE_VIRTUAL_STOCK) {
//compute virtual stock //compute virtual stock
$prod->fetch($prod->id); $prod->fetch($prod->id);
$result=$prod->load_stats_commande(0, '1,2'); $result=$prod->load_stats_commande(0, '1,2');
@ -461,8 +455,7 @@ if ($resql) {
} }
$stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty'];
$stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur;
} } else {
else {
$stock = $objp->stock_physique; $stock = $objp->stock_physique;
} }
if ($objp->seuil_stock_alerte if ($objp->seuil_stock_alerte
@ -516,8 +509,7 @@ if ($resql) {
0, 0,
'' ''
); );
} } else {
else {
$filters = '&sref=' . $sref . '&snom=' . $snom; $filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&fourn_id=' . $fourn_id; $filters .= '&fourn_id=' . $fourn_id;
$filters .= (isset($type)? '&amp;type=' . $type : ''); $filters .= (isset($type)? '&amp;type=' . $type : '');
@ -537,11 +529,9 @@ if ($resql) {
$db->free($resql); $db->free($resql);
} } else {
else {
dol_print_error($db); dol_print_error($db);
} }
llxFooter(); llxFooter();
$db->close(); $db->close();
?>

View File

@ -64,11 +64,11 @@ $page = GETPOST('page', 'int');
$sortorder = GETPOST('sortorder'); $sortorder = GETPOST('sortorder');
$sortfield = GETPOST('sortfield'); $sortfield = GETPOST('sortfield');
if(!$sortorder) { if (!$sortorder) {
$sortorder = 'DESC'; $sortorder = 'DESC';
} }
if(!$sortfield) { if (!$sortfield) {
$sortfield = 'cf.date_creation'; $sortfield = 'cf.date_creation';
} }
@ -80,7 +80,7 @@ $sql .= ", cf.fk_user_author, u.login";
$sql .= ' FROM (' . MAIN_DB_PREFIX . 'societe as s,'; $sql .= ' FROM (' . MAIN_DB_PREFIX . 'societe as s,';
$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf'; $sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
if(!$user->rights->societe->client->voir && !$socid) { if (!$user->rights->societe->client->voir && !$socid) {
$sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc'; $sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc';
} }
@ -92,37 +92,37 @@ $sql .= ' AND cf.entity = ' . $conf->entity;
$sql .= ' AND cf.source = 42'; $sql .= ' AND cf.source = 42';
$sql .= ' AND cf.fk_statut < 5'; $sql .= ' AND cf.fk_statut < 5';
if(!$user->rights->societe->client->voir && !$socid) { if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id; $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id;
} }
if($sref) { if ($sref) {
$sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"';
} }
if($snom) { if ($snom) {
$sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"';
} }
if($suser) { if ($suser) {
$sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';
} }
if($sttc) { if ($sttc) {
$sql .= ' AND cf.total_ttc = ' . price2num($sttc); $sql .= ' AND cf.total_ttc = ' . price2num($sttc);
} }
if($sdate) { if ($sdate) {
$elts = explode('/', $sdate); $elts = explode('/', $sdate);
$date = date('Y-m-d', $date = date('Y-m-d',
mktime(0, 0, 0, $elts[1], $elts[0], $elts[2]) mktime(0, 0, 0, $elts[1], $elts[0], $elts[2])
); );
$sql .= ' AND cf.date_creation LIKE "' . $date . '%"'; $sql .= ' AND cf.date_creation LIKE "' . $date . '%"';
} }
if($sall) { if ($sall) {
$sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" '; $sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" ';
$sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")'; $sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")';
} }
if($socid) { if ($socid) {
$sql .= ' AND s.rowid = ' . $socid; $sql .= ' AND s.rowid = ' . $socid;
} }
if(GETPOST('statut')) { if (GETPOST('statut')) {
$sql .= ' AND fk_statut = ' . GETPOST('statut'); $sql .= ' AND fk_statut = ' . GETPOST('statut');
} }
@ -130,7 +130,7 @@ $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ';
$sql .= $db->plimit($conf->liste_limit+1, $offset); $sql .= $db->plimit($conf->liste_limit+1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
if($resql) { if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -228,7 +228,7 @@ if($resql) {
$var = true; $var = true;
$userstatic = new User($db); $userstatic = new User($db);
while($i < min($num,$conf->liste_limit)) { while ($i < min($num,$conf->liste_limit)) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$var = !$var; $var = !$var;
@ -252,10 +252,9 @@ if($resql) {
$userstatic->login = $obj->login; $userstatic->login = $obj->login;
print '<td>'; print '<td>';
if($userstatic->id) { if ($userstatic->id) {
print $userstatic->getLoginUrl(1); print $userstatic->getLoginUrl(1);
} } else {
else {
print '&nbsp;'; print '&nbsp;';
} }
@ -268,8 +267,7 @@ if($resql) {
print '<td>'; print '<td>';
if ($obj->dc) { if ($obj->dc) {
print dol_print_date($db->jdate($obj->dc), 'day'); print dol_print_date($db->jdate($obj->dc), 'day');
} } else {
else {
print '-'; print '-';
} }
print '</td>'; print '</td>';
@ -288,4 +286,3 @@ if($resql) {
llxFooter(); llxFooter();
$db->close(); $db->close();
?>