From 2f5f96dc13748d99c903440441bb2513094f3967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 13 Jun 2013 17:40:18 +0200 Subject: [PATCH] PSR coding style --- htdocs/product/stock/replenish.php | 266 +++++++++++------------ htdocs/product/stock/replenishorders.php | 149 +++++++------ 2 files changed, 201 insertions(+), 214 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 4404780abae..105fe45c739 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -39,30 +39,31 @@ if ($user->societe_id) { $result=restrictedArea($user,'produit|service'); //checks if a product has been ordered -function ordered($product_id) { +function ordered($product_id) +{ global $db; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; - $sql .= MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd '; - $sql .= 'LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf'; - $sql .= ' ON cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; + $sql .= MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd '; + $sql .= 'LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf'; + $sql .= ' ON cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id; $sql .= ' GROUP BY cfd.fk_product'; - + $resql = $db->query($sql); - if($resql) { + if ($resql) { $exists = $db->num_rows($resql); - if($exists) { + if ($exists) { $obj = $db->fetch_array($resql); + return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); - } - else { + } else { return img_picto('', 'stcomm-1'); } - } - else { + } else { $error = $db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: ' . $error, LOG_ERROR); + return $langs->trans('error'); } } @@ -93,13 +94,13 @@ $offset = $limit * $page ; */ //orders creation -if($action == 'order') { +if ($action == 'order') { $linecount = GETPOST('linecount', 'int'); unset($_POST['linecount']); - if($linecount > 0) { + if ($linecount > 0) { $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on' + for ($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) { //one line $supplierpriceid = GETPOST('fourn'.$i, 'int'); //get all the parameters needed to create a line @@ -110,7 +111,7 @@ if($action == 'order') { $sql .= MAIN_DB_PREFIX . 'product_fournisseur_price'; $sql .= ' WHERE rowid = ' . $supplierpriceid; $resql = $db->query($sql); - if($resql && $db->num_rows($resql) > 0) { + if ($resql && $db->num_rows($resql) > 0) { //might need some value checks $obj = $db->fetch_object($resql); $line = new CommandeFournisseurLigne($db); @@ -125,8 +126,7 @@ if($action == 'order') { $line->total_ttc = $line->total_ht + $line->total_tva; $line->ref_fourn = $obj->ref_fourn; $suppliers[$obj->fk_soc]['lines'][] = $line; - } - else { + } else { $error=$db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: '.$error, LOG_ERROR); @@ -140,22 +140,22 @@ if($action == 'order') { $i = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach($suppliers as $supplier) { + foreach ($suppliers as $supplier) { $order = new CommandeFournisseur($db); $order->socid = $suppliersid[$i]; //trick to know which orders have been generated this way $order->source = 42; - foreach($supplier['lines'] as $line) { + foreach ($supplier['lines'] as $line) { $order->lines[] = $line; } $id = $order->create($user); - if($id < 0) { + if ($id < 0) { $fail++; setEventMessage($langs->trans('OrderFail'), 'errors'); } $i++; } - if(!$fail && $id) { + if (!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); header('Location: replenishorders.php'); exit; @@ -190,8 +190,7 @@ if ($sall) { if (dol_strlen($type)) { if ($type == 1) { $sql .= ' AND p.fk_product_type = 1'; - } - else { + } else { $sql .= ' AND p.fk_product_type != 1'; } } @@ -242,27 +241,26 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste($texte, - $page, - 'replenish.php', - $filters, - $sortfield, + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, $sortorder, '', $num ); - } - else { + } else { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&fourn_id=' . $fourn_id; $filters .= (isset($type)?'&type=' . $type:''); - print_barre_liste($texte, - $page, - 'replenish.php', - $filters, - $sortfield, - $sortorder, - '', + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', $num); } @@ -283,84 +281,83 @@ if ($resql) { // Lignes des titres print ''; print ' '; - print_liste_field_titre($langs->trans('Ref'), - 'replenish.php', - 'p.ref', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Ref'), + 'replenish.php', + 'p.ref', + $param, + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Label'), - 'replenish.php', - 'p.label', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Label'), + 'replenish.php', + 'p.label', + $param, + '', + '', + $sortfield, $sortorder ); if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre($langs->trans('Duration'), - 'replenish.php', - 'p.duration', - $param, - '', - 'align="center"', - $sortfield, + print_liste_field_titre($langs->trans('Duration'), + 'replenish.php', + 'p.duration', + $param, + '', + 'align="center"', + $sortfield, $sortorder ); } - print_liste_field_titre($langs->trans('DesiredStock'), - 'replenish.php', - 'p.desiredstock', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('DesiredStock'), + 'replenish.php', + 'p.desiredstock', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { $stocklabel = $langs->trans('VirtualStock'); - } - else { + } else { $stocklabel = $langs->trans('PhysicalStock'); } - print_liste_field_titre($stocklabel, - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($stocklabel, + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('StockToBuy'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('StockToBuy'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Ordered'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Ordered'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Supplier'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Supplier'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); print ' '; @@ -395,10 +392,10 @@ if ($resql) { $var = True; while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - if($conf->global->STOCK_SUPPORTS_SERVICES + if ($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0) { // Multilangs - if(! empty($conf->global->MAIN_MULTILANGS)) { + if (! empty($conf->global->MAIN_MULTILANGS)) { $sql = 'SELECT label'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; $sql .= ' WHERE fk_product = ' . $objp->rowid; @@ -406,7 +403,7 @@ if ($resql) { $sql .= ' LIMIT 1'; $result = $db->query($sql); - if($result) { + if ($result) { $objtp = $db->fetch_object($result); if (!empty($objtp->label)) { $objp->label = $objtp->label; @@ -426,28 +423,25 @@ if ($resql) { print '' . $objp->label . ''; print ''; - if(!empty($conf->service->enabled) && $type == 1) { + if (!empty($conf->service->enabled) && $type == 1) { print ''; - 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'); - } - else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationMonth'); - } - else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationDay'); - } - else { + } else { print $objp->duration; } print ''; } print '' . $objp->desiredstock . ''; print ''; - if(!$objp->stock_physique) { + if (!$objp->stock_physique) { $objp->stock_physique = 0; } - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { //compute virtual stock $prod->fetch($prod->id); $result=$prod->load_stats_commande(0, '1,2'); @@ -461,11 +455,10 @@ if ($resql) { } $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; - } - else { + } else { $stock = $objp->stock_physique; } - if ($objp->seuil_stock_alerte + if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { $warn = $langs->trans('StockTooLow'); print img_warning($warn) . ' '; @@ -482,8 +475,8 @@ if ($resql) { print ''; $form = new Form($db); print ''; - print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, + print $form->select_product_fourn_price($prod->id, + 'fourn' . $i, 1 ); print ''; @@ -505,31 +498,30 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste('', - $page, - 'replenish.php', - $filters, - $sortfield, - $sortorder, - '', - $num, - 0, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); - } - else { + } else { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&fourn_id=' . $fourn_id; $filters .= (isset($type)? '&type=' . $type : ''); - print_barre_liste('', - $page, - 'replenish.php', - $filters, - $sortfield, - $sortorder, - '', - $num, - 0, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); } @@ -537,11 +529,9 @@ if ($resql) { $db->free($resql); -} -else { +} else { dol_print_error($db); } llxFooter(); $db->close(); -?> diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 1a87736ef9e..d3fd138b01d 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -47,10 +47,10 @@ $head[0][2] = 'replenish'; $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php'; $head[1][1] = $texte; $head[1][2] = 'replenishorders'; -dol_fiche_head($head, - 'replenishorders', - $langs->trans('Replenishment'), - 0, +dol_fiche_head($head, + 'replenishorders', + $langs->trans('Replenishment'), + 0, 'stock'); $commandestatic = new CommandeFournisseur($db); $sref = GETPOST('search_ref'); @@ -64,11 +64,11 @@ $page = GETPOST('page', 'int'); $sortorder = GETPOST('sortorder'); $sortfield = GETPOST('sortfield'); -if(!$sortorder) { +if (!$sortorder) { $sortorder = 'DESC'; } -if(!$sortfield) { +if (!$sortfield) { $sortfield = 'cf.date_creation'; } @@ -80,7 +80,7 @@ $sql .= ", cf.fk_user_author, 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) { +if (!$user->rights->societe->client->voir && !$socid) { $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.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; } -if($sref) { +if ($sref) { $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; } -if($snom) { +if ($snom) { $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; } -if($suser) { +if ($suser) { $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; } -if($sttc) { +if ($sttc) { $sql .= ' AND cf.total_ttc = ' . price2num($sttc); } -if($sdate) { +if ($sdate) { $elts = explode('/', $sdate); - $date = date('Y-m-d', + $date = date('Y-m-d', mktime(0, 0, 0, $elts[1], $elts[0], $elts[2]) ); $sql .= ' AND cf.date_creation LIKE "' . $date . '%"'; } -if($sall) { +if ($sall) { $sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" '; $sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")'; } -if($socid) { +if ($socid) { $sql .= ' AND s.rowid = ' . $socid; } -if(GETPOST('statut')) { +if (GETPOST('statut')) { $sql .= ' AND fk_statut = ' . GETPOST('statut'); } @@ -130,74 +130,74 @@ $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' '; $sql .= $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if($resql) { +if ($resql) { $num = $db->num_rows($resql); $i = 0; - print_barre_liste($langs->trans('ReplenishmentOrders'), - $page, - 'replenishorders.php', - '', - $sortfield, - $sortorder, - '', + print_barre_liste($langs->trans('ReplenishmentOrders'), + $page, + 'replenishorders.php', + '', + $sortfield, + $sortorder, + '', $num ); print '
'; print ''; print ''; - print_liste_field_titre($langs->trans('Ref'), - $_SERVER['PHP_SELF'], - 'cf.ref', - '', - '', - '', - $sortfield, + 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, + 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, + print_liste_field_titre($langs->trans('Author'), + $_SERVER['PHP_SELF'], + 'u.login', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('AmountTTC'), - $_SERVER['PHP_SELF'], - 'cf.total_ttc', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('AmountTTC'), + $_SERVER['PHP_SELF'], + 'cf.total_ttc', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('OrderCreation'), - $_SERVER['PHP_SELF'], - 'cf.date_creation', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('OrderCreation'), + $_SERVER['PHP_SELF'], + 'cf.date_creation', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Status'), - $_SERVER['PHP_SELF'], - 'cf.fk_statut', - '', - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Status'), + $_SERVER['PHP_SELF'], + 'cf.fk_statut', + '', + '', + 'align="right"', + $sortfield, $sortorder ); print ''; @@ -228,7 +228,7 @@ if($resql) { $var = true; $userstatic = new User($db); - while($i < min($num,$conf->liste_limit)) { + while ($i < min($num,$conf->liste_limit)) { $obj = $db->fetch_object($resql); $var = !$var; @@ -251,14 +251,13 @@ if($resql) { $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; print ''; // Amount print ''; @@ -288,4 +286,3 @@ if($resql) { llxFooter(); $db->close(); -?>
'; - - if($userstatic->id) { + + if ($userstatic->id) { print $userstatic->getLoginUrl(1); - } - else { + } else { print ' '; } - + print ''; @@ -268,8 +267,7 @@ if($resql) { print ''; if ($obj->dc) { print dol_print_date($db->jdate($obj->dc), 'day'); - } - else { + } else { print '-'; } print '