diff --git a/htdocs/product/admin/dynamic_prices.php b/htdocs/product/admin/dynamic_prices.php index 4d2307d17ac..7a92d9a651b 100644 --- a/htdocs/product/admin/dynamic_prices.php +++ b/htdocs/product/admin/dynamic_prices.php @@ -37,7 +37,9 @@ $cancel = GETPOST('cancel', 'alpha'); $selection = GETPOST('selection', 'int'); // Security check -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} //Objects $price_globals = new PriceGlobalVariable($db); @@ -157,8 +159,7 @@ print ''.$langs->trans("DynamicPriceDesc").'< print '
'; //Global variables table -if ($action != 'create_updater' && $action != 'edit_updater') -{ +if ($action != 'create_updater' && $action != 'edit_updater') { print load_fiche_titre($langs->trans("GlobalVariables"), '', ''); print ''; @@ -171,7 +172,7 @@ if ($action != 'create_updater' && $action != 'edit_updater') $arrayglobalvars = $price_globals->listGlobalVariables(); if (!empty($arrayglobalvars)) { - foreach ($arrayglobalvars as $i=>$entry) { + foreach ($arrayglobalvars as $i => $entry) { print ''; print ''; print ''; @@ -187,8 +188,7 @@ if ($action != 'create_updater' && $action != 'edit_updater') } print '
'.$entry->code.''.$entry->description.'
'; - if (empty($action)) - { + if (empty($action)) { //Action Buttons print '
'; print ''.$langs->trans("AddVariable").''; @@ -234,8 +234,7 @@ if ($action == 'create_variable' || $action == 'edit_variable') { } // Updaters table -if ($action != 'create_variable' && $action != 'edit_variable') -{ +if ($action != 'create_variable' && $action != 'edit_variable') { print load_fiche_titre($langs->trans("GlobalVariableUpdaters"), '', ''); print ''; @@ -250,9 +249,8 @@ if ($action != 'create_variable' && $action != 'edit_variable') print ''; $arraypriceupdaters = $price_updaters->listUpdaters(); - if (!empty($arraypriceupdaters)) - { - foreach ($arraypriceupdaters as $i=>$entry) { + if (!empty($arraypriceupdaters)) { + foreach ($arraypriceupdaters as $i => $entry) { $code = ""; if ($entry->fk_variable > 0) { $res = $price_globals->fetch($entry->fk_variable); @@ -278,8 +276,7 @@ if ($action != 'create_variable' && $action != 'edit_variable') } print '
'; - if (empty($action)) - { + if (empty($action)) { //Action Buttons print '
'; print ''.$langs->trans("AddUpdater").''; diff --git a/htdocs/product/admin/price_rules.php b/htdocs/product/admin/price_rules.php index a38245d32c7..fada766f065 100644 --- a/htdocs/product/admin/price_rules.php +++ b/htdocs/product/admin/price_rules.php @@ -29,8 +29,9 @@ $langs->loadLangs(array('admin', 'products')); $action = GETPOST('action', 'aZ09'); // Security check -if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) +if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) { accessforbidden(); +} $error = 0; @@ -158,7 +159,7 @@ for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { trans('PercentDiscountOver', $langs->trans('SellingPrice').' 1') ?> - global->PRODUIT_MULTIPRICES_LIMIT; $i++): ?> + global->PRODUIT_MULTIPRICES_LIMIT; $i++) : ?> trans('SellingPrice').' '.$i; diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index f268003e1bb..0aa39a53bb3 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -40,8 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; $langs->loadLangs(array("admin", "products")); // Security check -if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) +if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) { accessforbidden(); +} $action = GETPOST('action', 'aZ09'); $value = GETPOST('value', 'alpha'); @@ -56,9 +57,13 @@ $select_pricing_rules = array( 'PRODUIT_CUSTOMER_PRICES'=>$langs->trans('PriceByCustomer'), // Different price for each customer ); $keyforparam = 'PRODUIT_CUSTOMER_PRICES_BY_QTY'; -if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || !empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // TODO If this is enabled, price must be hidden when price by qty is enabled, also price for quantity must be used when adding product into order/propal/invoice +if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || !empty($conf->global->$keyforparam)) { + $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // TODO If this is enabled, price must be hidden when price by qty is enabled, also price for quantity must be used when adding product into order/propal/invoice +} $keyforparam = 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; -if ($conf->global->MAIN_FEATURES_LEVEL >= 2 || !empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'] = $langs->trans('MultiPricesAbility').'+'.$langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; +if ($conf->global->MAIN_FEATURES_LEVEL >= 2 || !empty($conf->global->$keyforparam)) { + $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'] = $langs->trans('MultiPricesAbility').'+'.$langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; +} // Clean param if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) { @@ -75,10 +80,8 @@ $error = 0; $nomessageinsetmoduleoptions = 1; include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; -if ($action == 'setcodeproduct') -{ - if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON", $value, 'chaine', 0, '', $conf->entity) > 0) - { +if ($action == 'setcodeproduct') { + if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON", $value, 'chaine', 0, '', $conf->entity) > 0) { header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { @@ -86,33 +89,30 @@ if ($action == 'setcodeproduct') } } -if ($action == 'other' && GETPOST('value_PRODUIT_LIMIT_SIZE') >= 0) -{ +if ($action == 'other' && GETPOST('value_PRODUIT_LIMIT_SIZE') >= 0) { $res = dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", GETPOST('value_PRODUIT_LIMIT_SIZE'), 'chaine', 0, '', $conf->entity); - if (!($res > 0)) $error++; + if (!($res > 0)) { + $error++; + } } -if ($action == 'other' && GETPOST('value_PRODUIT_MULTIPRICES_LIMIT') > 0) -{ +if ($action == 'other' && GETPOST('value_PRODUIT_MULTIPRICES_LIMIT') > 0) { $res = dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", GETPOST('value_PRODUIT_MULTIPRICES_LIMIT'), 'chaine', 0, '', $conf->entity); - if (!($res > 0)) $error++; + if (!($res > 0)) { + $error++; + } } -if ($action == 'other') -{ +if ($action == 'other') { $princingrules = GETPOST('princingrule', 'alpha'); - foreach ($select_pricing_rules as $rule => $label) // Loop on each possible mode - { - if ($rule == $princingrules) // We are on selected rule, we enable it - { - if ($princingrules == 'PRODUCT_PRICE_UNIQ') // For this case, we disable entries manually - { + foreach ($select_pricing_rules as $rule => $label) { // Loop on each possible mode + if ($rule == $princingrules) { // We are on selected rule, we enable it + if ($princingrules == 'PRODUCT_PRICE_UNIQ') { // For this case, we disable entries manually $res = dolibarr_set_const($db, 'PRODUIT_MULTIPRICES', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_BY_QTY', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES', 0, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'PRODUCT_PRICE_UNIQ', 1, 'chaine', 0, '', $conf->entity); } else { $multirule = explode('&', $princingrules); - foreach ($multirule as $rulesselected) - { + foreach ($multirule as $rulesselected) { $res = dolibarr_set_const($db, $rulesselected, 1, 'chaine', 0, '', $conf->entity); } } @@ -151,8 +151,7 @@ if ($action == 'other') if ($value) { $sql_test = "SELECT count(desc_fourn) as cpt FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE 1"; $resql = $db->query($sql_test); - if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') // if the field does not exist, we create it - { + if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') { // if the field does not exist, we create it $sql_new = "ALTER TABLE ".MAIN_DB_PREFIX."product_fournisseur_price ADD COLUMN desc_fourn text"; $resql_new = $db->query($sql_new); } @@ -163,16 +162,14 @@ if ($action == 'other') if ($value) { $sql_test = "SELECT count(packaging) as cpt FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE 1"; $resql = $db->query($sql_test); - if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') // if the field does not exist, we create it - { + if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') { // if the field does not exist, we create it $sql_new = "ALTER TABLE ".MAIN_DB_PREFIX."product_fournisseur_price ADD COLUMN packaging double(24,8) DEFAULT 1"; $resql_new = $db->query($sql_new); } } } -if ($action == 'specimen') // For products -{ +if ($action == 'specimen') { // For products $modele = GETPOST('module', 'alpha'); $product = new Product($db); @@ -181,25 +178,21 @@ if ($action == 'specimen') // For products // Search template files $file = ''; $classname = ''; $filefound = 0; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) - { + foreach ($dirmodels as $reldir) { $file = dol_buildpath($reldir."core/modules/product/doc/pdf_".$modele.".modules.php", 0); - if (file_exists($file)) - { + if (file_exists($file)) { $filefound = 1; $classname = "pdf_".$modele; break; } } - if ($filefound) - { + if ($filefound) { require_once $file; $module = new $classname($db); - if ($module->write_file($product, $langs, '') > 0) - { + if ($module->write_file($product, $langs, '') > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=product&file=SPECIMEN.pdf"); return; } else { @@ -213,25 +206,22 @@ if ($action == 'specimen') // For products } // Activate a model -if ($action == 'set') -{ +if ($action == 'set') { $ret = addDocumentModel($value, $type, $label, $scandir); } -if ($action == 'del') -{ +if ($action == 'del') { $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - if ($conf->global->PRODUCT_ADDON_PDF == "$value") dolibarr_del_const($db, 'PRODUCT_ADDON_PDF', $conf->entity); + if ($ret > 0) { + if ($conf->global->PRODUCT_ADDON_PDF == "$value") { + dolibarr_del_const($db, 'PRODUCT_ADDON_PDF', $conf->entity); + } } } // Set default model -if ($action == 'setdoc') -{ - if (dolibarr_set_const($db, "PRODUCT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) - { +if ($action == 'setdoc') { + if (dolibarr_set_const($db, "PRODUCT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) { // La constante qui a ete lue en avant du nouveau set // on passe donc par une variable pour avoir un affichage coherent $conf->global->PRODUCT_ADDON_PDF = $value; @@ -239,20 +229,23 @@ if ($action == 'setdoc') // On active le modele $ret = delDocumentModel($value, $type); - if ($ret > 0) - { + if ($ret > 0) { $ret = addDocumentModel($value, $type, $label, $scandir); } } -if ($action == 'set') -{ +if ($action == 'set') { $const = "PRODUCT_SPECIAL_".strtoupper(GETPOST('spe', 'alpha')); $value = GETPOST('value'); - if (GETPOST('value', 'alpha')) $res = dolibarr_set_const($db, $const, $value, 'chaine', 0, '', $conf->entity); - else $res = dolibarr_del_const($db, $const, $conf->entity); - if (!($res > 0)) $error++; + if (GETPOST('value', 'alpha')) { + $res = dolibarr_set_const($db, $const, $value, 'chaine', 0, '', $conf->entity); + } else { + $res = dolibarr_del_const($db, $const, $conf->entity); + } + if (!($res > 0)) { + $error++; + } } //if ($action == 'other') @@ -262,10 +255,8 @@ if ($action == 'set') // if (! $res > 0) $error++; //} -if ($action) -{ - if (!$error) - { +if ($action) { + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("SetupNotError"), null, 'errors'); @@ -280,12 +271,10 @@ $formbarcode = new FormBarCode($db); $title = $langs->trans('ProductServiceSetup'); $tab = $langs->trans("ProductsAndServices"); -if (empty($conf->product->enabled)) -{ +if (empty($conf->product->enabled)) { $title = $langs->trans('ServiceSetup'); $tab = $langs->trans('Services'); -} elseif (empty($conf->service->enabled)) -{ +} elseif (empty($conf->service->enabled)) { $title = $langs->trans('ProductSetup'); $tab = $langs->trans('Products'); } @@ -315,50 +304,53 @@ print ' '.$langs->trans("Status").''; print ' '.$langs->trans("ShortInfo").''; print "\n"; -foreach ($dirproduct as $dirroot) -{ +foreach ($dirproduct as $dirroot) { $dir = dol_buildpath($dirroot, 0); $handle = @opendir($dir); - if (is_resource($handle)) - { + if (is_resource($handle)) { // Loop on each module find in opened directory - while (($file = readdir($handle)) !== false) - { - if (substr($file, 0, 16) == 'mod_codeproduct_' && substr($file, -3) == 'php') - { + while (($file = readdir($handle)) !== false) { + if (substr($file, 0, 16) == 'mod_codeproduct_' && substr($file, -3) == 'php') { $file = substr($file, 0, dol_strlen($file) - 4); try { dol_include_once($dirroot.$file.'.php'); - } catch (Exception $e) - { + } catch (Exception $e) { dol_syslog($e->getMessage(), LOG_ERR); } $modCodeProduct = new $file; // Show modules according to features level - if ($modCodeProduct->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($modCodeProduct->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + if ($modCodeProduct->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) { + continue; + } + if ($modCodeProduct->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) { + continue; + } print ''."\n"; print ''.$modCodeProduct->name.''."\n"; print ''.$modCodeProduct->info($langs).''."\n"; print ''.$modCodeProduct->getExample($langs).''."\n"; - if (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) && $conf->global->PRODUCT_CODEPRODUCT_ADDON == $file) - { + if (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) && $conf->global->PRODUCT_CODEPRODUCT_ADDON == $file) { print ''."\n"; print img_picto($langs->trans("Activated"), 'switch_on'); print "\n"; } else { $disabled = false; - if (!empty($conf->multicompany->enabled) && (is_object($mc) && !empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true); + if (!empty($conf->multicompany->enabled) && (is_object($mc) && !empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true) { + } print ''; - if (!$disabled) print ''; + if (!$disabled) { + print ''; + } print img_picto($langs->trans("Disabled"), 'switch_off'); - if (!$disabled) print ''; + if (!$disabled) { + print ''; + } print ''; } @@ -382,12 +374,10 @@ $sql .= " FROM ".MAIN_DB_PREFIX."document_model"; $sql .= " WHERE type = '".$db->escape($type)."'"; $sql .= " AND entity = ".$conf->entity; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $i = 0; $num_rows = $db->num_rows($resql); - while ($i < $num_rows) - { + while ($i < $num_rows) { $array = $db->fetch_array($resql); array_push($def, $array[0]); $i++; @@ -412,29 +402,21 @@ print "\n"; clearstatcache(); -foreach ($dirmodels as $reldir) -{ - foreach (array('', '/doc') as $valdir) - { +foreach ($dirmodels as $reldir) { + foreach (array('', '/doc') as $valdir) { $dir = dol_buildpath($reldir."core/modules/product".$valdir); - if (is_dir($dir)) - { + if (is_dir($dir)) { $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { $filelist[] = $file; } closedir($handle); arsort($filelist); - foreach ($filelist as $file) - { - if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) - { - if (file_exists($dir.'/'.$file)) - { + foreach ($filelist as $file) { + if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) { + if (file_exists($dir.'/'.$file)) { $name = substr($file, 4, dol_strlen($file) - 16); $classname = substr($file, 0, dol_strlen($file) - 12); @@ -442,21 +424,26 @@ foreach ($dirmodels as $reldir) $module = new $classname($db); $modulequalified = 1; - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) { + $modulequalified = 0; + } + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) { + $modulequalified = 0; + } - if ($modulequalified) - { + if ($modulequalified) { print ''; print (empty($module->name) ? $name : $module->name); print "\n"; - if (method_exists($module, 'info')) print $module->info($langs); - else print $module->description; + if (method_exists($module, 'info')) { + print $module->info($langs); + } else { + print $module->description; + } print ''; // Active - if (in_array($name, $def)) - { + if (in_array($name, $def)) { print ''."\n"; print ''; print img_picto($langs->trans("Enabled"), 'switch_on'); @@ -470,8 +457,7 @@ foreach ($dirmodels as $reldir) // Defaut print ''; - if ($conf->global->PRODUCT_ADDON_PDF == $name) - { + if ($conf->global->PRODUCT_ADDON_PDF == $name) { print img_picto($langs->trans("Default"), 'on'); } else { print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; @@ -481,8 +467,7 @@ foreach ($dirmodels as $reldir) // Info $htmltooltip = ''.$langs->trans("Name").': '.$module->name; $htmltooltip .= '
'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); - if ($module->type == 'pdf') - { + if ($module->type == 'pdf') { $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; } $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; @@ -496,8 +481,7 @@ foreach ($dirmodels as $reldir) // Preview print ''; - if ($module->type == 'pdf') - { + if ($module->type == 'pdf') { print ''.img_object($langs->trans("Preview"), 'contract').''; } else { print img_object($langs->trans("PreviewNotAvailable"), 'generic'); @@ -568,26 +552,32 @@ print ''; // Rule for price print ''; -if (empty($conf->multicompany->enabled)) -{ +if (empty($conf->multicompany->enabled)) { print ''.$langs->trans("PricingRule").''; } else { print ''.$form->textwithpicto($langs->trans("PricingRule"), $langs->trans("SamePriceAlsoForSharedCompanies"), 1).''; } print ''; $current_rule = 'PRODUCT_PRICE_UNIQ'; -if (!empty($conf->global->PRODUIT_MULTIPRICES)) $current_rule = 'PRODUIT_MULTIPRICES'; -if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY'; -if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $current_rule = 'PRODUIT_CUSTOMER_PRICES'; -if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; +if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + $current_rule = 'PRODUIT_MULTIPRICES'; +} +if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { + $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY'; +} +if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + $current_rule = 'PRODUIT_CUSTOMER_PRICES'; +} +if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; +} print $form->selectarray("princingrule", $select_pricing_rules, $current_rule, 0, 0, 0, '', 1, 0, 0, '', 'maxwidth400', 1); print ''; print ''; // multiprix nombre de prix a proposer -if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) -{ +if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { print ''; print ''.$langs->trans("MultiPricesNumPrices").''; print ''; @@ -606,8 +596,7 @@ print ''; print ''; print ''.$form->textwithpicto($langs->trans("UseSearchToSelectProduct"), $langs->trans('UseSearchToSelectProductTooltip'), 1).''; -if (empty($conf->use_javascript_ajax)) -{ +if (empty($conf->use_javascript_ajax)) { print ''; print $langs->trans("NotAvailableWhenAjaxDisabled"); print ''; @@ -624,8 +613,7 @@ if (empty($conf->use_javascript_ajax)) } print ''; -if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) -{ +if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { print ''; print ''.$langs->trans("NumberOfProductShowInSelect").''; print ''; @@ -685,8 +673,7 @@ print ''; */ // View product description in thirdparty language -if (!empty($conf->global->MAIN_MULTILANGS)) -{ +if (!empty($conf->global->MAIN_MULTILANGS)) { print ''; print ''.$langs->trans("ViewProductDescInThirdpartyLanguageAbility").''; print ''; @@ -695,8 +682,7 @@ if (!empty($conf->global->MAIN_MULTILANGS)) print ''; } -if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) -{ +if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { print ''; print ''.$langs->trans("UseProductFournDesc").''; print ''; @@ -713,8 +699,7 @@ if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUP } -if (!empty($conf->global->PRODUCT_CANVAS_ABILITY)) -{ +if (!empty($conf->global->PRODUCT_CANVAS_ABILITY)) { // Add canvas feature $dir = DOL_DOCUMENT_ROOT."/product/canvas/"; @@ -723,17 +708,13 @@ if (!empty($conf->global->PRODUCT_CANVAS_ABILITY)) print ''.$langs->trans("Value").''."\n"; print ''."\n"; - if (is_dir($dir)) - { + if (is_dir($dir)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (file_exists($dir.$file.'/product.'.$file.'.class.php')) - { + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (file_exists($dir.$file.'/product.'.$file.'.class.php')) { $classfile = $dir.$file.'/product.'.$file.'.class.php'; $classname = 'Product'.ucfirst($file); @@ -742,8 +723,7 @@ if (!empty($conf->global->PRODUCT_CANVAS_ABILITY)) $module = $object->module; - if ($conf->$module->enabled) - { + if ($conf->$module->enabled) { print ''; print $object->description; @@ -752,8 +732,7 @@ if (!empty($conf->global->PRODUCT_CANVAS_ABILITY)) $const = "PRODUCT_SPECIAL_".strtoupper($file); - if ($conf->global->$const) - { + if ($conf->global->$const) { print img_picto($langs->trans("Active"), 'tick'); print ''; print ''.$langs->trans("Disable").''; diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php index d82d175a9a7..0962d1ddf44 100644 --- a/htdocs/product/admin/product_extrafields.php +++ b/htdocs/product/admin/product_extrafields.php @@ -38,13 +38,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'product'; //Must be the $element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -61,12 +65,10 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; $title = $langs->trans('ProductServiceSetup'); $textobject = $langs->trans("ProductsAndServices"); -if (empty($conf->product->enabled)) -{ +if (empty($conf->product->enabled)) { $title = $langs->trans('ServiceSetup'); $textobject = $langs->trans('Services'); -} elseif (empty($conf->service->enabled)) -{ +} elseif (empty($conf->service->enabled)) { $title = $langs->trans('ProductSetup'); $textobject = $langs->trans('Products'); } @@ -90,8 +92,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '"; @@ -104,8 +105,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -117,8 +117,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/product/admin/product_lot_extrafields.php b/htdocs/product/admin/product_lot_extrafields.php index e89e5741cce..91e19ee1fa7 100644 --- a/htdocs/product/admin/product_lot_extrafields.php +++ b/htdocs/product/admin/product_lot_extrafields.php @@ -38,13 +38,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'product_lot'; //Must be the $element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -81,8 +85,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '"; @@ -95,8 +98,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -108,8 +110,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/product/admin/product_supplier_extrafields.php b/htdocs/product/admin/product_supplier_extrafields.php index 54d56ad9dd5..8c3a10a4b74 100644 --- a/htdocs/product/admin/product_supplier_extrafields.php +++ b/htdocs/product/admin/product_supplier_extrafields.php @@ -39,13 +39,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'product_fournisseur_price'; //Must be the $element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -62,12 +66,10 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; $title = $langs->trans('ProductServiceSetup'); $textobject = $langs->trans("ProductsAndServices"); -if (empty($conf->product->enabled)) -{ +if (empty($conf->product->enabled)) { $title = $langs->trans('ServiceSetup'); $textobject = $langs->trans('Services'); -} elseif (empty($conf->service->enabled)) -{ +} elseif (empty($conf->service->enabled)) { $title = $langs->trans('ProductSetup'); $textobject = $langs->trans('Products'); } @@ -91,8 +93,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '"; @@ -105,8 +106,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -118,8 +118,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php index 3bf85bdff4f..674e90f3614 100644 --- a/htdocs/product/admin/product_tools.php +++ b/htdocs/product/admin/product_tools.php @@ -35,7 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $langs->loadLangs(array('admin', 'products')); // Security check -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} $action = GETPOST('action', 'aZ09'); $oldvatrate = GETPOST('oldvatrate', 'alpha'); @@ -48,19 +50,16 @@ $newvatrate = GETPOST('newvatrate', 'alpha'); * Actions */ -if ($action == 'convert') -{ +if ($action == 'convert') { $error = 0; - if ($oldvatrate == $newvatrate) - { + if ($oldvatrate == $newvatrate) { $langs->load("errors"); setEventMessages($langs->trans("ErrorNewValueCantMatchOldValue"), null, 'errors'); $error++; } - if (!$error) - { + if (!$error) { $country_id = $mysoc->country_id; // TODO Allow to choose country into form $nbrecordsmodified = 0; @@ -69,62 +68,65 @@ if ($action == 'convert') // Clean vat code old $vat_src_code_old = ''; - if (preg_match('/\((.*)\)/', $oldvatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $oldvatrate, $reg)) { $vat_src_code_old = $reg[1]; $oldvatrateclean = preg_replace('/\s*\(.*\)/', '', $oldvatrate); // Remove code into vatrate. - } else $oldvatrateclean = $oldvatrate; + } else { + $oldvatrateclean = $oldvatrate; + } // Clean vat code new $vat_src_code_new = ''; - if (preg_match('/\((.*)\)/', $newvatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $newvatrate, $reg)) { $vat_src_code_new = $reg[1]; $newvatrateclean = preg_replace('/\s*\(.*\)/', '', $newvatrate); // Remove code into vatrate. - } else $newvatrateclean = $newvatrate; + } else { + $newvatrateclean = $newvatrate; + } // If country to edit is my country, so we change customer prices - if ($country_id == $mysoc->country_id) - { + if ($country_id == $mysoc->country_id) { $sql = 'SELECT rowid'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product'; $sql .= ' WHERE entity IN ('.getEntity('product').')'; $sql .= " AND tva_tx = '".$db->escape($oldvatrateclean)."'"; - if ($vat_src_code_old) $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; - else " AND default_vat_code = IS NULL"; + if ($vat_src_code_old) { + $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; + } else { + " AND default_vat_code = IS NULL"; + } $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); $objectstatic = new Product($db); // Object init must be into loop to avoid to get value of previous step $ret = $objectstatic->fetch($obj->rowid); - if ($ret > 0) - { + if ($ret > 0) { $ret = 0; $retm = 0; $updatelevel1 = false; // Update multiprice $listofmulti = array_reverse($objectstatic->multiprices, true); // To finish with level 1 - foreach ($listofmulti as $level => $multiprices) - { + foreach ($listofmulti as $level => $multiprices) { $price_base_type = $objectstatic->multiprices_base_type[$level]; // Get price_base_type of product/service to keep the same for update - if (empty($price_base_type)) continue; // Discard not defined price levels + if (empty($price_base_type)) { + continue; // Discard not defined price levels + } - if ($price_base_type == 'TTC') - { + if ($price_base_type == 'TTC') { $newprice = price2num($objectstatic->multiprices_ttc[$level], 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->multiprices_min_ttc[$level]; } else { $newprice = price2num($objectstatic->multiprices[$level], 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->multiprices_min[$level]; } - if ($newminprice > $newprice) $newminprice = $newprice; + if ($newminprice > $newprice) { + $newminprice = $newprice; + } $newvat = str_replace('*', '', $newvatrate); $localtaxes_type = getLocalTaxesFromRate($newvat, 0, $mysoc, $mysoc); @@ -134,45 +136,51 @@ if ($action == 'convert') //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode); - if ($retm < 0) - { + if ($retm < 0) { $error++; break; } - if ($newlevel == 1) $updatelevel1 = true; + if ($newlevel == 1) { + $updatelevel1 = true; + } } // Update single price $price_base_type = $objectstatic->price_base_type; // Get price_base_type of product/service to keep the same for update - if ($price_base_type == 'TTC') - { + if ($price_base_type == 'TTC') { $newprice = price2num($objectstatic->price_ttc, 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->price_min_ttc; } else { $newprice = price2num($objectstatic->price, 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->price_min; } - if ($newminprice > $newprice) $newminprice = $newprice; + if ($newminprice > $newprice) { + $newminprice = $newprice; + } $newvat = str_replace('*', '', $newvatrate); $localtaxes_type = getLocalTaxesFromRate($newvat, 0, $mysoc, $mysoc); $newnpr = $objectstatic->recuperableonly; $newdefaultvatcode = $vat_src_code_new; $newlevel = 0; - if (!empty($price_base_type) && !$updatelevel1) - { + if (!empty($price_base_type) && !$updatelevel1) { //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode); } - if ($ret < 0 || $retm < 0) $error++; - else $nbrecordsmodified++; + if ($ret < 0 || $retm < 0) { + $error++; + } else { + $nbrecordsmodified++; + } } unset($objectstatic); $i++; } - } else dol_print_error($db); + } else { + dol_print_error($db); + } } $fourn = new Fournisseur($db); @@ -182,24 +190,24 @@ if ($action == 'convert') $sql .= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.'societe as s'; $sql .= ' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity('product').')'; $sql .= " AND tva_tx = '".$db->escape($oldvatrate)."'"; - if ($vat_src_code_old) $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; - else " AND default_vat_code = IS NULL"; + if ($vat_src_code_old) { + $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; + } else { + " AND default_vat_code = IS NULL"; + } $sql .= " AND s.fk_pays = ".((int) $country_id); //print $sql; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); $objectstatic2 = new ProductFournisseur($db); // Object init must be into loop to avoid to get value of previous step $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid); - if ($ret > 0) - { + if ($ret > 0) { $ret = 0; $retm = 0; $updatelevel1 = false; $price_base_type = 'HT'; @@ -226,34 +234,39 @@ if ($action == 'convert') $newsupplierreputation = $objectstatic2->supplier_reputation; $newlevel = 0; - if (!empty($price_base_type) && !$updatelevel1) - { + if (!empty($price_base_type) && !$updatelevel1) { //print "$objectstatic2->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; $fourn->id = $obj->fk_soc; $ret = $objectstatic2->update_buyprice($obj->qty, $newprice, $user, $price_base_type, $fourn, $obj->fk_availability, $obj->ref_fourn, $newvat, '', $newpercent, 0, $newnpr, $newdeliverydelay, $newsupplierreputation, $localtaxes_type, $newdefaultvatcode); } - if ($ret < 0 || $retm < 0) $error++; - else $nbrecordsmodified++; + if ($ret < 0 || $retm < 0) { + $error++; + } else { + $nbrecordsmodified++; + } } unset($objectstatic2); $i++; } - } else dol_print_error($db); + } else { + dol_print_error($db); + } - if (!$error) - { + if (!$error) { $db->commit(); } else { $db->rollback(); } // Output result - if (!$error) - { - if ($nbrecordsmodified > 0) setEventMessages($langs->trans("RecordsModified", $nbrecordsmodified), null, 'mesgs'); - else setEventMessages($langs->trans("NoRecordFound"), null, 'warnings'); + if (!$error) { + if ($nbrecordsmodified > 0) { + setEventMessages($langs->trans("RecordsModified", $nbrecordsmodified), null, 'mesgs'); + } else { + setEventMessages($langs->trans("NoRecordFound"), null, 'warnings'); + } } else { setEventMessages($langs->trans("Error"), null, 'errors'); } @@ -274,8 +287,7 @@ print load_fiche_titre($title, '', 'title_setup'); print $langs->trans("ProductVatMassChangeDesc").'

'; -if (empty($mysoc->country_code)) -{ +if (empty($mysoc->country_code)) { $langs->load("errors"); $warnpicto = img_error($langs->trans("WarningMandatorySetupNotComplete")); print '
'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").''; diff --git a/htdocs/product/admin/stock_extrafields.php b/htdocs/product/admin/stock_extrafields.php index 9b5a0f23f07..3f860564b48 100644 --- a/htdocs/product/admin/stock_extrafields.php +++ b/htdocs/product/admin/stock_extrafields.php @@ -37,13 +37,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'entrepot'; //Must be the $table_element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -76,8 +80,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '"; @@ -90,8 +93,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print "
"; print load_fiche_titre($langs->trans('NewAttribute')); @@ -103,8 +105,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/product/agenda.php b/htdocs/product/agenda.php index 8a7ddf385d9..bf25675865f 100644 --- a/htdocs/product/agenda.php +++ b/htdocs/product/agenda.php @@ -36,10 +36,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; // Load translation files required by the page $langs->load("companies"); -if (GETPOST('actioncode', 'array')) -{ +if (GETPOST('actioncode', 'array')) { $actioncode = GETPOST('actioncode', 'array', 3); - if (!count($actioncode)) $actioncode = '0'; + if (!count($actioncode)) { + $actioncode = '0'; + } } else { $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); } @@ -48,19 +49,27 @@ $search_agenda_label = GETPOST('search_agenda_label'); // Security check $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -if ($user->socid) $id = $user->socid; +if ($user->socid) { + $id = $user->socid; +} $result = restrictedArea($user, 'produit|service', $id, 'product&product'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = 'a.datep,a.id'; -if (!$sortorder) $sortorder = 'DESC,DESC'; +if (!$sortfield) { + $sortfield = 'a.datep,a.id'; +} +if (!$sortorder) { + $sortorder = 'DESC,DESC'; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agendathirdparty')); @@ -72,20 +81,19 @@ $hookmanager->initHooks(array('agendathirdparty')); $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Cancel - if (GETPOST('cancel', 'alpha') && !empty($backtopage)) - { + if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { header("Location: ".$backtopage); exit; } // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $actioncode = ''; $search_agenda_label = ''; } @@ -101,8 +109,7 @@ $contactstatic = new Contact($db); $form = new Form($db); -if ($id > 0 || $ref) -{ +if ($id > 0 || $ref) { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; @@ -113,12 +120,18 @@ if ($id > 0 || $ref) $result = $object->fetch($id, $ref); $title = $langs->trans("Agenda"); - if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/productnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$title; + if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/productnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { + $title = $object->name." - ".$title; + } llxHeader('', $title); - if (!empty($conf->notification->enabled)) $langs->load("mails"); + if (!empty($conf->notification->enabled)) { + $langs->load("mails"); + } $type = $langs->trans('Product'); - if ($object->isService()) $type = $langs->trans('Service'); + if ($object->isService()) { + $type = $langs->trans('Service'); + } $head = product_prepare_head($object); @@ -130,7 +143,9 @@ if ($id > 0 || $ref) $object->next_prev_filter = " fk_product_type = ".$object->type; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -154,10 +169,11 @@ if ($id > 0 || $ref) $out = ''; $permok = $user->rights->agenda->myactions->create; - if ((!empty($objproduct->id) || !empty($objcon->id)) && $permok) - { + if ((!empty($objproduct->id) || !empty($objcon->id)) && $permok) { //$out.='trans("AddAnAction"),'filenew'); @@ -170,19 +186,21 @@ if ($id > 0 || $ref) $morehtmlcenter = ''; - if (!empty($conf->agenda->enabled)) - { + if (!empty($conf->agenda->enabled)) { $linktocreatetimeBtnStatus = !empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create); $morehtmlcenter = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', $linktocreatetimeBtnStatus); } - if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) - { + if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { print '
'; $param = '&id='.$id; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.$contextpage; + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.$limit; + } print_barre_liste($langs->trans("ActionsOnProduct"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlcenter, '', 0, 1, 1); diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 198d49defaf..9dacb4e547d 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -23,13 +23,27 @@ * \brief File to return Ajax response on product list request. */ -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', 1); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} require '../../main.inc.php'; @@ -58,8 +72,7 @@ $hidepriceinlabel = GETPOST('hidepriceinlabel', 'int'); dol_syslog(join(',', $_GET)); // print_r($_GET); -if (!empty($action) && $action == 'fetch' && !empty($id)) -{ +if (!empty($action) && $action == 'fetch' && !empty($id)) { // action='fetch' is used to get product information on a product. So when action='fetch', id must be the product id. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; @@ -68,8 +81,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $object = new Product($db); $ret = $object->fetch($id); - if ($ret > 0) - { + if ($ret > 0) { $outref = $object->ref; $outlabel = $object->label; $outlabel_trans =''; @@ -82,7 +94,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $found = false; $price_level = 1; - if ($socid > 0 ) { + if ($socid > 0) { $thirdpartytemp = new Societe($db); $thirdpartytemp->fetch($socid); @@ -107,8 +119,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) } // Price by qty - if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) // If we need a particular price related to qty - { + if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) { // If we need a particular price related to qty $sql = "SELECT price, unitprice, quantity, remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty "; $sql .= " WHERE rowid=".$price_by_qty_rowid.""; @@ -129,8 +140,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) } // Multiprice - if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) // If we need a particular price level (from 1 to 6) - { + if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) { // If we need a particular price level (from 1 to 6) $sql = "SELECT price, price_ttc, price_base_type, tva_tx"; $sql .= " FROM ".MAIN_DB_PREFIX."product_price "; $sql .= " WHERE fk_product = '".$id."'"; @@ -203,8 +213,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) top_httphead(); - if (empty($htmlname)) - { + if (empty($htmlname)) { print json_encode(array()); return; } @@ -214,8 +223,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $idprod = (!empty($match[0]) ? $match[0] : ''); - if (GETPOST($htmlname, 'alpha') == '' && (!$idprod || !GETPOST($idprod, 'alpha'))) - { + if (GETPOST($htmlname, 'alpha') == '' && (!$idprod || !GETPOST($idprod, 'alpha'))) { print json_encode(array()); return; } @@ -233,6 +241,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $db->close(); - if ($outjson) + if ($outjson) { print json_encode($arrayresult); + } } diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index e7e3c7ea4b3..55a8977a4bd 100644 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.class.php @@ -80,8 +80,10 @@ class ActionsCardProduct global $conf, $langs, $user, $mysoc, $canvas; global $form, $formproduct; - $tmpobject = new Product($this->db); - if (!empty($id) || !empty($ref)) $tmpobject->fetch($id, $ref); + $tmpobject = new Product($this->db); + if (!empty($id) || !empty($ref)) { + $tmpobject->fetch($id, $ref); + } $this->object = $tmpobject; //parent::assign_values($action); @@ -113,8 +115,7 @@ class ActionsCardProduct // Note $this->tpl['note'] = nl2br($this->note); - if ($action == 'create') - { + if ($action == 'create') { // Price $this->tpl['price'] = $this->price; $this->tpl['price_min'] = $this->price_min; @@ -124,8 +125,7 @@ class ActionsCardProduct $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, ''); } - if ($action == 'view') - { + if ($action == 'view') { $head = product_prepare_head($this->object); $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref'); @@ -152,19 +152,16 @@ class ActionsCardProduct $this->tpl['note'] = $this->object->note; $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte; - if ($action == 'create') - { + if ($action == 'create') { // Title $this->tpl['title'] = $langs->trans("NewProduct"); } - if ($action == 'edit') - { + if ($action == 'edit') { $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Product').' : '.$this->object->ref; } - if ($action == 'create' || $action == 'edit') - { + if ($action == 'create' || $action == 'edit') { // Status $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status); @@ -196,12 +193,10 @@ class ActionsCardProduct $this->tpl['volume_units'] = $formproduct->selectMeasuringUnits("volume_units", "volume", $this->object->volume_units, 0, 2); } - if ($action == 'view') - { + if ($action == 'view') { // Photo $this->tpl['nblines'] = 4; - if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) - { + if ($this->object->is_photo_available($conf->product->multidir_output[$this->object->entity])) { $this->tpl['photos'] = $this->object->show_photos('product', $conf->product->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80); } @@ -209,34 +204,29 @@ class ActionsCardProduct $this->tpl['finished'] = $this->object->getLibFinished(); // Weight - if ($this->object->weight != '') - { + if ($this->object->weight != '') { $this->tpl['weight'] = $this->object->weight." ".measuringUnitString(0, "weight", $this->object->weight_units); } // Length - if ($this->object->length != '') - { + if ($this->object->length != '') { $this->tpl['length'] = $this->object->length." ".measuringUnitString(0, "size", $this->object->length_units); } // Surface - if ($this->object->surface != '') - { + if ($this->object->surface != '') { $this->tpl['surface'] = $this->object->surface." ".measuringUnitString(0, "surface", $this->object->surface_units); } // Volume - if ($this->object->volume != '') - { + if ($this->object->volume != '') { $this->tpl['volume'] = $this->object->volume." ".measuringUnitString(0, "volume", $this->object->volume_units); } $this->tpl['fiche_end'] = dol_get_fiche_end(); } - if ($action == 'list') - { + if ($action == 'list') { $this->LoadListDatas($limit, $offset, $sortfield, $sortorder); } } @@ -260,13 +250,11 @@ class ActionsCardProduct $sql .= " ORDER BY rang ASC"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $fieldlist = array(); $obj = $this->db->fetch_object($resql); @@ -315,10 +303,8 @@ class ActionsCardProduct // Clean parameters $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); - foreach ($this->field_list as $field) - { - if ($field['enabled']) - { + foreach ($this->field_list as $field) { + if ($field['enabled']) { $fieldname = "s".$field['alias']; $$fieldname = GETPOST($fieldname); } @@ -330,10 +316,8 @@ class ActionsCardProduct $sql .= 'p.rowid, p.price_base_type, p.fk_product_type, p.seuil_stock_alerte, p.entity'; // Fields not requiered - foreach ($this->field_list as $field) - { - if ($field['enabled']) - { + foreach ($this->field_list as $field) { + if ($field['enabled']) { $sql .= ", ".$field['name']." as ".$field['alias']; } } @@ -341,37 +325,34 @@ class ActionsCardProduct $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql .= " WHERE p.entity IN (".getEntity('product').")"; - if ($sall) - { + if ($sall) { $clause = ''; $sql .= " AND ("; - foreach ($this->field_list as $field) - { - if ($field['enabled']) - { + foreach ($this->field_list as $field) { + if ($field['enabled']) { $sql .= $clause." ".$field['name']." LIKE '%".$this->db->escape($sall)."%'"; - if ($clause == '') $clause = ' OR'; + if ($clause == '') { + $clause = ' OR'; + } } } $sql .= ")"; } // Search fields - foreach ($this->field_list as $field) - { - if ($field['enabled']) - { + foreach ($this->field_list as $field) { + if ($field['enabled']) { $fieldname = "s".$field['alias']; - if (${$fieldname}) $sql .= " AND ".$field['name']." LIKE '%".$this->db->escape(${$fieldname})."%'"; + if (${$fieldname}) { + $sql .= " AND ".$field['name']." LIKE '%".$this->db->escape(${$fieldname})."%'"; + } } } - if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) - { + if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) { $sql .= " AND p.tosell = ".$this->db->escape($_GET["tosell"]); } - if (isset($_GET["canvas"]) && dol_strlen($_GET["canvas"]) > 0) - { + if (isset($_GET["canvas"]) && dol_strlen($_GET["canvas"]) > 0) { $sql .= " AND p.canvas = '".$this->db->escape($_GET["canvas"])."'"; } $sql .= $this->db->order($sortfield, $sortorder); @@ -379,42 +360,45 @@ class ActionsCardProduct //print $sql; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $datas = array(); $obj = $this->db->fetch_object($resql); $datas["id"] = $obj->rowid; - foreach ($this->field_list as $field) - { - if ($field['enabled']) - { + foreach ($this->field_list as $field) { + if ($field['enabled']) { $alias = $field['alias']; - if ($alias == 'ref') - { + if ($alias == 'ref') { $this->id = $obj->rowid; $this->ref = $obj->$alias; $this->type = $obj->fk_product_type; $this->entity = $obj->entity; $datas[$alias] = $this->getNomUrl(1, '', 24); - } elseif ($alias == 'stock') - { + } elseif ($alias == 'stock') { $this->load_stock(); - if ($this->stock_reel < $obj->seuil_stock_alerte) $datas[$alias] = $this->stock_reel.' '.img_warning($langs->trans("StockTooLow")); - else $datas[$alias] = $this->stock_reel; - } elseif ($alias == 'label') $datas[$alias] = dol_trunc($obj->$alias, 40); - elseif (preg_match('/price/i', $alias)) $datas[$alias] = price($obj->$alias); - elseif ($alias == 'datem') $datas[$alias] = dol_print_date($this->db->jdate($obj->$alias), 'day'); - elseif ($alias == 'status') $datas[$alias] = $this->LibStatut($obj->$alias, 5); - else $datas[$alias] = $obj->$alias; + if ($this->stock_reel < $obj->seuil_stock_alerte) { + $datas[$alias] = $this->stock_reel.' '.img_warning($langs->trans("StockTooLow")); + } else { + $datas[$alias] = $this->stock_reel; + } + } elseif ($alias == 'label') { + $datas[$alias] = dol_trunc($obj->$alias, 40); + } elseif (preg_match('/price/i', $alias)) { + $datas[$alias] = price($obj->$alias); + } elseif ($alias == 'datem') { + $datas[$alias] = dol_print_date($this->db->jdate($obj->$alias), 'day'); + } elseif ($alias == 'status') { + $datas[$alias] = $this->LibStatut($obj->$alias, 5); + } else { + $datas[$alias] = $obj->$alias; + } } } diff --git a/htdocs/product/canvas/product/tpl/card_create.tpl.php b/htdocs/product/canvas/product/tpl/card_create.tpl.php index 042734f8fd3..b862eddefc5 100644 --- a/htdocs/product/canvas/product/tpl/card_create.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_create.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -53,7 +52,9 @@ print dol_get_fiche_head(''); trans("Ref"); ?> -trans("RefAlreadyExists"); ?> +trans("RefAlreadyExists"); +} ?> diff --git a/htdocs/product/canvas/product/tpl/card_edit.tpl.php b/htdocs/product/canvas/product/tpl/card_edit.tpl.php index 512ab13416b..21f2edefc2d 100644 --- a/htdocs/product/canvas/product/tpl/card_edit.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_edit.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } diff --git a/htdocs/product/canvas/product/tpl/card_view.tpl.php b/htdocs/product/canvas/product/tpl/card_view.tpl.php index 2158be2b24d..a5f793e246d 100644 --- a/htdocs/product/canvas/product/tpl/card_view.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_view.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -37,7 +36,9 @@ $linkback = '
object); $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref'); @@ -155,19 +154,16 @@ class ActionsCardService // Duration $this->tpl['duration_value'] = $this->object->duration_value; - if ($action == 'create') - { + if ($action == 'create') { // Title $this->tpl['title'] = $langs->trans("NewService"); } - if ($action == 'edit') - { + if ($action == 'edit') { $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref; } - if ($action == 'create' || $action == 'edit') - { + if ($action == 'create' || $action == 'edit') { // Status $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status); @@ -192,21 +188,17 @@ class ActionsCardService $this->tpl['duration_unit'] = $duration_unit; } - if ($action == 'view') - { + if ($action == 'view') { // Photo $this->tpl['nblines'] = 4; - if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) - { + if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) { $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80); } // Duration - if ($this->object->duration_value > 1) - { + if ($this->object->duration_value > 1) { $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); - } elseif ($this->object->duration_value > 0) - { + } elseif ($this->object->duration_value > 0) { $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); } $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]); @@ -214,8 +206,7 @@ class ActionsCardService $this->tpl['fiche_end'] = dol_get_fiche_end(); } - if ($action == 'list') - { + if ($action == 'list') { $this->LoadListDatas($limit, $offset, $sortfield, $sortorder); } } @@ -239,13 +230,11 @@ class ActionsCardService $sql .= " ORDER BY rang ASC"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $fieldlist = array(); $obj = $this->db->fetch_object($resql); @@ -294,40 +283,43 @@ class ActionsCardService $sql .= ' p.duration, p.tosell as statut, p.seuil_stock_alerte'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; // We'll need this table joined to the select in order to filter by categ - if ($search_categ) $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; - if (GETPOST("fourn_id", 'int') > 0) - { + if ($search_categ) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; + } + if (GETPOST("fourn_id", 'int') > 0) { $fourn_id = GETPOST("fourn_id", 'int'); $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; } $sql .= " WHERE p.entity IN (".getEntity('product').")"; - if ($search_categ) $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ - if ($sall) - { + if ($search_categ) { + $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ + } + if ($sall) { $sql .= " AND (p.ref LIKE '%".$this->db->escape($sall)."%' OR p.label LIKE '%".$this->db->escape($sall)."%' OR p.description LIKE '%".$this->db->escape($sall)."%' OR p.note LIKE '%".$this->db->escape($sall)."%')"; } - if ($sref) $sql .= " AND p.ref LIKE '%".$sref."%'"; - if ($search_barcode) $sql .= " AND p.barcode LIKE '%".$search_barcode."%'"; - if ($snom) $sql .= " AND p.label LIKE '%".$this->db->escape($snom)."%'"; - if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) - { + if ($sref) { + $sql .= " AND p.ref LIKE '%".$sref."%'"; + } + if ($search_barcode) { + $sql .= " AND p.barcode LIKE '%".$search_barcode."%'"; + } + if ($snom) { + $sql .= " AND p.label LIKE '%".$this->db->escape($snom)."%'"; + } + if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) { $sql .= " AND p.tosell = ".$this->db->escape($_GET["tosell"]); } - if (isset($_GET["canvas"]) && dol_strlen($_GET["canvas"]) > 0) - { + if (isset($_GET["canvas"]) && dol_strlen($_GET["canvas"]) > 0) { $sql .= " AND p.canvas = '".$this->db->escape($_GET["canvas"])."'"; } - if ($catid) - { + if ($catid) { $sql .= " AND cp.fk_categorie = ".$catid; } - if ($fourn_id > 0) - { + if ($fourn_id > 0) { $sql .= " AND p.rowid = pfp.fk_product AND pfp.fk_soc = ".$fourn_id; } // Insert categ filter - if ($search_categ) - { + if ($search_categ) { $sql .= " AND cp.fk_categorie = ".$this->db->escape($search_categ); } $sql .= $this->db->order($sortfield, $sortorder); @@ -336,13 +328,11 @@ class ActionsCardService $this->list_datas = array(); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $datas = array(); $obj = $this->db->fetch_object($resql); diff --git a/htdocs/product/canvas/service/tpl/card_create.tpl.php b/htdocs/product/canvas/service/tpl/card_create.tpl.php index 13fceff4e22..ce3c4f5cc58 100644 --- a/htdocs/product/canvas/service/tpl/card_create.tpl.php +++ b/htdocs/product/canvas/service/tpl/card_create.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -50,7 +49,9 @@ print dol_get_fiche_head(''); trans("Ref"); ?> -trans("RefAlreadyExists"); ?> +trans("RefAlreadyExists"); +} ?> diff --git a/htdocs/product/canvas/service/tpl/card_edit.tpl.php b/htdocs/product/canvas/service/tpl/card_edit.tpl.php index 8e4613f21b0..4906b0dcf2c 100644 --- a/htdocs/product/canvas/service/tpl/card_edit.tpl.php +++ b/htdocs/product/canvas/service/tpl/card_edit.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } diff --git a/htdocs/product/canvas/service/tpl/card_view.tpl.php b/htdocs/product/canvas/service/tpl/card_view.tpl.php index d342d102af0..c816a36ae34 100644 --- a/htdocs/product/canvas/service/tpl/card_view.tpl.php +++ b/htdocs/product/canvas/service/tpl/card_view.tpl.php @@ -16,8 +16,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -37,7 +36,9 @@ $linkback = 'facture->enabled)) $langs->load("bills"); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->stock->enabled)) { + $langs->load("stocks"); +} +if (!empty($conf->facture->enabled)) { + $langs->load("bills"); +} +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} $mesg = ''; $error = 0; $errors = array(); @@ -91,7 +109,9 @@ $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha'); // by default 'alphanohtml' (better security); hidden conf MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML allows basic html $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML) ? 'alphanohtml' : 'restricthtml'; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $object = new Product($db); $object->type = $type; // so test later to fill $usercancxxx is correct @@ -100,17 +120,21 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); - if (!empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); - elseif (!empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + if (!empty($conf->product->enabled)) { + $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + } elseif (!empty($conf->service->enabled)) { + $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + } - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs - { - if (!empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; - else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; + if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs + if (!empty($conf->product->enabled)) { + $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; + } else { + $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; + } } } @@ -119,8 +143,7 @@ $modulepart = 'product'; // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas"); $objcanvas = null; -if (!empty($canvas)) -{ +if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('product', 'card', $canvas); @@ -140,23 +163,27 @@ $hookmanager->initHooks(array('productcard', 'globalcard')); * Actions */ -if ($cancel) $action = ''; +if ($cancel) { + $action = ''; +} $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire)); $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)); $usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)); $createbarcode = empty($conf->barcode->enabled) ? 0 : 1; -if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) $createbarcode = 0; +if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) { + $createbarcode = 0; +} $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Type - if ($action == 'setfk_product_type' && $usercancreate) - { + if ($action == 'setfk_product_type' && $usercancreate) { $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; @@ -170,29 +197,31 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Barcode type - if ($action == 'setfk_barcode_type' && $createbarcode) - { + if ($action == 'setfk_barcode_type' && $createbarcode) { $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } // Barcode value - if ($action == 'setbarcode' && $createbarcode) - { + if ($action == 'setbarcode' && $createbarcode) { $result = $object->check_barcode(GETPOST('barcode'), GETPOST('barcode_type_code')); - if ($result >= 0) - { + if ($result >= 0) { $result = $object->setValueFrom('barcode', GETPOST('barcode'), '', null, 'text', '', $user, 'PRODUCT_MODIFY'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { $langs->load("errors"); - if ($result == -1) $errors[] = 'ErrorBadBarCodeSyntax'; - elseif ($result == -2) $errors[] = 'ErrorBarCodeRequired'; - elseif ($result == -3) $errors[] = 'ErrorBarCodeAlreadyUsed'; - else $errors[] = 'FailedToValidateBarCode'; + if ($result == -1) { + $errors[] = 'ErrorBadBarCodeSyntax'; + } elseif ($result == -2) { + $errors[] = 'ErrorBarCodeRequired'; + } elseif ($result == -3) { + $errors[] = 'ErrorBarCodeAlreadyUsed'; + } else { + $errors[] = 'FailedToValidateBarCode'; + } $error++; setEventMessages($errors, null, 'errors'); @@ -200,43 +229,42 @@ if (empty($reshook)) } // Add a product or service - if ($action == 'add' && $usercancreate) - { + if ($action == 'add' && $usercancreate) { $error = 0; - if (!GETPOST('label', $label_security_check)) - { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Label')), null, 'errors'); - $action = "create"; - $error++; - } - if (empty($ref)) - { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); - $action = "create"; - $error++; - } - if (!empty($duration_value) && empty($duration_unit)) - { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors'); - $action = "create"; - $error++; - } + if (!GETPOST('label', $label_security_check)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Label')), null, 'errors'); + $action = "create"; + $error++; + } + if (empty($ref)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); + $action = "create"; + $error++; + } + if (!empty($duration_value) && empty($duration_unit)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors'); + $action = "create"; + $error++; + } - if (!$error) - { + if (!$error) { $units = GETPOST('units', 'int'); - $object->ref = $ref; - $object->label = GETPOST('label', $label_security_check); - $object->price_base_type = GETPOST('price_base_type', 'aZ09'); + $object->ref = $ref; + $object->label = GETPOST('label', $label_security_check); + $object->price_base_type = GETPOST('price_base_type', 'aZ09'); - if ($object->price_base_type == 'TTC') + if ($object->price_base_type == 'TTC') { $object->price_ttc = GETPOST('price'); - else $object->price = GETPOST('price'); - if ($object->price_base_type == 'TTC') + } else { + $object->price = GETPOST('price'); + } + if ($object->price_base_type == 'TTC') { $object->price_min_ttc = GETPOST('price_min'); - else $object->price_min = GETPOST('price_min'); + } else { + $object->price_min = GETPOST('price_min'); + } $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' @@ -247,8 +275,7 @@ if (empty($reshook)) $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes $reg = array(); - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price. $vatratecode = $reg[1]; // Get record from code @@ -258,8 +285,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; $sql .= " AND t.code = '".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -289,8 +315,7 @@ if (empty($reshook)) $stdobject->element = 'product'; $stdobject->barcode_type = GETPOST('fk_barcode_type'); $result = $stdobject->fetch_barcode(); - if ($result < 0) - { + if ($result < 0) { $error++; $mesg = 'Failed to get bar code type information '; setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors'); @@ -345,20 +370,41 @@ if (empty($reshook)) $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha'); $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha'); - if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } - if ($accountancy_code_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; } - if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; } - if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } - if ($accountancy_code_buy_intra <= 0) { $object->accountancy_code_buy_intra = ''; } else { $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; } - if ($accountancy_code_buy_export <= 0) { $object->accountancy_code_buy_export = ''; } else { $object->accountancy_code_buy_export = $accountancy_code_buy_export; } + if ($accountancy_code_sell <= 0) { + $object->accountancy_code_sell = ''; + } else { + $object->accountancy_code_sell = $accountancy_code_sell; + } + if ($accountancy_code_sell_intra <= 0) { + $object->accountancy_code_sell_intra = ''; + } else { + $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; + } + if ($accountancy_code_sell_export <= 0) { + $object->accountancy_code_sell_export = ''; + } else { + $object->accountancy_code_sell_export = $accountancy_code_sell_export; + } + if ($accountancy_code_buy <= 0) { + $object->accountancy_code_buy = ''; + } else { + $object->accountancy_code_buy = $accountancy_code_buy; + } + if ($accountancy_code_buy_intra <= 0) { + $object->accountancy_code_buy_intra = ''; + } else { + $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; + } + if ($accountancy_code_buy_export <= 0) { + $object->accountancy_code_buy_export = ''; + } else { + $object->accountancy_code_buy_export = $accountancy_code_buy_export; + } // MultiPrix - if (!empty($conf->global->PRODUIT_MULTIPRICES)) - { - for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { - if (GETPOSTISSET("price_".$i)) - { + if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { + if (GETPOSTISSET("price_".$i)) { $object->multiprices["$i"] = price2num($_POST["price_".$i], 'MU'); $object->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; } else { @@ -369,23 +415,24 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } - if (!$error) - { + if (!$error) { $id = $object->create($user); } - if ($id > 0) - { + if ($id > 0) { // Category association $categories = GETPOST('categories', 'array'); $object->setCategories($categories); - if (!empty($backtopage)) - { + if (!empty($backtopage)) { $backtopage = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation - if (preg_match('/\?/', $backtopage)) $backtopage .= '&socid='.$object->id; // Old method + if (preg_match('/\?/', $backtopage)) { + $backtopage .= '&socid='.$object->id; // Old method + } header("Location: ".$backtopage); exit; } else { @@ -393,22 +440,22 @@ if (empty($reshook)) exit; } } else { - if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors'); - else setEventMessages($langs->trans($object->error), null, 'errors'); + if (count($object->errors)) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans($object->error), null, 'errors'); + } $action = "create"; } } } // Update a product or service - if ($action == 'update' && $usercancreate) - { - if (GETPOST('cancel', 'alpha')) - { + if ($action == 'update' && $usercancreate) { + if (GETPOST('cancel', 'alpha')) { $action = ''; } else { - if ($object->id > 0) - { + if ($object->id > 0) { $object->oldcopy = clone $object; $object->ref = $ref; @@ -418,8 +465,7 @@ if (empty($reshook)) $object->description = $desc; $object->url = GETPOST('url'); - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml')); $object->note = $object->note_private; } @@ -432,9 +478,9 @@ if (empty($reshook)) $object->fk_default_warehouse = GETPOST('fk_default_warehouse'); // removed from update view so GETPOST always empty /* - $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); - $object->desiredstock = GETPOST('desiredstock'); - */ + $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); + $object->desiredstock = GETPOST('desiredstock'); + */ $object->duration_value = GETPOST('duration_value', 'int'); $object->duration_unit = GETPOST('duration_unit', 'alpha'); @@ -474,8 +520,7 @@ if (empty($reshook)) $stdobject->element = 'product'; $stdobject->barcode_type = GETPOST('fk_barcode_type'); $result = $stdobject->fetch_barcode(); - if ($result < 0) - { + if ($result < 0) { $error++; $mesg = 'Failed to get bar code type information '; setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors'); @@ -491,34 +536,64 @@ if (empty($reshook)) $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha'); $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha'); - if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } - if ($accountancy_code_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; } - if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; } - if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } - if ($accountancy_code_buy_intra <= 0) { $object->accountancy_code_buy_intra = ''; } else { $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; } - if ($accountancy_code_buy_export <= 0) { $object->accountancy_code_buy_export = ''; } else { $object->accountancy_code_buy_export = $accountancy_code_buy_export; } + if ($accountancy_code_sell <= 0) { + $object->accountancy_code_sell = ''; + } else { + $object->accountancy_code_sell = $accountancy_code_sell; + } + if ($accountancy_code_sell_intra <= 0) { + $object->accountancy_code_sell_intra = ''; + } else { + $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; + } + if ($accountancy_code_sell_export <= 0) { + $object->accountancy_code_sell_export = ''; + } else { + $object->accountancy_code_sell_export = $accountancy_code_sell_export; + } + if ($accountancy_code_buy <= 0) { + $object->accountancy_code_buy = ''; + } else { + $object->accountancy_code_buy = $accountancy_code_buy; + } + if ($accountancy_code_buy_intra <= 0) { + $object->accountancy_code_buy_intra = ''; + } else { + $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; + } + if ($accountancy_code_buy_export <= 0) { + $object->accountancy_code_buy_export = ''; + } else { + $object->accountancy_code_buy_export = $accountancy_code_buy_export; + } // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } - if (!$error && $object->check()) - { - if ($object->update($object->id, $user) > 0) - { + if (!$error && $object->check()) { + if ($object->update($object->id, $user) > 0) { // Category association $categories = GETPOST('categories', 'array'); $object->setCategories($categories); $action = 'view'; } else { - if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors'); - else setEventMessages($langs->trans($object->error), null, 'errors'); + if (count($object->errors)) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans($object->error), null, 'errors'); + } $action = 'edit'; } } else { - if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors'); - else setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors'); + if (count($object->errors)) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors'); + } $action = 'edit'; } } @@ -526,36 +601,31 @@ if (empty($reshook)) } // Action clone object - if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; } - if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) - { - if (!GETPOST('clone_content') && !GETPOST('clone_prices')) - { + if ($action == 'confirm_clone' && $confirm != 'yes') { + $action = ''; + } + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { + if (!GETPOST('clone_content') && !GETPOST('clone_prices')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { $db->begin(); $originalId = $id; - if ($object->id > 0) - { + if ($object->id > 0) { $object->ref = GETPOST('clone_ref', 'alphanohtml'); $object->status = 0; $object->status_buy = 0; $object->id = null; $object->barcode = -1; - if ($object->check()) - { + if ($object->check()) { $object->context['createfromclone'] = 'createfromclone'; $id = $object->create($user); - if ($id > 0) - { - if (GETPOST('clone_composition')) - { + if ($id > 0) { + if (GETPOST('clone_composition')) { $result = $object->clone_associations($originalId, $id); - if ($result < 1) - { + if ($result < 1) { $db->rollback(); setEventMessages($langs->trans('ErrorProductClone'), null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId); @@ -563,12 +633,10 @@ if (empty($reshook)) } } - if (GETPOST('clone_categories')) - { + if (GETPOST('clone_categories')) { $result = $object->cloneCategories($originalId, $id); - if ($result < 1) - { + if ($result < 1) { $db->rollback(); setEventMessages($langs->trans('ErrorProductClone'), null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId); @@ -597,8 +665,7 @@ if (empty($reshook)) } else { $id = $originalId; - if ($object->error == 'ErrorProductAlreadyExists') - { + if ($object->error == 'ErrorProductAlreadyExists') { $db->rollback(); $refalreadyexists++; @@ -610,8 +677,7 @@ if (empty($reshook)) $object->fetch($id); } else { $db->rollback(); - if (count($object->errors)) - { + if (count($object->errors)) { setEventMessages($object->error, $object->errors, 'errors'); dol_print_error($db, $object->errors); } else { @@ -631,13 +697,13 @@ if (empty($reshook)) } // Delete a product - if ($action == 'confirm_delete' && $confirm != 'yes') { $action = ''; } - if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) - { + if ($action == 'confirm_delete' && $confirm != 'yes') { + $action = ''; + } + if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { header('Location: '.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'&delprod='.urlencode($object->ref)); exit; } else { @@ -649,35 +715,28 @@ if (empty($reshook)) // Add product into object - if ($object->id > 0 && $action == 'addin') - { + if ($object->id > 0 && $action == 'addin') { $thirpdartyid = 0; - if (GETPOST('propalid') > 0) - { + if (GETPOST('propalid') > 0) { $propal = new Propal($db); $result = $propal->fetch(GETPOST('propalid')); - if ($result <= 0) - { + if ($result <= 0) { dol_print_error($db, $propal->error); exit; } $thirpdartyid = $propal->socid; - } elseif (GETPOST('commandeid') > 0) - { + } elseif (GETPOST('commandeid') > 0) { $commande = new Commande($db); $result = $commande->fetch(GETPOST('commandeid')); - if ($result <= 0) - { + if ($result <= 0) { dol_print_error($db, $commande->error); exit; } $thirpdartyid = $commande->socid; - } elseif (GETPOST('factureid') > 0) - { + } elseif (GETPOST('factureid') > 0) { $facture = new Facture($db); $result = $facture->fetch(GETPOST('factureid')); - if ($result <= 0) - { + if ($result <= 0) { dol_print_error($db, $facture->error); exit; } @@ -696,7 +755,9 @@ if (empty($reshook)) $tva_tx = get_default_tva($mysoc, $soc, $object->id); $tva_npr = get_default_npr($mysoc, $soc, $object->id); - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr); @@ -743,8 +804,7 @@ if (empty($reshook)) if (GETPOST('propalid') > 0) { // Define cost price for margin calculation $buyprice = 0; - if (($result = $propal->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), 2), $object->id)) < 0) - { + if (($result = $propal->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), 2), $object->id)) < 0) { dol_syslog($langs->trans('FailedToGetCostPrice')); setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors'); } else { @@ -784,8 +844,7 @@ if (empty($reshook)) } elseif (GETPOST('commandeid') > 0) { // Define cost price for margin calculation $buyprice = 0; - if (($result = $commande->defineBuyPrice($pu_ht, GETPOST('remise_percent', 2), $object->id)) < 0) - { + if (($result = $commande->defineBuyPrice($pu_ht, GETPOST('remise_percent', 2), $object->id)) < 0) { dol_syslog($langs->trans('FailedToGetCostPrice')); setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors'); } else { @@ -825,8 +884,7 @@ if (empty($reshook)) } elseif (GETPOST('factureid') > 0) { // Define cost price for margin calculation $buyprice = 0; - if (($result = $facture->defineBuyPrice($pu_ht, GETPOST('remise_percent', 2), $object->id)) < 0) - { + if (($result = $facture->defineBuyPrice($pu_ht, GETPOST('remise_percent', 2), $object->id)) < 0) { dol_syslog($langs->trans('FailedToGetCostPrice')); setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors'); } else { @@ -885,13 +943,11 @@ if (empty($reshook)) $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); -if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) -{ +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) -{ +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } @@ -902,36 +958,37 @@ $form = new Form($db); $formfile = new FormFile($db); $formproduct = new FormProduct($db); $formcompany = new FormCompany($db); -if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); +if (!empty($conf->accounting->enabled)) { + $formaccounting = new FormAccounting($db); +} // Load object modBarCodeProduct $res = 0; -if (!empty($conf->barcode->enabled) && !empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) -{ +if (!empty($conf->barcode->enabled) && !empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) { $module = strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM); $dirbarcode = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']); - foreach ($dirbarcode as $dirroot) - { + foreach ($dirbarcode as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } - if ($res > 0) - { + if ($res > 0) { $modBarCodeProduct = new $module(); } } -if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) -{ +if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (empty($object->error) && $id) - { + if (empty($object->error) && $id) { $object = new Product($db); $result = $object->fetch($id); - if ($result <= 0) dol_print_error('', $object->error); + if ($result <= 0) { + dol_print_error('', $object->error); + } } $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates $objcanvas->display_canvas($action); // Show template @@ -939,8 +996,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // ----------------------------------------- // When used in standard mode // ----------------------------------------- - if ($action == 'create' && $usercancreate) - { + if ($action == 'create' && $usercancreate) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -955,13 +1011,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Load object modCodeProduct $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); - if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') - { + if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') { $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/product/'.$module.'.php'); - if ($result > 0) - { + if ($result > 0) { $modCodeProduct = new $module(); } @@ -971,10 +1025,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print ''; print ''."\n"; - if (!empty($modCodeProduct->code_auto)) + if (!empty($modCodeProduct->code_auto)) { print ''; - if (!empty($modBarCodeProduct->code_auto)) + } + if (!empty($modBarCodeProduct->code_auto)) { print ''; + } print ''; if ($type == 1) { @@ -989,8 +1045,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // We set country_id, country_code and country for the selected country $object->country_id = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : null; - if ($object->country_id > 0) - { + if ($object->country_id > 0) { $tmparray = getCountry($object->country_id, 'all'); $object->country_code = $tmparray['code']; $object->country = $tmparray['label']; @@ -1002,10 +1057,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; $tmpcode = ''; - if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $type); + if (!empty($modCodeProduct->code_auto)) { + $tmpcode = $modCodeProduct->getNextValue($object, $type); + } print ''.$langs->trans("Ref").''; - if ($refalreadyexists) - { + if ($refalreadyexists) { print $langs->trans("RefAlreadyExists"); } print ''; @@ -1026,8 +1082,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Batch number management - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { print ''.$langs->trans("ManageLotSerial").''; $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch")); print $form->selectarray('status_batch', $statutarray, GETPOST('status_batch')); @@ -1035,24 +1090,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } $showbarcode = empty($conf->barcode->enabled) ? 0 : 1; - if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0; + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) { + $showbarcode = 0; + } - if ($showbarcode) - { - print ''.$langs->trans('BarcodeType').''; - if (GETPOSTISSET('fk_barcode_type')) { - $fk_barcode_type = GETPOST('fk_barcode_type'); + if ($showbarcode) { + print ''.$langs->trans('BarcodeType').''; + if (GETPOSTISSET('fk_barcode_type')) { + $fk_barcode_type = GETPOST('fk_barcode_type'); } else { - if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; + if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) { + $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; + } } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; $formbarcode = new FormBarCode($db); print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1); print ''; - if ($conf->browser->layout == 'phone') print ''; + if ($conf->browser->layout == 'phone') { + print ''; + } print ''.$langs->trans("BarcodeValue").''; $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) { + $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + } print ''; print ''; } @@ -1070,8 +1132,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print ''; - if ($type != 1 && !empty($conf->stock->enabled)) - { + if ($type != 1 && !empty($conf->stock->enabled)) { // Default warehouse print ''.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses(GETPOST('fk_default_warehouse'), 'fk_default_warehouse', 'warehouseopen', 1); @@ -1085,7 +1146,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''.$form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1).''; print ''; print ''; - if ($conf->browser->layout == 'phone') print ''; + if ($conf->browser->layout == 'phone') { + print ''; + } // Stock desired level print ''.$form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1).''; print ''; @@ -1096,16 +1159,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Duration - if ($type == 1) - { + if ($type == 1) { print ''.$langs->trans("Duration").''; print ''; print $formproduct->selectMeasuringUnits("duration_unit", "time", GETPOST('duration_value', 'alpha'), 0, 1); print ''; } - if ($type != 1) // Nature, Weight and volume only applies to products and not to services - { + if ($type != 1) { // Nature, Weight and volume only applies to products and not to services // Nature print ''.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).''; $statutarray = array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial")); @@ -1119,8 +1180,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Brut Length - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { print ''.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").''; print ' x '; print ' x '; @@ -1128,16 +1188,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ?GETPOST('size_units', 'alpha') : '0', 0, 2); print ''; } - if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) { // Brut Surface print ''.$langs->trans("Surface").''; print ''; print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ?GETPOST('surface_units', 'alpha') : '0', 0, 2); print ''; } - if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) - { + if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) { // Brut Volume print ''.$langs->trans("Volume").''; print ''; @@ -1145,8 +1203,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; } - if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) - { + if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) { // Net Measure print ''.$langs->trans("NetMeasure").''; print ''; @@ -1156,8 +1213,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Units - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { print ''.$langs->trans('DefaultUnitToShow').''; print ''; print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, 'units'); @@ -1165,8 +1221,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Custom code - if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) - { + if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) { print ''.$langs->trans("CustomCode").''; // Origin country @@ -1174,15 +1229,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print img_picto('', 'globe-americas', 'class="paddingrightonly"'); print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 widthcentpercentminusx'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print ''; // State - if (empty($conf->global->PRODUCT_DISABLE_STATE)) - { - if ($conf->browser->layout == 'phone') print ''; - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) - { + if (empty($conf->global->PRODUCT_DISABLE_STATE)) { + if ($conf->browser->layout == 'phone') { + print ''; + } + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) { print ''.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).''; } else { print ''.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).''; @@ -1199,8 +1256,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $parameters = array('colspan' => 3, 'cols' => '3'); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook)) - { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit', $parameters); } @@ -1228,8 +1284,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; - if (!empty($conf->global->PRODUIT_MULTIPRICES)) - { + if (!empty($conf->global->PRODUIT_MULTIPRICES)) { // We do no show price array on create when multiprices enabled. // We must set them on prices tab. print ''; @@ -1269,8 +1324,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Accountancy codes print '
'; - if (!empty($conf->accounting->enabled)) - { + if (!empty($conf->accounting->enabled)) { // Accountancy_code_sell print ''; print ''; // Accountancy_code_sell_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; print ''; print ''; // Accountancy_code_buy_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; print ''; } else // For external software { - if (!empty($accountancy_code_sell)) { $object->accountancy_code_sell = $accountancy_code_sell; } - if (!empty($accountancy_code_sell_intra)) { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; } - if (!empty($accountancy_code_sell_export)) { $object->accountancy_code_sell_export = $accountancy_code_sell_export; } - if (!empty($accountancy_code_buy)) { $object->accountancy_code_buy = $accountancy_code_buy; } - if (!empty($accountancy_code_buy_intra)) { $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; } - if (!empty($accountancy_code_buy_export)) { $object->accountancy_code_buy_export = $accountancy_code_buy_export; } + if (!empty($accountancy_code_sell)) { + $object->accountancy_code_sell = $accountancy_code_sell; + } + if (!empty($accountancy_code_sell_intra)) { + $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; + } + if (!empty($accountancy_code_sell_export)) { + $object->accountancy_code_sell_export = $accountancy_code_sell_export; + } + if (!empty($accountancy_code_buy)) { + $object->accountancy_code_buy = $accountancy_code_buy; + } + if (!empty($accountancy_code_buy_intra)) { + $object->accountancy_code_buy_intra = $accountancy_code_buy_intra; + } + if (!empty($accountancy_code_buy_export)) { + $object->accountancy_code_buy_export = $accountancy_code_buy_export; + } // Accountancy_code_sell print ''; @@ -1359,8 +1421,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Accountancy_code_sell_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; @@ -1377,8 +1438,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Accountancy_code_buy_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; @@ -1402,11 +1462,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; } elseif ($object->id > 0) { /* - * Product card - */ + * Product card + */ // Fiche en mode edition - if ($action == 'edit' && $usercancreate) - { + if ($action == 'edit' && $usercancreate) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -1421,8 +1480,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // We set country_id, country_code and country for the selected country $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id; - if ($object->country_id) - { + if ($object->country_id) { $tmparray = getCountry($object->country_id, 'all'); $object->country_code = $tmparray['code']; $object->country = $tmparray['label']; @@ -1430,7 +1488,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $type = $langs->trans('Product'); - if ($object->isService()) $type = $langs->trans('Service'); + if ($object->isService()) { + $type = $langs->trans('Service'); + } //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); // Main official, simple, and not duplicated code @@ -1457,8 +1517,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Status To sell print ''; // Batch number managment - if ($conf->productbatch->enabled) - { - if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($conf->productbatch->enabled) { + if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { print ''; } @@ -1533,32 +1594,30 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Stock - if ($object->isProduct() && !empty($conf->stock->enabled)) - { + if ($object->isProduct() && !empty($conf->stock->enabled)) { // Default warehouse print ''; /* - print "".''; + print "".''; - print ''; - */ + print ''; + */ } /* - else - { - print ''; - print ''; - }*/ - - if ($object->isService()) + else { + print ''; + print ''; + }*/ + + if ($object->isService()) { // Duration print ''; - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { // Brut Length print ''; } - if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) { // Brut Surface print ''; } - if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) - { + if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) { // Brut Volume print ''; } - if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) - { + if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) { // Net Measure print ''; print ''; // Origin country print ''; print ''; // State - if (empty($conf->global->PRODUCT_DISABLE_STATE)) - { - if ($conf->browser->layout == 'phone') print ''; - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) - { + if (empty($conf->global->PRODUCT_DISABLE_STATE)) { + if ($conf->browser->layout == 'phone') { + print ''; + } + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) { print '
'.$langs->trans("ProductAccountancySellCode").''; @@ -1283,8 +1337,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancySellIntraCode").''; if ($type == 0) { @@ -1299,8 +1352,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Accountancy_code_sell_export print '
'.$langs->trans("ProductAccountancySellExportCode").''; - if ($type == 0) - { + if ($type == 0) { $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT); } else { $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT); @@ -1311,17 +1363,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Accountancy_code_buy print '
'.$langs->trans("ProductAccountancyBuyCode").''; - if ($type == 0) { - $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT); - } else { - $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT); - } + if ($type == 0) { + $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT); + } else { + $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT); + } print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, ''); print '
'.$langs->trans("ProductAccountancyBuyIntraCode").''; if ($type == 0) { @@ -1336,8 +1387,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Accountancy_code_buy_export print '
'.$langs->trans("ProductAccountancyBuyExportCode").''; - if ($type == 0) - { + if ($type == 0) { $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT); } else { $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT); @@ -1346,12 +1396,24 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancySellCode").'
'.$langs->trans("ProductAccountancySellIntraCode").''; print '
'.$langs->trans("ProductAccountancyBuyIntraCode").''; print '
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'; print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; print '
'.$langs->trans("ManageLotSerial").''; $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch")); print $form->selectarray('status_batch', $statutarray, $object->status_batch); @@ -1496,23 +1552,28 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Barcode $showbarcode = empty($conf->barcode->enabled) ? 0 : 1; - if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0; + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) { + $showbarcode = 0; + } - if ($showbarcode) - { + if ($showbarcode) { print '
'.$langs->trans('BarcodeType').''; if (GETPOSTISSET('fk_barcode_type')) { - $fk_barcode_type = GETPOST('fk_barcode_type'); + $fk_barcode_type = GETPOST('fk_barcode_type'); } else { $fk_barcode_type = $object->barcode_type; - if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; + if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) { + $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; + } } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; $formbarcode = new FormBarCode($db); print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1); print ''.$langs->trans("BarcodeValue").''; $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) { + $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + } print ''; print '
'.$langs->trans("DefaultWarehouse").''; print $formproduct->selectWarehouses($object->fk_default_warehouse, 'fk_default_warehouse', 'warehouseopen', 1); print ' '; print '
'.$langs->trans("StockLimit").''; - print ''; - print '
'.$langs->trans("StockLimit").''; + print ''; + print ''.$langs->trans("DesiredStock").''; - print ''; - print '
'.$langs->trans("DesiredStock").''; + print ''; + print '
'.$langs->trans("Duration").''; print ' '; @@ -1576,8 +1635,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2); print '
'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").''; print 'x'; @@ -1586,16 +1644,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $formproduct->selectMeasuringUnits("size_units", "size", $object->length_units, 0, 2); print '
'.$langs->trans("Surface").''; print ' '; print $formproduct->selectMeasuringUnits("surface_units", "surface", $object->surface_units, 0, 2); print '
'.$langs->trans("Volume").''; print ' '; @@ -1603,8 +1659,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("NetMeasure").''; print ' '; @@ -1613,8 +1668,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } } // Units - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { print '
'.$langs->trans('DefaultUnitToShow').''; print $form->selectUnits($object->fk_unit, 'units'); @@ -1622,22 +1676,23 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Custom code - if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) - { + if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) { print '
'.$langs->trans("CustomCode").'
'.$langs->trans("CountryOrigin").''; print img_picto('', 'globe-americas', 'class="paddingrightonly"'); print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print '
'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).''; } else { print ''.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).''; @@ -1653,14 +1708,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $parameters = array('colspan' => ' colspan="3"', 'cols' => 3); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook)) - { + if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit', $parameters); } // Tags-Categories - if ($conf->categorie->enabled) - { + if ($conf->categorie->enabled) { print '
'.$langs->trans("Categories").''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1); $c = new Categorie($db); @@ -1676,8 +1729,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Note private - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { print '
'.$langs->trans("NoteNotVisibleOnBill").''; $doleditor = new DolEditor('note_private', $object->note_private, '', 140, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%'); @@ -1692,8 +1744,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; - if (!empty($conf->accounting->enabled)) - { + if (!empty($conf->accounting->enabled)) { // Accountancy_code_sell print ''; print ''; // Accountancy_code_sell_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; // Accountancy_code_buy_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; // Accountancy_code_sell_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; @@ -1761,8 +1809,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Accountancy_code_buy_intra - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; print ''; @@ -1787,7 +1834,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } else { // Fiche en mode visu $showbarcode = empty($conf->barcode->enabled) ? 0 : 1; - if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0; + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) { + $showbarcode = 0; + } $head = product_prepare_head($object); $titre = $langs->trans("CardProduct".$object->type); @@ -1799,7 +1848,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $object->next_prev_filter = " fk_product_type = ".$object->type; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -1811,8 +1862,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancySellCode").''; @@ -1701,8 +1752,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancySellIntraCode").''; print $formaccounting->select_account($object->accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, '', 1, 1); @@ -1722,8 +1772,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancyBuyIntraCode").''; print $formaccounting->select_account($object->accountancy_code_buy_intra, 'accountancy_code_buy_intra', 1, '', 1, 1); @@ -1743,8 +1792,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ProductAccountancySellIntraCode").''; print '
'.$langs->trans("ProductAccountancyBuyIntraCode").''; print '
'; // Type - if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) - { + if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) { $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); print ''; } - if ($showbarcode) - { + if ($showbarcode) { // Barcode type print ''; // Accountancy sell code intra-community - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; // Accountancy buy code intra-community - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { print ''; // Batch number management (to batch) - if (!empty($conf->productbatch->enabled)) - { - if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if (!empty($conf->productbatch->enabled)) { + if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { print ''; // Default warehouse - if ($object->isProduct() && !empty($conf->stock->enabled)) - { + if ($object->isProduct() && !empty($conf->stock->enabled)) { $warehouse = new Entrepot($db); $warehouse->fetch($object->fk_default_warehouse); @@ -2045,15 +2080,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print '
'; print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat) : $langs->trans('Type'); @@ -1821,25 +1871,24 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print ''; - if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) print ''; + if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) { + print ''; + } print '
'; print $langs->trans("BarcodeType"); print 'id.'">'.img_edit($langs->trans('Edit'), 1).'id.'">'.img_edit($langs->trans('Edit'), 1).'
'; print '
'; - if ($action == 'editbarcodetype' || $action == 'editbarcode') - { + if ($action == 'editbarcodetype' || $action == 'editbarcode') { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; $formbarcode = new FormBarCode($db); } $fk_barcode_type=''; - if ($action == 'editbarcodetype') - { + if ($action == 'editbarcodetype') { print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type'); $fk_barcode_type = $object->barcode_type; } else { @@ -1854,13 +1903,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; - if (($action != 'editbarcode') && $usercancreate && $createbarcode) print ''; + if (($action != 'editbarcode') && $usercancreate && $createbarcode) { + print ''; + } print '
'; print $langs->trans("BarcodeValue"); print 'id.'">'.img_edit($langs->trans('Edit'), 1).'id.'">'.img_edit($langs->trans('Edit'), 1).'
'; print '
'; - if ($action == 'editbarcode') - { + if ($action == 'editbarcode') { $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode; - if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) { + $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type); + } print '
'; print ''; @@ -1879,10 +1931,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancySellCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_sell)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_sell)) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch('', $object->accountancy_code_sell, 1); @@ -1894,15 +1944,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancySellIntraCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_sell_intra)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_sell_intra)) { $accountingaccount2 = new AccountingAccount($db); $accountingaccount2->fetch('', $object->accountancy_code_sell_intra, 1); @@ -1918,10 +1965,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancySellExportCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_sell_export)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_sell_export)) { $accountingaccount3 = new AccountingAccount($db); $accountingaccount3->fetch('', $object->accountancy_code_sell_export, 1); @@ -1936,10 +1981,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancyBuyCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_buy)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_buy)) { $accountingaccount4 = new AccountingAccount($db); $accountingaccount4->fetch('', $object->accountancy_code_buy, 1); @@ -1951,15 +1994,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancyBuyIntraCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_buy_intra)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_buy_intra)) { $accountingaccount5 = new AccountingAccount($db); $accountingaccount5->fetch('', $object->accountancy_code_buy_intra, 1); @@ -1975,10 +2015,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; print $langs->trans("ProductAccountancyBuyExportCode"); print ''; - if (!empty($conf->accounting->enabled)) - { - if (!empty($object->accountancy_code_buy_export)) - { + if (!empty($conf->accounting->enabled)) { + if (!empty($object->accountancy_code_buy_export)) { $accountingaccount6 = new AccountingAccount($db); $accountingaccount6->fetch('', $object->accountancy_code_buy_export, 1); @@ -1990,10 +2028,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'.$langs->trans("ManageLotSerial").''; if (!empty($conf->use_javascript_ajax) && $usercancreate && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { print ajax_object_onoff($object, 'status_batch', 'tobatch', 'ProductStatusOnBatch', 'ProductStatusNotOnBatch'); @@ -2013,8 +2049,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; - if ($object->isService()) - { + if ($object->isService()) { // Duration print '\n"; - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { // Brut Length print '\n"; } - if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) - { + if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) { // Brut Surface print '\n"; } - if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) - { + if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) { // Brut Volume print '\n"; } - if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) - { + if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) { // Net Measure print ''; // Origin country code print ''; } @@ -2163,8 +2190,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Note private - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { print ' '."\n"; print ''."\n"; print ' '."\n"; @@ -2178,40 +2204,37 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print dol_get_fiche_end(); } - } elseif ($action != 'create') - { + } elseif ($action != 'create') { exit; } } // Load object modCodeProduct $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); -if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') -{ +if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') { $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/product/'.$module.'.php'); -if ($result > 0) -{ +if ($result > 0) { $modCodeProduct = new $module(); } $tmpcode = ''; -if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $object->type); +if (!empty($modCodeProduct->code_auto)) { + $tmpcode = $modCodeProduct->getNextValue($object, $object->type); +} $formconfirm = ''; // Confirm delete product if (($action == 'delete' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js - || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js -{ + || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js $formconfirm = $form->formconfirm("card.php?id=".$object->id, $langs->trans("DeleteProduct"), $langs->trans("ConfirmDeleteProduct"), "confirm_delete", '', 0, "action-delete"); } // Clone confirmation if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js - || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js -{ + || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js // Define confirmation messages $formquestionclone = array( 'text' => $langs->trans("ConfirmClone"), @@ -2222,8 +2245,7 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->d if (!empty($conf->global->PRODUIT_MULTIPRICES)) { $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0); } - if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) - { + if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) { $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1); } @@ -2233,8 +2255,11 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->d // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'object' => $object); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; -elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} // Print form confirm print $formconfirm; @@ -2244,22 +2269,19 @@ print $formconfirm; /* Barre d'action */ /* */ /* ************************************************************************** */ -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print "\n".'
'."\n"; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) - { - if ($usercancreate) - { - if (!isset($object->no_button_edit) || $object->no_button_edit <> 1) print 'id.'">'.$langs->trans("Modify").''; + if (empty($reshook)) { + if ($usercancreate) { + if (!isset($object->no_button_edit) || $object->no_button_edit <> 1) { + print 'id.'">'.$langs->trans("Modify").''; + } - if (!isset($object->no_button_copy) || $object->no_button_copy <> 1) - { - if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) - { + if (!isset($object->no_button_copy) || $object->no_button_copy <> 1) { + if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) { print ''.$langs->trans('ToClone').''."\n"; } else { print 'id.'">'.$langs->trans("ToClone").''; @@ -2268,12 +2290,9 @@ if ($action != 'create' && $action != 'edit') } $object_is_used = $object->isObjectUsed($object->id); - if ($usercandelete) - { - if (empty($object_is_used) && (!isset($object->no_button_delete) || $object->no_button_delete <> 1)) - { - if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) - { + if ($usercandelete) { + if (empty($object_is_used) && (!isset($object->no_button_delete) || $object->no_button_delete <> 1)) { + if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) { print ''.$langs->trans('Delete').''."\n"; } else { print 'id.'">'.$langs->trans("Delete").''; @@ -2293,23 +2312,20 @@ if ($action != 'create' && $action != 'edit') * All the "Add to" areas */ -if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status) -{ +if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status) { //Variable used to check if any text is going to be printed $html = ''; //print '
'; // Propals - if (!empty($conf->propal->enabled) && $user->rights->propale->creer) - { + if (!empty($conf->propal->enabled) && $user->rights->propale->creer) { $propal = new Propal($db); $langs->load("propal"); $otherprop = $propal->liste_array(2, 1, 0); - if (is_array($otherprop) && count($otherprop)) - { + if (is_array($otherprop) && count($otherprop)) { $html .= '
'; } - foreach ($filearray as $filetoadd) - { - if ($ext = pathinfo($filetoadd['name'], PATHINFO_EXTENSION) == 'pdf') - { + foreach ($filearray as $filetoadd) { + if ($ext = pathinfo($filetoadd['name'], PATHINFO_EXTENSION) == 'pdf') { $checked = ''; $filename = $filetoadd['name']; - if ($conf->global->MAIN_MULTILANGS) - { - if (array_key_exists($filetoadd['name'].'_'.$default_lang, $filetomerge->lines)) - { + if ($conf->global->MAIN_MULTILANGS) { + if (array_key_exists($filetoadd['name'].'_'.$default_lang, $filetomerge->lines)) { $filename = $filetoadd['name'].' - '.$langs->trans('Language_'.$default_lang); $checked = ' checked '; } } else { - if (array_key_exists($filetoadd['name'], $filetomerge->lines)) - { + if (array_key_exists($filetoadd['name'], $filetomerge->lines)) { $checked = ' checked '; } } diff --git a/htdocs/product/dynamic_price/class/price_expression.class.php b/htdocs/product/dynamic_price/class/price_expression.class.php index 218780cce44..ce213222bb9 100644 --- a/htdocs/product/dynamic_price/class/price_expression.class.php +++ b/htdocs/product/dynamic_price/class/price_expression.class.php @@ -80,8 +80,12 @@ class PriceExpression $error = 0; // Clean parameters - if (isset($this->title)) $this->title = trim($this->title); - if (isset($this->expression)) $this->expression = trim($this->expression); + if (isset($this->title)) { + $this->title = trim($this->title); + } + if (isset($this->expression)) { + $this->expression = trim($this->expression); + } // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; @@ -95,10 +99,11 @@ class PriceExpression dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { + if (!$error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); //if (! $notrigger) @@ -114,10 +119,8 @@ class PriceExpression } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -139,8 +142,7 @@ class PriceExpression public function fetch($id) { // Check parameters - if (empty($id)) - { + if (empty($id)) { $this->error = 'ErrorWrongParameters'; return -1; } @@ -151,11 +153,9 @@ class PriceExpression dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->id = $id; $this->title = $obj->title; $this->expression = $obj->expression; @@ -184,12 +184,10 @@ class PriceExpression dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { $price_expression_obj = new PriceExpression($this->db); $price_expression_obj->id = $record["rowid"]; $price_expression_obj->title = $record["title"]; @@ -222,11 +220,9 @@ class PriceExpression dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { return (int) $obj->rowid; } else { return 0; @@ -250,8 +246,12 @@ class PriceExpression $error = 0; // Clean parameters - if (isset($this->title)) $this->title = trim($this->title); - if (isset($this->expression)) $this->expression = trim($this->expression); + if (isset($this->title)) { + $this->title = trim($this->title); + } + if (isset($this->expression)) { + $this->expression = trim($this->expression); + } // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; @@ -263,7 +263,9 @@ class PriceExpression dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // if (! $error) // { @@ -280,10 +282,8 @@ class PriceExpression // } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -325,21 +325,20 @@ class PriceExpression // } //} - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql .= " WHERE rowid = ".$rowid; dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } diff --git a/htdocs/product/dynamic_price/class/price_global_variable.class.php b/htdocs/product/dynamic_price/class/price_global_variable.class.php index fbe5956db7c..4e67b835b07 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable.class.php @@ -100,14 +100,14 @@ class PriceGlobalVariable dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { + if (!$error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - if (!$notrigger) - { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. @@ -119,10 +119,8 @@ class PriceGlobalVariable } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -149,11 +147,9 @@ class PriceGlobalVariable dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->id = $id; $this->code = $obj->code; $this->description = $obj->description; @@ -193,7 +189,9 @@ class PriceGlobalVariable dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // if (! $error) // { @@ -210,10 +208,8 @@ class PriceGlobalVariable // } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -240,10 +236,8 @@ class PriceGlobalVariable $this->db->begin(); - if (!$error) - { - if (!$notrigger) - { + if (!$error) { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. @@ -254,21 +248,20 @@ class PriceGlobalVariable } } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql .= " WHERE rowid = ".$rowid; dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -302,11 +295,17 @@ class PriceGlobalVariable public function checkParameters() { // Clean parameters - if (isset($this->code)) $this->code = trim($this->code); - if (isset($this->description)) $this->description = trim($this->description); + if (isset($this->code)) { + $this->code = trim($this->code); + } + if (isset($this->description)) { + $this->description = trim($this->description); + } // Check parameters - if (empty($this->value) || !is_numeric($this->value)) $this->value = 0; + if (empty($this->value) || !is_numeric($this->value)) { + $this->value = 0; + } } /** @@ -322,12 +321,10 @@ class PriceGlobalVariable dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { $variable_obj = new PriceGlobalVariable($this->db); $variable_obj->id = $record["rowid"]; $variable_obj->code = $record["code"]; diff --git a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php index 256e3525ead..eb72a8425f7 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php @@ -116,14 +116,14 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { + if (!$error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - if (!$notrigger) - { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. @@ -135,10 +135,8 @@ class PriceGlobalVariableUpdater } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -165,11 +163,9 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->id = $id; $this->type = $obj->type; $this->description = $obj->description; @@ -217,7 +213,9 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // if (! $error) // { @@ -234,10 +232,8 @@ class PriceGlobalVariableUpdater // } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -277,21 +273,20 @@ class PriceGlobalVariableUpdater // } //} - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql .= " WHERE rowid = ".$rowid; dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -345,15 +340,28 @@ class PriceGlobalVariableUpdater public function checkParameters() { // Clean parameters - if (isset($this->description)) $this->description = trim($this->description); - if (isset($this->parameters)) $this->parameters = trim($this->parameters); - else $this->parameters = ""; - if (isset($this->last_status)) $this->last_status = trim($this->last_status); + if (isset($this->description)) { + $this->description = trim($this->description); + } + if (isset($this->parameters)) { + $this->parameters = trim($this->parameters); + } else { + $this->parameters = ""; + } + if (isset($this->last_status)) { + $this->last_status = trim($this->last_status); + } // Check parameters - if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type = 0; - if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval = $this->update_min; - if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update = 0; + if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) { + $this->type = 0; + } + if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) { + $this->update_interval = $this->update_min; + } + if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) { + $this->next_update = 0; + } } /** @@ -368,12 +376,10 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { $updater_obj = new PriceGlobalVariableUpdater($this->db); $updater_obj->id = $record["rowid"]; $updater_obj->type = $record["type"]; @@ -408,12 +414,10 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { $updater_obj = new PriceGlobalVariableUpdater($this->db); $updater_obj->id = $record["rowid"]; $updater_obj->type = $record["type"]; @@ -572,13 +576,13 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -616,13 +620,13 @@ class PriceGlobalVariableUpdater dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index 47cb58c2a7f..3d28f4b6011 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -64,53 +64,49 @@ class PriceParser global $langs; $langs->load("errors"); /* - -No arg - 9, an unexpected error occured - 14, division by zero - 19, expression not found - 20, empty expression + -No arg + 9, an unexpected error occured + 14, division by zero + 19, expression not found + 20, empty expression - -1 Arg - 1, cannot assign to constant '%s' - 2, cannot redefine built-in function '%s' - 3, undefined variable '%s' in function definition - 4, illegal character '%s' - 5, unexpected '%s' - 8, unexpected operator '%s' - 10, operator '%s' lacks operand - 11, expecting '%s' - 17, undefined variable '%s' - 21, empty result '%s' - 22, negative result '%s' - 24, variable '%s' exists but has no value + -1 Arg + 1, cannot assign to constant '%s' + 2, cannot redefine built-in function '%s' + 3, undefined variable '%s' in function definition + 4, illegal character '%s' + 5, unexpected '%s' + 8, unexpected operator '%s' + 10, operator '%s' lacks operand + 11, expecting '%s' + 17, undefined variable '%s' + 21, empty result '%s' + 22, negative result '%s' + 24, variable '%s' exists but has no value - -2 Args - 6, wrong number of arguments (%s given, %s expected) - 23, unknown or non set variable '%s' after %s + -2 Args + 6, wrong number of arguments (%s given, %s expected) + 23, unknown or non set variable '%s' after %s - -internal errors - 7, internal error - 12, internal error - 13, internal error - 15, internal error - 16, internal error - 18, internal error - */ + -internal errors + 7, internal error + 12, internal error + 13, internal error + 15, internal error + 16, internal error + 18, internal error + */ if (empty($this->error_parser)) { return $langs->trans("ErrorPriceExpressionUnknown", 0); //this is not supposed to happen } list($code, $info) = $this->error_parser; - if (in_array($code, array(9, 14, 19, 20))) //Errors which have 0 arg - { + if (in_array($code, array(9, 14, 19, 20))) { //Errors which have 0 arg return $langs->trans("ErrorPriceExpression".$code); - } elseif (in_array($code, array(1, 2, 3, 4, 5, 8, 10, 11, 17, 21, 22))) //Errors which have 1 arg - { + } elseif (in_array($code, array(1, 2, 3, 4, 5, 8, 10, 11, 17, 21, 22))) { //Errors which have 1 arg return $langs->trans("ErrorPriceExpression".$code, $info); - } elseif (in_array($code, array(6, 23))) //Errors which have 2 args - { + } elseif (in_array($code, array(6, 23))) { //Errors which have 2 args return $langs->trans("ErrorPriceExpression".$code, $info[0], $info[1]); - } elseif (in_array($code, array(7, 12, 13, 15, 16, 18))) //Internal errors - { + } elseif (in_array($code, array(7, 12, 13, 15, 16, 18))) { //Internal errors return $langs->trans("ErrorPriceExpressionInternal", $code); } else //Unknown errors { @@ -140,8 +136,7 @@ class PriceParser } //Check if empty $expression = trim($expression); - if (empty($expression)) - { + if (empty($expression)) { $this->error_parser = array(20, null); return -2; } @@ -161,10 +156,8 @@ class PriceParser $extrafields = new ExtraFields($this->db); $extrafields->fetch_name_optionals_label('product', true); $product->fetch_optionals(); - if (is_array($extrafields->attributes[$product->table_element]['label'])) - { - foreach ($extrafields->attributes[$product->table_element]['label'] as $key=>$label) - { + if (is_array($extrafields->attributes[$product->table_element]['label'])) { + foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { $values["extrafield_".$key] = $product->array_options['options_'.$key]; } } @@ -182,8 +175,7 @@ class PriceParser //Get all global values $price_globals = new PriceGlobalVariable($this->db); - foreach ($price_globals->listGlobalVariables() as $entry) - { + foreach ($price_globals->listGlobalVariables() as $entry) { $values["global_".$entry->code] = $entry->value; } @@ -198,8 +190,7 @@ class PriceParser //Fill each variable in expression from values $expression = str_replace("\n", $this->separator_chr, $expression); - foreach ($values as $key => $value) - { + foreach ($values as $key => $value) { if ($value === null && strpos($expression, $key) !== false) { $this->error_parser = array(24, $key); return -7; @@ -208,11 +199,12 @@ class PriceParser } //Check if there is unfilled variable - if (strpos($expression, $this->special_chr) !== false) - { + if (strpos($expression, $this->special_chr) !== false) { $data = explode($this->special_chr, $expression); $variable = $this->special_chr.$data[1]; - if (isset($data[2])) $variable .= $this->special_chr; + if (isset($data[2])) { + $variable .= $this->special_chr; + } $this->error_parser = array(23, array($variable, $expression)); return -6; } @@ -222,8 +214,7 @@ class PriceParser $expressions = array_slice($expressions, 0, $this->limit); foreach ($expressions as $expr) { $expr = trim($expr); - if (!empty($expr)) - { + if (!empty($expr)) { $last_result = $em->evaluate($expr); $this->error_parser = $em->last_error_code; if ($this->error_parser !== null) { //$em->last_error_code is null if no error happened, so just check if error_parser is not null @@ -236,13 +227,11 @@ class PriceParser if (empty($vars["price"])) { $vars["price"] = $last_result; } - if (!isset($vars["price"])) - { + if (!isset($vars["price"])) { $this->error_parser = array(21, $expression); return -4; } - if ($vars["price"] < 0) - { + if ($vars["price"] < 0) { $this->error_parser = array(22, $expression); return -5; } @@ -305,8 +294,7 @@ class PriceParser //Get the expression from db $price_expression = new PriceExpression($this->db); $res = $price_expression->fetch($product_supplier->fk_supplier_price_expression); - if ($res < 1) - { + if ($res < 1) { $this->error_parser = array(19, null); return -1; } diff --git a/htdocs/product/dynamic_price/editor.php b/htdocs/product/dynamic_price/editor.php index 24f4856698f..418a71166a8 100644 --- a/htdocs/product/dynamic_price/editor.php +++ b/htdocs/product/dynamic_price/editor.php @@ -51,11 +51,9 @@ $price_expression = new PriceExpression($db); $price_globals = new PriceGlobalVariable($db); //Fetch expression data -if (empty($eid)) //This also disables fetch when eid == 0 -{ +if (empty($eid)) { //This also disables fetch when eid == 0 $eid = 0; -} elseif ($action != 'delete') -{ +} elseif ($action != 'delete') { $price_expression->fetch($eid); } @@ -64,13 +62,10 @@ if (empty($eid)) //This also disables fetch when eid == 0 * Actions */ -if ($action == 'add') -{ - if ($eid == 0) - { +if ($action == 'add') { + if ($eid == 0) { $result = $price_expression->find_title($title); - if ($result == 0) //No existing entry found with title, ok - { + if ($result == 0) { //No existing entry found with title, ok //Check the expression validity by parsing it $priceparser = new PriceParser($db); $price_result = $priceparser->testExpression($id, $expression); @@ -80,16 +75,14 @@ if ($action == 'add') $price_expression->title = $title; $price_expression->expression = $expression; $result = $price_expression->create($user); - if ($result > 0) //created successfully, set the eid to newly created entry - { + if ($result > 0) { //created successfully, set the eid to newly created entry $eid = $price_expression->id; setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); } else { setEventMessages("add: ".$price_expression->error, $price_expression->errors, 'errors'); } } - } elseif ($result < 0) - { + } elseif ($result < 0) { setEventMessages("add find: ".$price_expression->error, $price_expression->errors, 'errors'); } else { setEventMessages($langs->trans("ErrorRecordAlreadyExists"), null, 'errors'); @@ -97,13 +90,10 @@ if ($action == 'add') } } -if ($action == 'update') -{ - if ($eid != 0) - { +if ($action == 'update') { + if ($eid != 0) { $result = $price_expression->find_title($title); - if ($result == 0 || $result == $eid) //No existing entry found with title or existing one is the current one, ok - { + if ($result == 0 || $result == $eid) { //No existing entry found with title or existing one is the current one, ok //Check the expression validity by parsing it $priceparser = new PriceParser($db); $price_result = $priceparser->testExpression($id, $expression); @@ -114,15 +104,13 @@ if ($action == 'update') $price_expression->title = $title; $price_expression->expression = $expression; $result = $price_expression->update($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages("update: ".$price_expression->error, $price_expression->errors, 'errors'); } else { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); } } - } elseif ($result < 0) - { + } elseif ($result < 0) { setEventMessages("update find: ".$price_expression->error, $price_expression->errors, 'errors'); } else { setEventMessages($langs->trans("ErrorRecordAlreadyExists"), null, 'errors'); @@ -130,14 +118,11 @@ if ($action == 'update') } } -if ($action == 'delete') -{ - if ($eid != 0) - { +if ($action == 'delete') { + if ($eid != 0) { $price_expression->fetch($eid); $result = $price_expression->delete($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages("delete: ".$price_expression->error, $price_expression->errors, 'errors'); } $eid = 0; @@ -202,8 +187,7 @@ print dol_get_fiche_end(); print '
'; print ''; print ''.$langs->trans("Back").''; -if ($eid == 0) -{ +if ($eid == 0) { print '
'.$langs->trans('Delete').'
'."\n"; } else { print ''; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index d0e7ee279e2..9a4518f509e 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -40,7 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; -if (!empty($conf->barcode->enabled)) dol_include_once('/core/class/html.formbarcode.class.php'); +if (!empty($conf->barcode->enabled)) { + dol_include_once('/core/class/html.formbarcode.class.php'); +} // Load translation files required by the page $langs->loadLangs(array('products', 'suppliers', 'bills', 'margins', 'stocks')); @@ -59,8 +61,7 @@ $error = 0; $extrafields = new ExtraFields($db); // If socid provided by ajax company selector -if (!empty($_REQUEST['search_fourn_id'])) -{ +if (!empty($_REQUEST['search_fourn_id'])) { $_GET['id_fourn'] = $_GET['search_fourn_id']; $_POST['id_fourn'] = $_POST['search_fourn_id']; $_REQUEST['id_fourn'] = $_REQUEST['search_fourn_id']; @@ -69,62 +70,75 @@ if (!empty($_REQUEST['search_fourn_id'])) // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); -if (empty($user->rights->fournisseur->lire)) accessforbidden(); +if (empty($user->rights->fournisseur->lire)) { + accessforbidden(); +} $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = "s.nom"; -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "s.nom"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('pricesuppliercard', 'globalcard')); $object = new ProductFournisseur($db); -if ($id > 0 || $ref) -{ +if ($id > 0 || $ref) { $object->fetch($id, $ref); } $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (!$sortfield) $sortfield = "s.nom"; -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "s.nom"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} /* * Actions */ -if ($cancel) $action = ''; +if ($cancel) { + $action = ''; +} $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire)); $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)); $parameters = array('socid'=>$socid, 'id_prod'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if ($action == 'setcost_price') - { - if ($id) - { +if (empty($reshook)) { + if ($action == 'setcost_price') { + if ($id) { $result = $object->fetch($id); $object->cost_price = price2num($cost_price); $result = $object->update($object->id, $user); - if ($result > 0) - { + if ($result > 0) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $action = ''; } else { @@ -134,10 +148,8 @@ if (empty($reshook)) } } - if ($action == 'confirm_remove_pf') - { - if ($rowid) // id of product supplier price to remove - { + if ($action == 'confirm_remove_pf') { + if ($rowid) { // id of product supplier price to remove $action = ''; $result = $object->remove_product_fournisseur_price($rowid); if ($result > 0) { @@ -150,14 +162,19 @@ if (empty($reshook)) } } - if ($action == 'save_price') - { + if ($action == 'save_price') { $id_fourn = GETPOST("id_fourn"); - if (empty($id_fourn)) $id_fourn = GETPOST("search_id_fourn"); + if (empty($id_fourn)) { + $id_fourn = GETPOST("search_id_fourn"); + } $ref_fourn = GETPOST("ref_fourn"); - if (empty($ref_fourn)) $ref_fourn = GETPOST("search_ref_fourn"); + if (empty($ref_fourn)) { + $ref_fourn = GETPOST("search_ref_fourn"); + } $ref_fourn_old = GETPOST("ref_fourn_old"); - if (empty($ref_fourn_old)) $ref_fourn_old = $ref_fourn; + if (empty($ref_fourn_old)) { + $ref_fourn_old = $ref_fourn; + } $quantity = price2num(GETPOST("qty", 'nohtml'), 'MS'); $remise_percent = price2num(GETPOST('remise_percent', 'alpha')); @@ -175,40 +192,33 @@ if (empty($reshook)) $fk_barcode_type = GETPOST('fk_barcode_type', 'int'); $packaging = price2num(GETPOST("packaging", 'alphanohtml'), 'MS'); - if ($tva_tx == '') - { + if ($tva_tx == '') { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors'); } - if (!is_numeric($tva_tx)) - { + if (!is_numeric($tva_tx)) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors'); } - if (empty($quantity)) - { + if (empty($quantity)) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Qty")), null, 'errors'); } - if (empty($ref_fourn)) - { + if (empty($ref_fourn)) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefSupplier")), null, 'errors'); } - if ($id_fourn <= 0) - { + if ($id_fourn <= 0) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Supplier")), null, 'errors'); } - if (price2num($_POST["price"]) < 0 || $_POST["price"] == '') - { - if ($price_expression === '') // Return error of missing price only if price_expression not set - { + if (price2num($_POST["price"]) < 0 || $_POST["price"] == '') { + if ($price_expression === '') { // Return error of missing price only if price_expression not set $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Price")), null, 'errors'); @@ -234,30 +244,25 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { $db->begin(); - if (!$error) - { + if (!$error) { $ret = $object->add_fournisseur($user, $id_fourn, $ref_fourn_old, $quantity); // This insert record with no value for price. Values are update later with update_buyprice - if ($ret == -3) - { + if ($ret == -3) { $error++; $object->fetch($object->product_id_already_linked); $productLink = $object->getNomUrl(1, 'supplier'); setEventMessages($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct", $productLink), null, 'errors'); - } elseif ($ret < 0) - { + } elseif ($ret < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } } - if (!$error) - { + if (!$error) { $supplier = new Fournisseur($db); $result = $supplier->fetch($id_fourn); if (GETPOSTISSET('ref_fourn_price_id')) { @@ -294,12 +299,15 @@ if (empty($reshook)) $newprice = price2num(GETPOST("price", "alpha")); - if (empty($packaging)) $packaging = 1; - if ($packaging < $quantity) $packaging = $quantity; + if (empty($packaging)) { + $packaging = 1; + } + if ($packaging < $quantity) { + $packaging = $quantity; + } $object->packaging = $packaging; - if (!empty($conf->multicurrency->enabled)) - { + if (!empty($conf->multicurrency->enabled)) { $multicurrency_tx = price2num(GETPOST("multicurrency_tx", 'alpha')); $multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha')); $multicurrency_code = GETPOST("multicurrency_code", 'alpha'); @@ -308,13 +316,11 @@ if (empty($reshook)) } else { $ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type); } - if ($ret < 0) - { + if ($ret < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } else { - if (!empty($conf->dynamicprices->enabled) && $price_expression !== '') - { + if (!empty($conf->dynamicprices->enabled) && $price_expression !== '') { //Check the expression validity by parsing it $priceparser = new PriceParser($db); $object->fk_supplier_price_expression = $price_expression; @@ -324,12 +330,10 @@ if (empty($reshook)) setEventMessages($priceparser->translatedError(), null, 'errors'); } } - if (!$error && !empty($conf->dynamicprices->enabled)) - { + if (!$error && !empty($conf->dynamicprices->enabled)) { //Set the price expression for this supplier price $ret = $object->setSupplierPriceExpression($price_expression); - if ($ret < 0) - { + if ($ret < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } @@ -337,8 +341,7 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { $db->commit(); $action = ''; } else { @@ -358,13 +361,11 @@ if (empty($reshook)) $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); -if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) -{ +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('BuyingPrices'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) -{ +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('BuyingPrices'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } @@ -373,18 +374,15 @@ llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'classforhorizontalscrollo $form = new Form($db); -if ($id > 0 || $ref) -{ - if ($result) - { +if ($id > 0 || $ref) { + if ($result) { if ($action == 'ask_remove_pf') { $form = new Form($db); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&rowid='.$rowid, $langs->trans('DeleteProductBuyPrice'), $langs->trans('ConfirmDeleteProductBuyPrice'), 'confirm_remove_pf', '', 0, 1); echo $formconfirm; } - if ($action <> 'edit' && $action <> 're-edit') - { + if ($action <> 'edit' && $action <> 're-edit') { $head = product_prepare_head($object); $titre = $langs->trans("CardProduct".$object->type); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -395,7 +393,9 @@ if ($id > 0 || $ref) $object->next_prev_filter = " fk_product_type = ".$object->type; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -417,7 +417,9 @@ if ($id > 0 || $ref) // PMP print '
'; print ''; print ''; @@ -425,10 +427,12 @@ if ($id > 0 || $ref) print ''; print ''; @@ -441,12 +445,10 @@ if ($id > 0 || $ref) // Form to add or update a price - if (($action == 'add_price' || $action == 'update_price') && $usercancreate) - { + if (($action == 'add_price' || $action == 'update_price') && $usercancreate) { $langs->load("suppliers"); - if ($rowid) - { + if ($rowid) { $object->fetch_product_fournisseur_price($rowid, 1); //Ignore the math expression when getting the price print load_fiche_titre($langs->trans("ChangeSupplierPrice")); } else { @@ -463,8 +465,7 @@ if ($id > 0 || $ref) // Supplier print ''; // Availability - if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) - { + if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) { $langs->load("propal"); print ''; print ''; print ''; - if (!empty($conf->dynamicprices->enabled)) //Only show price mode and expression selector if module is enabled - { + if (!empty($conf->dynamicprices->enabled)) { //Only show price mode and expression selector if module is enabled // Price mode selector print ''; print ''; // Barcode - if (!empty($conf->barcode->enabled)) - { + if (!empty($conf->barcode->enabled)) { // Option to define a transport cost on supplier price print ''; print ''; @@ -743,10 +739,8 @@ END; } // Option to define a transport cost on supplier price - if ($conf->global->PRODUCT_CHARGES) - { - if (!empty($conf->margin->enabled)) - { + if ($conf->global->PRODUCT_CHARGES) { + if (!empty($conf->margin->enabled)) { print ''; print ''; print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>'; - if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); - else print $langs->trans($value); + if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) { + print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); + } else { + print $langs->trans($value); + } print ''; } } @@ -801,11 +799,16 @@ END; $obj = $db->fetch_object($resql); foreach ($extralabels as $key => $value) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); + if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) { + $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); + } print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>'; - if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); - else print $langs->trans($value); + if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) { + print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); + } else { + print $langs->trans($value); + } print ''; @@ -816,8 +819,7 @@ END; } } - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); print $hookmanager->resPrint; @@ -840,14 +842,11 @@ END; print "\n
\n"; - if ($action != 'add_price' && $action != 'update_price') - { + if ($action != 'add_price' && $action != 'update_price') { $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) - { - if ($usercancreate) - { + if (empty($reshook)) { + if ($usercancreate) { print ''; print $langs->trans("AddSupplierPrice").''; } @@ -857,11 +856,14 @@ END; print "\n
\n"; print '
'; - if ($user->rights->fournisseur->lire) // Duplicate ? this check is already in the head of this file - { + if ($user->rights->fournisseur->lire) { // Duplicate ? this check is already in the head of this file $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } $param .= '&ref='.urlencode($object->ref); $product_fourn = new ProductFournisseur($db); @@ -869,7 +871,9 @@ END; $product_fourn_list_all = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder, 0, 0); $nbtotalofrecords = count($product_fourn_list_all); $num = count($product_fourn_list); - if (($num + ($offset * $limit)) < $nbtotalofrecords) $num++; + if (($num + ($offset * $limit)) < $nbtotalofrecords) { + $num++; + } print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1); @@ -924,24 +928,52 @@ END; $param = "&id=".$object->id; print ''; - if (!empty($arrayfields['pfp.datec']['checked'])) print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder, '', '', 1); - if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre("Suppliers", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder, '', '', 1); + if (!empty($arrayfields['pfp.datec']['checked'])) { + print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder, '', '', 1); + } + if (!empty($arrayfields['s.nom']['checked'])) { + print_liste_field_titre("Suppliers", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder, '', '', 1); + } print_liste_field_titre("SupplierRef", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder, '', '', 1); - if (!empty($arrayfields['pfp.fk_availability']['checked'])) print_liste_field_titre("Availability", $_SERVER["PHP_SELF"], "pfp.fk_availability", "", $param, "", $sortfield, $sortorder); - if (!empty($arrayfields['pfp.quantity']['checked'])) print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['pfp.fk_availability']['checked'])) { + print_liste_field_titre("Availability", $_SERVER["PHP_SELF"], "pfp.fk_availability", "", $param, "", $sortfield, $sortorder); + } + if (!empty($arrayfields['pfp.quantity']['checked'])) { + print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, '', $sortfield, $sortorder, 'right '); + } print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("PriceQtyMinHT", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); - if (!empty($conf->multicurrency->enabled)) print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['pfp.unitprice']['checked'])) print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, '', $sortfield, $sortorder, 'right '); - if (!empty($conf->multicurrency->enabled)) print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + if (!empty($conf->multicurrency->enabled)) { + print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + } + if (!empty($arrayfields['pfp.unitprice']['checked'])) { + print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, '', $sortfield, $sortorder, 'right '); + } + if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) { + print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, '', $sortfield, $sortorder, 'right '); + } + if (!empty($conf->multicurrency->enabled)) { + print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + } print_liste_field_titre("DiscountQtyMin", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['pfp.barcode']['checked'])) print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['pfp.packaging']['checked'])) print_liste_field_titre("PackagingForThisProduct", $_SERVER["PHP_SELF"], "pfp.packaging", "", $param, 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['pfp.tms']['checked'])) print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ', '', 1); + if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) { + print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right '); + } + if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) { + print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['pfp.barcode']['checked'])) { + print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) { + print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['pfp.packaging']['checked'])) { + print_liste_field_titre("PackagingForThisProduct", $_SERVER["PHP_SELF"], "pfp.packaging", "", $param, 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['pfp.tms']['checked'])) { + print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ', '', 1); + } // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label("product_fournisseur_price"); @@ -951,26 +983,30 @@ END; foreach ($extralabels as $key => $value) { // Show field if not hidden if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { - if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); - if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); - else $extratitle = $langs->trans($value); - if (!empty($arrayfields['ef.'.$key]['checked'])) print_liste_field_titre($extratitle, $_SERVER["PHP_SELF"], 'ef.'.$key, '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) { + $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); + } + if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) { + $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); + } else { + $extratitle = $langs->trans($value); + } + if (!empty($arrayfields['ef.'.$key]['checked'])) { + print_liste_field_titre($extratitle, $_SERVER["PHP_SELF"], 'ef.'.$key, '', $param, '', $sortfield, $sortorder, 'right '); + } } } } - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); } print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; - if (is_array($product_fourn_list)) - { - foreach ($product_fourn_list as $productfourn) - { + if (is_array($product_fourn_list)) { + foreach ($product_fourn_list as $productfourn) { print ''; // Date from @@ -991,8 +1027,7 @@ END; } // Availability - if (!empty($arrayfields['pfp.fk_availability']['checked'])) - { + if (!empty($arrayfields['pfp.fk_availability']['checked'])) { $form->load_cache_availability(); $availability = $form->cache_availability[$productfourn->fk_availability]['label']; print ''; @@ -1041,7 +1076,8 @@ END; if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) { print ''; } + print ''; + } // Currency if (!empty($conf->multicurrency->enabled)) { @@ -1130,8 +1166,7 @@ END; } } - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array('id_pfp'=>$productfourn->product_fourn_price_id, 'id_fourn'=>$id_fourn, 'prod_id'=>$object->id); $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); } @@ -1139,8 +1174,7 @@ END; // Modify-Remove print '
'.$langs->trans("Duration").''.$object->duration_value.' '; - if ($object->duration_value > 1) - { + if ($object->duration_value > 1) { $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); - } elseif ($object->duration_value > 0) - { + } elseif ($object->duration_value > 0) { $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); } print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')." "; @@ -2067,47 +2099,44 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Brut Weight print '
'.$langs->trans("Weight").''; - if ($object->weight != '') - { + if ($object->weight != '') { print $object->weight." ".measuringUnitString(0, "weight", $object->weight_units); } else { print ' '; } print "
'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").''; - if ($object->length != '' || $object->width != '' || $object->height != '') - { + if ($object->length != '' || $object->width != '' || $object->height != '') { print $object->length; - if ($object->width) print " x ".$object->width; - if ($object->height) print " x ".$object->height; + if ($object->width) { + print " x ".$object->width; + } + if ($object->height) { + print " x ".$object->height; + } print ' '.measuringUnitString(0, "size", $object->length_units); } else { print ' '; } print "
'.$langs->trans("Surface").''; - if ($object->surface != '') - { + if ($object->surface != '') { print $object->surface." ".measuringUnitString(0, "surface", $object->surface_units); } else { print ' '; } print "
'.$langs->trans("Volume").''; - if ($object->volume != '') - { + if ($object->volume != '') { print $object->volume." ".measuringUnitString(0, "volume", $object->volume_units); } else { print ' '; @@ -2115,12 +2144,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print "
'.$langs->trans("NetMeasure").''; - if ($object->net_measure != '') - { + if ($object->net_measure != '') { print $object->net_measure." ".measuringUnitString($object->net_measure_units); } else { print ' '; @@ -2129,8 +2156,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Unit - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { $unit = $object->getLabelOfUnit(); print '
'.$langs->trans('DefaultUnitToShow').''; @@ -2141,13 +2167,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } // Custom code - if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) - { + if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) { print '
'.$langs->trans("CustomCode").''.$object->customcode.'
'.$langs->trans("Origin").''.getCountry($object->country_id, 0, $db); - if (!empty($object->state_id)) print ' - '.getState($object->state_id, 0, $db); + if (!empty($object->state_id)) { + print ' - '.getState($object->state_id, 0, $db); + } print '
'.$langs->trans("NotePrivate").''.(dol_textishtml($object->note_private) ? $object->note_private : dol_nl2br($object->note_private, 1, true)).'
'; $html .= $langs->trans("AddToDraftProposals").''; $html .= $form->selectarray("propalid", $otherprop, 0, 1); @@ -2323,15 +2339,13 @@ if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == } // Commande - if (!empty($conf->commande->enabled) && $user->rights->commande->creer) - { + if (!empty($conf->commande->enabled) && $user->rights->commande->creer) { $commande = new Commande($db); $langs->load("orders"); $othercom = $commande->liste_array(2, 1, null); - if (is_array($othercom) && count($othercom)) - { + if (is_array($othercom) && count($othercom)) { $html .= '
'; $html .= $langs->trans("AddToDraftOrders").''; $html .= $form->selectarray("commandeid", $othercom, 0, 1); @@ -2345,15 +2359,13 @@ if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == } // Factures - if (!empty($conf->facture->enabled) && $user->rights->facture->creer) - { + if (!empty($conf->facture->enabled) && $user->rights->facture->creer) { $invoice = new Facture($db); $langs->load("bills"); $otherinvoice = $invoice->liste_array(2, 1, null); - if (is_array($otherinvoice) && count($otherinvoice)) - { + if (is_array($otherinvoice) && count($otherinvoice)) { $html .= '
'; $html .= $langs->trans("AddToDraftInvoices").''; $html .= $form->selectarray("factureid", $otherinvoice, 0, 1); @@ -2367,8 +2379,7 @@ if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == } //If any text is going to be printed, then we show the table - if (!empty($html)) - { + if (!empty($html)) { print ''; print ''; print ''; @@ -2402,8 +2413,7 @@ if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == * Documents generes */ -if ($action != 'create' && $action != 'edit' && $action != 'delete') -{ +if ($action != 'create' && $action != 'edit' && $action != 'delete') { print '
'; print ''; // ancre diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 189161712d5..2f2d24f7458 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -37,7 +37,7 @@ class Products extends DolibarrApi /** * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'ref', 'label' ); @@ -217,8 +217,7 @@ class Products extends DolibarrApi $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $product_static = new Product($this->db); if ($product_static->fetch($obj->rowid)) { @@ -290,7 +289,8 @@ class Products extends DolibarrApi $oldproduct = dol_clone($this->product, 0); foreach ($request_data as $field => $value) { - if ($field == 'id') { continue; + if ($field == 'id') { + continue; } if ($field == 'stock_reel') { throw new RestException(400, 'Stock reel cannot be updated here. Use the /stockmovements endpoint instead'); @@ -309,24 +309,32 @@ class Products extends DolibarrApi if ($result > 0 && !empty($conf->global->PRODUCT_PRICE_UNIQ)) { // We update price only if it was changed $pricemodified = false; - if ($this->product->price_base_type != $oldproduct->price_base_type) { $pricemodified = true; + if ($this->product->price_base_type != $oldproduct->price_base_type) { + $pricemodified = true; } else { - if ($this->product->tva_tx != $oldproduct->tva_tx) { $pricemodified = true; + if ($this->product->tva_tx != $oldproduct->tva_tx) { + $pricemodified = true; } - if ($this->product->tva_npr != $oldproduct->tva_npr) { $pricemodified = true; + if ($this->product->tva_npr != $oldproduct->tva_npr) { + $pricemodified = true; } - if ($this->product->default_vat_code != $oldproduct->default_vat_code) { $pricemodified = true; + if ($this->product->default_vat_code != $oldproduct->default_vat_code) { + $pricemodified = true; } if ($this->product->price_base_type == 'TTC') { - if ($this->product->price_ttc != $oldproduct->price_ttc) { $pricemodified = true; + if ($this->product->price_ttc != $oldproduct->price_ttc) { + $pricemodified = true; } - if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) { $pricemodified = true; + if ($this->product->price_min_ttc != $oldproduct->price_min_ttc) { + $pricemodified = true; } } else { - if ($this->product->price != $oldproduct->price) { $pricemodified = true; + if ($this->product->price != $oldproduct->price) { + $pricemodified = true; } - if ($this->product->price_min != $oldproduct->price_min) { $pricemodified = true; + if ($this->product->price_min != $oldproduct->price_min) { + $pricemodified = true; } } } @@ -586,7 +594,9 @@ class Products extends DolibarrApi $prodcustprice = new Productcustomerprice($this->db); $filter = array(); $filter['t.fk_product'] .= $id; - if ($thirdparty_id) $filter['t.fk_soc'] .= $thirdparty_id; + if ($thirdparty_id) { + $filter['t.fk_soc'] .= $thirdparty_id; + } $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); } @@ -805,8 +815,7 @@ class Products extends DolibarrApi $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $product_fourn = new ProductFournisseur($this->db); @@ -1149,7 +1158,8 @@ class Products extends DolibarrApi } foreach ($request_data as $field => $value) { - if ($field == 'rowid') { continue; + if ($field == 'rowid') { + continue; } $prodattr->$field = $value; } @@ -1447,7 +1457,8 @@ class Products extends DolibarrApi } foreach ($request_data as $field => $value) { - if ($field == 'rowid') { continue; + if ($field == 'rowid') { + continue; } $objectval->$field = $value; } @@ -1606,8 +1617,7 @@ class Products extends DolibarrApi $prodcomb = new ProductCombination($this->db); $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext); - if ($result > 0) - { + if ($result > 0) { return $result; } else { throw new RestException(500, "Error creating new product variant"); @@ -1662,11 +1672,9 @@ class Products extends DolibarrApi } $prodcomb = new ProductCombination($this->db); - if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) - { + if (!$prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) { $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact); - if ($result > 0) - { + if ($result > 0) { return $result; } else { throw new RestException(500, "Error creating new product variant"); @@ -1698,14 +1706,14 @@ class Products extends DolibarrApi $prodcomb->fetch((int) $id); foreach ($request_data as $field => $value) { - if ($field == 'rowid') { continue; + if ($field == 'rowid') { + continue; } $prodcomb->$field = $value; } $result = $prodcomb->update(DolibarrApiAccess::$user); - if ($result > 0) - { + if ($result > 0) { return 1; } throw new RestException(500, "Error editing variant"); @@ -1731,8 +1739,7 @@ class Products extends DolibarrApi $prodcomb = new ProductCombination($this->db); $prodcomb->id = (int) $id; $result = $prodcomb->delete(DolibarrApiAccess::$user); - if ($result <= 0) - { + if ($result <= 0) { throw new RestException(500, "Error deleting variant"); } return $result; diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index eed18bbf8bd..56efd8565d1 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -76,57 +76,54 @@ class FormProduct { 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 + 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 + } - if (is_array($exclude)) $excludeGroups = implode("','", $exclude); + if (is_array($exclude)) { + $excludeGroups = implode("','", $exclude); + } $warehouseStatus = array(); - if (preg_match('/warehouseclosed/', $status)) - { + if (preg_match('/warehouseclosed/', $status)) { $warehouseStatus[] = Entrepot::STATUS_CLOSED; } - if (preg_match('/warehouseopen/', $status)) - { + if (preg_match('/warehouseopen/', $status)) { $warehouseStatus[] = Entrepot::STATUS_OPEN_ALL; } - if (preg_match('/warehouseinternal/', $status)) - { + if (preg_match('/warehouseinternal/', $status)) { $warehouseStatus[] = Entrepot::STATUS_OPEN_INTERNAL; } $sql = "SELECT e.rowid, e.ref as label, e.description, e.fk_parent"; - if (!empty($fk_product)) - { - if (!empty($batch)) - { + if (!empty($fk_product)) { + if (!empty($batch)) { $sql .= ", pb.qty as stock"; } else { $sql .= ", ps.reel as stock"; } - } elseif ($sumStock) - { + } elseif ($sumStock) { $sql .= ", sum(ps.reel) as stock"; } $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid"; - if (!empty($fk_product)) - { + if (!empty($fk_product)) { $sql .= " AND ps.fk_product = ".((int) $fk_product); - if (!empty($batch)) - { + if (!empty($batch)) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'"; } } $sql .= " WHERE e.entity IN (".getEntity('stock').")"; - if (count($warehouseStatus)) - { + if (count($warehouseStatus)) { $sql .= " AND e.statut IN (".$this->db->sanitize($this->db->escape(implode(',', $warehouseStatus))).")"; } else { $sql .= " AND e.statut = 1"; } - if (!empty($exclude)) $sql .= ' AND e.rowid NOT IN('.$this->db->escape(implode(',', $exclude)).')'; + if (!empty($exclude)) { + $sql .= ' AND e.rowid NOT IN('.$this->db->escape(implode(',', $exclude)).')'; + } // minimum stock if ($stockMin !== false) { @@ -151,14 +148,14 @@ class FormProduct dol_syslog(get_class($this).'::loadWarehouses', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); - if ($sumStock) $obj->stock = price2num($obj->stock, 5); + if ($sumStock) { + $obj->stock = price2num($obj->stock, 5); + } $this->cache_warehouses[$obj->rowid]['id'] = $obj->rowid; $this->cache_warehouses[$obj->rowid]['label'] = $obj->label; $this->cache_warehouses[$obj->rowid]['parent_id'] = $obj->fk_parent; @@ -168,7 +165,7 @@ class FormProduct } // Full label init - foreach ($this->cache_warehouses as $obj_rowid=>$tab) { + foreach ($this->cache_warehouses as $obj_rowid => $tab) { $this->cache_warehouses[$obj_rowid]['full_label'] = $this->get_parent_path($tab); } @@ -190,10 +187,13 @@ class FormProduct private function get_parent_path($tab, $final_label = '') { //phpcs:enable - if (empty($final_label)) $final_label = $tab['label']; + if (empty($final_label)) { + $final_label = $tab['label']; + } - if (empty($tab['parent_id'])) return $final_label; - else { + if (empty($tab['parent_id'])) { + return $final_label; + } else { if (!empty($this->cache_warehouses[$tab['parent_id']])) { $final_label = $this->cache_warehouses[$tab['parent_id']]['label'].' >> '.$final_label; return $this->get_parent_path($this->cache_warehouses[$tab['parent_id']], $final_label); @@ -235,14 +235,17 @@ class FormProduct dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filterstatus, $empty, $disabled, $fk_product, $empty_label, $showstock, $forcecombo, $morecss", LOG_DEBUG); $out = ''; - if (empty($conf->global->ENTREPOT_EXTRA_STATUS)) $filterstatus = ''; - if (!empty($fk_product)) $this->cache_warehouses = array(); + if (empty($conf->global->ENTREPOT_EXTRA_STATUS)) { + $filterstatus = ''; + } + if (!empty($fk_product)) { + $this->cache_warehouses = array(); + } $this->loadWarehouses($fk_product, '', $filterstatus, true, $exclude, $stockMin, $orderBy); $nbofwarehouses = count($this->cache_warehouses); - if ($conf->use_javascript_ajax && !$forcecombo) - { + if ($conf->use_javascript_ajax && !$forcecombo) { include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname, $events); $out .= $comboenhancement; @@ -250,22 +253,28 @@ class FormProduct if (strpos($htmlname, 'search_') !== 0) { if (empty($user->fk_warehouse) || $user->fk_warehouse == -1) { - if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) $selected = $conf->global->MAIN_DEFAULT_WAREHOUSE; - } - else { - if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) $selected = $user->fk_warehouse; + if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) { + $selected = $conf->global->MAIN_DEFAULT_WAREHOUSE; + } + } else { + if (($selected == '-2' || $selected == 'ifone') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { + $selected = $user->fk_warehouse; + } } } $out .= ''; + } $parameters = array( 'selected' => $selected, @@ -302,8 +315,11 @@ class FormProduct ); $reshook = $hookmanager->executeHooks('selectWarehouses', $parameters, $this); - if ($reshook > 0) $out = $hookmanager->resPrint; - elseif ($reshook == 0) $out .= $hookmanager->resPrint; + if ($reshook > 0) { + $out = $hookmanager->resPrint; + } elseif ($reshook == 0) { + $out .= $hookmanager->resPrint; + } return $out; } @@ -385,7 +401,9 @@ class FormProduct $filter = array(); $filter['t.active'] = 1; - if ($measuring_style) $filter['t.unit_type'] = $measuring_style; + if ($measuring_style) { + $filter['t.unit_type'] = $measuring_style; + } $result = $measuringUnits->fetchAll( '', @@ -399,24 +417,33 @@ class FormProduct return -1; } else { $return .= ''; @@ -472,8 +499,11 @@ class FormProduct if (!empty($productNature->records) && is_array($productNature->records)) { foreach ($productNature->records as $lines) { $return .= '
'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).''; - if ($object->pmp > 0) print price($object->pmp).' '.$langs->trans("HT"); + if ($object->pmp > 0) { + print price($object->pmp).' '.$langs->trans("HT"); + } print '
'.$langs->trans("BuyingPriceMin").''; $product_fourn = new ProductFournisseur($db); - if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) - { - if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(); - else print $langs->trans("NotDefined"); + if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) { + if ($product_fourn->product_fourn_price_id > 0) { + print $product_fourn->display_price_product_fournisseur(); + } else { + print $langs->trans("NotDefined"); + } } print '
'.$langs->trans("Supplier").''; - if ($rowid) - { + if ($rowid) { $supplier = new Fournisseur($db); $supplier->fetch($socid); print $supplier->getNomUrl(1); @@ -479,10 +480,8 @@ if ($id > 0 || $ref) $parameters = array('filtre'=>"fournisseur=1", 'html_name'=>'id_fourn', 'selected'=>GETPOST("id_fourn"), 'showempty'=>1, 'prod_id'=>$object->id); $reshook = $hookmanager->executeHooks('formCreateThirdpartyOptions', $parameters, $object, $action); - if (empty($reshook)) - { - if (empty($form->result)) - { + if (empty($reshook)) { + if (empty($form->result)) { print ' - '.$langs->trans("CreateDolibarrThirdPartySupplier").''; } } @@ -491,8 +490,7 @@ if ($id > 0 || $ref) // Ref supplier print '
'.$langs->trans("SupplierRef").''; - if ($rowid) - { + if ($rowid) { print ''; print ''; } else { @@ -502,8 +500,7 @@ if ($id > 0 || $ref) print '
'.$langs->trans("Availability").''; $form->selectAvailabilityDelay($object->fk_availability, "oselDispo", 1); @@ -515,8 +512,7 @@ if ($id > 0 || $ref) print ''.$langs->trans("QtyMin").''; $quantity = GETPOSTISSET('qty') ? price2num(GETPOST('qty', 'nohtml'), 'MS') : "1"; - if ($rowid) - { + if ($rowid) { print ''; print $object->fourn_qty; } else { @@ -558,20 +554,20 @@ if ($id > 0 || $ref) $mysoc2->tva_assuj = 1; $default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0); $default_npr = get_default_npr($mysoc2, $mysoc, $object->id, 0); - if (empty($default_vat)) $default_npr = $default_vat; + if (empty($default_vat)) { + $default_npr = $default_vat; + } print '
'.$langs->trans("VATRateForSupplierProduct").''; //print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country - if (!empty($rowid)) // If we have a supplier, it is an update, we must show the vat of current supplier price - { + if (!empty($rowid)) { // If we have a supplier, it is an update, we must show the vat of current supplier price $tmpproductsupplier = new ProductFournisseur($db); $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1); $default_vat = $tmpproductsupplier->fourn_tva_tx; $default_npr = $tmpproductsupplier->fourn_tva_npr; } else { - if (empty($default_vat)) - { + if (empty($default_vat)) { $default_vat = $object->tva_tx; } } @@ -580,8 +576,7 @@ if ($id > 0 || $ref) print ''; print '
'.$langs->trans("PriceMode").''; $price_expression = new PriceExpression($db); @@ -619,7 +614,9 @@ if ($id > 0 || $ref) print '
'.$langs->trans("Currency").''; $currencycodetouse = GETPOST('multicurrency_code') ?GETPOST('multicurrency_code') : (isset($object->fourn_multicurrency_code) ? $object->fourn_multicurrency_code : ''); - if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) $currencycodetouse = $conf->currency; + if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) { + $currencycodetouse = $conf->currency; + } print $form->selectMultiCurrency($currencycodetouse, "multicurrency_code", 1); print '   '.$langs->trans("CurrencyRate").' '; print ''; @@ -724,8 +721,7 @@ END; print '
'.$langs->trans('BarcodeValue').'
'.$langs->trans("Charges").''; @@ -756,8 +750,7 @@ END; } // Product description of the supplier - if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) - { + if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -780,11 +773,16 @@ END; if (empty($rowid)) { foreach ($extralabels as $key => $value) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); + if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) { + $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); + } print '
'.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : '', '', '', '', '', 0, 'product_fournisseur_price').'
'.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : $obj->{$key}, '', '', '', '', 0, 'product_fournisseur_price'); print '
'.$availability.''; print price($productfourn->fourn_multicurrency_unitprice); - print ''; - if ($usercancreate) - { + if ($usercancreate) { print ''.img_edit().""; print '   '; print ''.img_picto($langs->trans("Remove"), 'delete').''; diff --git a/htdocs/product/index.php b/htdocs/product/index.php index 7e19d8f3818..89054a11cc5 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -34,13 +34,21 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $type = GETPOST("type", 'int'); -if ($type == '' && !$user->rights->produit->lire) $type = '1'; // Force global page on service page only -if ($type == '' && !$user->rights->service->lire) $type = '0'; // Force global page on product page only +if ($type == '' && !$user->rights->produit->lire) { + $type = '1'; // Force global page on service page only +} +if ($type == '' && !$user->rights->service->lire) { + $type = '0'; // Force global page on product page only +} // Security check -if ($type == '0') $result = restrictedArea($user, 'produit'); -elseif ($type == '1') $result = restrictedArea($user, 'service'); -else $result = restrictedArea($user, 'produit|service|expedition'); +if ($type == '0') { + $result = restrictedArea($user, 'produit'); +} elseif ($type == '1') { + $result = restrictedArea($user, 'service'); +} else { + $result = restrictedArea($user, 'produit|service|expedition'); +} // Load translation files required by the page $langs->loadLangs(array('products', 'stocks')); @@ -58,18 +66,15 @@ $product_static = new Product($db); $transAreaType = $langs->trans("ProductsAndServicesArea"); $helpurl = ''; -if (!isset($_GET["type"])) -{ +if (!isset($_GET["type"])) { $transAreaType = $langs->trans("ProductsAndServicesArea"); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if ((isset($_GET["type"]) && $_GET["type"] == 0) || empty($conf->service->enabled)) -{ +if ((isset($_GET["type"]) && $_GET["type"] == 0) || empty($conf->service->enabled)) { $transAreaType = $langs->trans("ProductsArea"); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if ((isset($_GET["type"]) && $_GET["type"] == 1) || empty($conf->product->enabled)) -{ +if ((isset($_GET["type"]) && $_GET["type"] == 1) || empty($conf->product->enabled)) { $transAreaType = $langs->trans("ServicesArea"); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } @@ -83,27 +88,27 @@ print load_fiche_titre($transAreaType, $linkback, 'product'); print '
'; -if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo -{ +if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo // Search contract - if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) - { + if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) { $listofsearchfields['search_product'] = array('text'=>'ProductOrService'); } - if (count($listofsearchfields)) - { + if (count($listofsearchfields)) { print ''; print ''; print '
'; print ''; $i = 0; - foreach ($listofsearchfields as $key => $value) - { - if ($i == 0) print ''; + foreach ($listofsearchfields as $key => $value) { + if ($i == 0) { + print ''; + } print ''; print ''; - if ($i == 0) print ''; + if ($i == 0) { + print ''; + } print ''; $i++; } @@ -117,8 +122,7 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useles /* * Number of products and/or services */ -if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) -{ +if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) { $prodser = array(); $prodser[0][0] = $prodser[0][1] = $prodser[0][2] = $prodser[0][3] = 0; $prodser[1][0] = $prodser[1][1] = $prodser[1][2] = $prodser[1][3] = 0; @@ -132,20 +136,30 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us $sql .= $hookmanager->resPrint; $sql .= " GROUP BY p.fk_product_type, p.tosell, p.tobuy"; $result = $db->query($sql); - while ($objp = $db->fetch_object($result)) - { + while ($objp = $db->fetch_object($result)) { $status = 3; // On sale + On purchase - if (!$objp->tosell && !$objp->tobuy) $status = 0; // Not on sale, not on purchase - if ($objp->tosell && !$objp->tobuy) $status = 1; // On sale only - if (!$objp->tosell && $objp->tobuy) $status = 2; // On purchase only + if (!$objp->tosell && !$objp->tobuy) { + $status = 0; // Not on sale, not on purchase + } + if ($objp->tosell && !$objp->tobuy) { + $status = 1; // On sale only + } + if (!$objp->tosell && $objp->tobuy) { + $status = 2; // On purchase only + } $prodser[$objp->fk_product_type][$status] = $objp->total; - if ($objp->tosell) $prodser[$objp->fk_product_type]['sell'] += $objp->total; - if ($objp->tobuy) $prodser[$objp->fk_product_type]['buy'] += $objp->total; - if (!$objp->tosell && !$objp->tobuy) $prodser[$objp->fk_product_type]['none'] += $objp->total; + if ($objp->tosell) { + $prodser[$objp->fk_product_type]['sell'] += $objp->total; + } + if ($objp->tobuy) { + $prodser[$objp->fk_product_type]['buy'] += $objp->total; + } + if (!$objp->tosell && !$objp->tobuy) { + $prodser[$objp->fk_product_type]['none'] += $objp->total; + } } - if ($conf->use_javascript_ajax) - { + if ($conf->use_javascript_ajax) { print '
'; print '
'.$langs->trans("Search").'
'.$langs->trans("Search").'
'; print ''; @@ -164,14 +178,12 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us $total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF; $dataseries = array(); - if (!empty($conf->product->enabled)) - { + if (!empty($conf->product->enabled)) { $dataseries[] = array($langs->transnoentitiesnoconv("ProductsOnSale"), round($SommeA)); $dataseries[] = array($langs->transnoentitiesnoconv("ProductsOnPurchase"), round($SommeB)); $dataseries[] = array($langs->transnoentitiesnoconv("ProductsNotOnSell"), round($SommeC)); } - if (!empty($conf->service->enabled)) - { + if (!empty($conf->service->enabled)) { $dataseries[] = array($langs->transnoentitiesnoconv("ServicesOnSale"), round($SommeD)); $dataseries[] = array($langs->transnoentitiesnoconv("ServicesOnPurchase"), round($SommeE)); $dataseries[] = array($langs->transnoentitiesnoconv("ServicesNotOnSell"), round($SommeF)); @@ -193,8 +205,7 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us } -if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS)) -{ +if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS)) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; print '
'; print '
'; @@ -209,20 +220,16 @@ if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTA $sql .= " GROUP BY c.label"; $total = 0; $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); $i = 0; - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { $dataseries = array(); $rest = 0; $nbmax = 10; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($result); - if ($i < $nbmax) - { + if ($i < $nbmax) { $dataseries[] = array($obj->label, round($obj->nb)); } else { $rest += $obj->nb; @@ -230,8 +237,7 @@ if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTA $total += $obj->nb; $i++; } - if ($i > $nbmax) - { + if ($i > $nbmax) { $dataseries[] = array($langs->trans("Other"), round($rest)); } @@ -245,8 +251,7 @@ if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTA $dolgraph->draw('idstatscategproduct'); print $dolgraph->show($total ? 0 : 1); } else { - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($result); print '
'; @@ -268,15 +273,16 @@ print '
'; /* * Latest modified products */ -if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) -{ +if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) { $max = 15; $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,"; $sql .= " p.entity,"; $sql .= " p.tms as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; $sql .= " WHERE p.entity IN (".getEntity($product_static->element, 1).")"; - if ($type != '') $sql .= " AND p.fk_product_type = ".$type; + if ($type != '') { + $sql .= " AND p.fk_product_type = ".$type; + } // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook @@ -286,30 +292,33 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us //print $sql; $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); $i = 0; - if ($num > 0) - { + if ($num > 0) { $transRecordedType = $langs->trans("LastModifiedProductsAndServices", $max); - if (isset($_GET["type"]) && $_GET["type"] == 0) $transRecordedType = $langs->trans("LastRecordedProducts", $max); - if (isset($_GET["type"]) && $_GET["type"] == 1) $transRecordedType = $langs->trans("LastRecordedServices", $max); + if (isset($_GET["type"]) && $_GET["type"] == 0) { + $transRecordedType = $langs->trans("LastRecordedProducts", $max); + } + if (isset($_GET["type"]) && $_GET["type"] == 1) { + $transRecordedType = $langs->trans("LastRecordedServices", $max); + } print '
'; print '
'.$langs->trans("Statistics").'
'.$obj->label.''.$obj->nb.'
'; $colnb = 2; - if (empty($conf->global->PRODUIT_MULTIPRICES)) $colnb++; + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + $colnb++; + } print ''; print ''; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($result); $product_static->id = $objp->rowid; @@ -322,18 +331,18 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us $product_static->status_batch = $objp->tobatch; //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; $sql .= " AND lang='".$db->escape($langs->getDefaultLang())."'"; $resultd = $db->query($sql); - if ($resultd) - { + if ($resultd) { $objtp = $db->fetch_object($resultd); - if ($objtp && $objtp->label != '') $objp->label = $objtp->label; + if ($objtp && $objtp->label != '') { + $objp->label = $objtp->label; + } } } @@ -347,10 +356,8 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us print dol_print_date($db->jdate($objp->datem), 'day'); print ""; // Sell price - if (empty($conf->global->PRODUIT_MULTIPRICES)) - { - if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_price_expression)) - { + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_price_expression)) { $product = new Product($db); $product->fetch($objp->rowid); $priceparser = new PriceParser($db); @@ -360,8 +367,11 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us } } print ''; } print '
'.$transRecordedType.''.$langs->trans("FullList").''; print '
'; - if (isset($objp->price_base_type) && $objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC"); - else print price($objp->price).' '.$langs->trans("HT"); + if (isset($objp->price_base_type) && $objp->price_base_type == 'TTC') { + print price($objp->price_ttc).' '.$langs->trans("TTC"); + } else { + print price($objp->price).' '.$langs->trans("HT"); + } print ''; @@ -389,10 +399,13 @@ if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($us // TODO Move this into a page that should be available into menu "accountancy - report - turnover - per quarter" // Also method used for counting must provide the 2 possible methods like done by all other reports into menu "accountancy - report - turnover": // "commitment engagment" method and "cash accounting" method -if (!empty($conf->global->MAIN_SHOW_PRODUCT_ACTIVITY_TRIM)) -{ - if (!empty($conf->product->enabled)) activitytrim(0); - if (!empty($conf->service->enabled)) activitytrim(1); +if (!empty($conf->global->MAIN_SHOW_PRODUCT_ACTIVITY_TRIM)) { + if (!empty($conf->product->enabled)) { + activitytrim(0); + } + if (!empty($conf->service->enabled)) { + activitytrim(1); + } } @@ -433,8 +446,7 @@ function activitytrim($product_type) $sql .= " ORDER BY annee, mois "; $result = $db->query($sql); - if ($result) - { + if ($result) { $tmpyear = 0; $trim1 = 0; $trim2 = 0; @@ -443,14 +455,15 @@ function activitytrim($product_type) $lgn = 0; $num = $db->num_rows($result); - if ($num > 0) - { + if ($num > 0) { print '
'; print ''; - if ($product_type == 0) + if ($product_type == 0) { print ''; - else print ''; + } else { + print ''; + } print ''; print ''; print ''; @@ -460,13 +473,10 @@ function activitytrim($product_type) } $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($result); - if ($tmpyear != $objp->annee) - { - if ($trim1 + $trim2 + $trim3 + $trim4 > 0) - { + if ($tmpyear != $objp->annee) { + if ($trim1 + $trim2 + $trim3 + $trim4 > 0) { print ''; print ''; print ''; @@ -484,22 +494,25 @@ function activitytrim($product_type) $trim4 = 0; } - if ($objp->mois == "01" || $objp->mois == "02" || $objp->mois == "03") + if ($objp->mois == "01" || $objp->mois == "02" || $objp->mois == "03") { $trim1 += $objp->Mnttot; + } - if ($objp->mois == "04" || $objp->mois == "05" || $objp->mois == "06") + if ($objp->mois == "04" || $objp->mois == "05" || $objp->mois == "06") { $trim2 += $objp->Mnttot; + } - if ($objp->mois == "07" || $objp->mois == "08" || $objp->mois == "09") + if ($objp->mois == "07" || $objp->mois == "08" || $objp->mois == "09") { $trim3 += $objp->Mnttot; + } - if ($objp->mois == "10" || $objp->mois == "11" || $objp->mois == "12") + if ($objp->mois == "10" || $objp->mois == "11" || $objp->mois == "12") { $trim4 += $objp->Mnttot; + } $i++; } - if ($trim1 + $trim2 + $trim3 + $trim4 > 0) - { + if ($trim1 + $trim2 + $trim3 + $trim4 > 0) { print ''; print ''; print ''; @@ -508,7 +521,8 @@ function activitytrim($product_type) print ''; print ''; } - if ($num > 0) + if ($num > 0) { print '
'.$langs->trans("ProductSellByQuarterHT").'
'.$langs->trans("ServiceSellByQuarterHT").'
'.$langs->trans("ServiceSellByQuarterHT").''.$langs->trans("Quarter1").''.$langs->trans("Quarter2").''.$langs->trans("Quarter3").'
'.$tmpyear.''.price($trim1).''.price($trim2).'
'.$tmpyear.''.price($trim1).''.price($trim2).''.price($trim1 + $trim2 + $trim3 + $trim4).'
'; + } } } diff --git a/htdocs/product/inventory/ajax/ajax.inventory.php b/htdocs/product/inventory/ajax/ajax.inventory.php index 85dd488df6f..920607f4c1e 100644 --- a/htdocs/product/inventory/ajax/ajax.inventory.php +++ b/htdocs/product/inventory/ajax/ajax.inventory.php @@ -6,16 +6,16 @@ require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; $get = GETPOST('get', 'alpha'); $put = GETPOST('put', 'alpha'); -switch ($put) -{ +switch ($put) { case 'qty': - if (empty($user->rights->stock->creer)) { echo -1; exit; } + if (empty($user->rights->stock->creer)) { + echo -1; exit; + } $fk_det_inventory = GETPOST('fk_det_inventory'); $det = new InventoryLine($db); - if ($det->fetch($fk_det_inventory)) - { + if ($det->fetch($fk_det_inventory)) { $det->qty_view += GETPOST('qty'); $res = $det->update($user); @@ -27,13 +27,14 @@ switch ($put) break; case 'pmp': - if (empty($user->rights->stock->creer) || empty($user->rights->stock->changePMP)) { echo -1; exit; } + if (empty($user->rights->stock->creer) || empty($user->rights->stock->changePMP)) { + echo -1; exit; + } $fk_det_inventory = GETPOST('fk_det_inventory'); $det = new InventoryLine($db); - if ($det->fetch($fk_det_inventory)) - { + if ($det->fetch($fk_det_inventory)) { $det->new_pmp = price2num(GETPOST('pmp')); $det->update($user); diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 425dd3622e3..e0a03cb322d 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -40,8 +40,7 @@ $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $result = restrictedArea($user, 'stock', $id); } else { $result = restrictedArea($user, 'stock', $id, '', 'inventory_advance'); @@ -61,12 +60,15 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); -foreach ($object->fields as $key => $val) -{ - if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } } -if (empty($action) && empty($id) && empty($ref)) $action = 'view'; +if (empty($action) && empty($id) && empty($ref)) { + $action = 'view'; +} // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. @@ -76,8 +78,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ //if ($user->socid > 0) $socid = $user->socid; //$result = restrictedArea($user, 'mymodule', $id); -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $permissiontoread = $user->rights->stock->lire; $permissiontoadd = $user->rights->stock->creer; $permissiontodelete = $user->rights->stock->supprimer; @@ -100,18 +101,22 @@ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { $error = 0; $backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php'; if (empty($backtopage) || ($cancel && empty($id))) { if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { - if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist; - else $backtopage = dol_buildpath('/product/inventory/card.php', 1).'?id='.($id > 0 ? $id : '__ID__'); + if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { + $backtopage = $backurlforlist; + } else { + $backtopage = dol_buildpath('/product/inventory/card.php', 1).'?id='.($id > 0 ? $id : '__ID__'); + } } } $triggermodname = 'STOCK_INVENTORY_MODIFY'; // Name of trigger action code to execute when we modify record @@ -135,8 +140,7 @@ if (empty($reshook)) { $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY'); }*/ - if ($action == 'classin' && $permissiontoadd) - { + if ($action == 'classin' && $permissiontoadd) { $object->setProject(GETPOST('projectid', 'int')); } @@ -179,15 +183,18 @@ jQuery(document).ready(function() { // Part to create -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($langs->trans("NewInventory"), '', 'product'); print ''; print ''; print ''; - if ($backtopage) print ''; - if ($backtopageforcancel) print ''; + if ($backtopage) { + print ''; + } + if ($backtopageforcancel) { + print ''; + } print dol_get_fiche_head(array(), ''); @@ -218,16 +225,19 @@ if ($action == 'create') } // Part to edit record -if (($id || $ref) && $action == 'edit') -{ +if (($id || $ref) && $action == 'edit') { print load_fiche_titre($langs->trans("Inventory"), '', 'product'); print ''; print ''; print ''; print ''; - if ($backtopage) print ''; - if ($backtopageforcancel) print ''; + if ($backtopage) { + print ''; + } + if ($backtopageforcancel) { + print ''; + } print dol_get_fiche_head(); @@ -251,8 +261,7 @@ if (($id || $ref) && $action == 'edit') } // Part to show record -if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) -{ +if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); $head = inventoryPrepareHead($object); @@ -277,8 +286,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Confirmation of action xxxx - if ($action == 'xxx') - { + if ($action == 'xxx') { $formquestion = array(); /* $forcecombo=0; @@ -296,8 +304,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } // Print form confirm print $formconfirm; @@ -317,34 +328,34 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Project if (! empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($permissiontoadd) - { - if ($action != 'classify') - { - $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= $proj->getNomUrl(); - } else { - $morehtmlref.=''; - } - } + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($permissiontoadd) + { + if ($action != 'classify') + { + $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= $proj->getNomUrl(); + } else { + $morehtmlref.=''; + } + } } */ $morehtmlref .= ''; @@ -378,29 +389,26 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'."\n"; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } - if (empty($reshook)) - { + if (empty($reshook)) { // Send if (empty($user->socid)) { print ''.$langs->trans('SendMail').''."\n"; } // Back to draft - if ($object->status == $object::STATUS_VALIDATED) - { - if ($permissiontoadd) - { + if ($object->status == $object::STATUS_VALIDATED) { + if ($permissiontoadd) { print ''.$langs->trans("SetToDraft").''; } } // Modify - if ($object->status == $object::STATUS_DRAFT) - { - if ($permissiontoadd) - { + if ($object->status == $object::STATUS_DRAFT) { + if ($permissiontoadd) { print ''.$langs->trans("Modify").''."\n"; } else { print ''.$langs->trans('Modify').''."\n"; @@ -408,23 +416,20 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Validate - if ($object->status == $object::STATUS_DRAFT) - { - if ($permissiontoadd) - { + if ($object->status == $object::STATUS_DRAFT) { + if ($permissiontoadd) { print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; } } // Clone /*if ($permissiontoadd) - { - print ''.$langs->trans("ToClone").''."\n"; - }*/ + { + print ''.$langs->trans("ToClone").''."\n"; + }*/ // Delete (need delete permission, or if draft, just need create/modify permission) - if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) - { + if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { print ''.$langs->trans('Delete').''."\n"; } else { print ''.$langs->trans('Delete').''."\n"; @@ -439,8 +444,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $action = 'presend'; } - if ($action != 'presend') - { + if ($action != 'presend') { print '
'; print ''; // ancre @@ -478,7 +482,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea //Select mail models is same action as presend - if (GETPOST('modelselected')) $action = 'presend'; + if (GETPOST('modelselected')) { + $action = 'presend'; + } // Presend form $modelmail = 'inventory'; diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 47d9425530f..d7bd4956638 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -222,8 +222,12 @@ class Inventory extends CommonObject $this->db = $db; - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible'] = 0; - if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled'] = 0; + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) { + $this->fields['rowid']['visible'] = 0; + } + if (empty($conf->multicompany->enabled)) { + $this->fields['entity']['enabled'] = 0; + } } @@ -272,20 +276,24 @@ class Inventory extends CommonObject $sql .= ' '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'entrepot as e'; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; $sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid'; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0"; - if ($this->fk_product > 0) $sql .= ' AND ps.fk_product = '.$this->fk_product; - if ($this->fk_warehouse > 0) $sql .= ' AND ps.fk_entrepot = '.$this->fk_warehouse; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= " AND p.fk_product_type = 0"; + } + if ($this->fk_product > 0) { + $sql .= ' AND ps.fk_product = '.$this->fk_product; + } + if ($this->fk_warehouse > 0) { + $sql .= ' AND ps.fk_entrepot = '.$this->fk_warehouse; + } $inventoryline = new InventoryLine($this->db); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); $inventoryline->fk_inventory = $this->id; @@ -464,8 +472,7 @@ class Inventory extends CommonObject */ public function deleteLine(User $user, $idline, $notrigger = false) { - if ($this->status < 0) - { + if ($this->status < 0) { $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; return -2; } @@ -489,7 +496,9 @@ class Inventory extends CommonObject global $dolibarr_main_authentication, $dolibarr_main_demo; global $menumanager; - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } $result = ''; $companylink = ''; @@ -501,24 +510,28 @@ class Inventory extends CommonObject $url = dol_buildpath('/product/inventory/card.php', 1).'?id='.$this->id; $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowInventory"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } else { + $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } $linkstart = ''; $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->ref; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->ref; + } $result .= $linkend; //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); @@ -573,28 +586,23 @@ class Inventory extends CommonObject $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' WHERE t.rowid = '.$id; $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_author) - { + if ($obj->fk_user_author) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_author); $this->user_creation = $cuser; } - if ($obj->fk_user_valid) - { + if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); $this->user_validation = $vuser; } - if ($obj->fk_user_cloture) - { + if ($obj->fk_user_cloture) { $cluser = new User($this->db); $cluser->fetch($obj->fk_user_cloture); $this->user_cloture = $cluser; diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index d5c9ec4966b..40a7b3f6f64 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -45,8 +45,7 @@ $fk_product = GETPOST('fk_product', 'int'); $lineid = GETPOST('lineid', 'int'); $batch = GETPOST('batch', 'alphanohtml'); -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $result = restrictedArea($user, 'stock', $id); } else { $result = restrictedArea($user, 'stock', $id, '', 'inventory_advance'); @@ -66,12 +65,15 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); -foreach ($object->fields as $key => $val) -{ - if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } } -if (empty($action) && empty($id) && empty($ref)) $action = 'view'; +if (empty($action) && empty($id) && empty($ref)) { + $action = 'view'; +} // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. @@ -81,8 +83,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ //if ($user->socid > 0) $socid = $user->socid; //$result = restrictedArea($user, 'mymodule', $id); -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $permissiontoadd = $user->rights->stock->creer; $permissiontodelete = $user->rights->stock->supprimer; } else { @@ -99,10 +100,11 @@ $now = dol_now(); $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { $error = 0; $backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php'; @@ -197,8 +199,7 @@ jQuery(document).ready(function() { // Part to show record -if ($object->id > 0) -{ +if ($object->id > 0) { $res = $object->fetch_optionals(); $head = inventoryPrepareHead($object); @@ -211,8 +212,7 @@ if ($object->id > 0) $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); } // Confirmation to delete line - if ($action == 'deleteline') - { + if ($action == 'deleteline') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); } @@ -226,8 +226,11 @@ if ($object->id > 0) // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } // Print form confirm print $formconfirm; @@ -247,34 +250,34 @@ if ($object->id > 0) // Project if (! empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->inventory->creer) - { - if ($action != 'classify') - { - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.='
'; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=$proj->getNomUrl(); - } else { - $morehtmlref.=''; - } - } + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->inventory->creer) + { + if ($action != 'classify') + { + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=$proj->getNomUrl(); + } else { + $morehtmlref.=''; + } + } } */ $morehtmlref .= '
'; @@ -309,7 +312,9 @@ if ($object->id > 0) print ''; print ''; print ''; - if ($backtopage) print ''; + if ($backtopage) { + print ''; + } print '
'; print ''.$langs->trans("InventoryDesc").'
'; @@ -323,31 +328,28 @@ if ($object->id > 0) print '
'."\n"; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } - if (empty($reshook)) - { - if ($object->status == Inventory::STATUS_DRAFT) - { - if ($permissiontoadd) - { + if (empty($reshook)) { + if ($object->status == Inventory::STATUS_DRAFT) { + if ($permissiontoadd) { print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; } else { print ''.$langs->trans('Validate').' ('.$langs->trans("Start").')'."\n"; } } - if ($object->status == Inventory::STATUS_VALIDATED) - { - if ($permissiontoadd) - { + if ($object->status == Inventory::STATUS_VALIDATED) { + if ($permissiontoadd) { /* - if (!empty($conf->barcode->enabled)) { - print ''.$langs->trans("UpdateByScaningProductBarcode").''; - } - if (!empty($conf->productbatch->enabled)) { - print ''.$langs->trans('UpdateByScaningLot').''; - }*/ + if (!empty($conf->barcode->enabled)) { + print ''.$langs->trans("UpdateByScaningProductBarcode").''; + } + if (!empty($conf->productbatch->enabled)) { + print ''.$langs->trans('UpdateByScaningLot').''; + }*/ if (!empty($conf->barcode->enabled) || !empty($conf->productbatch->enabled)) { print ''.$langs->trans("UpdateByScaning").''; } @@ -356,10 +358,8 @@ if ($object->id > 0) } } - if ($object->status == Inventory::STATUS_VALIDATED) - { - if ($permissiontoadd) - { + if ($object->status == Inventory::STATUS_VALIDATED) { + if ($permissiontoadd) { print ''.$langs->trans("Finish").''."\n"; } else { print ''.$langs->trans('Finish').''."\n"; @@ -367,16 +367,16 @@ if ($object->id > 0) } /*if ($object->status == Inventory::STATUS_VALIDATED) - { - if ($permissiontoadd) - { - print ''.$langs->trans("RecordVerb").''."\n"; - } - else - { - print ''.$langs->trans('RecordVerb').''."\n"; - } - }*/ + { + if ($permissiontoadd) + { + print ''.$langs->trans("RecordVerb").''."\n"; + } + else + { + print ''.$langs->trans('RecordVerb').''."\n"; + } + }*/ } print '
'."\n"; } @@ -394,7 +394,9 @@ if ($object->id > 0) print ''; print ''; print ''; - if ($backtopage) print ''; + if ($backtopage) { + print ''; + } print '
'; //print '
'; @@ -459,14 +461,12 @@ if ($object->id > 0) //$sql = ''; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; $totalarray = array(); - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); if (is_object($cacheOfWarehouses[$obj->fk_warehouse])) { diff --git a/htdocs/product/inventory/list.php b/htdocs/product/inventory/list.php index 747abda86b8..64c332fbe1b 100644 --- a/htdocs/product/inventory/list.php +++ b/htdocs/product/inventory/list.php @@ -48,7 +48,9 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action +if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { + $page = 0; +} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -63,18 +65,20 @@ $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Default sort order (if not yet defined by previous GETPOST) -if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Security check $socid = 0; -if ($user->socid > 0) // Protection if external user -{ +if ($user->socid > 0) { // Protection if external user //$socid = $user->socid; accessforbidden(); } -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $result = restrictedArea($user, 'stock', $objectid); } else { $result = restrictedArea($user, 'stock', $objectid, '', 'inventory_advance'); @@ -83,30 +87,31 @@ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); -foreach ($object->fields as $key => $val) -{ - if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha')) { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } } // List of fields to search into when doing a "search in all" $fieldstosearchall = array(); -foreach ($object->fields as $key => $val) -{ - if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; +foreach ($object->fields as $key => $val) { + if ($val['searchall']) { + $fieldstosearchall['t.'.$key] = $val['label']; + } } // Definition of fields for list $arrayfields = array(); -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { // If $val['visible']==0, then we never show the field - if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']); + if (!empty($val['visible'])) { + $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']); + } } // Extra fields -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) -{ - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) - { +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) { $arrayfields["ef.".$key] = array( 'label'=>$extrafields->attributes[$object->table_element]['label'][$key], @@ -129,31 +134,33 @@ $permissiontodelete = $user->rights->stock->supprimer; * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { - foreach ($object->fields as $key => $val) - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + foreach ($object->fields as $key => $val) { $search[$key] = ''; } $toselect = ''; $search_array_options = array(); } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) - { + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation } @@ -182,13 +189,14 @@ $title = $langs->trans('ListOfInventories'); // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $sql .= 't.'.$key.', '; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + } } // Add fields from hooks $parameters = array(); @@ -196,20 +204,32 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $obje $sql .= preg_replace('/^,/', '', $hookmanager->resPrint); $sql = preg_replace('/,\s*$/', '', $sql); $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; -if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; -else $sql .= " WHERE 1 = 1"; -foreach ($search as $key => $val) -{ - if ($key == 'status' && $search[$key] == -1) continue; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +} +if ($object->ismultientitymanaged == 1) { + $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; +} else { + $sql .= " WHERE 1 = 1"; +} +foreach ($search as $key => $val) { + if ($key == 'status' && $search[$key] == -1) { + continue; + } $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); if (strpos($object->fields[$key]['type'], 'integer:') === 0) { - if ($search[$key] == '-1') $search[$key] = ''; + if ($search[$key] == '-1') { + $search[$key] = ''; + } $mode_search = 2; } - if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + if ($search[$key] != '') { + $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + } +} +if ($search_all) { + $sql .= natural_search(array_keys($fieldstosearchall), $search_all); } -if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all); //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear); // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -222,7 +242,7 @@ $sql .= $hookmanager->resPrint; $sql.= " GROUP BY " foreach($object->fields as $key => $val) { - $sql.='t.'.$key.', '; + $sql.='t.'.$key.', '; } // Add fields from extrafields if (! empty($extrafields->attributes[$object->table_element]['label'])) { @@ -239,26 +259,24 @@ $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $resql = $db->query($sql); $nbtotalofrecords = $db->num_rows($resql); - if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } } // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. -if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) -{ +if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) { $num = $nbtotalofrecords; } else { - if ($limit) $sql .= $db->plimit($limit + 1, $offset); + if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); + } $resql = $db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($db); exit; } @@ -267,8 +285,7 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit } // Direct jump if only one record found -if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) -{ +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) { $obj = $db->fetch_object($resql); $id = $obj->rowid; header("Location: ".DOL_URL_ROOT.'/inventory/card.php?id='.$id); @@ -284,14 +301,24 @@ llxHeader('', $title, $help_url); $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -foreach ($search as $key => $val) -{ - if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); - else $param .= '&search_'.$key.'='.urlencode($search[$key]); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +foreach ($search as $key => $val) { + if (is_array($search[$key]) && count($search[$key])) { + foreach ($search[$key] as $skey) { + $param .= '&search_'.$key.'[]='.urlencode($skey); + } + } else { + $param .= '&search_'.$key.'='.urlencode($search[$key]); + } +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); } -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -302,12 +329,18 @@ $arrayofmassactions = array( //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); -if ($permissiontodelete) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($permissiontodelete) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); +} +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); +} $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print '
'; -if ($optioncss != '') print ''; +if ($optioncss != '') { + print ''; +} print ''; print ''; print ''; @@ -327,9 +360,10 @@ $objecttmp = new Inventory($db); $trackid = 'stockinv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -if ($search_all) -{ - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); +if ($search_all) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; } @@ -340,11 +374,13 @@ $moreforfilter.= '
';*/ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} -if (!empty($moreforfilter)) -{ +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -361,20 +397,26 @@ print ''; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; } } @@ -396,15 +438,18 @@ print ''."\n"; // Fields title label // -------------------------------------------------------------------- print ''; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n"; } } @@ -421,11 +466,11 @@ print ''."\n"; // Detect if we need a fetch on each output line $needToFetchEachLine = 0; -if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) -{ - foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) - { - if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object +if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) { + foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) { + if (preg_match('/\$object/', $val)) { + $needToFetchEachLine++; // There is at least one compute field that use $object + } } } @@ -433,37 +478,50 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co // -------------------------------------------------------------------- $i = 0; $totalarray = array(); -while ($i < ($limit ? min($num, $limit) : $num)) -{ +while ($i < ($limit ? min($num, $limit) : $num)) { $obj = $db->fetch_object($resql); - if (empty($obj)) break; // Should not happen + if (empty($obj)) { + break; // Should not happen + } // Store properties in $object $object->setVarsFromFetchObj($obj); // Show here line of result print ''; - foreach ($object->fields as $key => $val) - { + foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } - if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + if (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif ($key == 'ref') { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } - if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; - if ($key == 'status') print $object->getLibStatut(5); - else print $object->showOutputField($val, $key, $object->$key, ''); + if ($key == 'status') { + print $object->getLibStatut(5); + } else { + print $object->showOutputField($val, $key, $object->$key, ''); + } print ''; - if (!$i) $totalarray['nbfield']++; - if (!empty($val['isameasure'])) - { - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + if (!$i) { + $totalarray['nbfield']++; + } + if (!empty($val['isameasure'])) { + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + } $totalarray['val']['t.'.$key] += $object->$key; } } @@ -476,14 +534,17 @@ while ($i < ($limit ? min($num, $limit) : $num)) print $hookmanager->resPrint; // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print ''."\n"; @@ -495,10 +556,13 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; // If no record found -if ($num == 0) -{ +if ($num == 0) { $colspan = 1; - foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } print ''; } @@ -514,10 +578,11 @@ print ''."\n"; print ''."\n"; -if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) -{ +if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $formfile = new FormFile($db); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index ff035dcdb9c..c0a35dabdb1 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -41,12 +41,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; -if (!empty($conf->categorie->enabled)) +if (!empty($conf->categorie->enabled)) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('products', 'stocks', 'suppliers', 'companies', 'margins')); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} $action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); @@ -92,17 +95,31 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action +if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { + $page = 0; +} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = "p.ref"; -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "p.ref"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Initialize context for list $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'productservicelist'; -if ((string) $type == '1') { $contextpage = 'servicelist'; if ($search_type == '') $search_type = '1'; } -if ((string) $type == '0') { $contextpage = 'productlist'; if ($search_type == '') $search_type = '0'; } +if ((string) $type == '1') { + $contextpage = 'servicelist'; if ($search_type == '') { + $search_type = '1'; + } +} +if ((string) $type == '0') { + $contextpage = 'productlist'; if ($search_type == '') { + $search_type = '0'; + } +} // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks $object = new Product($db); @@ -116,22 +133,27 @@ $formproduct = new FormProduct($db); $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); -if (empty($action)) $action = 'list'; +if (empty($action)) { + $action = 'list'; +} // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); $objcanvas = null; -if (!empty($canvas)) -{ +if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('product', 'list', $canvas); } // Security check -if ($search_type == '0') $result = restrictedArea($user, 'produit', '', '', '', '', '', 0); -elseif ($search_type == '1') $result = restrictedArea($user, 'service', '', '', '', '', '', 0); -else $result = restrictedArea($user, 'produit|service', '', '', '', '', '', 0); +if ($search_type == '0') { + $result = restrictedArea($user, 'produit', '', '', '', '', '', 0); +} elseif ($search_type == '1') { + $result = restrictedArea($user, 'service', '', '', '', '', '', 0); +} else { + $result = restrictedArea($user, 'produit|service', '', '', '', '', '', 0); +} // Define virtualdiffersfromphysical $virtualdiffersfromphysical = 0; @@ -140,8 +162,7 @@ if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) - || !empty($conf->mrp->enabled)) -{ + || !empty($conf->mrp->enabled)) { $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs. } @@ -155,8 +176,7 @@ $fieldstosearchall = array( ); // multilang -if (!empty($conf->global->MAIN_MULTILANGS)) -{ +if (!empty($conf->global->MAIN_MULTILANGS)) { $fieldstosearchall['pl.label'] = 'ProductLabelTranslated'; $fieldstosearchall['pl.description'] = 'ProductDescriptionTranslated'; $fieldstosearchall['pl.note'] = 'ProductNoteTranslated'; @@ -166,13 +186,13 @@ if (!empty($conf->barcode->enabled)) { $fieldstosearchall['pfp.barcode'] = 'GencodBuyPrice'; } // Personalized search criterias. Example: $conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS = 'p.ref=ProductRef;p.label=ProductLabel' -if (!empty($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS)) $fieldstosearchall = dolExplodeIntoArray($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS); +if (!empty($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS)) { + $fieldstosearchall = dolExplodeIntoArray($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS); +} -if (empty($conf->global->PRODUIT_MULTIPRICES)) -{ +if (empty($conf->global->PRODUIT_MULTIPRICES)) { $titlesellprice = $langs->trans("SellingPrice"); - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { $titlesellprice = $form->textwithpicto($langs->trans("SellingPrice"), $langs->trans("DefaultPriceRealPriceMayDependOnCustomer")); } } @@ -228,8 +248,7 @@ $arrayfields = array( // MultiPrices if ($conf->global->PRODUIT_MULTIPRICES) { - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i; if (!empty($conf->global->$keyforlabel)) { $labelp = $i.' - '.$langs->transnoentitiesnoconv($conf->global->$keyforlabel); @@ -254,24 +273,30 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} $rightskey = 'produit'; -if ($type == Product::TYPE_SERVICE) $rightskey = 'service'; +if ($type == Product::TYPE_SERVICE) { + $rightskey = 'service'; +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $sall = ""; $search_ref = ""; $search_label = ""; @@ -299,8 +324,12 @@ if (empty($reshook)) // Mass actions $objectclass = 'Product'; - if ((string) $search_type == '1') { $objectlabel = 'Services'; } - if ((string) $search_type == '0') { $objectlabel = 'Products'; } + if ((string) $search_type == '1') { + $objectlabel = 'Services'; + } + if ((string) $search_type == '0') { + $objectlabel = 'Products'; + } $permissiontoread = $user->rights->{$rightskey}->lire; $permissiontodelete = $user->rights->{$rightskey}->supprimer; @@ -316,10 +345,8 @@ if (empty($reshook)) $title = $langs->trans("ProductsAndServices"); -if ($search_type != '' && $search_type != '-1') -{ - if ($search_type == 1) - { +if ($search_type != '' && $search_type != '-1') { + if ($search_type == 1) { $texte = $langs->trans("Services"); } else { $texte = $langs->trans("Products"); @@ -334,55 +361,91 @@ $sql .= ' p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.a $sql .= ' p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,'; $sql .= ' p.datec as date_creation, p.tms as date_update, p.pmp, p.stock, p.cost_price,'; $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, fk_country, fk_state,'; -if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= ' p.fk_unit, cu.label as cu_label,'; +if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= ' p.fk_unit, cu.label as cu_label,'; +} $sql .= ' MIN(pfp.unitprice) as minsellprice'; if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) { $sql .= ', pac.rowid prod_comb_id'; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; -if (!empty($searchCategoryProductList) || !empty($catid)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; +} +if (!empty($searchCategoryProductList) || !empty($catid)) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; // multilang -if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'"; +if (!empty($conf->global->MAIN_MULTILANGS)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'"; +} if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; } -if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units cu ON cu.rowid = p.fk_unit"; +if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units cu ON cu.rowid = p.fk_unit"; +} $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; -if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); +if ($sall) { + $sql .= natural_search(array_keys($fieldstosearchall), $sall); +} // if the type is not 1, we show all products (type = 0,2,3) -if (dol_strlen($search_type) && $search_type != '-1') -{ - if ($search_type == 1) $sql .= " AND p.fk_product_type = 1"; - else $sql .= " AND p.fk_product_type <> 1"; +if (dol_strlen($search_type) && $search_type != '-1') { + if ($search_type == 1) { + $sql .= " AND p.fk_product_type = 1"; + } else { + $sql .= " AND p.fk_product_type <> 1"; + } } if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) { $sql .= " AND pac.rowid IS NULL"; } -if ($search_ref) $sql .= natural_search('p.ref', $search_ref); -if ($search_label) $sql .= natural_search('p.label', $search_label); -if ($search_barcode) $sql .= natural_search('p.barcode', $search_barcode); -if (isset($search_tosell) && dol_strlen($search_tosell) > 0 && $search_tosell != -1) $sql .= " AND p.tosell = ".((int) $search_tosell); -if (isset($search_tobuy) && dol_strlen($search_tobuy) > 0 && $search_tobuy != -1) $sql .= " AND p.tobuy = ".((int) $search_tobuy); -if (isset($search_tobatch) && dol_strlen($search_tobatch) > 0 && $search_tobatch != -1) $sql .= " AND p.tobatch = ".((int) $search_tobatch); -if ($search_vatrate) $sql .= natural_search('p.tva_tx', $search_vatrate, 1); -if (dol_strlen($canvas) > 0) $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; -if ($catid > 0) $sql .= " AND cp.fk_categorie = ".$catid; -if ($catid == -2) $sql .= " AND cp.fk_categorie IS NULL"; +if ($search_ref) { + $sql .= natural_search('p.ref', $search_ref); +} +if ($search_label) { + $sql .= natural_search('p.label', $search_label); +} +if ($search_barcode) { + $sql .= natural_search('p.barcode', $search_barcode); +} +if (isset($search_tosell) && dol_strlen($search_tosell) > 0 && $search_tosell != -1) { + $sql .= " AND p.tosell = ".((int) $search_tosell); +} +if (isset($search_tobuy) && dol_strlen($search_tobuy) > 0 && $search_tobuy != -1) { + $sql .= " AND p.tobuy = ".((int) $search_tobuy); +} +if (isset($search_tobatch) && dol_strlen($search_tobatch) > 0 && $search_tobatch != -1) { + $sql .= " AND p.tobatch = ".((int) $search_tobatch); +} +if ($search_vatrate) { + $sql .= natural_search('p.tva_tx', $search_vatrate, 1); +} +if (dol_strlen($canvas) > 0) { + $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; +} +if ($catid > 0) { + $sql .= " AND cp.fk_categorie = ".$catid; +} +if ($catid == -2) { + $sql .= " AND cp.fk_categorie IS NULL"; +} $searchCategoryProductSqlList = array(); if ($searchCategoryProductOperator == 1) { foreach ($searchCategoryProductList as $searchCategoryProduct) { @@ -407,16 +470,36 @@ if ($searchCategoryProductOperator == 1) { $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; } } -if ($fourn_id > 0) $sql .= " AND pfp.fk_soc = ".((int) $fourn_id); -if ($search_country) $sql .= " AND p.fk_country = ".$search_country; -if ($search_state) $sql .= " AND p.fk_state = ".$search_state; -if ($search_finished >= 0 && $search_finished !== '') $sql .= " AND p.finished = ".$search_finished; -if ($search_accountancy_code_sell) $sql .= natural_search('p.accountancy_code_sell', $search_accountancy_code_sell); -if ($search_accountancy_code_sell_intra) $sql .= natural_search('p.accountancy_code_sell_intra', $search_accountancy_code_sell_intra); -if ($search_accountancy_code_sell_export) $sql .= natural_search('p.accountancy_code_sell_export', $search_accountancy_code_sell_export); -if ($search_accountancy_code_buy) $sql .= natural_search('p.accountancy_code_buy', $search_accountancy_code_buy); -if ($search_accountancy_code_buy_intra) $sql .= natural_search('p.accountancy_code_buy_intra', $search_accountancy_code_buy_intra); -if ($search_accountancy_code_buy_export) $sql .= natural_search('p.accountancy_code_buy_export', $search_accountancy_code_buy_export); +if ($fourn_id > 0) { + $sql .= " AND pfp.fk_soc = ".((int) $fourn_id); +} +if ($search_country) { + $sql .= " AND p.fk_country = ".$search_country; +} +if ($search_state) { + $sql .= " AND p.fk_state = ".$search_state; +} +if ($search_finished >= 0 && $search_finished !== '') { + $sql .= " AND p.finished = ".$search_finished; +} +if ($search_accountancy_code_sell) { + $sql .= natural_search('p.accountancy_code_sell', $search_accountancy_code_sell); +} +if ($search_accountancy_code_sell_intra) { + $sql .= natural_search('p.accountancy_code_sell_intra', $search_accountancy_code_sell_intra); +} +if ($search_accountancy_code_sell_export) { + $sql .= natural_search('p.accountancy_code_sell_export', $search_accountancy_code_sell_export); +} +if ($search_accountancy_code_buy) { + $sql .= natural_search('p.accountancy_code_buy', $search_accountancy_code_buy); +} +if ($search_accountancy_code_buy_intra) { + $sql .= natural_search('p.accountancy_code_buy_intra', $search_accountancy_code_buy_intra); +} +if ($search_accountancy_code_buy_export) { + $sql .= natural_search('p.accountancy_code_buy_export', $search_accountancy_code_buy_export); +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -429,14 +512,18 @@ $sql .= " p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_ $sql .= ' p.datec, p.tms, p.entity, p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,'; $sql .= ' p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.pmp, p.cost_price, p.stock,'; $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.fk_country, p.fk_state'; -if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= ', p.fk_unit, cu.label'; +if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= ', p.fk_unit, cu.label'; +} if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) { $sql .= ', pac.rowid'; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); + } } // Add fields from hooks $parameters = array(); @@ -446,12 +533,10 @@ $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -461,14 +546,12 @@ $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $arrayofselected = is_array($toselect) ? $toselect : array(); - if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) - { + if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { $obj = $db->fetch_object($resql); $id = $obj->rowid; header("Location: ".DOL_URL_ROOT.'/product/card.php?id='.$id); @@ -476,22 +559,19 @@ if ($resql) } $helpurl = ''; - if ($search_type != '') - { - if ($search_type == 0) - { + if ($search_type != '') { + if ($search_type == 0) { $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; - } elseif ($search_type == 1) - { + } elseif ($search_type == 1) { $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } } - foreach ($searchCategoryProductList as $searchCategoryProduct) { - $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); - } + foreach ($searchCategoryProductList as $searchCategoryProduct) { + $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); + } - llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs'); + llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs'); // Displays product removal confirmation if (GETPOST('delprod')) { @@ -499,36 +579,88 @@ if ($resql) } $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sall) $param .= "&sall=".urlencode($sall); - if ($searchCategoryProductOperator == 1) $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sall) { + $param .= "&sall=".urlencode($sall); + } + if ($searchCategoryProductOperator == 1) { + $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator); + } foreach ($searchCategoryProductList as $searchCategoryProduct) { $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); } - if ($search_ref) $param = "&search_ref=".urlencode($search_ref); - if ($search_ref_supplier) $param = "&search_ref_supplier=".urlencode($search_ref_supplier); - if ($search_barcode) $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : ""); - if ($search_label) $param .= "&search_label=".urlencode($search_label); - if ($search_tosell != '') $param .= "&search_tosell=".urlencode($search_tosell); - if ($search_tobuy != '') $param .= "&search_tobuy=".urlencode($search_tobuy); - if ($search_tobatch) $param = "&search_tobatch=".urlencode($search_tobatch); - if ($search_country != '') $param .= "&search_country=".urlencode($search_country); - if ($search_state != '') $param .= "&search_state=".urlencode($search_state); - if ($search_vatrate) $param = "&search_vatrate=".urlencode($search_vatrate); - if ($fourn_id > 0) $param .= ($fourn_id ? "&fourn_id=".$fourn_id : ""); + if ($search_ref) { + $param = "&search_ref=".urlencode($search_ref); + } + if ($search_ref_supplier) { + $param = "&search_ref_supplier=".urlencode($search_ref_supplier); + } + if ($search_barcode) { + $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : ""); + } + if ($search_label) { + $param .= "&search_label=".urlencode($search_label); + } + if ($search_tosell != '') { + $param .= "&search_tosell=".urlencode($search_tosell); + } + if ($search_tobuy != '') { + $param .= "&search_tobuy=".urlencode($search_tobuy); + } + if ($search_tobatch) { + $param = "&search_tobatch=".urlencode($search_tobatch); + } + if ($search_country != '') { + $param .= "&search_country=".urlencode($search_country); + } + if ($search_state != '') { + $param .= "&search_state=".urlencode($search_state); + } + if ($search_vatrate) { + $param = "&search_vatrate=".urlencode($search_vatrate); + } + if ($fourn_id > 0) { + $param .= ($fourn_id ? "&fourn_id=".$fourn_id : ""); + } //if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):""); - if ($show_childproducts) $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); - if ($type != '') $param .= '&type='.urlencode($type); - if ($search_type != '') $param .= '&search_type='.urlencode($search_type); - if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); - if ($search_accountancy_code_sell) $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); - if ($search_accountancy_code_sell_intra) $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra); - if ($search_accountancy_code_sell_export) $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export); - if ($search_accountancy_code_buy) $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); - if ($search_accountancy_code_buy_intra) $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra); - if ($search_accountancy_code_buy_export) $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export); - if ($search_finished) $param = "&search_finished=".urlencode($search_finished); + if ($show_childproducts) { + $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); + } + if ($type != '') { + $param .= '&type='.urlencode($type); + } + if ($search_type != '') { + $param .= '&search_type='.urlencode($search_type); + } + if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); + } + if ($search_accountancy_code_sell) { + $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); + } + if ($search_accountancy_code_sell_intra) { + $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra); + } + if ($search_accountancy_code_sell_export) { + $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export); + } + if ($search_accountancy_code_buy) { + $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); + } + if ($search_accountancy_code_buy_intra) { + $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra); + } + if ($search_accountancy_code_buy_export) { + $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export); + } + if ($search_finished) { + $param = "&search_finished=".urlencode($search_finished); + } // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -539,30 +671,46 @@ if ($resql) //'presend'=>$langs->trans("SendByMail"), ); - if ($user->rights->{$rightskey}->supprimer) $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); - if ($user->rights->{$rightskey}->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); - if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); + if ($user->rights->{$rightskey}->supprimer) { + $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); + } + if ($user->rights->{$rightskey}->creer) { + $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); + } + if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) { + $arrayofmassactions = array(); + } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $newcardbutton = ''; - if ($type === "") $perm = ($user->rights->produit->creer || $user->rights->service->creer); - elseif ($type == Product::TYPE_SERVICE) $perm = $user->rights->service->creer; - elseif ($type == Product::TYPE_PRODUCT) $perm = $user->rights->produit->creer; + if ($type === "") { + $perm = ($user->rights->produit->creer || $user->rights->service->creer); + } elseif ($type == Product::TYPE_SERVICE) { + $perm = $user->rights->service->creer; + } elseif ($type == Product::TYPE_PRODUCT) { + $perm = $user->rights->produit->creer; + } $oldtype = $type; $params = array(); - if ($type === "") $params['forcenohideoftext'] = 1; + if ($type === "") { + $params['forcenohideoftext'] = 1; + } if ($type === "") { $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', $perm, $params); $type = Product::TYPE_SERVICE; } $label = 'NewProduct'; - if ($type == Product::TYPE_SERVICE) $label = 'NewService'; + if ($type == Product::TYPE_SERVICE) { + $label = 'NewService'; + } $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type='.$type, '', $perm, $params); $type = $oldtype; print ''; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; @@ -570,10 +718,14 @@ if ($resql) print ''; //print ''; print ''; - if (empty($arrayfields['p.fk_product_type']['checked'])) print ''; + if (empty($arrayfields['p.fk_product_type']['checked'])) { + print ''; + } $picto = 'product'; - if ($type == 1) $picto = 'service'; + if ($type == 1) { + $picto = 'service'; + } print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1); @@ -583,8 +735,7 @@ if ($resql) $trackid = 'prod'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - if (!empty($catid)) - { + if (!empty($catid)) { print "
"; $c = new Categorie($db); $ways = $c->print_all_ways(' > ', 'product/list.php'); @@ -592,16 +743,16 @@ if ($resql) print "

"; } - if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } // Filter on categories $moreforfilter = ''; - if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) - { + if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $moreforfilter .= '
'; $moreforfilter .= $langs->trans('Categories').': '; $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1); @@ -621,11 +772,13 @@ if ($resql) $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; - else $moreforfilter = $hookmanager->resPrint; + if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; + } else { + $moreforfilter = $hookmanager->resPrint; + } - if ($moreforfilter) - { + if ($moreforfilter) { print '
'; print $moreforfilter; print '
'; @@ -633,63 +786,57 @@ if ($resql) $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + if ($massactionbutton) { + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + } print '
'; print '
'; - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); - elseif (strpos($val['type'], 'integer:') === 0) { + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); + } elseif (strpos($val['type'], 'integer:') === 0) { print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1); - } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print ''; + } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) { + print ''; + } print '
'; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($object->id, $arrayofselected)) $selected = 1; + if (in_array($object->id, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'.$langs->trans("NoRecordFound").'
'."\n"; // Lines with input filters print ''; - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { print ''; } - if (!empty($arrayfields['pfp.ref_fourn']['checked'])) - { + if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { print ''; } - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { print ''; } // Type - if (!empty($arrayfields['p.fk_product_type']['checked'])) - { + if (!empty($arrayfields['p.fk_product_type']['checked'])) { print ''; } // Barcode - if (!empty($arrayfields['p.barcode']['checked'])) - { + if (!empty($arrayfields['p.barcode']['checked'])) { print ''; } // Duration - if (!empty($arrayfields['p.duration']['checked'])) - { + if (!empty($arrayfields['p.duration']['checked'])) { print ''; } // Finished - if (!empty($arrayfields['p.finished']['checked'])) - { + if (!empty($arrayfields['p.finished']['checked'])) { print ''; } // Weight - if (!empty($arrayfields['p.weight']['checked'])) - { + if (!empty($arrayfields['p.weight']['checked'])) { print ''; } @@ -699,8 +846,7 @@ if ($resql) print ''; } // Length - if (!empty($arrayfields['p.length']['checked'])) - { + if (!empty($arrayfields['p.length']['checked'])) { print ''; } @@ -720,8 +866,7 @@ if ($resql) print ''; } // Height - if (!empty($arrayfields['p.height']['checked'])) - { + if (!empty($arrayfields['p.height']['checked'])) { print ''; } @@ -731,8 +876,7 @@ if ($resql) print ''; } // Surface - if (!empty($arrayfields['p.surface']['checked'])) - { + if (!empty($arrayfields['p.surface']['checked'])) { print ''; } @@ -742,8 +886,7 @@ if ($resql) print ''; } // Volume - if (!empty($arrayfields['p.volume']['checked'])) - { + if (!empty($arrayfields['p.volume']['checked'])) { print ''; } @@ -754,25 +897,21 @@ if ($resql) } // Unit - if (!empty($arrayfields['cu.label']['checked'])) - { + if (!empty($arrayfields['cu.label']['checked'])) { print ''; } // Sell price - if (!empty($arrayfields['p.sellprice']['checked'])) - { + if (!empty($arrayfields['p.sellprice']['checked'])) { print ''; } // Multiprice if ($conf->global->PRODUIT_MULTIPRICES) { - foreach ($arraypricelevel as $key => $value) - { - if (!empty($arrayfields['p.sellprice'.$key]['checked'])) - { + foreach ($arraypricelevel as $key => $value) { + if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { print ''; } @@ -780,72 +919,87 @@ if ($resql) } // Minimum buying Price - if (!empty($arrayfields['p.minbuyprice']['checked'])) - { + if (!empty($arrayfields['p.minbuyprice']['checked'])) { print ''; } // Number buying Price - if (!empty($arrayfields['p.numbuyprice']['checked'])) - { + if (!empty($arrayfields['p.numbuyprice']['checked'])) { print ''; } // Sell price - if (!empty($arrayfields['p.tva_tx']['checked'])) - { + if (!empty($arrayfields['p.tva_tx']['checked'])) { print ''; } // WAP - if (!empty($arrayfields['p.pmp']['checked'])) - { + if (!empty($arrayfields['p.pmp']['checked'])) { print ''; } // cost_price - if (!empty($arrayfields['p.cost_price']['checked'])) - { + if (!empty($arrayfields['p.cost_price']['checked'])) { print ''; } // Limit for alert - if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) - { + if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { print ''; } // Desired stock - if (!empty($arrayfields['p.desiredstock']['checked'])) - { + if (!empty($arrayfields['p.desiredstock']['checked'])) { print ''; } // Stock - if (!empty($arrayfields['p.stock']['checked'])) print ''; + if (!empty($arrayfields['p.stock']['checked'])) { + print ''; + } // Stock - if (!empty($arrayfields['stock_virtual']['checked'])) print ''; + if (!empty($arrayfields['stock_virtual']['checked'])) { + print ''; + } // To batch - if (!empty($arrayfields['p.tobatch']['checked'])) print ''; + if (!empty($arrayfields['p.tobatch']['checked'])) { + print ''; + } // Country - if (!empty($arrayfields['p.fk_country']['checked'])) print ''; + if (!empty($arrayfields['p.fk_country']['checked'])) { + print ''; + } // State - if (!empty($arrayfields['p.fk_state']['checked'])) print ''; + if (!empty($arrayfields['p.fk_state']['checked'])) { + print ''; + } // Accountancy code sell - if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) print ''; - if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) print ''; - if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) print ''; + if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) { + print ''; + } + if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) { + print ''; + } + if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) { + print ''; + } // Accountancy code buy - if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) print ''; - if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) print ''; - if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) print ''; + if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) { + print ''; + } + if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) { + print ''; + } + if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) { + print ''; + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; // Fields from hook @@ -853,25 +1007,21 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['p.datec']['checked'])) - { + if (!empty($arrayfields['p.datec']['checked'])) { print ''; } // Date modification - if (!empty($arrayfields['p.tms']['checked'])) - { + if (!empty($arrayfields['p.tms']['checked'])) { print ''; } - if (!empty($arrayfields['p.tosell']['checked'])) - { + if (!empty($arrayfields['p.tosell']['checked'])) { print ''; } - if (!empty($arrayfields['p.tobuy']['checked'])) - { + if (!empty($arrayfields['p.tobuy']['checked'])) { print ''; @@ -906,29 +1056,53 @@ if ($resql) print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center '); } - if (!empty($arrayfields['p.weight']['checked'])) print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.weight_units']['checked'])) print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.length']['checked'])) print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.length_units']['checked'])) print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.width']['checked'])) print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.width_units']['checked'])) print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.height']['checked'])) print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.height_units']['checked'])) print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.surface']['checked'])) print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.surface_units']['checked'])) print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.volume']['checked'])) print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['p.volume_units']['checked'])) print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['cu.label']['checked'])) print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['p.weight']['checked'])) { + print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.weight_units']['checked'])) { + print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.length']['checked'])) { + print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.length_units']['checked'])) { + print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.width']['checked'])) { + print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.width_units']['checked'])) { + print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.height']['checked'])) { + print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.height_units']['checked'])) { + print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.surface']['checked'])) { + print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.surface_units']['checked'])) { + print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.volume']['checked'])) { + print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['p.volume_units']['checked'])) { + print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['cu.label']['checked'])) { + print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); + } if (!empty($arrayfields['p.sellprice']['checked'])) { print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); } // Multiprices if ($conf->global->PRODUIT_MULTIPRICES) { - foreach ($arraypricelevel as $key => $value) - { - if (!empty($arrayfields['p.sellprice'.$key]['checked'])) - { + foreach ($arraypricelevel as $key => $value) { + if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { print_liste_field_titre($arrayfields['p.sellprice'.$key]['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); } } @@ -1015,13 +1189,11 @@ if ($resql) $i = 0; $totalarray = array(); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) // If multilang is enabled - { + if (!empty($conf->global->MAIN_MULTILANGS)) { // If multilang is enabled $sql = "SELECT label"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; $sql .= " WHERE fk_product=".$obj->rowid; @@ -1029,10 +1201,11 @@ if ($resql) $sql .= " LIMIT 1"; $result = $db->query($sql); - if ($result) - { + if ($result) { $objtp = $db->fetch_object($result); - if (!empty($objtp->label)) $obj->label = $objtp->label; + if (!empty($objtp->label)) { + $obj->label = $objtp->label; + } } } @@ -1071,12 +1244,12 @@ if ($resql) } // STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock. - if ((!empty($conf->stock->enabled) && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) // To optimize call of load_stock - { - if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Not a service - { + if ((!empty($conf->stock->enabled) && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) { // To optimize call of load_stock + if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Not a service $option = 'nobatch'; - if (empty($arrayfields['stock_virtual']['checked'])) $option .= ',novirtual'; + if (empty($arrayfields['stock_virtual']['checked'])) { + $option .= ',novirtual'; + } $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock() } } @@ -1084,33 +1257,35 @@ if ($resql) print ''; // Ref - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { print '\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Ref supplier - if (!empty($arrayfields['pfp.ref_fourn']['checked'])) - { + if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { print '\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Label - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Type - if (!empty($arrayfields['p.fk_product_type']['checked'])) - { + if (!empty($arrayfields['p.fk_product_type']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Barcode - if (!empty($arrayfields['p.barcode']['checked'])) - { + if (!empty($arrayfields['p.barcode']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Duration - if (!empty($arrayfields['p.duration']['checked'])) - { + if (!empty($arrayfields['p.duration']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Finished - if (!empty($arrayfields['p.finished']['checked'])) - { + if (!empty($arrayfields['p.finished']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Weight - if (!empty($arrayfields['p.weight']['checked'])) - { + if (!empty($arrayfields['p.weight']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Weight units if (!empty($arrayfields['p.weight_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Length - if (!empty($arrayfields['p.length']['checked'])) - { + if (!empty($arrayfields['p.length']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Length units if (!empty($arrayfields['p.length_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Width - if (!empty($arrayfields['p.width']['checked'])) - { + if (!empty($arrayfields['p.width']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Width units if (!empty($arrayfields['p.width_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Height - if (!empty($arrayfields['p.height']['checked'])) - { + if (!empty($arrayfields['p.height']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Height units if (!empty($arrayfields['p.height_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Surface - if (!empty($arrayfields['p.surface']['checked'])) - { + if (!empty($arrayfields['p.surface']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Surface units if (!empty($arrayfields['p.surface_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Volume - if (!empty($arrayfields['p.volume']['checked'])) - { + if (!empty($arrayfields['p.volume']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Volume units if (!empty($arrayfields['p.volume_units']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Unit - if (!empty($arrayfields['cu.label']['checked'])) - { + if (!empty($arrayfields['cu.label']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Sell price - if (!empty($arrayfields['p.sellprice']['checked'])) - { + if (!empty($arrayfields['p.sellprice']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } @@ -1291,8 +1501,7 @@ if ($resql) $productpricescache[$obj->rowid] = array(); } - if ($obj->tosell) - { + if ($obj->tosell) { // Make 1 request for all price levels (without filter on price_level) and saved result into an cache array // then reuse the cache array if we need prices for other price levels $sqlp = "SELECT p.rowid, p.fk_product, p.price, p.price_ttc, p.price_level, p.date_price, p.price_base_type"; @@ -1300,16 +1509,13 @@ if ($resql) $sqlp .= " WHERE fk_product = ".$obj->rowid; $sqlp .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC"; $resultp = $db->query($sqlp); - if ($resultp) - { + if ($resultp) { $nump = $db->num_rows($resultp); $j = 0; - while ($j < $nump) - { + while ($j < $nump) { $objp = $db->fetch_object($resultp); - if (empty($productpricescache[$obj->rowid][$objp->price_level])) - { + if (empty($productpricescache[$obj->rowid][$objp->price_level])) { $productpricescache[$obj->rowid][$objp->price_level]['price'] = $objp->price; $productpricescache[$obj->rowid][$objp->price_level]['price_ttc'] = $objp->price_ttc; $productpricescache[$obj->rowid][$objp->price_level]['price_base_type'] = $objp->price_base_type; @@ -1324,13 +1530,10 @@ if ($resql) } } - foreach ($arraypricelevel as $key => $value) - { - if (!empty($arrayfields['p.sellprice'.$key]['checked'])) - { + foreach ($arraypricelevel as $key => $value) { + if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } } } // Better buy price - if (!empty($arrayfields['p.minbuyprice']['checked'])) - { + if (!empty($arrayfields['p.minbuyprice']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Number of buy prices - if (!empty($arrayfields['p.numbuyprice']['checked'])) - { + if (!empty($arrayfields['p.numbuyprice']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // WAP - if (!empty($arrayfields['p.pmp']['checked'])) - { + if (!empty($arrayfields['p.pmp']['checked'])) { print ''; } // Cost price - if (!empty($arrayfields['p.cost_price']['checked'])) - { + if (!empty($arrayfields['p.cost_price']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Desired stock - if (!empty($arrayfields['p.desiredstock']['checked'])) - { + if (!empty($arrayfields['p.desiredstock']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Stock real - if (!empty($arrayfields['p.stock']['checked'])) - { + if (!empty($arrayfields['p.stock']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Stock virtual - if (!empty($arrayfields['stock_virtual']['checked'])) - { + if (!empty($arrayfields['stock_virtual']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Lot/Serial - if (!empty($arrayfields['p.tobatch']['checked'])) - { + if (!empty($arrayfields['p.tobatch']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Country - if (!empty($arrayfields['p.fk_country']['checked'])) - { + if (!empty($arrayfields['p.fk_country']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // State - if (!empty($arrayfields['p.fk_state']['checked'])) - { + if (!empty($arrayfields['p.fk_state']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Accountancy code sell - if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Accountancy code buy - if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) - { + if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; @@ -1513,25 +1728,26 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['p.datec']['checked'])) - { + if (!empty($arrayfields['p.datec']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date modification - if (!empty($arrayfields['p.tms']['checked'])) - { + if (!empty($arrayfields['p.tms']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status (to sell) - if (!empty($arrayfields['p.tosell']['checked'])) - { + if (!empty($arrayfields['p.tosell']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status (to buy) - if (!empty($arrayfields['p.tobuy']['checked'])) - { + if (!empty($arrayfields['p.tobuy']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Action print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; $i++; diff --git a/htdocs/product/note.php b/htdocs/product/note.php index f0a6293383d..348d5956588 100644 --- a/htdocs/product/note.php +++ b/htdocs/product/note.php @@ -40,11 +40,15 @@ $action = GETPOST('action', 'aZ09'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); $object = new Product($db); -if ($id > 0 || !empty($ref)) $object->fetch($id, $ref); +if ($id > 0 || !empty($ref)) { + $object->fetch($id, $ref); +} $permissionnote = $user->rights->produit->creer; // Used by the include of actions_setnotes.inc.php @@ -63,30 +67,33 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, $form = new Form($db); $helpurl = ''; -if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; -if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { + $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; +} +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { + $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; +} $title = $langs->trans('ProductServiceCard'); $shortlabel = dol_trunc($object->label, 16); -if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) -{ +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Notes'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) -{ +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Notes'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } llxHeader('', $title, $help_url); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { /* - * Affichage onglets - */ - if (!empty($conf->notification->enabled)) $langs->load("mails"); + * Affichage onglets + */ + if (!empty($conf->notification->enabled)) { + $langs->load("mails"); + } $head = product_prepare_head($object); $titre = $langs->trans("CardProduct".$object->type); @@ -98,7 +105,9 @@ if ($id > 0 || !empty($ref)) $object->next_prev_filter = " fk_product_type = ".$object->type; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); diff --git a/htdocs/product/popuprop.php b/htdocs/product/popuprop.php index 37019616e96..001635be24b 100644 --- a/htdocs/product/popuprop.php +++ b/htdocs/product/popuprop.php @@ -39,16 +39,24 @@ $type = GETPOST("type", "int"); $mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : ''; // Security check -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -if (!$sortfield) $sortfield = "c"; -if (!$sortorder) $sortorder = "DESC"; +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 +if (!$sortfield) { + $sortfield = "c"; +} +if (!$sortorder) { + $sortorder = "DESC"; +} $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -88,8 +96,12 @@ if ((string) $type == '0') { $title = $langs->trans("ListProductByPopularity"); } -if ($type != '') $param .= '&type='.urlencode($type); -if ($mode != '') $param .= '&mode='.urlencode($mode); +if ($type != '') { + $param .= '&type='.urlencode($type); +} +if ($mode != '') { + $param .= '&mode='.urlencode($mode); +} $h = 0; $head = array(); @@ -134,8 +146,7 @@ $sql .= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type"; if (!empty($mode) && $mode != '-1') { $result = $db->query($sql); - if ($result) - { + if ($result) { $totalnboflines = $db->num_rows($result); } @@ -143,13 +154,11 @@ if (!empty($mode) && $mode != '-1') { $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($resql); $infoprod[$objp->rowid] = array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label); @@ -179,8 +188,12 @@ print ''; print ''; print ''; print ''; -if ($backtopage) print ''; -if ($backtopageforcancel) print ''; +if ($backtopage) { + print ''; +} +if ($backtopageforcancel) { + print ''; +} print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '', 0, '', '', -1, 0, 0, 1); @@ -195,11 +208,9 @@ print_liste_field_titre($textforqty, $_SERVER["PHP_SELF"], 'c', '', $param, '', print "\n"; if ($mode && $mode != '-1') { - foreach ($infoprod as $prodid => $vals) - { + foreach ($infoprod as $prodid => $vals) { // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { + if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active $sql = "SELECT label"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; $sql .= " WHERE fk_product=".$prodid; @@ -207,22 +218,29 @@ if ($mode && $mode != '-1') { $sql .= " LIMIT 1"; $resultp = $db->query($sql); - if ($resultp) - { + if ($resultp) { $objtp = $db->fetch_object($resultp); - if (!empty($objtp->label)) $vals['label'] = $objtp->label; + if (!empty($objtp->label)) { + $vals['label'] = $objtp->label; + } } } print ""; print ''; print ''; print ''; print ''; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 89695690d38..408c169e363 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -65,17 +65,20 @@ $search_soc = GETPOST('search_soc'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object = new Product($db); $object->fetch($id, $ref); } // Clean param -if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; +if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) { + $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('productpricecard', 'globalcard')); @@ -85,37 +88,36 @@ $hookmanager->initHooks(array('productpricecard', 'globalcard')); * Actions */ -if ($cancel) $action = ''; +if ($cancel) { + $action = ''; +} $parameters = array('id'=>$id, 'ref'=>$ref); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { +if (empty($reshook)) { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_soc = ''; } - if ($action == 'setlabelsellingprice' && $user->admin) - { + if ($action == 'setlabelsellingprice' && $user->admin) { require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.GETPOST('pricelevel'); dolibarr_set_const($db, $keyforlabel, GETPOST('labelsellingprice', 'alpha'), 'chaine', 0, '', $conf->entity); $action = ''; } - if (($action == 'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) - { + if (($action == 'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' // We must define tva_tx, npr and local taxes $tva_tx = $tva_tx_txt; $reg = array(); $vatratecode = ''; - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { $vat_src_code = $reg[1]; $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. } @@ -124,8 +126,7 @@ if (empty($reshook)) $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in create product. $vatratecode = $reg[1]; // Get record from code @@ -135,8 +136,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -157,21 +157,18 @@ if (empty($reshook)) $db->begin(); $resql = $object->update($object->id, $user); - if ($resql <= 0) - { + if ($resql <= 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } - if ($error) - { + if ($error) { //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2); $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them. $object->updatePrice(0, $object->price_base_type, $user, $tva_tx, '', 0, $npr, 0, 0, $localtaxarray, $vatratecode); } - if (!$error) - { + if (!$error) { $db->commit(); } else { $db->rollback(); @@ -180,8 +177,7 @@ if (empty($reshook)) $action = ''; } - if (($action == 'update_price') && !$cancel && $object->getRights()->creer) - { + if (($action == 'update_price') && !$cancel && $object->getRights()->creer) { $error = 0; $pricestoupdate = array(); @@ -218,8 +214,7 @@ if (empty($reshook)) //Shall we generate prices using price rules? $object->price_autogen = GETPOST('usePriceRules') == 'on'; - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { if (!isset($newprice[$i])) { continue; } @@ -229,8 +224,7 @@ if (empty($reshook)) $tva_tx = $tva_tx_txt; $vatratecode = ''; $reg = array(); - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { $vat_src_code = $reg[1]; $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. } @@ -241,8 +235,7 @@ if (empty($reshook)) $localtax1_type = $newlocaltax1_type[$i]; $localtax2 = $newlocaltax2_tx[$i]; $localtax2_type = $newlocaltax2_type[$i]; - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code $vatratecode = $reg[1]; // Get record from code @@ -252,8 +245,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -278,8 +270,7 @@ if (empty($reshook)) break; } } - } elseif (!$error) - { + } elseif (!$error) { $newprice = price2num(GETPOST('price', 'alpha'), '', 2); $newprice_min = price2num(GETPOST('price_min', 'alpha'), '', 2); $newpricebase = GETPOST('price_base_type', 'alpha'); @@ -288,8 +279,7 @@ if (empty($reshook)) $tva_tx = $tva_tx_txt; $vatratecode = ''; $reg = array(); - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { $vat_src_code = $reg[1]; $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. } @@ -298,8 +288,7 @@ if (empty($reshook)) $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code $vatratecode = $reg[1]; // Get record from code @@ -309,8 +298,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -319,10 +307,9 @@ if (empty($reshook)) $localtax2_type = $obj->localtax2_type; // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule - if (in_array($mysoc->country_code, array('ES'))) - { + if (in_array($mysoc->country_code, array('ES'))) { $localtax1 = get_localtax($tva_tx, 1); - $localtax2 = get_localtax($tva_tx, 2); + $localtax2 = get_localtax($tva_tx, 2); } } } @@ -356,9 +343,11 @@ if (empty($reshook)) break; } - if ($object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type']) - $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']); - else $res = 0; + if ($object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type']) { + $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']); + } else { + $res = 0; + } if ($res < 0) { @@ -385,8 +374,7 @@ if (empty($reshook)) } - if ($action == 'delete' && $user->rights->produit->supprimer) - { + if ($action == 'delete' && $user->rights->produit->supprimer) { $result = $object->log_price_delete($user, GETPOST('lineid', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -394,28 +382,24 @@ if (empty($reshook)) } // Set Price by quantity - if ($action == 'activate_price_by_qty') - { + if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price line with price_by_qty set to 1 $level = GETPOST('level', 'int'); $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1); } // Unset Price by quantity - if ($action == 'disable_price_by_qty') - { + if ($action == 'disable_price_by_qty') { // Disabling product price by quantity add a new price line with price_by_qty set to 0 $level = GETPOST('level', 'int'); $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0); } - if ($action == 'edit_price_by_qty') - { // Edition d'un prix par quantité + if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité $rowid = GETPOST('rowid', 'int'); } // Add or update price by quantity - if ($action == 'update_price_by_qty') - { + if ($action == 'update_price_by_qty') { // Récupération des variables $rowid = GETPOST('rowid', 'int'); $priceid = GETPOST('priceid', 'int'); @@ -453,7 +437,9 @@ if (empty($reshook)) $sql .= " WHERE rowid = ".$rowid; $result = $db->query($sql); - if (!$result) dol_print_error($db); + if (!$result) { + dol_print_error($db); + } } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values ("; $sql .= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')'; @@ -470,8 +456,7 @@ if (empty($reshook)) } } - if ($action == 'delete_price_by_qty') - { + if ($action == 'delete_price_by_qty') { $rowid = GETPOST('rowid', 'int'); if (!empty($rowid)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty"; @@ -517,8 +502,7 @@ if (empty($reshook)) $tva_tx = $tva_tx_txt; $vatratecode = ''; - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { $vat_src_code = $reg[1]; $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. } @@ -527,8 +511,7 @@ if (empty($reshook)) $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code $vatratecode = $reg[1]; // Get record from code @@ -538,8 +521,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -557,23 +539,20 @@ if (empty($reshook)) $prodcustprice->localtax1_type = $localtax1_type; $prodcustprice->localtax2_type = $localtax2_type; - if (!($prodcustprice->fk_soc > 0)) - { + if (!($prodcustprice->fk_soc > 0)) { $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors'); $error++; $action = 'add_customer_price'; } - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min < $maxpricesupplier) - { + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min < $maxpricesupplier) { $langs->load("errors"); setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors'); $error++; $action = 'add_customer_price'; } - if (!$error) - { + if (!$error) { $result = $prodcustprice->create($user, 0, $update_child_soc); if ($result < 0) { @@ -586,8 +565,7 @@ if (empty($reshook)) } } - if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) - { + if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) { // Delete price by customer $prodcustprice->id = GETPOST('lineid'); $result = $prodcustprice->delete($user); @@ -600,8 +578,7 @@ if (empty($reshook)) $action = ''; } - if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) - { + if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { $maxpricesupplier = $object->min_recommended_price(); $update_child_soc = GETPOST('updatechildprice', 'int'); @@ -618,8 +595,7 @@ if (empty($reshook)) $tva_tx = $tva_tx_txt; $vatratecode = ''; - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { $vat_src_code = $reg[1]; $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. } @@ -628,8 +604,7 @@ if (empty($reshook)) $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes - if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) - { + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) { // We look into database using code $vatratecode = $reg[1]; // Get record from code @@ -639,8 +614,7 @@ if (empty($reshook)) $sql .= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; $localtax1 = $obj->localtax1; @@ -658,15 +632,13 @@ if (empty($reshook)) $prodcustprice->localtax1_type = $localtax1_type; $prodcustprice->localtax2_type = $localtax2_type; - if ($prodcustprice->price_min < $maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) - { + if ($prodcustprice->price_min < $maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors'); $error++; $action = 'update_customer_price'; } - if (!$error) - { + if (!$error) { $result = $prodcustprice->update($user, 0, $update_child_soc); if ($result < 0) { @@ -687,8 +659,7 @@ if (empty($reshook)) $form = new Form($db); -if (!empty($id) || !empty($ref)) -{ +if (!empty($id) || !empty($ref)) { // fetch updated prices $object->fetch($id, $ref); } @@ -696,13 +667,11 @@ if (!empty($id) || !empty($ref)) $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); -if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) -{ +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('SellingPrices'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } -if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) -{ +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('SellingPrices'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } @@ -719,7 +688,9 @@ $linkback = ''; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; $array = array('-1'=>' ', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service')); print $form->selectarray('search_type', $array, $search_type); print ''; print ''; print ''; print ''; print $formproduct->selectProductNature('search_finished', $search_finished); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ' '; print ''; print ' '; print ''; print ''; print ''; print ' '; print ''; print ' '; print ''; print ' '; print ''; print ' '; print '    '.$form->selectyesno('search_tobatch', $search_tobatch, 1, false, 1).''.$form->selectyesno('search_tobatch', $search_tobatch, 1, false, 1).''.$form->select_country($search_country, 'search_country', '', 0).''.$form->select_country($search_country, 'search_country', '', 0).''.$formcompany->select_state($search_state, $search_country).''.$formcompany->select_state($search_state, $search_country).''; print ''; print ''; print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1); print ''; print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1); print '
'; print $product_static->getNomUrl(1); print "'; print $product_static->getNomUrl(1); print "'.$obj->label.''; $s = ''; if ($obj->fk_product_type == 0) { @@ -1120,165 +1295,200 @@ if ($resql) } print $s; print ''.$obj->barcode.''; - if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) - { + if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) { $duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); $duration_unit = substr($obj->duration, -1); - if ((float) $duration_value > 1) - { + if ((float) $duration_value > 1) { $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); - } elseif ((float) $duration_value > 0) - { + } elseif ((float) $duration_value > 0) { $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); } print $duration_value; print ((!empty($duration_unit) && isset($dur[$duration_unit]) && $duration_value != '') ? ' '.$langs->trans($dur[$duration_unit]) : ''); - } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) // If duration is a simple char (like 's' of 'm'), we do not show value - { + } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) { // If duration is a simple char (like 's' of 'm'), we do not show value print $obj->duration; } print ''; print $product_static->getLibFinished(); print ''; print $obj->weight; print ''; - if ($product_static->weight != '') print measuringUnitString(0, 'weight', $product_static->weight_units); + if ($product_static->weight != '') { + print measuringUnitString(0, 'weight', $product_static->weight_units); + } print ''; print $obj->length; print ''; - if ($product_static->length != '') print measuringUnitString(0, 'size', $product_static->length_units); + if ($product_static->length != '') { + print measuringUnitString(0, 'size', $product_static->length_units); + } print ''; print $obj->width; print ''; - if ($product_static->width != '') print measuringUnitString(0, 'size', $product_static->width_units); + if ($product_static->width != '') { + print measuringUnitString(0, 'size', $product_static->width_units); + } print ''; print $obj->height; print ''; - if ($product_static->height != '') print measuringUnitString(0, 'size', $product_static->height_units); + if ($product_static->height != '') { + print measuringUnitString(0, 'size', $product_static->height_units); + } print ''; print $obj->surface; print ''; - if ($product_static->surface != '') print measuringUnitString(0, 'surface', $product_static->surface_units); + if ($product_static->surface != '') { + print measuringUnitString(0, 'surface', $product_static->surface_units); + } print ''; print $obj->volume; print ''; - if ($product_static->volume != '') print measuringUnitString(0, 'volume', $product_static->volume_units); + if ($product_static->volume != '') { + print measuringUnitString(0, 'volume', $product_static->volume_units); + } print ''; if (!empty($obj->cu_label)) { print $langs->trans($obj->cu_label); } print ''; - if ($obj->tosell) - { - if ($obj->price_base_type == 'TTC') print price($obj->price_ttc).' '.$langs->trans("TTC"); - else print price($obj->price).' '.$langs->trans("HT"); + if ($obj->tosell) { + if ($obj->price_base_type == 'TTC') { + print price($obj->price_ttc).' '.$langs->trans("TTC"); + } else { + print price($obj->price).' '.$langs->trans("HT"); + } } print ''; - if (!empty($productpricescache[$obj->rowid])) - { + if (!empty($productpricescache[$obj->rowid])) { if ($productpricescache[$obj->rowid][$key]['price_base_type'] == 'TTC') { print price($productpricescache[$obj->rowid][$key]['price_ttc']).' '.$langs->trans("TTC"); } else { @@ -1338,42 +1541,40 @@ if ($resql) } } print ''; - if ($obj->tobuy && $obj->minsellprice != '') - { + if ($obj->tobuy && $obj->minsellprice != '') { //print price($obj->minsellprice).' '.$langs->trans("HT"); - if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) - { - if ($product_fourn->product_fourn_price_id > 0) - { - if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire) - { + if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) { + if ($product_fourn->product_fourn_price_id > 0) { + if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire) { $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1); print $form->textwithpicto(price($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent / 100) - $product_fourn->fourn_remise).' '.$langs->trans("HT"), $htmltext); - } else print price($product_fourn->fourn_unitprice).' '.$langs->trans("HT"); + } else { + print price($product_fourn->fourn_unitprice).' '.$langs->trans("HT"); + } } } } print ''; - if ($obj->tobuy) - { - if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) - { + if ($obj->tobuy) { + if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) { $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1, $productFournList); print $form->textwithpicto(count($productFournList), $htmltext); } @@ -1382,24 +1583,23 @@ if ($resql) } // VAT or Sell Tax Rate - if (!empty($arrayfields['p.tva_tx']['checked'])) - { + if (!empty($arrayfields['p.tva_tx']['checked'])) { print ''; print vatrate($obj->tva_tx, true); print ''; print price($product_static->pmp, 1, $langs); print ''; //print $obj->cost_price; print price($obj->cost_price).' '.$langs->trans("HT"); @@ -1407,104 +1607,119 @@ if ($resql) } // Limit alert - if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) - { + if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { print ''; - if ($obj->fk_product_type != 1) - { + if ($obj->fk_product_type != 1) { print $obj->seuil_stock_alerte; } print ''; - if ($obj->fk_product_type != 1) - { + if ($obj->fk_product_type != 1) { print $obj->desiredstock; } print ''; - if ($obj->fk_product_type != 1) - { - if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + if ($obj->fk_product_type != 1) { + if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) { + print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + } print price2num($product_static->stock_reel, 'MS'); } print ''; - if ($obj->fk_product_type != 1) - { - if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + if ($obj->fk_product_type != 1) { + if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) { + print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + } print price2num($product_static->stock_theorique, 'MS'); } print ''; print yn($obj->tobatch); print ''.getCountry($obj->fk_country, 0, $db).''; - if (!empty($obj->fk_state)) print getState($obj->fk_state, 0, $db); + if (!empty($obj->fk_state)) { + print getState($obj->fk_state, 0, $db); + } print ''.$obj->accountancy_code_sell.''.$obj->accountancy_code_sell_intra.''.$obj->accountancy_code_sell_export.''.$obj->accountancy_code_buy.''.$obj->accountancy_code_buy_intra.''.$obj->accountancy_code_buy_export.''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); print ''; if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell'); @@ -1539,11 +1755,12 @@ if ($resql) print $product_static->LibStatut($obj->tosell, 5, 0); } print ''; if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy'); @@ -1551,19 +1768,24 @@ if ($resql) print $product_static->LibStatut($obj->tobuy, 5, 1); } print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'; - if ($vals['type'] == 1) print img_object($langs->trans("ShowService"), "service"); - else print img_object($langs->trans("ShowProduct"), "product"); + if ($vals['type'] == 1) { + print img_object($langs->trans("ShowService"), "service"); + } else { + print img_object($langs->trans("ShowProduct"), "product"); + } print " "; print $vals['ref'].''; - if ($vals['type'] == 1) print $langs->trans("Service"); - else print $langs->trans("Product"); + if ($vals['type'] == 1) { + print $langs->trans("Service"); + } else { + print $langs->trans("Product"); + } print ''.$vals['label'].''.$vals['nbline'].'
'; // Price per customer segment/level -if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) -{ +if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { // Price and min price are variable (depends on level of company). - if (!empty($socid)) - { + if (!empty($socid)) { $soc = new Societe($db); $soc->id = $socid; $soc->fetch($socid); @@ -758,24 +727,30 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ // Price min print ''; - if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility - { + if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility // TVA print ''; @@ -784,22 +759,29 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; } } else { - if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility - { + if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility // We show only vat for level 1 print ''; print ''; @@ -809,17 +791,25 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; } print '
'.$langs->trans("MinPrice").''; - if ($object->multiprices_base_type[$soc->price_level] == 'TTC') - { + if ($object->multiprices_base_type[$soc->price_level] == 'TTC') { print price($object->multiprices_min_ttc[$soc->price_level]).' '.$langs->trans($object->multiprices_base_type[$soc->price_level]); } else { print price($object->multiprices_min[$soc->price_level]).' '.$langs->trans(empty($object->multiprices_base_type[$soc->price_level]) ? 'HT' : $object->multiprices_base_type[$soc->price_level]); } print '
'.$langs->trans("DefaultTaxRate").''; $positiverates = ''; - if (price2num($object->multiprices_tva_tx[$soc->price_level])) $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_tva_tx[$soc->price_level]); - if (price2num($object->multiprices_localtax1_type[$soc->price_level])) $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax1_tx[$soc->price_level]); - if (price2num($object->multiprices_localtax2_type[$soc->price_level])) $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax2_tx[$soc->price_level]); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($object->multiprices_tva_tx[$soc->price_level])) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_tva_tx[$soc->price_level]); + } + if (price2num($object->multiprices_localtax1_type[$soc->price_level])) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax1_tx[$soc->price_level]); + } + if (price2num($object->multiprices_localtax2_type[$soc->price_level])) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax2_tx[$soc->price_level]); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); //print vatrate($object->multiprices_tva_tx[$soc->price_level], true); print '
'.$langs->trans("DefaultTaxRate").''; $positiverates = ''; - if (price2num($object->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); - if (price2num($object->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); - if (price2num($object->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($object->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); + } + if (price2num($object->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); + } + if (price2num($object->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); /* if ($object->default_vat_code) - { - print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; - } - else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ print '
'.$langs->trans("DefaultTaxRate").''.vatrate($object->multiprices_tva_tx[1], true).'
'.$langs->trans("DefaultTaxRate").''; $positiverates = ''; - if (price2num($object->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); - if (price2num($object->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); - if (price2num($object->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($object->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); + } + if (price2num($object->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); + } + if (price2num($object->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); /* - if ($object->default_vat_code) - { - print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; - } - else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ + if ($object->default_vat_code) + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ print '
'; @@ -829,21 +819,21 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; print ''; print ''; print ''; print ''; - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { print ''; // Label of price print ''; @@ -872,9 +864,10 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ // Prix min print ''; // Price by quantity - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // TODO Fix the form included into a tr instead of a td - { + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { // TODO Fix the form included into a tr instead of a td print ''; print ''; print ''; - foreach ($object->prices_by_qty_list[$i] as $ii => $prices) - { + foreach ($object->prices_by_qty_list[$i] as $ii => $prices) { if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) { print ''; print ''; @@ -963,15 +956,23 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; @@ -995,8 +996,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; // Price by quantity - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // TODO Fix the form inside tr instead of td - { + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { // TODO Fix the form inside tr instead of td print '
'; print $langs->trans("PriceLevel"); - if ($user->admin) print ' id.'">'.img_edit($langs->trans('EditSellingPriceLabel'), 0).''; + if ($user->admin) { + print ' id.'">'.img_edit($langs->trans('EditSellingPriceLabel'), 0).''; + } print ''.$langs->trans("SellingPrice").''.$langs->trans("MinPrice").'
'; $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i; - if (preg_match('/editlabelsellingprice/', $action)) - { + if (preg_match('/editlabelsellingprice/', $action)) { print ''; print ''; print ''; @@ -854,7 +844,9 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; } else { print $langs->trans("SellingPrice").' '.$i; - if (!empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel); + if (!empty($conf->global->$keyforlabel)) { + print ' - '.$langs->trans($conf->global->$keyforlabel); + } } print ''; - if (empty($object->multiprices_base_type[$i])) $object->multiprices_base_type[$i] = "HT"; - if ($object->multiprices_base_type[$i] == 'TTC') - { + if (empty($object->multiprices_base_type[$i])) { + $object->multiprices_base_type[$i] = "HT"; + } + if ($object->multiprices_base_type[$i] == 'TTC') { print price($object->multiprices_min_ttc[$i]).' '.$langs->trans($object->multiprices_base_type[$i]); } else { print price($object->multiprices_min[$i]).' '.$langs->trans($object->multiprices_base_type[$i]); @@ -882,10 +875,11 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print '
'.$langs->trans("PriceByQuantity").' '.$i; - if (!empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel); + if (!empty($conf->global->$keyforlabel)) { + print ' - '.$langs->trans($conf->global->$keyforlabel); + } print ''; if ($object->prices_by_qty[$i] == 1) { @@ -898,8 +892,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''.$langs->trans("Discount").' 
'.$langs->trans("DefaultTaxRate").''; $positiverates = ''; - if (price2num($object->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); - if (price2num($object->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); - if (price2num($object->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($object->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); + } + if (price2num($object->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); + } + if (price2num($object->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); /* if ($object->default_vat_code) { - print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; } else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/ print '
'.$langs->trans("PriceByQuantity"); if ($object->prices_by_qty[0] == 0) { print '  ('.$langs->trans("Activate").')'; @@ -1005,8 +1005,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ } print ''; - if ($object->prices_by_qty[0] == 1) - { + if ($object->prices_by_qty[0] == 1) { print ''; print ''; //print ''; @@ -1017,8 +1016,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; print ''; print ''; - if ($action != 'edit_price_by_qty') - { + if ($action != 'edit_price_by_qty') { print ''; // FIXME a form into a table is not allowed print ''; print ''; @@ -1038,10 +1036,8 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; } - foreach ($object->prices_by_qty_list[0] as $ii => $prices) - { - if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) - { + foreach ($object->prices_by_qty_list[0] as $ii => $prices) { + if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) { print ''; print ''; print ''; @@ -1070,8 +1066,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_ print ''; print ''; print ''; print ''; - // Only show price mode and expression selector if module is enabled + // Only show price mode and expression selector if module is enabled if (!empty($conf->dynamicprices->enabled)) { // Price mode selector print ''; } print ''; @@ -1333,8 +1323,11 @@ if ($action == 'edit_price' && $object->getRights()->creer) print ''; - if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) print ''; - else print ''; + if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { + print ''; + } else { + print ''; + } print ''; @@ -1347,8 +1340,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) print ''; - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { print ''; print ''; } print ''; @@ -1415,8 +1406,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) // List of price changes - log historic (ordered by descending date) -if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_default_price') && !in_array($action, array('edit_price', 'edit_vat'))) -{ +if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_default_price') && !in_array($action, array('edit_price', 'edit_vat'))) { $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type,"; $sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,"; $sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login"; @@ -1425,29 +1415,29 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul $sql .= " WHERE fk_product = ".$object->id; $sql .= " AND p.entity IN (".getEntity('productprice').")"; $sql .= " AND p.fk_user_author = u.rowid"; - if (!empty($socid) && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql .= " AND p.price_level = ".$soc->price_level; + if (!empty($socid) && !empty($conf->global->PRODUIT_MULTIPRICES)) { + $sql .= " AND p.price_level = ".$soc->price_level; + } $sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC"; // $sql .= $db->plimit(); $result = $db->query($sql); - if ($result) - { + if ($result) { print '
'; $num = $db->num_rows($result); - if (!$num) - { + if (!$num) { $db->free($result); - // Il doit au moins y avoir la ligne de prix initial. - // On l'ajoute donc pour remettre a niveau (pb vieilles versions) - // We emulate the change of the price from interface with the same value than the one into table llx_product - if (!empty($conf->global->PRODUIT_MULTIPRICES)) { - $object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1); - } else { - $object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min)); - } + // Il doit au moins y avoir la ligne de prix initial. + // On l'ajoute donc pour remettre a niveau (pb vieilles versions) + // We emulate the change of the price from interface with the same value than the one into table llx_product + if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + $object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1); + } else { + $object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min)); + } $result = $db->query($sql); $num = $db->num_rows($result); @@ -1458,8 +1448,11 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul // Log of previous customer prices $backbutton = ''.$langs->trans("Back").''; - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print_barre_liste($langs->trans("DefaultPriceLog"), 0, $_SERVER["PHP_SELF"], '', '', '', $backbutton, 0, $num, 'title_accountancy.png'); - else print_barre_liste($langs->trans("PriceByCustomerLog"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $num, 'title_accountancy.png'); + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + print_barre_liste($langs->trans("DefaultPriceLog"), 0, $_SERVER["PHP_SELF"], '', '', '', $backbutton, 0, $num, 'title_accountancy.png'); + } else { + print_barre_liste($langs->trans("PriceByCustomerLog"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $num, 'title_accountancy.png'); + } print '
'; print '
' . $langs->trans("PriceByQuantityRange") . ''.$langs->trans("Discount").' 
'.price($prices['unitprice']).''.price($prices['remise_percent']).' %'; - if (($user->rights->produit->creer || $user->rights->service->creer)) - { + if (($user->rights->produit->creer || $user->rights->service->creer)) { print ''; print img_edit().''; print ''; @@ -1108,8 +1103,7 @@ print dol_get_fiche_end(); /* ************************************************************************** */ if (!$action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'showlog_default_price' || $action == 'add_customer_price' - || $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty') -{ + || $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty') { print "\n".'
'."\n"; if ($object->isVariant()) { @@ -1149,8 +1143,7 @@ if (!$action || $action == 'delete' || $action == 'showlog_customer_price' || $a * Edit price area */ -if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->service->creer)) -{ +if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->service->creer)) { print load_fiche_titre($langs->trans("UpdateVAT"), ''); print ''; @@ -1180,12 +1173,10 @@ if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->se print '

'; } -if ($action == 'edit_price' && $object->getRights()->creer) -{ +if ($action == 'edit_price' && $object->getRights()->creer) { print load_fiche_titre($langs->trans("NewPrice"), ''); - if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { + if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { print ''."\n"; print '
'; print ''; @@ -1210,7 +1201,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) print '
'.$langs->trans("PriceMode").''; @@ -1270,8 +1261,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) } else { print ''; } - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) - { + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { print '   '.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().''.$langs->trans("PriceLevel").''.$langs->trans("DefaultTaxRate").''.$langs->trans("DefaultTaxRate").''.$langs->trans("SellingPrice").'
'; $text = $langs->trans('SellingPrice').' '.$i; @@ -1389,8 +1381,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) } else { print ''; } - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) - { + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'
'; @@ -1476,7 +1469,9 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print ''; print $conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL; - if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) print ''; + if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + print ''; + } print ''; print ''; if (!empty($conf->dynamicprices->enabled)) { @@ -1485,15 +1480,15 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print ''; print ''; print ''; - if ($user->rights->produit->supprimer) + if ($user->rights->produit->supprimer) { print ''; + } print ''; $notfirstlineforlevel = array(); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($result); print ''; @@ -1505,8 +1500,7 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print '"; } // Price by quantity - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { $type = ($objp->price_by_qty == 1) ? 'PriceByQuantity' : 'Standard'; print '"; } @@ -1517,31 +1511,37 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul } print ""; - if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { + if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { print '"; } // Price - if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) - { + if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) { $price_expression = new PriceExpression($db); $res = $price_expression->fetch($objp->fk_price_expression); $title = $price_expression->title; @@ -1586,22 +1586,26 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul print ''; // Action - if ($user->rights->produit->supprimer) - { + if ($user->rights->produit->supprimer) { $candelete = 0; - if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { - if (empty($notfirstlineforlevel[$objp->price_level])) $notfirstlineforlevel[$objp->price_level] = 1; - else $candelete = 1; - } elseif ($i > 0) $candelete = 1; + if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + if (empty($notfirstlineforlevel[$objp->price_level])) { + $notfirstlineforlevel[$objp->price_level] = 1; + } else { + $candelete = 1; + } + } elseif ($i > 0) { + $candelete = 1; + } print ''; } @@ -1623,22 +1627,25 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul // Add area to show/add/edit a price for a dedicated customer -if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) -{ +if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { $prodcustprice = new Productcustomerprice($db); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0); - if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 + if (empty($page) || $page == -1) { + $page = 0; + } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; - if (!$sortorder) + if (!$sortorder) { $sortorder = "ASC"; - if (!$sortfield) + } + if (!$sortfield) { $sortfield = "soc.nom"; + } // Build filter to diplay only concerned lines $filter = array('t.fk_product' => $object->id); @@ -1647,8 +1654,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $filter['soc.nom'] = $search_soc; } - if ($action == 'add_customer_price') - { + if ($action == 'add_customer_price') { // Form to add a new customer price $maxpricesupplier = $object->min_recommended_price(); @@ -1708,8 +1714,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } else { print ''; } print ''; @@ -1732,8 +1737,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; - } elseif ($action == 'edit_customer_price') - { + } elseif ($action == 'edit_customer_price') { // Edit mode $maxpricesupplier = $object->min_recommended_price(); @@ -1800,8 +1804,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; } print ''; - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) - { + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { print ''; } print ''; @@ -1829,8 +1832,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print '
'; - } elseif ($action == 'showlog_customer_price') - { + } elseif ($action == 'showlog_customer_price') { // List of all log of prices by customers print ''."\n"; @@ -1859,8 +1861,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png'); - if (count($prodcustprice->lines) > 0) - { + if (count($prodcustprice->lines) > 0) { print ''; print ''; print ''; @@ -1874,8 +1875,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; print ''; - if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") - { + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print ''; print ''; } else { @@ -1887,8 +1887,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; - foreach ($prodcustprice->lines as $line) - { + foreach ($prodcustprice->lines as $line) { // Date $staticsoc = new Societe($db); $staticsoc->fetch($line->fk_soc); @@ -1896,8 +1895,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx; // Line for default price - if ($line->price_base_type == 'HT') - { + if ($line->price_base_type == 'HT') { $pu = $line->price; } else { $pu = $line->price_ttc; @@ -1923,10 +1921,18 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '"; print '"; - if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") - { + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print '"; print ''; } else { @@ -1958,8 +1963,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } else { print $langs->trans('None'); } - } elseif ($action != 'showlog_default_price' && $action != 'edit_price') - { + } elseif ($action != 'showlog_default_price' && $action != 'edit_price') { // List of all prices by customers print ''."\n"; @@ -1984,8 +1988,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '
'.$langs->trans("PriceBase").''.$langs->trans("DefaultTaxRate").''.$langs->trans("DefaultTaxRate").''.$langs->trans("HT").''.$langs->trans("TTC").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("ChangedBy").' 
'.$objp->price_level."'.$langs->trans($type)."'; if (empty($objp->price_by_qty)) { $positiverates = ''; - if (price2num($objp->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($objp->tva_tx); - if (price2num($objp->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax1_tx); - if (price2num($objp->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($objp->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($objp->tva_tx); + } + if (price2num($objp->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax1_tx); + } + if (price2num($objp->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($objp->default_vat_code ? ' ('.$objp->default_vat_code.')' : ''), '%', $objp->tva_npr); /* - if ($objp->default_vat_code) - { - print vatrate($objp->tva_tx, true) . ' ('.$objp->default_vat_code.')'; - } - else print vatrate($objp->tva_tx, true, $objp->recuperableonly);*/ + if ($objp->default_vat_code) + { + print vatrate($objp->tva_tx, true) . ' ('.$objp->default_vat_code.')'; + } + else print vatrate($objp->tva_tx, true, $objp->recuperableonly);*/ } print "'; - if ($candelete) - { + if ($candelete) { print 'id.'&lineid='.$objp->rowid.'">'; print img_delete(); print ''; - } else print ' '; // Can not delete last price (it's current price) + } else { + print ' '; // Can not delete last price (it's current price) + } print ''; } - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) - { + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'
'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'
'.$langs->trans("PriceBase").''.$langs->trans("DefaultTaxRate").''.$langs->trans("HT").'' . $langs->trans("INCVATONLY") . ''.$langs->trans("INCT").' 
'; $positiverates = ''; - if (price2num($line->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx); - if (price2num($line->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx); - if (price2num($line->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($line->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx); + } + if (price2num($line->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx); + } + if (price2num($line->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly)); @@ -1934,8 +1940,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print "'.price($line->price)."' . price($line->price_ttc) . "'.price($resultarray[2]).'
'; - if (count($prodcustprice->lines) > 0 || $search_soc) - { + if (count($prodcustprice->lines) > 0 || $search_soc) { $colspan = 9; //if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") $colspan++; @@ -2007,8 +2010,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; print ''; - if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") - { + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print ''; print ''; } else { @@ -2022,8 +2024,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; // Line for default price - if ($object->price_base_type == 'HT') - { + if ($object->price_base_type == 'HT') { $pu = $object->price; } else { $pu = $object->price_ttc; @@ -2047,10 +2048,18 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '"; - if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") - { + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print '"; print ''; } else { @@ -2072,8 +2080,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; - if ($user->rights->produit->supprimer || $user->rights->service->supprimer) - { + if ($user->rights->produit->supprimer || $user->rights->service->supprimer) { print '\n"; - if (count($prodcustprice->lines) > 0) - { - foreach ($prodcustprice->lines as $line) - { + if (count($prodcustprice->lines) > 0) { + foreach ($prodcustprice->lines as $line) { // Date $staticsoc = new Societe($db); $staticsoc->fetch($line->fk_soc); @@ -2098,8 +2103,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx; // Line for default price - if ($line->price_base_type == 'HT') - { + if ($line->price_base_type == 'HT') { $pu = $line->price; } else { $pu = $line->price_ttc; @@ -2126,17 +2130,24 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '"; print '"; - if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") - { + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { //print '"; print ''; } else { @@ -2155,8 +2166,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) // Todo Edit or delete button // Action - if ($user->rights->produit->supprimer || $user->rights->service->supprimer) - { + if ($user->rights->produit->supprimer || $user->rights->service->supprimer) { print '
'.$langs->trans("PriceBase").''.$langs->trans("DefaultTaxRate").''.$langs->trans("HT").'' . $langs->trans("INCVATONLY") . ''.$langs->trans("INCT").'
'; $positiverates = ''; - if (price2num($object->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); - if (price2num($object->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); - if (price2num($object->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($object->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx); + } + if (price2num($object->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx); + } + if (price2num($object->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr); //print vatrate($object->tva_tx, true, $object->tva_npr); @@ -2059,8 +2068,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''.price($object->price)."' . price($object->price_ttc) . "'.price($resultarray[2]).''.price($object->price_min_ttc).''; print ''; print 'id.'">'; print img_info($langs->trans('PriceByCustomerLog')); @@ -2087,10 +2094,8 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } print "
'; $positiverates = ''; - if (price2num($line->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx); - if (price2num($line->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx); - if (price2num($line->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx); - if (empty($positiverates)) $positiverates = '0'; + if (price2num($line->tva_tx)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx); + } + if (price2num($line->localtax1_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx); + } + if (price2num($line->localtax2_type)) { + $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx); + } + if (empty($positiverates)) { + $positiverates = '0'; + } echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly)); print "'.price($line->price)."' . price($line->price_ttc) . "'.price($resultarray[2]).''; print 'id.'&socid='.$line->fk_soc.'">'; print img_info($langs->trans('PriceByCustomerLog')); diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 715ad66e977..e0d1d7447a0 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -36,7 +36,9 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $langs->loadLangs(array('products', 'stocks')); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service'); @@ -55,11 +57,19 @@ $fourn_id = GETPOST("fourn_id", 'int'); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0) $page = 0; -if (!$sortfield) $sortfield = "p.ref"; -if (!$sortorder) $sortorder = "ASC"; +if (empty($page) || $page < 0) { + $page = 0; +} +if (!$sortfield) { + $sortfield = "p.ref"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; // Load sale and categ filters @@ -69,8 +79,7 @@ $search_categ = GETPOST("search_categ"); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); $objcanvas = null; -if (!empty($canvas)) -{ +if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('product', 'list', $canvas); @@ -83,8 +92,7 @@ if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) - || !empty($conf->mrp->enabled)) -{ + || !empty($conf->mrp->enabled)) { $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs. } @@ -97,8 +105,7 @@ $hookmanager->initHooks(array('productreassortlist')); * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $sref = ""; $snom = ""; $sall = ""; @@ -128,7 +135,9 @@ $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price $sql .= ' p.fk_product_type, p.tms as datem,'; $sql .= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,'; $sql .= ' SUM(s.reel) as stock_physique'; -if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= ', u.short_label as unit_short'; +if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= ', u.short_label as unit_short'; +} // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook @@ -136,49 +145,73 @@ $sql .= $hookmanager->resPrint; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e ON s.fk_entrepot = e.rowid AND e.entity IN ('.getEntity('entrepot').')'; -if (!empty($conf->global->PRODUCT_USE_UNITS)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid'; +if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid'; +} // We'll need this table joined to the select in order to filter by categ -if ($search_categ) $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; +if ($search_categ) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; +} $sql .= " WHERE p.entity IN (".getEntity('product').")"; -if ($search_categ) $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +if ($search_categ) { + $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +} +if ($sall) { + $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +} // if the type is not 1, we show all products (type = 0,2,3) -if (dol_strlen($type)) -{ - if ($type == 1) - { +if (dol_strlen($type)) { + if ($type == 1) { $sql .= " AND p.fk_product_type = '1'"; } else { $sql .= " AND p.fk_product_type <> '1'"; } } -if ($sref) $sql .= natural_search('p.ref', $sref); -if ($search_barcode) $sql .= natural_search('p.barcode', $search_barcode); -if ($snom) $sql .= natural_search('p.label', $snom); -if (!empty($tosell)) $sql .= " AND p.tosell = ".$tosell; -if (!empty($tobuy)) $sql .= " AND p.tobuy = ".$tobuy; -if (!empty($canvas)) $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; -if ($catid) $sql .= " AND cp.fk_categorie = ".$catid; -if ($fourn_id > 0) $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; +if ($sref) { + $sql .= natural_search('p.ref', $sref); +} +if ($search_barcode) { + $sql .= natural_search('p.barcode', $search_barcode); +} +if ($snom) { + $sql .= natural_search('p.label', $snom); +} +if (!empty($tosell)) { + $sql .= " AND p.tosell = ".$tosell; +} +if (!empty($tobuy)) { + $sql .= " AND p.tobuy = ".$tobuy; +} +if (!empty($canvas)) { + $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; +} +if ($catid) { + $sql .= " AND cp.fk_categorie = ".$catid; +} +if ($fourn_id > 0) { + $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; +} // Insert categ filter -if ($search_categ) $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +if ($search_categ) { + $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +} $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,"; $sql .= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock"; // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; -if ($toolowstock) $sql .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; +if ($toolowstock) { + $sql .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; +} $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -187,41 +220,68 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; - if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall || $snom || $sref)) - { + if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall || $snom || $sref)) { $objp = $db->fetch_object($resql); header("Location: card.php?id=$objp->rowid"); exit; } - if (isset($type)) - { - if ($type == 1) { $texte = $langs->trans("Services"); } else { $texte = $langs->trans("Products"); } + if (isset($type)) { + if ($type == 1) { + $texte = $langs->trans("Services"); + } else { + $texte = $langs->trans("Products"); + } } else { $texte = $langs->trans("ProductsAndServices"); } $texte .= ' ('.$langs->trans("MenuStocks").')'; $param = ''; - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sall) $param .= "&sall=".urlencode($sall); - if ($tosell) $param .= "&tosell=".urlencode($tosell); - if ($tobuy) $param .= "&tobuy=".urlencode($tobuy); - if ($type) $param .= "&type=".urlencode($type); - if ($fourn_id) $param .= "&fourn_id=".urlencode($fourn_id); - if ($snom) $param .= "&snom=".urlencode($snom); - if ($sref) $param .= "&sref=".urlencode($sref); - if ($search_sale) $param .= "&search_sale=".urlencode($search_sale); - if ($search_categ) $param .= "&search_categ=".urlencode($search_categ); - if ($toolowstock) $param .= "&toolowstock=".urlencode($toolowstock); - if ($sbarcode) $param .= "&sbarcode=".urlencode($sbarcode); - if ($catid) $param .= "&catid=".urlencode($catid); + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sall) { + $param .= "&sall=".urlencode($sall); + } + if ($tosell) { + $param .= "&tosell=".urlencode($tosell); + } + if ($tobuy) { + $param .= "&tobuy=".urlencode($tobuy); + } + if ($type) { + $param .= "&type=".urlencode($type); + } + if ($fourn_id) { + $param .= "&fourn_id=".urlencode($fourn_id); + } + if ($snom) { + $param .= "&snom=".urlencode($snom); + } + if ($sref) { + $param .= "&sref=".urlencode($sref); + } + if ($search_sale) { + $param .= "&search_sale=".urlencode($search_sale); + } + if ($search_categ) { + $param .= "&search_categ=".urlencode($search_categ); + } + if ($toolowstock) { + $param .= "&toolowstock=".urlencode($toolowstock); + } + if ($sbarcode) { + $param .= "&sbarcode=".urlencode($sbarcode); + } + if ($catid) { + $param .= "&catid=".urlencode($catid); + } llxHeader("", $texte, $helpurl); @@ -234,8 +294,7 @@ if ($resql) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit); - if (!empty($catid)) - { + if (!empty($catid)) { print "
"; $c = new Categorie($db); $c->fetch($catid); @@ -245,21 +304,19 @@ if ($resql) } // Filter on categories - $moreforfilter = ''; - if (!empty($conf->categorie->enabled)) - { - $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('Categories').': '; + $moreforfilter = ''; + if (!empty($conf->categorie->enabled)) { + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('Categories').': '; $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ'); - $moreforfilter .= '
'; + $moreforfilter .= '
'; } $moreforfilter .= '
'; $moreforfilter .= $langs->trans("StockTooLow").' '; $moreforfilter .= '
'; - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; $parameters = array(); @@ -269,21 +326,39 @@ if ($resql) } $param = ''; - if ($tosell) $param .= "&tosell=".urlencode($tosell); - if ($tobuy) $param .= "&tobuy=".urlencode($tobuy); - if ($type) $param .= "&type=".urlencode($type); - if ($fourn_id) $param .= "&fourn_id=".urlencode($fourn_id); - if ($snom) $param .= "&snom=".urlencode($snom); - if ($sref) $param .= "&sref=".urlencode($sref); - if ($toolowstock) $param .= "&toolowstock=".urlencode($toolowstock); - if ($search_categ) $param .= "&search_categ=".urlencode($search_categ); + if ($tosell) { + $param .= "&tosell=".urlencode($tosell); + } + if ($tobuy) { + $param .= "&tobuy=".urlencode($tobuy); + } + if ($type) { + $param .= "&type=".urlencode($type); + } + if ($fourn_id) { + $param .= "&fourn_id=".urlencode($fourn_id); + } + if ($snom) { + $param .= "&snom=".urlencode($snom); + } + if ($sref) { + $param .= "&sref=".urlencode($sref); + } + if ($toolowstock) { + $param .= "&toolowstock=".urlencode($toolowstock); + } + if ($search_categ) { + $param .= "&search_categ=".urlencode($search_categ); + } $formProduct = new FormProduct($db); $formProduct->loadWarehouses(); $warehouses_list = $formProduct->cache_warehouses; $nb_warehouse = count($warehouses_list); $colspan_warehouse = 1; - if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) { $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1; } + if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) { + $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1; + } print '
'; print ''; @@ -297,8 +372,7 @@ if ($resql) print ''; print ''; // Duration - if (!empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; @@ -307,7 +381,9 @@ if ($resql) print ''; print ''; print ''; - if ($virtualdiffersfromphysical) print ''; + if ($virtualdiffersfromphysical) { + print ''; + } print ''; print ''; print ''; @@ -315,8 +391,8 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print ''; print ''; @@ -324,20 +400,23 @@ if ($resql) print ""; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder); - if (!empty($conf->service->enabled) && $type == 1) print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + if (!empty($conf->service->enabled) && $type == 1) { + print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + } print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", $param, "", '', $sortfield, $sortorder, 'right '); print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", $param, "", '', $sortfield, $sortorder, 'right '); print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", $param, "", '', $sortfield, $sortorder, 'right '); // Details per warehouse - if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context) - { + if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context) if ($nb_warehouse > 1) { foreach ($warehouses_list as &$wh) { print_liste_field_titre($wh['label'], '', '', '', '', '', '', '', 'right '); } } } - if ($virtualdiffersfromphysical) print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", $param, "", '', $sortfield, $sortorder, 'right ', 'VirtualStockDesc'); + if ($virtualdiffersfromphysical) { + print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", $param, "", '', $sortfield, $sortorder, 'right ', 'VirtualStockDesc'); + } // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", $param, "", 'align="right"', $sortfield, $sortorder); @@ -352,8 +431,7 @@ if ($resql) print_liste_field_titre(''); print "\n"; - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); $product = new Product($db); @@ -367,13 +445,17 @@ if ($resql) print ''; print ''; - if (!empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; } //print ''; @@ -381,13 +463,14 @@ if ($resql) print ''; // Real stock print ''; // Details per warehouse - if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context) - { + if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context) if ($nb_warehouse > 1) { foreach ($warehouses_list as &$wh) { print ''; } diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 7949c5441c1..5983d5e6b4e 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -38,7 +38,9 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $langs->loadLangs(array('products', 'stocks', 'productbatch')); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service'); @@ -59,11 +61,19 @@ $fourn_id = GETPOST("fourn_id", 'int'); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0) $page = 0; -if (!$sortfield) $sortfield = "p.ref"; -if (!$sortorder) $sortorder = "ASC"; +if (empty($page) || $page < 0) { + $page = 0; +} +if (!$sortfield) { + $sortfield = "p.ref"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; // Load sale and categ filters @@ -73,8 +83,7 @@ $search_categ = GETPOST("search_categ"); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); $objcanvas = null; -if (!empty($canvas)) -{ +if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('product', 'list', $canvas); @@ -86,8 +95,7 @@ if (!empty($canvas)) * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $sref = ""; $snom = ""; $sall = ""; @@ -129,32 +137,58 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid' $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key // We'll need this table joined to the select in order to filter by categ -if ($search_categ) $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; +if ($search_categ) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; +} $sql .= " WHERE p.entity IN (".getEntity('product').")"; -if ($search_categ) $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +if ($search_categ) { + $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +} +if ($sall) { + $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +} // if the type is not 1, we show all products (type = 0,2,3) -if (dol_strlen($type)) -{ - if ($type == 1) - { +if (dol_strlen($type)) { + if ($type == 1) { $sql .= " AND p.fk_product_type = '1'"; } else { $sql .= " AND p.fk_product_type <> '1'"; } } -if ($sref) $sql .= natural_search("p.ref", $sref); -if ($search_barcode) $sql .= natural_search("p.barcode", $search_barcode); -if ($snom) $sql .= natural_search("p.label", $snom); -if (!empty($tosell)) $sql .= " AND p.tosell = ".$tosell; -if (!empty($tobuy)) $sql .= " AND p.tobuy = ".$tobuy; -if (!empty($canvas)) $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; -if ($catid) $sql .= " AND cp.fk_categorie = ".$catid; -if ($fourn_id > 0) $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; +if ($sref) { + $sql .= natural_search("p.ref", $sref); +} +if ($search_barcode) { + $sql .= natural_search("p.barcode", $search_barcode); +} +if ($snom) { + $sql .= natural_search("p.label", $snom); +} +if (!empty($tosell)) { + $sql .= " AND p.tosell = ".$tosell; +} +if (!empty($tobuy)) { + $sql .= " AND p.tobuy = ".$tobuy; +} +if (!empty($canvas)) { + $sql .= " AND p.canvas = '".$db->escape($canvas)."'"; +} +if ($catid) { + $sql .= " AND cp.fk_categorie = ".$catid; +} +if ($fourn_id > 0) { + $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; +} // Insert categ filter -if ($search_categ) $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); -if ($search_warehouse) $sql .= natural_search("e.ref", $search_warehouse); -if ($search_batch) $sql .= natural_search("pb.batch", $search_batch); +if ($search_categ) { + $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +} +if ($search_warehouse) { + $sql .= natural_search("e.ref", $search_warehouse); +} +if ($search_batch) { + $sql .= natural_search("pb.batch", $search_batch); +} $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,"; $sql .= " p.fk_product_type, p.tms,"; $sql .= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tosell, p.tobuy, p.tobatch,"; @@ -162,16 +196,16 @@ $sql .= " ps.fk_entrepot,"; $sql .= " e.ref, e.lieu, e.fk_parent,"; $sql .= " pb.batch, pb.eatby, pb.sellby,"; $sql .= " pl.rowid, pl.eatby, pl.sellby"; -if ($toolowstock) $sql .= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet +if ($toolowstock) { + $sql .= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet +} $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -180,43 +214,74 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; - if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall or $snom or $sref)) - { + if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall or $snom or $sref)) { $objp = $db->fetch_object($resql); header("Location: card.php?id=$objp->rowid"); exit; } - if (isset($type)) - { - if ($type == 1) { $texte = $langs->trans("Services"); } else { $texte = $langs->trans("Products"); } + if (isset($type)) { + if ($type == 1) { + $texte = $langs->trans("Services"); + } else { + $texte = $langs->trans("Products"); + } } else { $texte = $langs->trans("ProductsAndServices"); } $texte .= ' ('.$langs->trans("StocksByLotSerial").')'; $param = ''; - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sall) $param .= "&sall=".urlencode($sall); - if ($tosell) $param .= "&tosell=".urlencode($tosell); - if ($tobuy) $param .= "&tobuy=".urlencode($tobuy); - if ($type) $param .= "&type=".urlencode($type); - if ($fourn_id) $param .= "&fourn_id=".urlencode($fourn_id); - if ($snom) $param .= "&snom=".urlencode($snom); - if ($sref) $param .= "&sref=".urlencode($sref); - if ($search_batch) $param .= "&search_batch=".urlencode($search_batch); - if ($sbarcode) $param .= "&sbarcode=".urlencode($sbarcode); - if ($search_warehouse) $param .= "&search_warehouse=".urlencode($search_warehouse); - if ($catid) $param .= "&catid=".urlencode($catid); - if ($toolowstock) $param .= "&toolowstock=".urlencode($toolowstock); - if ($search_sale) $param .= "&search_sale=".urlencode($search_sale); - if ($search_categ) $param .= "&search_categ=".urlencode($search_categ); + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sall) { + $param .= "&sall=".urlencode($sall); + } + if ($tosell) { + $param .= "&tosell=".urlencode($tosell); + } + if ($tobuy) { + $param .= "&tobuy=".urlencode($tobuy); + } + if ($type) { + $param .= "&type=".urlencode($type); + } + if ($fourn_id) { + $param .= "&fourn_id=".urlencode($fourn_id); + } + if ($snom) { + $param .= "&snom=".urlencode($snom); + } + if ($sref) { + $param .= "&sref=".urlencode($sref); + } + if ($search_batch) { + $param .= "&search_batch=".urlencode($search_batch); + } + if ($sbarcode) { + $param .= "&sbarcode=".urlencode($sbarcode); + } + if ($search_warehouse) { + $param .= "&search_warehouse=".urlencode($search_warehouse); + } + if ($catid) { + $param .= "&catid=".urlencode($catid); + } + if ($toolowstock) { + $param .= "&toolowstock=".urlencode($toolowstock); + } + if ($search_sale) { + $param .= "&search_sale=".urlencode($search_sale); + } + if ($search_categ) { + $param .= "&search_categ=".urlencode($search_categ); + } /*if ($eatby) $param.="&eatby=".$eatby; if ($sellby) $param.="&sellby=".$sellby;*/ @@ -231,8 +296,7 @@ if ($resql) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit, 0, 0, 1); - if (!empty($catid)) - { + if (!empty($catid)) { print "
"; $c = new Categorie($db); $c->fetch($catid); @@ -242,18 +306,16 @@ if ($resql) } // Filter on categories - $moreforfilter = ''; - if (!empty($conf->categorie->enabled)) - { - $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('Categories').': '; + $moreforfilter = ''; + if (!empty($conf->categorie->enabled)) { + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('Categories').': '; $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ'); - $moreforfilter .= '
'; + $moreforfilter .= '
'; } //$moreforfilter.=$langs->trans("StockTooLow").' '; - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; $parameters = array(); @@ -274,8 +336,7 @@ if ($resql) print '
'; - if (!empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; @@ -302,7 +363,9 @@ if ($resql) print ""; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder); - if (!empty($conf->service->enabled) && $type == 1) print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + if (!empty($conf->service->enabled) && $type == 1) { + print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", $param, "", '', $sortfield, $sortorder, 'center '); + } print_liste_field_titre("Warehouse", $_SERVER["PHP_SELF"], "e.ref", $param, "", '', $sortfield, $sortorder); //print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'',$sortfield,$sortorder, 'right ); print_liste_field_titre("Batch", $_SERVER["PHP_SELF"], "pb.batch", $param, "", '', $sortfield, $sortorder, 'center '); @@ -325,13 +388,11 @@ if ($resql) $product_lot_static = new Productlot($db); $warehousetmp = new Entrepot($db); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { + if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active $sql = "SELECT label"; $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; $sql .= " WHERE fk_product=".$objp->rowid; @@ -339,10 +400,11 @@ 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; + if (!empty($objtp->label)) { + $objp->label = $objtp->label; + } } } @@ -379,13 +441,17 @@ if ($resql) // Label print ''; - if (!empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; } //print ''; @@ -394,16 +460,14 @@ if ($resql) // Warehouse print ''; // Lot print ''; diff --git a/htdocs/product/stats/bom.php b/htdocs/product/stats/bom.php index d1254a65b1e..053d9d6b1a8 100644 --- a/htdocs/product/stats/bom.php +++ b/htdocs/product/stats/bom.php @@ -38,7 +38,9 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -52,12 +54,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "b.date_valid"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "b.date_valid"; +} /* @@ -66,8 +74,7 @@ if (!$sortfield) $sortfield = "b.date_valid"; $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -75,12 +82,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -88,12 +96,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -130,8 +142,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); if ($result) { $totalofrecords = $db->num_rows($result); @@ -180,8 +191,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); if ($result) { $totalofrecords = $db->num_rows($result); @@ -223,20 +233,32 @@ if ($id > 0 || !empty($ref)) $db->free($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("BOMs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', count($bom_data_result), count($bom_data_result), '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; print ' '; print '       '; - $searchpicto = $form->showFilterAndCheckAddButtons(0); - print $searchpicto; + $searchpicto = $form->showFilterAndCheckAddButtons(0); + print $searchpicto; print '
'.$product->label.''; - if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationYear"); + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationMonth"); + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationDay"); + } else { + print $objp->duration; + } print ''.$objp->stock_theorique.''.$objp->desiredstock.''; - if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) { + print img_warning($langs->trans("StockTooLow")).' '; + } print price2num($objp->stock_physique, 'MS'); print ''; @@ -398,10 +481,11 @@ if ($resql) } // Virtual stock - if ($virtualdiffersfromphysical) - { + if ($virtualdiffersfromphysical) { print ''; - if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < $objp->seuil_stock_alerte)) { + print img_warning($langs->trans("StockTooLow")).' '; + } print price2num($product->stock_theorique, 'MS'); print ''; print ''; print ''; print ' '; print '
'.$objp->label.''; - if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationYear"); + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationMonth"); + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + print $regs[1].' '.$langs->trans("DurationDay"); + } else { + print $objp->duration; + } print ''.$objp->stock_theorique.''; - if ($objp->fk_entrepot > 0) - { + if ($objp->fk_entrepot > 0) { print $warehousetmp->getNomUrl(1); } print ''; - if ($product_lot_static->batch) - { + if ($product_lot_static->batch) { print $product_lot_static->getNomUrl(1); } print '
'; @@ -250,8 +272,7 @@ if ($id > 0 || !empty($ref)) print "\n"; if (!empty($bom_data_result)) { - foreach ($bom_data_result as $data) - { + foreach ($bom_data_result as $data) { print ''; print ''; @@ -206,25 +215,45 @@ if ($result || empty($id)) { // Choice of stats mode (byunit or bynumber) - if (!empty($conf->dol_use_jmobile)) print "\n".'
'."\n"; + if (!empty($conf->dol_use_jmobile)) { + print "\n".'
'."\n".'
'."\n"; - else print '   '; + if (!empty($conf->dol_use_jmobile)) { + print '
'."\n".'
'; - else print '
'; + if (!empty($conf->dol_use_jmobile)) { + print '
'; + } else { + print '
'; + } print '
'; //print '
'; print $data['link']; diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index e899cee797f..b55976bface 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -51,7 +51,9 @@ $mesg = ''; $graphfiles = array(); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} // Security check $fieldvalue = (!empty($id) ? $id : $ref); @@ -60,7 +62,9 @@ $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product $tmp = dol_getdate(dol_now()); $currentyear = $tmp['year']; -if (empty($search_year)) $search_year = $currentyear; +if (empty($search_year)) { + $search_year = $currentyear; +} /* @@ -83,7 +87,7 @@ if (!$id && empty($ref)) { $type = GETPOST('type', 'int'); - $helpurl = ''; + $helpurl = ''; if ($type == '0') { $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; //$title=$langs->trans("StatisticsOfProducts"); @@ -99,7 +103,9 @@ if (!$id && empty($ref)) { } $picto = 'product'; - if ($type == 1) $picto = 'service'; + if ($type == 1) { + $picto = 'service'; + } print load_fiche_titre($title, $mesg, $picto); } else { @@ -189,12 +195,15 @@ if ($result || empty($id)) { // Year print '
'.$langs->trans("Year").''; $arrayyears = array(); - for ($year = $currentyear - 25; $year < $currentyear; $year++) - { + for ($year = $currentyear - 25; $year < $currentyear; $year++) { $arrayyears[$year] = $year; } - if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; - if (!in_array($currentyear, $arrayyears)) $arrayyears[$currentyear] = $currentyear; + if (!in_array($year, $arrayyears)) { + $arrayyears[$year] = $year; + } + if (!in_array($currentyear, $arrayyears)) { + $arrayyears[$currentyear] = $currentyear; + } arsort($arrayyears); print $form->selectarray('search_year', $arrayyears, $search_year, 1); print '
'; @@ -294,7 +323,9 @@ if ($result || empty($id)) { $mesg = $px->isGraphKo(); if (!$mesg) { foreach ($graphfiles as $key => $val) { - if (!$graphfiles[$key]['file']) continue; + if (!$graphfiles[$key]['file']) { + continue; + } $graph_data = array(); @@ -312,14 +343,30 @@ if ($result || empty($id)) { $morefilters = ' AND d.fk_product NOT IN (SELECT cp.fk_product from '.MAIN_DB_PREFIX.'categorie_product as cp)'; } - if ($key == 'propal') $graph_data = $object->get_nb_propal($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'orders') $graph_data = $object->get_nb_order($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'invoices') $graph_data = $object->get_nb_vente($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'proposalssuppliers') $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'invoicessuppliers') $graph_data = $object->get_nb_achat($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'orderssuppliers') $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'contracts') $graph_data = $object->get_nb_contract($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); - if ($key == 'mrp') $graph_data = $object->get_nb_mos($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + if ($key == 'propal') { + $graph_data = $object->get_nb_propal($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'orders') { + $graph_data = $object->get_nb_order($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'invoices') { + $graph_data = $object->get_nb_vente($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'proposalssuppliers') { + $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'invoicessuppliers') { + $graph_data = $object->get_nb_achat($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'orderssuppliers') { + $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'contracts') { + $graph_data = $object->get_nb_contract($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } + if ($key == 'mrp') { + $graph_data = $object->get_nb_mos($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + } // TODO Save cachefile $graphfiles[$key]['file'] } @@ -354,15 +401,31 @@ if ($result || empty($id)) { $i = 0; if (count($graphfiles) > 0) { foreach ($graphfiles as $key => $val) { - if (!$graphfiles[$key]['file']) continue; + if (!$graphfiles[$key]['file']) { + continue; + } - if ($graphfiles == 'propal' && !$user->rights->propale->lire) continue; - if ($graphfiles == 'order' && !$user->rights->commande->lire) continue; - if ($graphfiles == 'invoices' && !$user->rights->facture->lire) continue; - if ($graphfiles == 'proposals_suppliers' && !$user->rights->supplier_proposal->lire) continue; - if ($graphfiles == 'invoices_suppliers' && !$user->rights->fournisseur->facture->lire) continue; - if ($graphfiles == 'orders_suppliers' && !$user->rights->fournisseur->commande->lire) continue; - if ($graphfiles == 'mrp' && empty($user->rights->mrp->mo->read)) continue; + if ($graphfiles == 'propal' && !$user->rights->propale->lire) { + continue; + } + if ($graphfiles == 'order' && !$user->rights->commande->lire) { + continue; + } + if ($graphfiles == 'invoices' && !$user->rights->facture->lire) { + continue; + } + if ($graphfiles == 'proposals_suppliers' && !$user->rights->supplier_proposal->lire) { + continue; + } + if ($graphfiles == 'invoices_suppliers' && !$user->rights->fournisseur->facture->lire) { + continue; + } + if ($graphfiles == 'orders_suppliers' && !$user->rights->fournisseur->commande->lire) { + continue; + } + if ($graphfiles == 'mrp' && empty($user->rights->mrp->mo->read)) { + continue; + } if ($i % 2 == 0) { @@ -373,8 +436,11 @@ if ($result || empty($id)) { // Date generation if ($graphfiles[$key]['output'] && !$px->isGraphKo()) { - if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) $dategenerated = $langs->trans("GeneratedOn", dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']), "dayhour")); - else $dategenerated = $langs->trans("GeneratedOn", dol_print_date(dol_now(), "dayhour")); + if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) { + $dategenerated = $langs->trans("GeneratedOn", dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']), "dayhour")); + } else { + $dategenerated = $langs->trans("GeneratedOn", dol_print_date(dol_now(), "dayhour")); + } } else { $dategenerated = ($mesg ? ''.$mesg.'' : $langs->trans("ChartNotGenerated")); } diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index f89305b4d95..cb5087c63f2 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -40,7 +40,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -53,12 +55,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "c.date_commande"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "c.date_commande"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -77,8 +85,7 @@ $societestatic = new Societe($db); $form = new Form($db); $formother = new FormOther($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -86,12 +93,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -99,12 +107,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -123,26 +135,35 @@ if ($id > 0 || !empty($ref)) print dol_get_fiche_end(); - if ($user->rights->commande->lire) - { + if ($user->rights->commande->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client, c.rowid, d.total_ht as total_ht, c.ref,"; $sql .= " c.ref_client,"; $sql .= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.rowid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; + 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"; $sql .= ", ".MAIN_DB_PREFIX."commandedet as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('commande').")"; $sql .= " AND d.fk_commande = c.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) - $sql .= ' AND MONTH(c.date_commande) IN ('.$search_month.')'; - if (!empty($search_year)) - $sql .= ' AND YEAR(c.date_commande) IN ('.$search_year.')'; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($socid) $sql .= " AND c.fk_soc = ".$socid; + if (!empty($search_month)) { + $sql .= ' AND MONTH(c.date_commande) IN ('.$search_month.')'; + } + if (!empty($search_year)) { + $sql .= ' AND YEAR(c.date_commande) IN ('.$search_year.')'; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND c.fk_soc = ".$socid; + } $sql .= $db->order($sortfield, $sortorder); //Calcul total qty and amount for global if full scan list @@ -151,8 +172,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -160,25 +180,36 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; print ''; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("CustomersOrders"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -205,10 +236,8 @@ if ($id > 0 || !empty($ref)) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $total_ht += $objp->total_ht; @@ -220,7 +249,7 @@ if ($id > 0 || !empty($ref)) $societestatic->fetch($objp->socid); print '
'; - print '\n"; print ''; @@ -235,8 +264,11 @@ if ($id > 0 || !empty($ref)) } } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php index 611047f7f13..16dd040887d 100644 --- a/htdocs/product/stats/commande_fournisseur.php +++ b/htdocs/product/stats/commande_fournisseur.php @@ -39,8 +39,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) +if (!empty($user->socid)) { $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -53,14 +54,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) +if (!$sortorder) { $sortorder = "DESC"; -if (!$sortfield) +} +if (!$sortfield) { $sortfield = "c.date_commande"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -88,13 +93,13 @@ if ($id > 0 || !empty($ref)) { $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) + if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -102,12 +107,16 @@ if ($id > 0 || !empty($ref)) { $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -126,30 +135,35 @@ if ($id > 0 || !empty($ref)) { print dol_get_fiche_end(); - if ($user->rights->fournisseur->commande->lire) - { + if ($user->rights->fournisseur->commande->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,"; $sql .= " c.rowid, d.total_ht as total_ht, c.ref,"; $sql .= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.rowid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) + 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"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as d"; - if (!$user->rights->societe->client->voir && !$socid) + if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity = ".$conf->entity; $sql .= " AND d.fk_commande = c.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) + if (!empty($search_month)) { $sql .= ' AND MONTH(c.date_commande) IN ('.$search_month.')'; - if (!empty($search_year)) + } + if (!empty($search_year)) { $sql .= ' AND YEAR(c.date_commande) IN ('.$search_year.')'; - 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 ($socid) + } + if ($socid) { $sql .= " AND c.fk_soc = ".$socid; + } $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list @@ -158,8 +172,7 @@ if ($id > 0 || !empty($ref)) { // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -170,20 +183,32 @@ if ($id > 0 || !empty($ref)) { if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("SuppliersOrders"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -210,10 +235,8 @@ if ($id > 0 || !empty($ref)) { print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "
\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $total_ht += $objp->total_ht; @@ -240,8 +263,11 @@ if ($id > 0 || !empty($ref)) { } } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stats/contrat.php b/htdocs/product/stats/contrat.php index 91ca0bd87e2..93778a19047 100644 --- a/htdocs/product/stats/contrat.php +++ b/htdocs/product/stats/contrat.php @@ -37,7 +37,9 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -50,12 +52,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "c.date_contrat"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "c.date_contrat"; +} /* @@ -67,8 +75,7 @@ $staticcontratligne = new ContratLigne($db); $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -76,12 +83,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -89,12 +97,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -123,15 +135,21 @@ if ($id > 0 || !empty($ref)) $sql .= " c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,"; $sql .= " s.nom as name, s.rowid as socid, s.code_client"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= " WHERE c.rowid = cd.fk_contrat"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('contract').")"; $sql .= " AND cd.fk_product =".$product->id; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($socid) $sql .= " AND s.rowid = ".$socid; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND s.rowid = ".$socid; + } $sql .= " GROUP BY c.rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut, s.nom, s.rowid, s.code_client"; $sql .= $db->order($sortfield, $sortorder); @@ -141,8 +159,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -150,25 +167,36 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("Contrats"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } $i = 0; print '
'; @@ -187,10 +215,8 @@ if ($id > 0 || !empty($ref)) $contracttmp = new Contrat($db); - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $contracttmp->id = $objp->rowid; diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 8091de9c320..271a834570b 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -41,7 +41,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -54,12 +56,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "f.datef"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "f.datef"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -81,8 +89,7 @@ $societestatic = new Societe($db); $form = new Form($db); $formother = new FormOther($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -90,26 +97,25 @@ if ($id > 0 || !empty($ref)) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); - if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) - { + if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Referers'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } - if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) - { + if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Referers'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } llxHeader('', $title, $helpurl); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -117,12 +123,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -140,29 +150,37 @@ if ($id > 0 || !empty($ref)) print dol_get_fiche_end(); - if ($showmessage && $nboflines > 1) - { + if ($showmessage && $nboflines > 1) { print ''.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).''; - } elseif ($user->rights->facture->lire) - { + } elseif ($user->rights->facture->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,"; $sql .= " f.ref, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,"; $sql .= " d.rowid, d.total_ht as total_ht, d.qty"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; + 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"; $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; $sql .= " AND d.fk_facture = f.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) + if (!empty($search_month)) { $sql .= ' AND MONTH(f.datef) IN ('.$search_month.')'; - if (!empty($search_year)) + } + if (!empty($search_year)) { $sql .= ' AND YEAR(f.datef) IN ('.$search_year.')'; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($socid) $sql .= " AND f.fk_soc = ".$socid; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND f.fk_soc = ".$socid; + } $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list @@ -171,8 +189,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -180,24 +197,35 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("CustomersInvoices"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -224,13 +252,13 @@ if ($id > 0 || !empty($ref)) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "
\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); - if ($objp->type == Facture::TYPE_CREDIT_NOTE) $objp->qty = -($objp->qty); + if ($objp->type == Facture::TYPE_CREDIT_NOTE) { + $objp->qty = -($objp->qty); + } $total_ht += $objp->total_ht; $total_qty += $objp->qty; @@ -256,8 +284,11 @@ if ($id > 0 || !empty($ref)) } } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php index 7e0e463e1a5..a42615fdaa9 100644 --- a/htdocs/product/stats/facture_fournisseur.php +++ b/htdocs/product/stats/facture_fournisseur.php @@ -41,7 +41,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -54,12 +56,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "f.datef"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "f.datef"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -78,8 +86,7 @@ $societestatic = new Societe($db); $form = new Form($db); $formother = new FormOther($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -87,12 +94,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -100,12 +108,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -124,26 +136,34 @@ if ($id > 0 || !empty($ref)) print dol_get_fiche_end(); - if ($user->rights->fournisseur->facture->lire) - { + if ($user->rights->fournisseur->facture->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client, d.rowid, d.total_ht as line_total_ht,"; $sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.libelle as label, f.total_ht, f.total_ttc, f.total_tva, f.paye, f.fk_statut as statut, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) + 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"; $sql .= ", ".MAIN_DB_PREFIX."facture_fourn_det as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture_fourn').")"; $sql .= " AND d.fk_facture_fourn = f.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) + if (!empty($search_month)) { $sql .= ' AND MONTH(f.datef) IN ('.$search_month.')'; - if (!empty($search_year)) + } + if (!empty($search_year)) { $sql .= ' AND YEAR(f.datef) IN ('.$search_year.')'; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($socid) $sql .= " AND f.fk_soc = ".$socid; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND f.fk_soc = ".$socid; + } $sql .= " ORDER BY $sortfield $sortorder "; // Calcul total qty and amount for global if full scan list @@ -152,8 +172,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -161,24 +180,35 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("SuppliersInvoices"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -205,10 +235,8 @@ if ($id > 0 || !empty($ref)) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "
\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $total_ht += $objp->line_total_ht; @@ -231,7 +259,7 @@ if ($id > 0 || !empty($ref)) print "\n"; print ''; print "\n"; - print '"; print '\n"; print '\n"; @@ -241,8 +269,11 @@ if ($id > 0 || !empty($ref)) } } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stats/mo.php b/htdocs/product/stats/mo.php index cb159646047..479dbdd1a17 100644 --- a/htdocs/product/stats/mo.php +++ b/htdocs/product/stats/mo.php @@ -37,7 +37,9 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -50,12 +52,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "c.date_valid"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "c.date_valid"; +} /* @@ -67,8 +75,7 @@ $staticmoligne = new MoLine($db); $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -76,12 +83,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -89,12 +97,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -127,7 +139,9 @@ if ($id > 0 || !empty($ref)) $sql .= " WHERE c.rowid = cd.fk_mo"; $sql .= " AND c.entity IN (".getEntity('mo').")"; $sql .= " AND cd.fk_product =".$product->id; - if ($socid) $sql .= " AND s.rowid = ".$socid; + if ($socid) { + $sql .= " AND s.rowid = ".$socid; + } $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status"; //$sql .= ", s.nom, s.rowid, s.code_client"; $sql .= $db->order($sortfield, $sortorder); @@ -138,8 +152,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -147,24 +160,35 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("Mos"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } $i = 0; print '
'; @@ -183,10 +207,8 @@ if ($id > 0 || !empty($ref)) $motmp = new Mo($db); - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $motmp->id = $objp->rowid; diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 9e9a078d8f0..7d08f3ab9c3 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -40,7 +40,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -53,12 +55,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "p.datep"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "p.datep"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -78,8 +86,7 @@ $societestatic = new Societe($db); $form = new Form($db); $formother = new FormOther($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -87,12 +94,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -100,12 +108,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -124,30 +136,35 @@ if ($id > 0 || !empty($ref)) print dol_get_fiche_end(); - if ($user->rights->propale->lire) - { + if ($user->rights->propale->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, d.total_ht as amount,"; $sql .= " p.ref_client,"; $sql .= "p.datep, p.fk_statut as statut, d.rowid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) + 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"; $sql .= ", ".MAIN_DB_PREFIX."propaldet as d"; - if (!$user->rights->societe->client->voir && !$socid) + if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; $sql .= " AND d.fk_propal = p.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) + if (!empty($search_month)) { $sql .= ' AND MONTH(p.datep) IN ('.$search_month.')'; - if (!empty($search_year)) + } + if (!empty($search_year)) { $sql .= ' AND YEAR(p.datep) IN ('.$search_year.')'; - 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 ($socid) + } + if ($socid) { $sql .= " AND p.fk_soc = ".$socid; + } $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list @@ -156,8 +173,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -165,24 +181,35 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("Proposals"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -208,10 +235,8 @@ if ($id > 0 || !empty($ref)) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "p.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "
\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $total_ht += $objp->amount; @@ -238,8 +263,11 @@ if ($id > 0 || !empty($ref)) } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stats/supplier_proposal.php b/htdocs/product/stats/supplier_proposal.php index b4816028d98..19647e85431 100644 --- a/htdocs/product/stats/supplier_proposal.php +++ b/htdocs/product/stats/supplier_proposal.php @@ -40,7 +40,9 @@ $ref = GETPOST('ref', 'alpha'); $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); $socid = ''; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -53,12 +55,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "p.date_valid"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "p.date_valid"; +} $search_month = GETPOST('search_month', 'int'); $search_year = GETPOST('search_year', 'int'); @@ -78,8 +86,7 @@ $societestatic = new Societe($db); $form = new Form($db); $formother = new FormOther($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); @@ -87,12 +94,13 @@ if ($id > 0 || !empty($ref)) $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } llxHeader("", "", $langs->trans("CardProduct".$product->type)); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($product); $titre = $langs->trans("CardProduct".$product->type); $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -100,12 +108,16 @@ if ($id > 0 || !empty($ref)) $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -124,30 +136,35 @@ if ($id > 0 || !empty($ref)) print dol_get_fiche_end(); - if ($user->rights->propale->lire) - { + if ($user->rights->propale->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, d.total_ht as amount,"; //$sql .= " p.ref_supplier,"; $sql .= "p.date_valid, p.fk_statut as statut, d.rowid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) + 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."supplier_proposal as p"; $sql .= ", ".MAIN_DB_PREFIX."supplier_proposaldet as d"; - if (!$user->rights->societe->client->voir && !$socid) + if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; $sql .= " AND d.fk_supplier_proposal = p.rowid"; $sql .= " AND d.fk_product =".$product->id; - if (!empty($search_month)) + if (!empty($search_month)) { $sql .= ' AND MONTH(p.datep) IN ('.$search_month.')'; - if (!empty($search_year)) + } + if (!empty($search_year)) { $sql .= ' AND YEAR(p.datep) IN ('.$search_year.')'; - 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 ($socid) + } + if ($socid) { $sql .= " AND p.fk_soc = ".$socid; + } $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list @@ -156,8 +173,7 @@ if ($id > 0 || !empty($ref)) // Count total nb of records $totalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $totalofrecords = $db->num_rows($result); } @@ -165,24 +181,35 @@ if ($id > 0 || !empty($ref)) $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); - if ($result) - { + if ($result) { $num = $db->num_rows($result); - if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit); - if (!empty($id)) $option .= '&id='.$product->id; - if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month); - if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year); + if ($limit > 0 && $limit != $conf->liste_limit) { + $option .= '&limit='.urlencode($limit); + } + if (!empty($id)) { + $option .= '&id='.$product->id; + } + if (!empty($search_month)) { + $option .= '&search_month='.urlencode($search_month); + } + if (!empty($search_year)) { + $option .= '&search_year='.urlencode($search_year); + } print ''."\n"; - if (!empty($sortfield)) + if (!empty($sortfield)) { print ''; - if (!empty($sortorder)) + } + if (!empty($sortorder)) { print ''; + } print_barre_liste($langs->trans("Proposals"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1); - if (!empty($page)) $option .= '&page='.urlencode($page); + if (!empty($page)) { + $option .= '&page='.urlencode($page); + } print '
'; print '
'; @@ -208,10 +235,8 @@ if ($id > 0 || !empty($ref)) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "p.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); print "
\n"; - if ($num > 0) - { - while ($i < min($num, $limit)) - { + if ($num > 0) { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $total_ht += $objp->amount; @@ -237,8 +262,11 @@ if ($id > 0 || !empty($ref)) } print ''; - if ($num < $limit) print ''; - else print ''; + if ($num < $limit) { + print ''; + } else { + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index ffd7add3c20..252cccd90ab 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -47,8 +47,12 @@ $ref = GETPOST('ref', 'alpha'); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (!$sortfield) $sortfield = "p.ref"; -if (!$sortorder) $sortorder = "DESC"; +if (!$sortfield) { + $sortfield = "p.ref"; +} +if (!$sortorder) { + $sortorder = "DESC"; +} $backtopage = GETPOST('backtopage', 'alpha'); @@ -87,12 +91,12 @@ $usercandelete = (($user->rights->stock->supprimer)); $parameters = array('id'=>$id, 'ref'=>$ref); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} +if (empty($reshook)) { // Ajout entrepot - if ($action == 'add' && $user->rights->stock->creer) - { + if ($action == 'add' && $user->rights->stock->creer) { $object->ref = (string) GETPOST("ref", "alpha"); $object->fk_parent = (int) GETPOST("fk_parent", "int"); $object->label = (string) GETPOST("libelle", "alpha"); @@ -140,12 +144,10 @@ if (empty($reshook)) } // Delete warehouse - if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) - { + if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) { $object->fetch(GETPOST('id', 'int')); $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1'); exit; @@ -156,10 +158,8 @@ if (empty($reshook)) } // Modification entrepot - if ($action == 'update' && $cancel <> $langs->trans("Cancel")) - { - if ($object->fetch($id)) - { + if ($action == 'update' && $cancel <> $langs->trans("Cancel")) { + if ($object->fetch($id)) { $object->label = GETPOST("libelle"); $object->fk_parent = GETPOST("fk_parent"); $object->description = GETPOST("desc"); @@ -174,11 +174,15 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } if (!$error) { $ret = $object->update($id, $user); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } } if ($error) { @@ -198,7 +202,9 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } if (!$error) { $result = $object->insertExtraFields(); if ($result < 0) { @@ -206,11 +212,12 @@ if (empty($reshook)) $error++; } } - if ($error) $action = 'edit_extras'; + if ($error) { + $action = 'edit_extras'; + } } - if ($cancel == $langs->trans("Cancel")) - { + if ($cancel == $langs->trans("Cancel")) { $action = ''; } @@ -236,8 +243,7 @@ $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("", $langs->trans("WarehouseCard"), $help_url); -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($langs->trans("NewWarehouse"), '', 'stock'); dol_set_focus('input[name="libelle"]'); @@ -285,7 +291,9 @@ if ($action == 'create') print ''; // Phone / Fax @@ -300,10 +308,8 @@ if ($action == 'create') // Status print ''; } @@ -610,8 +617,7 @@ if ($action == 'create') $totalvalue += price2num($objp->ppmp * $objp->value, 'MT'); // Price sell min - if (empty($conf->global->PRODUIT_MULTIPRICES)) - { + if (empty($conf->global->PRODUIT_MULTIPRICES)) { $pricemin = $objp->price; print '"; } - if ($user->rights->stock->creer) - { + if ($user->rights->stock->creer) { print '"; } if (!empty($conf->global->PRODUCT_USE_UNITS)) { - if ($i == 0) $units = $productstatic->fk_unit; - elseif ($productstatic->fk_unit != $units) $sameunits = false; + if ($i == 0) { + $units = $productstatic->fk_unit; + } elseif ($productstatic->fk_unit != $units) { + $sameunits = false; + } } print ""; $i++; @@ -648,14 +655,17 @@ if ($action == 'create') print ''; print ''; print ''; print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) - { + if (empty($conf->global->PRODUIT_MULTIPRICES)) { print ''; print ''; } @@ -672,8 +682,7 @@ if ($action == 'create') /* * Edition fiche */ - if ($action == 'edit' || $action == 're-edit') - { + if ($action == 'edit' || $action == 're-edit') { $langs->trans("WarehouseEdit"); print ''; @@ -721,7 +730,9 @@ if ($action == 'create') print ''; // Phone / Fax @@ -735,10 +746,8 @@ if ($action == 'create') // Status print ''; $i = 0; - if ($num) - { - while ($i < min($max, $num)) - { + if ($num) { + while ($i < min($max, $num)) { $objp = $db->fetch_object($result); $warehouse->id = $objp->rowid; @@ -153,14 +149,15 @@ $sql .= ", ".MAIN_DB_PREFIX."product as p"; $sql .= " WHERE m.fk_product = p.rowid"; $sql .= " AND m.fk_entrepot = e.rowid"; $sql .= " AND e.entity IN (".getEntity('stock').")"; -if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT; +if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT; +} $sql .= $db->order("datem", "DESC"); $sql .= $db->plimit($max, 0); dol_syslog("Index:list stock movements", LOG_DEBUG); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); print '
'; @@ -168,8 +165,7 @@ if ($resql) print "
"; print ''; print ''; - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { print ''; /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { print ''; @@ -185,8 +181,7 @@ if ($resql) $tmplotstatic = new Productlot($db); $i = 0; - while ($i < min($num, $max)) - { + while ($i < min($num, $max)) { $objp = $db->fetch_object($resql); $producttmp->id = $objp->rowid; @@ -225,7 +220,9 @@ if ($resql) print $warehouse->getNomUrl(1); print "\n"; print ''; print "\n"; $i++; diff --git a/htdocs/product/stock/info.php b/htdocs/product/stock/info.php index 884deaaefff..84c0111f290 100644 --- a/htdocs/product/stock/info.php +++ b/htdocs/product/stock/info.php @@ -60,7 +60,9 @@ $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; $morehtmlref .= ''; $shownav = 1; -if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; +if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; +} dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); diff --git a/htdocs/product/stock/lib/replenishment.lib.php b/htdocs/product/stock/lib/replenishment.lib.php index b6ce237a2b5..d0415ccad78 100644 --- a/htdocs/product/stock/lib/replenishment.lib.php +++ b/htdocs/product/stock/lib/replenishment.lib.php @@ -43,30 +43,33 @@ function dolDispatchToDo($order_id) $sql .= ' GROUP BY fk_product'; $sql .= ' ORDER by fk_product'; $resql = $db->query($sql); - if ($resql && $db->num_rows($resql)) - { - while ($obj = $db->fetch_object($resql)) + if ($resql && $db->num_rows($resql)) { + while ($obj = $db->fetch_object($resql)) { $dispatched[$obj->fk_product] = $obj; + } } // Count nb of quantity to dispatch per product $sql = 'SELECT fk_product, SUM(qty) FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet'; $sql .= ' WHERE fk_commande = '.$order_id; $sql .= ' AND fk_product > 0'; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= ' AND product_type = 0'; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= ' AND product_type = 0'; + } $sql .= ' GROUP BY fk_product'; $sql .= ' ORDER by fk_product'; $resql = $db->query($sql); - if ($resql && $db->num_rows($resql)) - { - while ($obj = $db->fetch_object($resql)) + if ($resql && $db->num_rows($resql)) { + while ($obj = $db->fetch_object($resql)) { $ordered[$obj->fk_product] = $obj; + } } $todispatch = 0; - foreach ($ordered as $key => $val) - { - if ($ordered[$key] > $dispatched[$key]) $todispatch++; + foreach ($ordered as $key => $val) { + if ($ordered[$key] > $dispatched[$key]) { + $todispatch++; + } } return ($todispatch ? true : false); @@ -85,19 +88,15 @@ function dispatchedOrders() $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur'; $resql = $db->query($sql); $resarray = array(); - if ($resql && $db->num_rows($resql) > 0) - { - while ($obj = $db->fetch_object($resql)) - { - if (!dolDispatchToDo($obj->rowid)) - { + if ($resql && $db->num_rows($resql) > 0) { + while ($obj = $db->fetch_object($resql)) { + if (!dolDispatchToDo($obj->rowid)) { $resarray[] = $obj->rowid; } } } - if (count($resarray)) - { + if (count($resarray)) { $res = '('.implode(',', $resarray).')'; } else { //hack to make sure ordered SQL request won't syntax error @@ -131,11 +130,9 @@ function ordered($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['qty']; //. ' ' . img_picto('','tick'); } else { diff --git a/htdocs/product/stock/list.php b/htdocs/product/stock/list.php index c823042eba0..1aafe3c6ae2 100644 --- a/htdocs/product/stock/list.php +++ b/htdocs/product/stock/list.php @@ -28,8 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; -if (!empty($conf->categorie->enabled)) -{ +if (!empty($conf->categorie->enabled)) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; } @@ -54,8 +53,7 @@ $search_ref = GETPOST("sref", "alpha") ?GETPOST("sref", "alpha") : GETPOST("sear $search_label = GETPOST("snom", "alpha") ?GETPOST("snom", "alpha") : GETPOST("search_label", "alpha"); $search_status = GETPOST("search_status", "int"); -if (!empty($conf->categorie->enabled)) -{ +if (!empty($conf->categorie->enabled)) { $search_category_list = GETPOST("search_category_".Categorie::TYPE_WAREHOUSE."_list", "array"); } @@ -64,12 +62,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action +if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { + $page = 0; +} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = "t.ref"; -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "t.ref"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Security check $result = restrictedArea($user, 'stock'); @@ -89,18 +93,22 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Initialize array of search criterias $search_all = GETPOST("search_all", 'alpha'); $search = array(); -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $search_key = $key; - if ($search_key == 'statut') $search_key = 'status'; // remove this after refactor entrepot.class property statut to status - if (GETPOST('search_'.$search_key, 'alpha') !== '') $search[$search_key] = GETPOST('search_'.$search_key, 'alpha'); + if ($search_key == 'statut') { + $search_key = 'status'; // remove this after refactor entrepot.class property statut to status + } + if (GETPOST('search_'.$search_key, 'alpha') !== '') { + $search[$search_key] = GETPOST('search_'.$search_key, 'alpha'); + } } // List of fields to search into when doing a "search in all" $fieldstosearchall = array(); -foreach ($object->fields as $key => $val) -{ - if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; +foreach ($object->fields as $key => $val) { + if ($val['searchall']) { + $fieldstosearchall['t.'.$key] = $val['label']; + } } // Definition of array of fields for columns @@ -133,31 +141,33 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { - foreach ($object->fields as $key => $val) - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + foreach ($object->fields as $key => $val) { $search[$key] = ''; } $toselect = array(); $search_array_options = array(); } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) - { + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation } @@ -189,13 +199,14 @@ $title = $langs->trans("ListOfWarehouses"); // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $sql .= 't.'.$key.', '; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + } } $sql .= " SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty"; // Add fields from hooks @@ -204,33 +215,42 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $obje $sql .= $hookmanager->resPrint; $sql = preg_replace('/,\s*$/', '', $sql); $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -if (!empty($conf->categorie->enabled)) -{ +if (!empty($conf->categorie->enabled)) { $sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_WAREHOUSE, "t.rowid"); } -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON t.rowid = ps.fk_entrepot"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c_dep ON c_dep.rowid = t.fk_departement"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as ccount ON ccount.rowid = t.fk_pays"; $sql .= " WHERE t.entity IN (".getEntity('stock').")"; -if (!empty($conf->categorie->enabled)) -{ +if (!empty($conf->categorie->enabled)) { $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_WAREHOUSE, "t.rowid", $search_category_list); } -foreach ($search as $key => $val) -{ +foreach ($search as $key => $val) { $class_key = $key; - if ($class_key == 'status') $class_key = 'statut'; // remove this after refactor entrepot.class property statut to status - if (($key == 'status' && $search[$key] == -1) || $key == 'entity') continue; + if ($class_key == 'status') { + $class_key = 'statut'; // remove this after refactor entrepot.class property statut to status + } + if (($key == 'status' && $search[$key] == -1) || $key == 'entity') { + continue; + } $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); if (strpos($object->fields[$key]['type'], 'integer:') === 0) { - if ($search[$key] == '-1') $search[$key] = ''; + if ($search[$key] == '-1') { + $search[$key] = ''; + } $mode_search = 2; } - if ($search[$key] != '') $sql .= natural_search((($key == 'ref') ? 't.ref' : 't.'.$class_key), $search[$key], (($key == 'status') ? 2 : $mode_search)); + if ($search[$key] != '') { + $sql .= natural_search((($key == 'ref') ? 't.ref' : 't.'.$class_key), $search[$key], (($key == 'status') ? 2 : $mode_search)); + } +} +if ($search_all) { + $sql .= natural_search(array_keys($fieldstosearchall), $search_all); } -if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all); // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -238,13 +258,14 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= " GROUP BY "; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $sql .= 't.'.$key.', '; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : ''); + } } // Add where from hooks $parameters = array(); @@ -253,13 +274,11 @@ $sql .= $hookmanager->resPrint; $sql = preg_replace('/,\s*$/', '', $sql); $totalnboflines = 0; $result = $db->query($sql); -if ($result) -{ +if ($result) { $totalnboflines = $db->num_rows($result); // fetch totals $line = $total = $totalsell = $totalStock = 0; - while ($line < $totalnboflines) - { + while ($line < $totalnboflines) { $objp = $db->fetch_object($result); $total += price2num($objp->estimatedvalue, 'MU'); $totalsell += price2num($objp->sellvalue, 'MU'); @@ -274,26 +293,22 @@ $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $resql = $db->query($sql); $nbtotalofrecords = $db->num_rows($resql); - if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } } // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. -if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) -{ +if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) { $num = $nbtotalofrecords; } else { $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($db); exit; } @@ -302,8 +317,7 @@ if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) } // Direct jump if only one record found -if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) -{ +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) { $obj = $db->fetch_object($resql); $id = $obj->rowid; header("Location: ".DOL_URL_ROOT.'/product/stock/card.php?id='.$id); @@ -319,14 +333,24 @@ llxHeader('', $title, $help_url); $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -foreach ($search as $key => $val) -{ - if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); - else $param .= '&search_'.$key.'='.urlencode($search[$key]); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +foreach ($search as $key => $val) { + if (is_array($search[$key]) && count($search[$key])) { + foreach ($search[$key] as $skey) { + $param .= '&search_'.$key.'[]='.urlencode($skey); + } + } else { + $param .= '&search_'.$key.'='.urlencode($search[$key]); + } +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); } -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -336,12 +360,18 @@ $arrayofmassactions = array( //'builddoc'=>$langs->trans("PDFMerge"), ); //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array(); -if ($user->rights->stock->creer) $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) { + $arrayofmassactions = array(); +} +if ($user->rights->stock->creer) { + $arrayofmassactions['preaffecttag'] = ''.$langs->trans("AffectTag"); +} $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print ''; -if ($optioncss != '') print ''; +if ($optioncss != '') { + print ''; +} print ''; print ''; print ''; @@ -361,16 +391,16 @@ $trackid = 'ware'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -if ($search_all) -{ - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); +if ($search_all) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } $moreforfilter = ''; -if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) -{ +if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $formcategory = new FormCategory($db); $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_WAREHOUSE, $search_category_list); } @@ -381,11 +411,13 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} -if (!empty($moreforfilter)) -{ +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -402,21 +434,29 @@ print '
'; + print ''; print $orderstatic->getNomUrl(1); print "'.$societestatic->getNomUrl(1).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$societestatic->getNomUrl(1).'".$objp->code_client."'; + print ''; print dol_print_date($db->jdate($objp->datef), 'dayhour')."'.$objp->qty."'.price($objp->line_total_ht)."
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.$total_qty.''.price($total_ht).'
'.$langs->trans('Country').''; print img_picto('', 'globe-americas', 'class="paddingright"'); print $form->select_country((!empty($object->country_id) ? $object->country_id : $mysoc->country_code), 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print '
'.$langs->trans("Status").''; print ''; - if (is_null($productstatic->fk_unit))$productstatic->fk_unit = 1; + if (is_null($productstatic->fk_unit)) { + $productstatic->fk_unit = 1; + } print $langs->trans($productstatic->getLabelOfUnit()); print ''; print price(price2num($pricemin, 'MU'), 1); @@ -623,22 +629,23 @@ if ($action == 'create') } $totalvaluesell += price2num($pricemin * $objp->value, 'MT'); - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { print ''; print img_picto($langs->trans("StockMovement"), 'uparrow.png', 'class="hideonsmartphone"').' '.$langs->trans("StockMovement"); print "'; print $langs->trans("StockCorrection"); print "
'.$langs->trans("Total").''; $valtoshow = price2num($totalunit, 'MS'); - if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) print empty($valtoshow) ? '0' : $valtoshow; + if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) { + print empty($valtoshow) ? '0' : $valtoshow; + } print ''; - if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) print $langs->trans($productstatic->getLabelOfUnit()); + if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) { + print $langs->trans($productstatic->getLabelOfUnit()); + } print ''.price(price2num($totalvalue, 'MT')).' '.price(price2num($totalvaluesell, 'MT')).'
'.$langs->trans('Country').''; print img_picto('', 'globe-americas', 'class="paddingright"'); print $form->select_country($object->country_id ? $object->country_id : $mysoc->country_code, 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print '
'.$langs->trans("Status").''; print '
'.$langs->trans("Categories").''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1); $c = new Categorie($db); @@ -792,8 +799,7 @@ if ($action == 'create') $modulepart = 'stock'; -if ($action != 'create' && $action != 'edit' && $action != 'delete') -{ +if ($action != 'create' && $action != 'edit' && $action != 'delete') { print '
'; print '
'; print ''; // ancre diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index dba209e5b6f..90b3895c0f2 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -31,7 +31,7 @@ class StockMovements extends DolibarrApi /** * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'product_id', 'warehouse_id', 'qty' @@ -63,23 +63,23 @@ class StockMovements extends DolibarrApi * @throws RestException */ /* - public function get($id) - { - if(! DolibarrApiAccess::$user->rights->stock->lire) { - throw new RestException(401); - } + public function get($id) + { + if(! DolibarrApiAccess::$user->rights->stock->lire) { + throw new RestException(401); + } - $result = $this->stockmovement->fetch($id); - if( ! $result ) { - throw new RestException(404, 'warehouse not found'); - } + $result = $this->stockmovement->fetch($id); + if( ! $result ) { + throw new RestException(404, 'warehouse not found'); + } - if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->stockmovement->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->stockmovement->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - return $this->_cleanObjectDatas($this->stockmovement); - }*/ + return $this->_cleanObjectDatas($this->stockmovement); + }*/ /** * Get a list of stock movement @@ -108,10 +108,8 @@ class StockMovements extends DolibarrApi //$sql.= ' WHERE t.entity IN ('.getEntity('stock').')'; $sql .= ' WHERE 1 = 1'; // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { + if ($sqlfilters) { + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -120,8 +118,7 @@ class StockMovements extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -130,13 +127,11 @@ class StockMovements extends DolibarrApi } $result = $this->db->query($sql); - if ($result) - { + if ($result) { $i = 0; $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $stockmovement_static = new MouvementStock($this->db); if ($stockmovement_static->fetch($obj->rowid)) { @@ -196,7 +191,9 @@ class StockMovements extends DolibarrApi if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { $errormessage = $this->stockmovement->error; - if (empty($errormessage)) $errormessage = join(',', $this->stockmovement->errors); + if (empty($errormessage)) { + $errormessage = join(',', $this->stockmovement->errors); + } throw new RestException(503, 'Error when create stock movement : '.$errormessage); } @@ -211,31 +208,31 @@ class StockMovements extends DolibarrApi * @return int */ /* - public function put($id, $request_data = null) - { - if(! DolibarrApiAccess::$user->rights->stock->creer) { - throw new RestException(401); - } + public function put($id, $request_data = null) + { + if(! DolibarrApiAccess::$user->rights->stock->creer) { + throw new RestException(401); + } - $result = $this->stockmovement->fetch($id); - if( ! $result ) { - throw new RestException(404, 'stock movement not found'); - } + $result = $this->stockmovement->fetch($id); + if( ! $result ) { + throw new RestException(404, 'stock movement not found'); + } - if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - foreach($request_data as $field => $value) { - if ($field == 'id') continue; - $this->stockmovement->$field = $value; - } + foreach($request_data as $field => $value) { + if ($field == 'id') continue; + $this->stockmovement->$field = $value; + } - if($this->stockmovement->update($id, DolibarrApiAccess::$user)) - return $this->get ($id); + if($this->stockmovement->update($id, DolibarrApiAccess::$user)) + return $this->get ($id); - return false; - }*/ + return false; + }*/ /** * Delete stock movement @@ -244,31 +241,31 @@ class StockMovements extends DolibarrApi * @return array */ /* - public function delete($id) - { - if(! DolibarrApiAccess::$user->rights->stock->supprimer) { - throw new RestException(401); - } - $result = $this->stockmovement->fetch($id); - if( ! $result ) { - throw new RestException(404, 'stock movement not found'); - } + public function delete($id) + { + if(! DolibarrApiAccess::$user->rights->stock->supprimer) { + throw new RestException(401); + } + $result = $this->stockmovement->fetch($id); + if( ! $result ) { + throw new RestException(404, 'stock movement not found'); + } - if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - if (! $this->stockmovement->delete(DolibarrApiAccess::$user)) { - throw new RestException(401,'error when delete stock movement'); - } + if (! $this->stockmovement->delete(DolibarrApiAccess::$user)) { + throw new RestException(401,'error when delete stock movement'); + } - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Warehouse deleted' - ) - ); - }*/ + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Warehouse deleted' + ) + ); + }*/ @@ -341,8 +338,9 @@ class StockMovements extends DolibarrApi { $stockmovement = array(); foreach (self::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $stockmovement[$field] = $data[$field]; } return $stockmovement; diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index d6f2333f3ef..34338232169 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -31,7 +31,7 @@ class Warehouses extends DolibarrApi /** * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'label', ); @@ -115,10 +115,8 @@ class Warehouses extends DolibarrApi $sql .= " AND c.fk_warehouse = t.rowid "; } // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { + if ($sqlfilters) { + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -127,8 +125,7 @@ class Warehouses extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -137,13 +134,11 @@ class Warehouses extends DolibarrApi } $result = $this->db->query($sql); - if ($result) - { + if ($result) { $i = 0; $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $warehouse_static = new Entrepot($this->db); if ($warehouse_static->fetch($obj->rowid)) { @@ -208,12 +203,15 @@ class Warehouses extends DolibarrApi } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->warehouse->$field = $value; } - if ($this->warehouse->update($id, DolibarrApiAccess::$user)) + if ($this->warehouse->update($id, DolibarrApiAccess::$user)) { return $this->get($id); + } return false; } @@ -282,8 +280,9 @@ class Warehouses extends DolibarrApi { $warehouse = array(); foreach (Warehouses::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $warehouse[$field] = $data[$field]; } return $warehouse; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index ac3ce4636e6..7450b19715f 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -203,37 +203,29 @@ class Entrepot extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); - if ($id > 0) - { + if ($id > 0) { $this->id = $id; - if (!$error) - { + if (!$error) { $result = $this->update($id, $user); - if ($result <= 0) - { + if ($result <= 0) { $error++; } } // Actions on extra fields - if (!$error) - { - if (!$error) - { + if (!$error) { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } } - if (!$error) - { + if (!$error) { $this->db->commit(); return $id; } else { @@ -267,16 +259,18 @@ class Entrepot extends CommonObject $error = 0; - if (empty($id)) $id = $this->id; - if (empty($this->label)) $this->label = $this->libelle; // For backward compatibility + if (empty($id)) { + $id = $this->id; + } + if (empty($this->label)) { + $this->label = $this->libelle; // For backward compatibility + } // Check if new parent is already a child of current warehouse - if (!empty($this->fk_parent)) - { + if (!empty($this->fk_parent)) { $TChildWarehouses = array($id); $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses); - if (in_array($this->fk_parent, $TChildWarehouses)) - { + if (in_array($this->fk_parent, $TChildWarehouses)) { $this->error = 'ErrorCannotAddThisParentWarehouse'; return -2; } @@ -319,8 +313,7 @@ class Entrepot extends CommonObject if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } @@ -353,25 +346,23 @@ class Entrepot extends CommonObject $this->db->begin(); - if (!$error && empty($notrigger)) - { + if (!$error && empty($notrigger)) { // Call trigger $result = $this->call_trigger('WAREHOUSE_DELETE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties'); - foreach ($elements as $table) - { - if (!$error) - { + foreach ($elements as $table) { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; $sql .= " WHERE fk_entrepot = ".$this->id; $result = $this->db->query($sql); - if (!$result) - { + if (!$result) { $error++; $this->errors[] = $this->db->lasterror(); } @@ -379,47 +370,39 @@ class Entrepot extends CommonObject } // Removed extrafields - if (!$error) - { - if (!$error) - { + if (!$error) { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR); } } } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; $sql .= " WHERE rowid = ".$this->id; $resql1 = $this->db->query($sql); - if (!$resql1) - { + if (!$resql1) { $error++; $this->errors[] = $this->db->lasterror(); dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR); } } - if (!$error) - { + if (!$error) { // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; $resql2 = $this->db->query($sql); - if (!$resql2) - { + if (!$resql2) { $error++; $this->errors[] = $this->db->lasterror(); dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR); } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -443,8 +426,7 @@ class Entrepot extends CommonObject dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref); // Check parameters - if (!$id && !$ref) - { + if (!$id && !$ref) { $this->error = 'ErrorWrongParameters'; dol_syslog(get_class($this)."::fetch ".$this->error); return -1; @@ -453,19 +435,18 @@ class Entrepot extends CommonObject $sql = "SELECT rowid, entity, fk_parent, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; $sql .= " model_pdf, import_key"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; - if ($id) - { + if ($id) { $sql .= " WHERE rowid = '".$id."'"; } else { $sql .= " WHERE entity = ".$conf->entity; - if ($ref) $sql .= " AND ref = '".$this->db->escape($ref)."'"; + if ($ref) { + $sql .= " AND ref = '".$this->db->escape($ref)."'"; + } } $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result) > 0) - { + if ($result) { + if ($this->db->num_rows($result) > 0) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -522,10 +503,8 @@ class Entrepot extends CommonObject dol_syslog(get_class($this)."::info", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -573,10 +552,8 @@ class Entrepot extends CommonObject $result = $this->db->query($sql); $i = 0; $num = $this->db->num_rows($result); - if ($result) - { - while ($i < $num) - { + if ($result) { + while ($i < $num) { $row = $this->db->fetch_row($result); $liste[$row[0]] = $row[1]; $i++; @@ -605,8 +582,7 @@ class Entrepot extends CommonObject //print $sql; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $obj = $this->db->fetch_object($result); $ret['nb'] = $obj->nb; $this->db->free($result); @@ -637,8 +613,7 @@ class Entrepot extends CommonObject //print $sql; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $obj = $this->db->fetch_object($result); $ret['nb'] = $obj->nb; $ret['value'] = $obj->value; @@ -676,7 +651,9 @@ class Entrepot extends CommonObject global $langs; $statusType = 'status5'; - if ($status > 0) $statusType = 'status4'; + if ($status > 0) { + $statusType = 'status4'; + } $langs->load('stocks'); $label = $langs->trans($this->statuts[$status]); @@ -700,9 +677,13 @@ class Entrepot extends CommonObject global $conf, $langs, $hookmanager; $langs->load("stocks"); - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0; + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) { + $withpicto = 0; + } $result = ''; @@ -718,10 +699,8 @@ class Entrepot extends CommonObject $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id; $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("Warehouse"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -734,8 +713,12 @@ class Entrepot extends CommonObject $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label)); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label)); + } $result .= $linkend; global $action; @@ -798,20 +781,21 @@ class Entrepot extends CommonObject $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents $i = 0; - while ($parentid > 0 && $i < $protection) - { + while ($parentid > 0 && $i < $protection) { $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'entrepot WHERE rowid = '.$parentid; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $objarbo = $this->db->fetch_object($resql); - if ($objarbo) - { + if ($objarbo) { $warehousetmp->fetch($parentid); $TArbo[] = $warehousetmp->label; - $parentid = $objarbo->fk_parent; - } else break; - } else dol_print_error($this->db); + $parentid = $objarbo->fk_parent; + } else { + break; + } + } else { + dol_print_error($this->db); + } $i++; } diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 639816f842d..17fe7193658 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -164,32 +164,32 @@ class MouvementStock extends CommonObject $hookmanager->initHooks(array('mouvementstock')); // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters = array( - 'currentcontext' => 'mouvementstock', - 'user' => &$user, - 'fk_product' => &$fk_product, - 'entrepot_id' => &$entrepot_id, - 'qty' => &$qty, - 'type' => &$type, - 'price' => &$price, - 'label' => &$label, - 'inventorycode' => &$inventorycode, - 'datem' => &$datem, - 'eatby' => &$eatby, - 'sellby' => &$sellby, - 'batch' => &$batch, - 'skip_batch' => &$skip_batch, - 'id_product_batch' => &$id_product_batch - ); - $reshook = $hookmanager->executeHooks('stockMovementCreate', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array( + 'currentcontext' => 'mouvementstock', + 'user' => &$user, + 'fk_product' => &$fk_product, + 'entrepot_id' => &$entrepot_id, + 'qty' => &$qty, + 'type' => &$type, + 'price' => &$price, + 'label' => &$label, + 'inventorycode' => &$inventorycode, + 'datem' => &$datem, + 'eatby' => &$eatby, + 'sellby' => &$sellby, + 'batch' => &$batch, + 'skip_batch' => &$skip_batch, + 'id_product_batch' => &$id_product_batch + ); + $reshook = $hookmanager->executeHooks('stockMovementCreate', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) { - if (!empty($hookmanager->resPrint)) - dol_print_error('', $hookmanager->resPrint); - return $reshook; - } elseif ($reshook > 0) { - return $hookmanager->resPrint; - } + if ($reshook < 0) { + if (!empty($hookmanager->resPrint)) + dol_print_error('', $hookmanager->resPrint); + return $reshook; + } elseif ($reshook > 0) { + return $hookmanager->resPrint; + } } // end hook at beginning @@ -1020,15 +1020,13 @@ class MouvementStock extends CommonObject break; default: - if ($origintype) - { + if ($origintype) { // Separate originetype with "@" : left part is class name, right part is module name $origintype_array = explode('@', $origintype); $classname = ucfirst($origintype_array[0]); $modulename = empty($origintype_array[1]) ? $classname : $origintype_array[1]; $result = dol_include_once('/'.$modulename.'/class/'.strtolower($classname).'.class.php'); - if ($result) - { + if ($result) { $classname = ucfirst($classname); $origin = new $classname($this->db); } @@ -1036,7 +1034,9 @@ class MouvementStock extends CommonObject break; } - if (empty($origin) || !is_object($origin)) return ''; + if (empty($origin) || !is_object($origin)) { + return ''; + } if ($origin->fetch($fk_origin) > 0) { return $origin->getNomUrl(1); @@ -1055,17 +1055,16 @@ class MouvementStock extends CommonObject */ public function setOrigin($origin_element, $origin_id) { - if (!empty($origin_element) && $origin_id > 0) - { + if (!empty($origin_element) && $origin_id > 0) { $origin = ''; - if ($origin_element == 'project') - { - if (!class_exists('Project')) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + if ($origin_element == 'project') { + if (!class_exists('Project')) { + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + } $origin = new Project($this->db); } - if (!empty($origin)) - { + if (!empty($origin)) { $this->origin = $origin; $this->origin->id = $origin_id; } @@ -1119,10 +1118,11 @@ class MouvementStock extends CommonObject $link .= '>'; $linkend = ''; - if ($withpicto) - { + if ($withpicto) { $result .= ($link.img_object(($notooltip ? '' : $label), 'stock', ($notooltip ? '' : 'class="classfortooltip"')).$linkend); - if ($withpicto != 2) $result .= ' '; + if ($withpicto != 2) { + $result .= ' '; + } } $result .= $link.$this->id.$linkend; return $result; diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 96650c034f3..10294b2c585 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -215,11 +215,9 @@ class Productlot extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } @@ -230,7 +228,9 @@ class Productlot extends CommonObject // Call triggers $result = $this->call_trigger('PRODUCTLOT_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } } @@ -358,8 +358,7 @@ class Productlot extends CommonObject // Check parameters // Put here code to add a control on parameters values - if (empty($this->oldcopy)) - { + if (empty($this->oldcopy)) { $org = new self($this->db); $org->fetch($this->id); $this->oldcopy = $org; @@ -389,11 +388,9 @@ class Productlot extends CommonObject } // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } @@ -401,7 +398,9 @@ class Productlot extends CommonObject if (!$error && !$notrigger) { // Call triggers $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } @@ -581,25 +580,28 @@ class Productlot extends CommonObject $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id; - if ($option != 'nolink') - { + if ($option != 'nolink') { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowMyObject"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } else { + $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } if ($option == 'nolink') { $linkstart = 'picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->batch; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->batch; + } $result .= $linkend; return $result; diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index ad36dc43c15..98632325ead 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -93,11 +93,21 @@ class ProductStockEntrepot extends CommonObject // Clean parameters - if (isset($this->fk_product)) $this->fk_product = (int) $this->fk_product; - if (isset($this->fk_entrepot)) $this->fk_entrepot = (int) $this->fk_entrepot; - if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); - if (isset($this->desiredstock)) $this->desiredstock = trim($this->desiredstock); - if (isset($this->import_key)) $this->import_key = trim($this->import_key); + if (isset($this->fk_product)) { + $this->fk_product = (int) $this->fk_product; + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = (int) $this->fk_entrepot; + } + if (isset($this->seuil_stock_alerte)) { + $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); + } + if (isset($this->desiredstock)) { + $this->desiredstock = trim($this->desiredstock); + } + if (isset($this->import_key)) { + $this->import_key = trim($this->import_key); + } // Check parameters // Put here code to add control on parameters values @@ -168,7 +178,9 @@ class ProductStockEntrepot extends CommonObject */ public function fetch($id, $fk_product = 0, $fk_entrepot = 0) { - if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) return -1; + if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) { + return -1; + } dol_syslog(__METHOD__, LOG_DEBUG); @@ -181,15 +193,16 @@ class ProductStockEntrepot extends CommonObject $sql .= " t.desiredstock,"; $sql .= " t.import_key"; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - if (!empty($id)) $sql .= ' WHERE t.rowid = '.$id; - else $sql .= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot; + if (!empty($id)) { + $sql .= ' WHERE t.rowid = '.$id; + } else { + $sql .= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $numrows = $this->db->num_rows($resql); - if ($numrows) - { + if ($numrows) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -263,14 +276,23 @@ class ProductStockEntrepot extends CommonObject $sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; } } - if (count($sqlwhere) > 0) $sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere); + if (count($sqlwhere) > 0) { + $sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere); + } - if (!empty($fk_product)) $sql .= ' AND fk_product = '.$fk_product; - elseif (!empty($fk_entrepot)) $sql .= ' AND fk_entrepot = '.$fk_entrepot; + if (!empty($fk_product)) { + $sql .= ' AND fk_product = '.$fk_product; + } elseif (!empty($fk_entrepot)) { + $sql .= ' AND fk_entrepot = '.$fk_entrepot; + } // "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch - if (!empty($sortfield)) $sql .= $this->db->order($sortfield, $sortorder); - if (!empty($limit)) $sql .= ' '.$this->db->plimit($limit, $offset); + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (!empty($limit)) { + $sql .= ' '.$this->db->plimit($limit, $offset); + } $lines = array(); @@ -312,11 +334,21 @@ class ProductStockEntrepot extends CommonObject // Clean parameters - if (isset($this->fk_product)) $this->fk_product = (int) $this->fk_product; - if (isset($this->fk_entrepot)) $this->fk_entrepot = (int) $this->fk_entrepot; - if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); - if (isset($this->desiredstock)) $this->desiredstock = trim($this->desiredstock); - if (isset($this->import_key)) $this->import_key = trim($this->import_key); + if (isset($this->fk_product)) { + $this->fk_product = (int) $this->fk_product; + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = (int) $this->fk_entrepot; + } + if (isset($this->seuil_stock_alerte)) { + $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); + } + if (isset($this->desiredstock)) { + $this->desiredstock = trim($this->desiredstock); + } + if (isset($this->import_key)) { + $this->import_key = trim($this->import_key); + } // Check parameters @@ -495,10 +527,11 @@ class ProductStockEntrepot extends CommonObject $link .= '>'; $linkend = ''; - if ($withpicto) - { + if ($withpicto) { $result .= ($link.img_object(($notooltip ? '' : $label), 'label', ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend); - if ($withpicto != 2) $result .= ' '; + if ($withpicto != 2) { + $result .= ' '; + } } $result .= $link.$this->ref.$linkend; return $result; @@ -528,30 +561,42 @@ class ProductStockEntrepot extends CommonObject // phpcs:enable global $langs; - if ($mode == 0) - { - if ($status == 1) return $langs->trans('Enabled'); - elseif ($status == 0) return $langs->trans('Disabled'); - } elseif ($mode == 1) - { - if ($status == 1) return $langs->trans('Enabled'); - elseif ($status == 0) return $langs->trans('Disabled'); - } elseif ($mode == 2) - { - if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } elseif ($mode == 3) - { - if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5'); - } elseif ($mode == 4) - { - if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); - elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } elseif ($mode == 5) - { - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); - elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); + if ($mode == 0) { + if ($status == 1) { + return $langs->trans('Enabled'); + } elseif ($status == 0) { + return $langs->trans('Disabled'); + } + } elseif ($mode == 1) { + if ($status == 1) { + return $langs->trans('Enabled'); + } elseif ($status == 0) { + return $langs->trans('Disabled'); + } + } elseif ($mode == 2) { + if ($status == 1) { + return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); + } elseif ($status == 0) { + return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); + } + } elseif ($mode == 3) { + if ($status == 1) { + return img_picto($langs->trans('Enabled'), 'statut4'); + } elseif ($status == 0) { + return img_picto($langs->trans('Disabled'), 'statut5'); + } + } elseif ($mode == 4) { + if ($status == 1) { + return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); + } elseif ($status == 0) { + return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); + } + } elseif ($mode == 5) { + if ($status == 1) { + return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); + } elseif ($status == 0) { + return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); + } } } diff --git a/htdocs/product/stock/fiche-valo.php b/htdocs/product/stock/fiche-valo.php index 55ac057985b..34380efbe7a 100644 --- a/htdocs/product/stock/fiche-valo.php +++ b/htdocs/product/stock/fiche-valo.php @@ -43,14 +43,14 @@ $form = new Form($db); $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("", $langs->trans("WarehouseCard"), $help_url); -if ($_GET["id"]) -{ - if ($mesg) print $mesg; +if ($_GET["id"]) { + if ($mesg) { + print $mesg; + } $entrepot = new Entrepot($db); $result = $entrepot->fetch($_GET["id"]); - if ($result < 0) - { + if ($result < 0) { dol_print_error($db); } @@ -120,13 +120,11 @@ if ($_GET["id"]) - if (file_exists($file)) - { + if (file_exists($file)) { $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file=entrepot-'.$entrepot->id.'-'.$year.'.png'; print 'Valorisation du stock annee '.($year).''; - if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year - 1).'.png')) - { + if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year - 1).'.png')) { $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file=entrepot-'.$entrepot->id.'-'.($year - 1).'.png'; print '
Valorisation du stock annee '.($year - 1).''; } diff --git a/htdocs/product/stock/index.php b/htdocs/product/stock/index.php index 8a4d81419c4..ff2c99c0b09 100644 --- a/htdocs/product/stock/index.php +++ b/htdocs/product/stock/index.php @@ -60,8 +60,7 @@ print load_fiche_titre($langs->trans("StocksArea"), '', 'stock'); print '
'; -if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo -{ +if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo print ''; print ''; print '
'; @@ -84,8 +83,7 @@ $sql .= $db->plimit($max + 1, 0); $result = $db->query($sql); -if ($result) -{ +if ($result) { $num = $db->num_rows($result); print '
'; @@ -102,10 +100,8 @@ if ($result) print '
'.$langs->trans("LastMovements", min($num, $max)).''.$langs->trans("Product").''.$langs->trans("Batch").''.$langs->trans("SellByDate").''; - if ($objp->qty > 0) print '+'; + if ($objp->qty > 0) { + print '+'; + } print $objp->qty.'
'; -foreach ($object->fields as $key => $val) -{ - if ($key == 'statut') { continue; } +foreach ($object->fields as $key => $val) { + if ($key == 'statut') { + continue; + } $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; } } @@ -459,16 +499,21 @@ print ''."\n"; // -------------------------------------------------------------------- print ''; -foreach ($object->fields as $key => $val) -{ - if ($key == 'statut') { continue; } +foreach ($object->fields as $key => $val) { + if ($key == 'statut') { + continue; + } $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n"; } } @@ -504,14 +549,14 @@ print ''."\n"; // Loop on record // -------------------------------------------------------------------- $i = 0; -if ($num) -{ +if ($num) { $warehouse = new Entrepot($db); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); - if (empty($obj)) break; // Should not happen + if (empty($obj)) { + break; // Should not happen + } $warehouse->id = $obj->rowid; $warehouse->ref = $obj->ref; @@ -527,22 +572,32 @@ if ($num) // Show here line of result print ''; - foreach ($warehouse->fields as $key => $val) - { - if ($key == 'statut') { continue; } + foreach ($warehouse->fields as $key => $val) { + if ($key == 'statut') { + continue; + } $cssforfield = (empty($val['css']) ? '' : $val['css']); - if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } - if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + if (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif ($key == 'ref') { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } - if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; - if ($key == 'statut') print $warehouse->getLibStatut(5); + if ($key == 'statut') { + print $warehouse->getLibStatut(5); + } if ($key == 'phone') { print dol_print_phone($obj->phone, '', 0, $obj->rowid, 'AC_TEL'); } elseif ($key == 'fax') { @@ -551,10 +606,13 @@ if ($num) print $warehouse->showOutputField($val, $key, $warehouse->$key, ''); } print ''; - if (!$i) $totalarray['nbfield']++; - if (!empty($val['isameasure'])) - { - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + if (!$i) { + $totalarray['nbfield']++; + } + if (!empty($val['isameasure'])) { + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + } $totalarray['val']['t.'.$key] += $warehouse->$key; } } @@ -563,31 +621,47 @@ if ($num) // Stock qty if (!empty($arrayfields["stockqty"]['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'stockqty'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'stockqty'; + } } // PMP value if (!empty($arrayfields["estimatedvalue"]['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'estimatedvalue'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'estimatedvalue'; + } } // Selling value if (!empty($arrayfields["estimatedstockvaluesell"]['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'estimatedstockvaluesell'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'estimatedstockvaluesell'; + } } // Extra fields @@ -600,19 +674,24 @@ if ($num) // Status if (!empty($arrayfields['t.statut']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print ''."\n"; @@ -620,8 +699,7 @@ if ($num) $i++; } - if ($totalnboflines - $offset <= $limit) - { + if ($totalnboflines - $offset <= $limit) { // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; } @@ -638,10 +716,11 @@ print ''."\n"; print ''."\n"; -if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) -{ +if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $formfile = new FormFile($db); diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index 4e35d3832e5..a9a69dd4522 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -56,7 +56,9 @@ $idline = GETPOST('idline'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 if (!$sortfield) { $sortfield = 'p.ref'; @@ -69,51 +71,44 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; $listofdata = array(); -if (!empty($_SESSION['massstockmove'])) $listofdata = json_decode($_SESSION['massstockmove'], true); +if (!empty($_SESSION['massstockmove'])) { + $listofdata = json_decode($_SESSION['massstockmove'], true); +} /* * Actions */ -if ($action == 'addline') -{ - if (!($id_product > 0)) - { +if ($action == 'addline') { + if (!($id_product > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); } - if (!($id_sw > 0)) - { + if (!($id_sw > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors'); } - if (!($id_tw > 0)) - { + if (!($id_tw > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors'); } - if ($id_sw > 0 && $id_tw == $id_sw) - { + if ($id_sw > 0 && $id_tw == $id_sw) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors'); } - if (!$qty) - { + if (!$qty) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); } // Check a batch number is provided if product need it - if (!$error) - { + if (!$error) { $producttmp = new Product($db); $producttmp->fetch($id_product); - if ($producttmp->hasbatch()) - { - if (empty($batch)) - { + if ($producttmp->hasbatch()) { + if (empty($batch)) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors'); @@ -123,19 +118,19 @@ if ($action == 'addline') // TODO Check qty is ok for stock move. Note qty may not be enough yet, but we make a check now to report a warning. // What is more important is to have qty when doing action 'createmovements' - if (!$error) - { + if (!$error) { // Warning, don't forget lines already added into the $_SESSION['massstockmove'] - if ($producttmp->hasbatch()) - { + if ($producttmp->hasbatch()) { } else { } } - if (!$error) - { - if (count(array_keys($listofdata)) > 0) $id = max(array_keys($listofdata)) + 1; - else $id = 1; + if (!$error) { + if (count(array_keys($listofdata)) > 0) { + $id = max(array_keys($listofdata)) + 1; + } else { + $id = 1; + } $listofdata[$id] = array('id'=>$id, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch); $_SESSION['massstockmove'] = json_encode($listofdata); @@ -147,31 +142,31 @@ if ($action == 'addline') } } -if ($action == 'delline' && $idline != '') -{ - if (!empty($listofdata[$idline])) unset($listofdata[$idline]); - if (count($listofdata) > 0) $_SESSION['massstockmove'] = json_encode($listofdata); - else unset($_SESSION['massstockmove']); +if ($action == 'delline' && $idline != '') { + if (!empty($listofdata[$idline])) { + unset($listofdata[$idline]); + } + if (count($listofdata) > 0) { + $_SESSION['massstockmove'] = json_encode($listofdata); + } else { + unset($_SESSION['massstockmove']); + } } -if ($action == 'createmovements') -{ +if ($action == 'createmovements') { $error = 0; - if (!GETPOST("label")) - { + if (!GETPOST("label")) { $error++; setEventMessages($langs->trans("ErrorFieldRequired"), $langs->transnoentitiesnoconv("MovementLabel"), null, 'errors'); } $db->begin(); - if (!$error) - { + if (!$error) { $product = new Product($db); - foreach ($listofdata as $key => $val) // Loop on each movement to do - { + foreach ($listofdata as $key => $val) { // Loop on each movement to do $id = $val['id']; $id_product = $val['id_product']; $id_sw = $val['id_sw']; @@ -181,21 +176,21 @@ if ($action == 'createmovements') $dlc = -1; // They are loaded later from serial $dluo = -1; // They are loaded later from serial - if (!$error && $id_sw <> $id_tw && is_numeric($qty) && $id_product) - { + if (!$error && $id_sw <> $id_tw && is_numeric($qty) && $id_product) { $result = $product->fetch($id_product); $product->load_stock('novirtual'); // Load array product->stock_warehouse // Define value of products moved $pricesrc = 0; - if (!empty($product->pmp)) $pricesrc = $product->pmp; + if (!empty($product->pmp)) { + $pricesrc = $product->pmp; + } $pricedest = $pricesrc; //print 'price src='.$pricesrc.', price dest='.$pricedest;exit; - if (empty($conf->productbatch->enabled) || !$product->hasbatch()) // If product does not need lot/serial - { + if (empty($conf->productbatch->enabled) || !$product->hasbatch()) { // If product does not need lot/serial // Remove stock $result1 = $product->correct_stock( $user, @@ -206,8 +201,7 @@ if ($action == 'createmovements') $pricesrc, GETPOST("codemove") ); - if ($result1 < 0) - { + if ($result1 < 0) { $error++; setEventMessages($product->errors, $product->errorss, 'errors'); } @@ -222,15 +216,13 @@ if ($action == 'createmovements') $pricedest, GETPOST("codemove") ); - if ($result2 < 0) - { + if ($result2 < 0) { $error++; setEventMessages($product->errors, $product->errorss, 'errors'); } } else { $arraybatchinfo = $product->loadBatchInfo($batch); - if (count($arraybatchinfo) > 0) - { + if (count($arraybatchinfo) > 0) { $firstrecord = array_shift($arraybatchinfo); $dlc = $firstrecord['eatby']; $dluo = $firstrecord['sellby']; @@ -253,8 +245,7 @@ if ($action == 'createmovements') $batch, GETPOST("codemove") ); - if ($result1 < 0) - { + if ($result1 < 0) { $error++; setEventMessages($product->errors, $product->errorss, 'errors'); } @@ -272,8 +263,7 @@ if ($action == 'createmovements') $batch, GETPOST("codemove") ); - if ($result2 < 0) - { + if ($result2 < 0) { $error++; setEventMessages($product->errors, $product->errorss, 'errors'); } @@ -285,8 +275,7 @@ if ($action == 'createmovements') } } - if (!$error) - { + if (!$error) { unset($_SESSION['massstockmove']); $db->commit(); @@ -362,7 +351,9 @@ print ''; // Product print ''; // Batch number -if ($conf->productbatch->enabled) -{ +if ($conf->productbatch->enabled) { print ''; @@ -386,8 +376,7 @@ print ''; - if ($conf->productbatch->enabled) - { + if ($conf->productbatch->enabled) { print ''; diff --git a/htdocs/product/stock/movement_card.php b/htdocs/product/stock/movement_card.php index cf3cc67bdc2..5107a558288 100644 --- a/htdocs/product/stock/movement_card.php +++ b/htdocs/product/stock/movement_card.php @@ -44,7 +44,9 @@ if (!empty($conf->projet->enabled)) { // Load translation files required by the page $langs->loadLangs(array('products', 'stocks', 'orders')); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} // Security check $result = restrictedArea($user, 'stock'); @@ -75,10 +77,16 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; -if (!$sortfield) $sortfield = "m.datem"; -if (!$sortorder) $sortorder = "DESC"; +if (!$sortfield) { + $sortfield = "m.datem"; +} +if (!$sortorder) { + $sortorder = "DESC"; +} $pdluoid = GETPOST('pdluoid', 'int'); @@ -123,18 +131,23 @@ $usercandelete = (($user->rights->stock->mouvement->supprimer)); * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Do we click on purge search criteria ? -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers $year = ''; $month = ''; $search_ref = ''; @@ -153,39 +166,35 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' } // Correct stock -if ($action == "correct_stock") -{ +if ($action == "correct_stock") { $product = new Product($db); - if (!empty($product_id)) $result = $product->fetch($product_id); + if (!empty($product_id)) { + $result = $product->fetch($product_id); + } $error = 0; - if (empty($product_id)) - { + if (empty($product_id)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); $action = 'correction'; } - if (!is_numeric($_POST["nbpiece"])) - { + if (!is_numeric($_POST["nbpiece"])) { $error++; setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $action = 'correction'; } - if (!$error) - { + if (!$error) { $origin_element = ''; $origin_id = null; - if (GETPOST('projectid', 'int')) - { + if (GETPOST('projectid', 'int')) { $origin_element = 'project'; $origin_id = GETPOST('projectid', 'int'); } - if ($product->hasbatch()) - { + if ($product->hasbatch()) { $batch = GETPOST('batch_number', 'alpha'); //$eatby=GETPOST('eatby'); @@ -221,8 +230,7 @@ if ($action == "correct_stock") ); // We do not change value of stock for a correction } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { @@ -232,57 +240,52 @@ if ($action == "correct_stock") } } - if (!$error) $action = ''; + if (!$error) { + $action = ''; + } } // Transfer stock from a warehouse to another warehouse -if ($action == "transfert_stock" && !$cancel) -{ +if ($action == "transfert_stock" && !$cancel) { $product = new Product($db); - if (!empty($product_id)) $result = $product->fetch($product_id); + if (!empty($product_id)) { + $result = $product->fetch($product_id); + } - if (!(GETPOST("id_entrepot_destination", 'int') > 0)) - { + if (!(GETPOST("id_entrepot_destination", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'transfert'; } - if (empty($product_id)) - { + if (empty($product_id)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); $action = 'transfert'; } - if (!GETPOST("nbpiece", 'int')) - { + if (!GETPOST("nbpiece", 'int')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'transfert'; } - if ($id == GETPOST("id_entrepot_destination", 'int')) - { + if ($id == GETPOST("id_entrepot_destination", 'int')) { setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); $error++; $action = 'transfert'; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { $product = new Product($db); $result = $product->fetch($product_id); - if ($product->hasbatch() && !GETPOST("batch_number", 'alpha')) - { + if ($product->hasbatch() && !GETPOST("batch_number", 'alpha')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'transfert'; } } - if (!$error) - { - if ($id) - { + if (!$error) { + if ($id) { $object = new Entrepot($db); $result = $object->fetch($id); @@ -292,18 +295,17 @@ if ($action == "transfert_stock" && !$cancel) // Define value of products moved $pricesrc = 0; - if (isset($product->pmp)) $pricesrc = $product->pmp; + if (isset($product->pmp)) { + $pricesrc = $product->pmp; + } $pricedest = $pricesrc; - if ($product->hasbatch()) - { + if ($product->hasbatch()) { $pdluo = new Productbatch($db); - if ($pdluoid > 0) - { + if ($pdluoid > 0) { $result = $pdluo->fetch($pdluoid); - if ($result) - { + if ($result) { $srcwarehouseid = $pdluo->warehouseid; $batch = $pdluo->batch; $eatby = $pdluo->eatby; @@ -319,8 +321,7 @@ if ($action == "transfert_stock" && !$cancel) $sellby = $d_sellby; } - if (!$error) - { + if (!$error) { // Remove stock $result1 = $product->correct_stock_batch( $user, @@ -371,12 +372,10 @@ if ($action == "transfert_stock" && !$cancel) GETPOST('inventorycode', 'alpha') ); } - if (!$error && $result1 >= 0 && $result2 >= 0) - { + if (!$error && $result1 >= 0 && $result2 >= 0) { $db->commit(); - if ($backtopage) - { + if ($backtopage) { header("Location: ".$backtopage); exit; } else { @@ -403,8 +402,7 @@ $permissiontoadd = $user->rights->stock->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; -if (empty($reshook) && $action != 'remove_file') -{ +if (empty($reshook) && $action != 'remove_file') { $objectclass = 'MouvementStock'; $objectlabel = 'Movements'; $permissiontoread = $user->rights->stock->lire; @@ -427,7 +425,9 @@ $userstatic = new User($db); $form = new Form($db); $formother = new FormOther($db); $formproduct = new FormProduct($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,"; $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu,"; @@ -438,7 +438,9 @@ $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,"; $sql .= " u.login, u.photo, u.lastname, u.firstname"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); @@ -447,27 +449,57 @@ $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; $sql .= " ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product"; $sql .= " WHERE m.fk_product = p.rowid"; -if ($msid > 0) $sql .= " AND m.rowid = ".$msid; +if ($msid > 0) { + $sql .= " AND m.rowid = ".$msid; +} $sql .= " AND m.fk_entrepot = e.rowid"; $sql .= " AND e.entity IN (".getEntity('stock').")"; -if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0"; -if ($id > 0) $sql .= " AND e.rowid ='".$id."'"; +if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= " AND p.fk_product_type = 0"; +} +if ($id > 0) { + $sql .= " AND e.rowid ='".$id."'"; +} $sql .= dolSqlDateFilter('m.datem', 0, $month, $year); -if ($idproduct > 0) $sql .= " AND p.rowid = ".((int) $idproduct); -if (!empty($search_ref)) $sql .= natural_search('m.rowid', $search_ref, 1); -if (!empty($search_movement)) $sql .= natural_search('m.label', $search_movement); -if (!empty($search_inventorycode)) $sql .= natural_search('m.inventorycode', $search_inventorycode); -if (!empty($search_product_ref)) $sql .= natural_search('p.ref', $search_product_ref); -if (!empty($search_product)) $sql .= natural_search('p.label', $search_product); -if ($search_warehouse != '' && $search_warehouse != '-1') $sql .= natural_search('e.rowid', $search_warehouse, 2); -if (!empty($search_user)) $sql .= natural_search('u.login', $search_user); -if (!empty($search_batch)) $sql .= natural_search('m.batch', $search_batch); -if ($search_qty != '') $sql .= natural_search('m.value', $search_qty, 1); -if ($search_type_mouvement != '' && $search_type_mouvement != '-1') $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2); +if ($idproduct > 0) { + $sql .= " AND p.rowid = ".((int) $idproduct); +} +if (!empty($search_ref)) { + $sql .= natural_search('m.rowid', $search_ref, 1); +} +if (!empty($search_movement)) { + $sql .= natural_search('m.label', $search_movement); +} +if (!empty($search_inventorycode)) { + $sql .= natural_search('m.inventorycode', $search_inventorycode); +} +if (!empty($search_product_ref)) { + $sql .= natural_search('p.ref', $search_product_ref); +} +if (!empty($search_product)) { + $sql .= natural_search('p.label', $search_product); +} +if ($search_warehouse != '' && $search_warehouse != '-1') { + $sql .= natural_search('e.rowid', $search_warehouse, 2); +} +if (!empty($search_user)) { + $sql .= natural_search('u.login', $search_user); +} +if (!empty($search_batch)) { + $sql .= natural_search('m.batch', $search_batch); +} +if ($search_qty != '') { + $sql .= natural_search('m.value', $search_qty, 1); +} +if ($search_type_mouvement != '' && $search_type_mouvement != '-1') { + $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2); +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -477,12 +509,10 @@ $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -492,20 +522,16 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $product = new Product($db); $object = new Entrepot($db); - if ($idproduct > 0) - { + if ($idproduct > 0) { $product->fetch($idproduct); } - if ($id > 0 || $ref) - { + if ($id > 0 || $ref) { $result = $object->fetch($id, $ref); - if ($result < 0) - { + if ($result < 0) { dol_print_error($db); } } @@ -517,18 +543,20 @@ if ($resql) $i = 0; $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - if ($msid) $texte = $langs->trans('StockMovementForId', $msid); - else { + if ($msid) { + $texte = $langs->trans('StockMovementForId', $msid); + } else { $texte = $langs->trans("ListOfStockMovements"); - if ($id) $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; + if ($id) { + $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; + } } llxHeader("", $texte, $help_url); /* - * Show tab only if we ask a particular warehouse - */ - if ($object->id > 0) - { + * Show tab only if we ask a particular warehouse + */ + if ($object->id > 0) { $head = stock_prepare_head($object); print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock'); @@ -541,7 +569,9 @@ if ($resql) $morehtmlref .= ''; $shownav = 1; - if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); @@ -590,8 +620,7 @@ if ($resql) $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " WHERE m.fk_entrepot = ".(int) $object->id; $resqlbis = $db->query($sql); - if ($resqlbis) - { + if ($resqlbis) { $obj = $db->fetch_object($resqlbis); $lastmovementdate = $db->jdate($obj->datem); } else { @@ -599,8 +628,7 @@ if ($resql) } print ''; - if (!empty($arrayfields['m.rowid']['checked'])) - { + if (!empty($arrayfields['m.rowid']['checked'])) { // Ref print ''; } - if (!empty($arrayfields['m.datem']['checked'])) - { + if (!empty($arrayfields['m.datem']['checked'])) { print ''; } - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { // Product Ref print ''; } - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { // Product label print ''; } // Batch - if (!empty($arrayfields['m.batch']['checked'])) - { + if (!empty($arrayfields['m.batch']['checked'])) { print ''; } - if (!empty($arrayfields['pl.eatby']['checked'])) - { + if (!empty($arrayfields['pl.eatby']['checked'])) { print ''; } - if (!empty($arrayfields['pl.sellby']['checked'])) - { + if (!empty($arrayfields['pl.sellby']['checked'])) { print ''; } // Warehouse - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print ''; } - if (!empty($arrayfields['m.fk_user_author']['checked'])) - { + if (!empty($arrayfields['m.fk_user_author']['checked'])) { // Author print ''; } - if (!empty($arrayfields['m.inventorycode']['checked'])) - { + if (!empty($arrayfields['m.inventorycode']['checked'])) { // Inventory code print ''; } - if (!empty($arrayfields['m.label']['checked'])) - { + if (!empty($arrayfields['m.label']['checked'])) { // Label of movement print ''; } - if (!empty($arrayfields['m.type_mouvement']['checked'])) - { + if (!empty($arrayfields['m.type_mouvement']['checked'])) { // Type of movement print ''; } - if (!empty($arrayfields['origin']['checked'])) - { + if (!empty($arrayfields['origin']['checked'])) { // Origin of movement print ''; } - if (!empty($arrayfields['m.value']['checked'])) - { + if (!empty($arrayfields['m.value']['checked'])) { // Qty print ''; } - if (!empty($arrayfields['m.price']['checked'])) - { + if (!empty($arrayfields['m.price']['checked'])) { // Price print ''; } // Date modification - if (!empty($arrayfields['m.tms']['checked'])) - { + if (!empty($arrayfields['m.tms']['checked'])) { print ''; } @@ -871,38 +915,52 @@ if ($resql) print "\n"; print ''; - if (!empty($arrayfields['m.rowid']['checked'])) + if (!empty($arrayfields['m.rowid']['checked'])) { print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['m.datem']['checked'])) + } + if (!empty($arrayfields['m.datem']['checked'])) { print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['p.ref']['checked'])) + } + if (!empty($arrayfields['p.ref']['checked'])) { print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['p.label']['checked'])) + } + if (!empty($arrayfields['p.label']['checked'])) { print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['m.batch']['checked'])) + } + if (!empty($arrayfields['m.batch']['checked'])) { print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['pl.eatby']['checked'])) + } + if (!empty($arrayfields['pl.eatby']['checked'])) { print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['pl.sellby']['checked'])) + } + if (!empty($arrayfields['pl.sellby']['checked'])) { print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center '); + } if (!empty($arrayfields['e.ref']['checked'])) { // We are on a specific warehouse card, no filter on other should be possible print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder); } - if (!empty($arrayfields['m.fk_user_author']['checked'])) + if (!empty($arrayfields['m.fk_user_author']['checked'])) { print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder); - if (!empty($arrayfields['m.inventorycode']['checked'])) + } + if (!empty($arrayfields['m.inventorycode']['checked'])) { print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder); - if (!empty($arrayfields['m.label']['checked'])) + } + if (!empty($arrayfields['m.label']['checked'])) { print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder); - if (!empty($arrayfields['m.type_mouvement']['checked'])) + } + if (!empty($arrayfields['m.type_mouvement']['checked'])) { print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['origin']['checked'])) + } + if (!empty($arrayfields['origin']['checked'])) { print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder); - if (!empty($arrayfields['m.value']['checked'])) + } + if (!empty($arrayfields['m.value']['checked'])) { print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['m.price']['checked'])) + } + if (!empty($arrayfields['m.price']['checked'])) { print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right '); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -956,65 +1014,58 @@ if ($resql) print ''; // Id movement - if (!empty($arrayfields['m.rowid']['checked'])) - { + if (!empty($arrayfields['m.rowid']['checked'])) { // This is primary not movement id print ''; } - if (!empty($arrayfields['m.datem']['checked'])) - { + if (!empty($arrayfields['m.datem']['checked'])) { // Date print ''; } - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { // Product ref print '\n"; } - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { // Product label print '\n"; } - if (!empty($arrayfields['m.batch']['checked'])) - { + if (!empty($arrayfields['m.batch']['checked'])) { print ''; } - if (!empty($arrayfields['pl.eatby']['checked'])) - { + if (!empty($arrayfields['pl.eatby']['checked'])) { print ''; } - if (!empty($arrayfields['pl.sellby']['checked'])) - { + if (!empty($arrayfields['pl.sellby']['checked'])) { print ''; } // Warehouse - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print '\n"; } // Author - if (!empty($arrayfields['m.fk_user_author']['checked'])) - { + if (!empty($arrayfields['m.fk_user_author']['checked'])) { print '\n"; } - if (!empty($arrayfields['m.inventorycode']['checked'])) - { + if (!empty($arrayfields['m.inventorycode']['checked'])) { // Inventory code print ''; } - if (!empty($arrayfields['m.type_mouvement']['checked'])) - { + if (!empty($arrayfields['m.type_mouvement']['checked'])) { // Type of movement switch ($objp->type_mouvement) { case "0": @@ -1047,36 +1096,40 @@ if ($resql) break; } } - if (!empty($arrayfields['origin']['checked'])) - { + if (!empty($arrayfields['origin']['checked'])) { // Origin of movement print ''; } - if (!empty($arrayfields['m.value']['checked'])) - { + if (!empty($arrayfields['m.value']['checked'])) { // Qty print ''; } - if (!empty($arrayfields['m.price']['checked'])) - { + if (!empty($arrayfields['m.price']['checked'])) { // Price print ''; } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; $i++; @@ -1088,8 +1141,7 @@ if ($resql) print ""; // Add number of product when there is a filter on period - if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) - { + if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) { print "
"; $productidselected = 0; @@ -1129,8 +1181,7 @@ if ($resql) //Area for doc and last events of warehouse are stored on the main card of warehouse $modulepart = 'movement'; -if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id > 0) -{ +if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id > 0) { print '
'; print '
'; print ''; // ancre @@ -1138,8 +1189,12 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id > 0) // Documents $objectref = dol_sanitizeFileName($object->ref); // Add inventorycode & type_mouvement to filename of the pdf - if (!empty($search_inventorycode)) $objectref .= "_".$id."_".$search_inventorycode; - if ($search_type_mouvement) $objectref .= "_".$search_type_mouvement; + if (!empty($search_inventorycode)) { + $objectref .= "_".$id."_".$search_inventorycode; + } + if ($search_type_mouvement) { + $objectref .= "_".$search_type_mouvement; + } $relativepath = $comref.'/'.$objectref.'.pdf'; $filedir = $conf->stock->dir_output.'/movement/'.$objectref; diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index d67a72d2d63..b4d1c9a1fe8 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -45,7 +45,9 @@ if (!empty($conf->projet->enabled)) { // Load translation files required by the page $langs->loadLangs(array('products', 'stocks', 'orders')); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} // Security check $result = restrictedArea($user, 'stock'); @@ -89,10 +91,16 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; -if (!$sortfield) $sortfield = "m.datem"; -if (!$sortorder) $sortorder = "DESC"; +if (!$sortfield) { + $sortfield = "m.datem"; +} +if (!$sortorder) { + $sortorder = "DESC"; +} $pdluoid = GETPOST('pdluoid', 'int'); @@ -154,20 +162,24 @@ $error = 0; * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Do we click on purge search criteria ? - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers $search_date_startday = ''; $search_date_startmonth = ''; $search_date_startyear = ''; @@ -206,7 +218,9 @@ if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $tmpwarehouse, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } if (!$error) { $result = $tmpwarehouse->insertExtraFields(); if ($result < 0) { @@ -214,43 +228,41 @@ if ($action == 'update_extras') { $error++; } } - if ($error) $action = 'edit_extras'; + if ($error) { + $action = 'edit_extras'; + } } // Correct stock -if ($action == "correct_stock") -{ +if ($action == "correct_stock") { $product = new Product($db); - if (!empty($product_id)) $result = $product->fetch($product_id); + if (!empty($product_id)) { + $result = $product->fetch($product_id); + } $error = 0; - if (empty($product_id)) - { + if (empty($product_id)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); $action = 'correction'; } - if (!is_numeric($_POST["nbpiece"])) - { + if (!is_numeric($_POST["nbpiece"])) { $error++; setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $action = 'correction'; } - if (!$error) - { + if (!$error) { $origin_element = ''; $origin_id = null; - if (GETPOST('projectid', 'int')) - { + if (GETPOST('projectid', 'int')) { $origin_element = 'project'; $origin_id = GETPOST('projectid', 'int'); } - if ($product->hasbatch()) - { + if ($product->hasbatch()) { $batch = GETPOST('batch_number', 'alphanohtml'); //$eatby=GETPOST('eatby'); @@ -265,7 +277,9 @@ if ($action == "correct_stock") GETPOST("mouvement"), GETPOST("label", 'san_alpha'), GETPOST('unitprice'), - $eatby, $sellby, $batch, + $eatby, + $sellby, + $batch, GETPOST('inventorycode', 'alphanohtml'), $origin_element, $origin_id @@ -284,8 +298,7 @@ if ($action == "correct_stock") ); // We do not change value of stock for a correction } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { @@ -295,57 +308,52 @@ if ($action == "correct_stock") } } - if (!$error) $action = ''; + if (!$error) { + $action = ''; + } } // Transfer stock from a warehouse to another warehouse -if ($action == "transfert_stock" && !$cancel) -{ +if ($action == "transfert_stock" && !$cancel) { $product = new Product($db); - if (!empty($product_id)) $result = $product->fetch($product_id); + if (!empty($product_id)) { + $result = $product->fetch($product_id); + } - if (!(GETPOST("id_entrepot_destination", 'int') > 0)) - { + if (!(GETPOST("id_entrepot_destination", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'transfert'; } - if (empty($product_id)) - { + if (empty($product_id)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); $action = 'transfert'; } - if (!GETPOST("nbpiece", 'int')) - { + if (!GETPOST("nbpiece", 'int')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'transfert'; } - if ($id == GETPOST("id_entrepot_destination", 'int')) - { + if ($id == GETPOST("id_entrepot_destination", 'int')) { setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); $error++; $action = 'transfert'; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { $product = new Product($db); $result = $product->fetch($product_id); - if ($product->hasbatch() && !GETPOST("batch_number")) - { + if ($product->hasbatch() && !GETPOST("batch_number")) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'transfert'; } } - if (!$error) - { - if ($id) - { + if (!$error) { + if ($id) { $object = new Entrepot($db); $result = $object->fetch($id); @@ -355,18 +363,17 @@ if ($action == "transfert_stock" && !$cancel) // Define value of products moved $pricesrc = 0; - if (isset($product->pmp)) $pricesrc = $product->pmp; + if (isset($product->pmp)) { + $pricesrc = $product->pmp; + } $pricedest = $pricesrc; - if ($product->hasbatch()) - { + if ($product->hasbatch()) { $pdluo = new Productbatch($db); - if ($pdluoid > 0) - { + if ($pdluoid > 0) { $result = $pdluo->fetch($pdluoid); - if ($result) - { + if ($result) { $srcwarehouseid = $pdluo->warehouseid; $batch = $pdluo->batch; $eatby = $pdluo->eatby; @@ -382,8 +389,7 @@ if ($action == "transfert_stock" && !$cancel) $sellby = $d_sellby; } - if (!$error) - { + if (!$error) { // Remove stock $result1 = $product->correct_stock_batch( $user, @@ -392,9 +398,11 @@ if ($action == "transfert_stock" && !$cancel) 1, GETPOST("label", 'san_alpha'), $pricesrc, - $eatby, $sellby, $batch, + $eatby, + $sellby, + $batch, GETPOST('inventorycode') - ); + ); // Add stock $result2 = $product->correct_stock_batch( $user, @@ -403,9 +411,11 @@ if ($action == "transfert_stock" && !$cancel) 0, GETPOST("label", 'san_alpha'), $pricedest, - $eatby, $sellby, $batch, + $eatby, + $sellby, + $batch, GETPOST('inventorycode', 'alphanohtml') - ); + ); } } else { // Remove stock @@ -417,7 +427,7 @@ if ($action == "transfert_stock" && !$cancel) GETPOST("label", 'san_alpha'), $pricesrc, GETPOST('inventorycode', 'alphanohtml') - ); + ); // Add stock $result2 = $product->correct_stock( @@ -428,14 +438,12 @@ if ($action == "transfert_stock" && !$cancel) GETPOST("label", 'san_alpha'), $pricedest, GETPOST('inventorycode', 'alphanohtml') - ); + ); } - if (!$error && $result1 >= 0 && $result2 >= 0) - { + if (!$error && $result1 >= 0 && $result2 >= 0) { $db->commit(); - if ($backtopage) - { + if ($backtopage) { header("Location: ".$backtopage); exit; } else { @@ -464,7 +472,9 @@ $userstatic = new User($db); $form = new Form($db); $formother = new FormOther($db); $formproduct = new FormProduct($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tosell, p.tobuy, p.tobatch, p.fk_product_type as type, p.entity,"; $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,"; @@ -476,7 +486,9 @@ $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,"; $sql .= " u.login, u.photo, u.lastname, u.firstname, u.email as user_email, u.statut as user_status"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); @@ -485,29 +497,65 @@ $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; $sql .= " ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product"; $sql .= " WHERE m.fk_product = p.rowid"; -if ($msid > 0) $sql .= " AND m.rowid = ".$msid; +if ($msid > 0) { + $sql .= " AND m.rowid = ".$msid; +} $sql .= " AND m.fk_entrepot = e.rowid"; $sql .= " AND e.entity IN (".getEntity('stock').")"; -if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0"; -if ($id > 0) $sql .= " AND e.rowid ='".$id."'"; -if (!empty($search_date_start)) $sql .= " AND m.datem >= '" . $db->idate($search_date_start) . "'"; -if (!empty($search_date_end)) $sql .= " AND m.datem <= '" . $db->idate($search_date_end) . "'"; -if ($idproduct > 0) $sql .= " AND p.rowid = ".((int) $idproduct); -if (!empty($search_ref)) $sql .= natural_search('m.rowid', $search_ref, 1); -if (!empty($search_movement)) $sql .= natural_search('m.label', $search_movement); -if (!empty($search_inventorycode)) $sql .= natural_search('m.inventorycode', $search_inventorycode); -if (!empty($search_product_ref)) $sql .= natural_search('p.ref', $search_product_ref); -if (!empty($search_product)) $sql .= natural_search('p.label', $search_product); -if ($search_warehouse != '' && $search_warehouse != '-1') $sql .= natural_search('e.rowid', $search_warehouse, 2); -if (!empty($search_user)) $sql .= natural_search('u.login', $search_user); -if (!empty($search_batch)) $sql .= natural_search('m.batch', $search_batch); -if (!empty($product_id)) $sql .= natural_search('p.rowid', $product_id); -if ($search_qty != '') $sql .= natural_search('m.value', $search_qty, 1); -if ($search_type_mouvement != '' && $search_type_mouvement != '-1') $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2); +if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= " AND p.fk_product_type = 0"; +} +if ($id > 0) { + $sql .= " AND e.rowid ='".$id."'"; +} +if (!empty($search_date_start)) { + $sql .= " AND m.datem >= '" . $db->idate($search_date_start) . "'"; +} +if (!empty($search_date_end)) { + $sql .= " AND m.datem <= '" . $db->idate($search_date_end) . "'"; +} +if ($idproduct > 0) { + $sql .= " AND p.rowid = ".((int) $idproduct); +} +if (!empty($search_ref)) { + $sql .= natural_search('m.rowid', $search_ref, 1); +} +if (!empty($search_movement)) { + $sql .= natural_search('m.label', $search_movement); +} +if (!empty($search_inventorycode)) { + $sql .= natural_search('m.inventorycode', $search_inventorycode); +} +if (!empty($search_product_ref)) { + $sql .= natural_search('p.ref', $search_product_ref); +} +if (!empty($search_product)) { + $sql .= natural_search('p.label', $search_product); +} +if ($search_warehouse != '' && $search_warehouse != '-1') { + $sql .= natural_search('e.rowid', $search_warehouse, 2); +} +if (!empty($search_user)) { + $sql .= natural_search('u.login', $search_user); +} +if (!empty($search_batch)) { + $sql .= natural_search('m.batch', $search_batch); +} +if (!empty($product_id)) { + $sql .= natural_search('p.rowid', $product_id); +} +if ($search_qty != '') { + $sql .= natural_search('m.value', $search_qty, 1); +} +if ($search_type_mouvement != '' && $search_type_mouvement != '-1') { + $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2); +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -517,19 +565,16 @@ $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } } -if (empty($search_inventorycode)) -{ +if (empty($search_inventorycode)) { $sql .= $db->plimit($limit + 1, $offset); } else { $limit = 0; @@ -539,22 +584,20 @@ if (empty($search_inventorycode)) $resql = $db->query($sql); -if (!empty($search_inventorycode)) $limit = $db->num_rows($resql); +if (!empty($search_inventorycode)) { + $limit = $db->num_rows($resql); +} -if ($resql) -{ +if ($resql) { $product = new Product($db); $object = new Entrepot($db); - if ($idproduct > 0) - { + if ($idproduct > 0) { $product->fetch($idproduct); } - if ($id > 0 || $ref) - { + if ($id > 0 || $ref) { $result = $object->fetch($id, $ref); - if ($result < 0) - { + if ($result < 0) { dol_print_error($db); } } @@ -566,18 +609,20 @@ if ($resql) $i = 0; $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - if ($msid) $texte = $langs->trans('StockMovementForId', $msid); - else { + if ($msid) { + $texte = $langs->trans('StockMovementForId', $msid); + } else { $texte = $langs->trans("ListOfStockMovements"); - if ($id) $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; + if ($id) { + $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; + } } llxHeader("", $texte, $help_url); /* - * Show tab only if we ask a particular warehouse - */ - if ($object->id > 0) - { + * Show tab only if we ask a particular warehouse + */ + if ($object->id > 0) { $head = stock_prepare_head($object); print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock'); @@ -590,7 +635,9 @@ if ($resql) $morehtmlref .= '
'; $shownav = 1; - if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); @@ -639,8 +686,7 @@ if ($resql) $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " WHERE m.fk_entrepot = ".((int) $object->id); $resqlbis = $db->query($sql); - if ($resqlbis) - { + if ($resqlbis) { $objbis = $db->fetch_object($resqlbis); $lastmovementdate = $db->jdate($objbis->datem); } else { @@ -648,8 +694,7 @@ if ($resql) } print '
'; - if (!empty($arrayfields['m.rowid']['checked'])) - { + if (!empty($arrayfields['m.rowid']['checked'])) { // Ref print ''; } - if (! empty($arrayfields['m.datem']['checked'])) - { + if (! empty($arrayfields['m.datem']['checked'])) { print ''; } - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { // Product Ref print ''; } - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { // Product label print ''; } // Batch - if (!empty($arrayfields['m.batch']['checked'])) - { + if (!empty($arrayfields['m.batch']['checked'])) { print ''; } - if (!empty($arrayfields['pl.eatby']['checked'])) - { + if (!empty($arrayfields['pl.eatby']['checked'])) { print ''; } - if (!empty($arrayfields['pl.sellby']['checked'])) - { + if (!empty($arrayfields['pl.sellby']['checked'])) { print ''; } // Warehouse - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print ''; } - if (!empty($arrayfields['m.fk_user_author']['checked'])) - { + if (!empty($arrayfields['m.fk_user_author']['checked'])) { // Author print ''; } - if (!empty($arrayfields['m.inventorycode']['checked'])) - { + if (!empty($arrayfields['m.inventorycode']['checked'])) { // Inventory code print ''; } - if (!empty($arrayfields['m.label']['checked'])) - { + if (!empty($arrayfields['m.label']['checked'])) { // Label of movement print ''; } - if (!empty($arrayfields['m.type_mouvement']['checked'])) - { + if (!empty($arrayfields['m.type_mouvement']['checked'])) { // Type of movement print ''; } - if (!empty($arrayfields['origin']['checked'])) - { + if (!empty($arrayfields['origin']['checked'])) { // Origin of movement print ''; } - if (!empty($arrayfields['m.value']['checked'])) - { + if (!empty($arrayfields['m.value']['checked'])) { // Qty print ''; } - if (!empty($arrayfields['m.price']['checked'])) - { + if (!empty($arrayfields['m.price']['checked'])) { // Price print ''; } - if (!empty($arrayfields['m.fk_projet']['checked'])) - { + if (!empty($arrayfields['m.fk_projet']['checked'])) { // fk_project print ''; } // Date modification - if (!empty($arrayfields['m.tms']['checked'])) - { + if (!empty($arrayfields['m.tms']['checked'])) { print ''; } @@ -1022,8 +1094,7 @@ if ($resql) $i = 0; $totalarray = array(); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); $userstatic->id = $objp->fk_user_author; @@ -1064,60 +1135,53 @@ if ($resql) print ''; // Id movement - if (!empty($arrayfields['m.rowid']['checked'])) - { + if (!empty($arrayfields['m.rowid']['checked'])) { print ''; // This is primary not movement id } - if (!empty($arrayfields['m.datem']['checked'])) - { + if (!empty($arrayfields['m.datem']['checked'])) { // Date print ''; } - if (!empty($arrayfields['p.ref']['checked'])) - { + if (!empty($arrayfields['p.ref']['checked'])) { // Product ref print '\n"; } - if (!empty($arrayfields['p.label']['checked'])) - { + if (!empty($arrayfields['p.label']['checked'])) { // Product label print '\n"; } - if (!empty($arrayfields['m.batch']['checked'])) - { + if (!empty($arrayfields['m.batch']['checked'])) { print ''; } - if (!empty($arrayfields['pl.eatby']['checked'])) - { + if (!empty($arrayfields['pl.eatby']['checked'])) { print ''; } - if (!empty($arrayfields['pl.sellby']['checked'])) - { + if (!empty($arrayfields['pl.sellby']['checked'])) { print ''; } // Warehouse - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print '\n"; } // Author - if (!empty($arrayfields['m.fk_user_author']['checked'])) - { + if (!empty($arrayfields['m.fk_user_author']['checked'])) { print '\n"; } - if (!empty($arrayfields['m.inventorycode']['checked'])) - { + if (!empty($arrayfields['m.inventorycode']['checked'])) { // Inventory code print ''; } - if (!empty($arrayfields['m.label']['checked'])) - { + if (!empty($arrayfields['m.label']['checked'])) { // Label of movement print ''; } - if (!empty($arrayfields['m.type_mouvement']['checked'])) - { + if (!empty($arrayfields['m.type_mouvement']['checked'])) { // Type of movement switch ($objp->type_mouvement) { case "0": @@ -1148,43 +1210,48 @@ if ($resql) break; } } - if (!empty($arrayfields['origin']['checked'])) - { + if (!empty($arrayfields['origin']['checked'])) { // Origin of movement print ''; } - if (!empty($arrayfields['m.value']['checked'])) - { + if (!empty($arrayfields['m.value']['checked'])) { // Qty print ''; } - if (!empty($arrayfields['m.price']['checked'])) - { + if (!empty($arrayfields['m.price']['checked'])) { // Price print ''; } - if (!empty($arrayfields['m.fk_projet']['checked'])) - { + if (!empty($arrayfields['m.fk_projet']['checked'])) { // fk_project print ''; } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; $i++; @@ -1196,13 +1263,11 @@ if ($resql) print ""; // Add number of product when there is a filter on period - if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) - { + if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) { print "
"; $productidselected = 0; - foreach ($arrayofuniqueproduct as $key => $val) - { + foreach ($arrayofuniqueproduct as $key => $val) { $productidselected = $key; $productlabelselected = $val; } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index d1c1ea99ff7..e45f48d9ef8 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -55,7 +55,9 @@ if (!empty($conf->variants->enabled)) { // Load translation files required by the page $langs->loadlangs(array('products', 'suppliers', 'orders', 'bills', 'stocks', 'sendings', 'margins')); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); @@ -76,7 +78,9 @@ if (!empty($batchnumber)) { } // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit&stock', $id, 'product&product', '', '', $fieldid); @@ -86,20 +90,20 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); } -if (empty($id) && !empty($object->id)) $id = $object->id; +if (empty($id) && !empty($object->id)) { + $id = $object->id; +} $modulepart = 'product'; // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas"); $objcanvas = null; -if (!empty($canvas)) -{ +if (!empty($canvas)) { require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; $objcanvas = new Canvas($db, $action); $objcanvas->getCanvas('stockproduct', 'card', $canvas); @@ -115,14 +119,17 @@ $error = 0; * Actions */ -if ($cancel) $action = ''; +if ($cancel) { + $action = ''; +} $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)) -{ +if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)) { $seuil_stock_alerte = GETPOST('seuil_stock_alerte'); $desiredstock = GETPOST('desiredstock'); @@ -142,14 +149,18 @@ if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer) // Update $pse->seuil_stock_alerte = $seuil_stock_alerte; $pse->desiredstock = $desiredstock; - if ($pse->update($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs'); + if ($pse->update($user) > 0) { + setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs'); + } } else { // Create $pse->fk_entrepot = GETPOST('fk_entrepot', 'int'); $pse->fk_product = $id; $pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); $pse->desiredstock = GETPOST('desiredstock'); - if ($pse->create($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs'); + if ($pse->create($user) > 0) { + setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs'); + } } } @@ -157,66 +168,62 @@ if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer) exit; } -if ($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->creer)) -{ +if ($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->creer)) { $pse = new ProductStockEntrepot($db); $pse->fetch(GETPOST('fk_productstockwarehouse', 'int')); - if ($pse->delete($user) > 0) setEventMessages($langs->trans('ProductStockWarehouseDeleted'), null, 'mesgs'); + if ($pse->delete($user) > 0) { + setEventMessages($langs->trans('ProductStockWarehouseDeleted'), null, 'mesgs'); + } $action = ''; } // Set stock limit -if ($action == 'setseuil_stock_alerte' && !empty($user->rights->produit->creer)) -{ +if ($action == 'setseuil_stock_alerte' && !empty($user->rights->produit->creer)) { $object = new Product($db); $result = $object->fetch($id); $object->seuil_stock_alerte = $stocklimit; $result = $object->update($object->id, $user, 0, 'update'); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } //else // setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs'); $action = ''; } // Set desired stock -if ($action == 'setdesiredstock' && !empty($user->rights->produit->creer)) -{ +if ($action == 'setdesiredstock' && !empty($user->rights->produit->creer)) { $object = new Product($db); $result = $object->fetch($id); $object->desiredstock = $desiredstock; $result = $object->update($object->id, $user, 0, 'update'); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } $action = ''; } // Correct stock -if ($action == "correct_stock" && !$cancel) -{ - if (!(GETPOST("id_entrepot", 'int') > 0)) - { +if ($action == "correct_stock" && !$cancel) { + if (!(GETPOST("id_entrepot", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'correction'; } - if (!GETPOST("nbpiece")) - { + if (!GETPOST("nbpiece")) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'correction'; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { $object = new Product($db); $result = $object->fetch($id); - if ($object->hasbatch() && !$batchnumber) - { + if ($object->hasbatch() && !$batchnumber) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'correction'; @@ -293,43 +300,35 @@ if ($action == "correct_stock" && !$cancel) } // Transfer stock from a warehouse to another warehouse -if ($action == "transfert_stock" && !$cancel) -{ - if (!(GETPOST("id_entrepot", 'int') > 0) || !(GETPOST("id_entrepot_destination", 'int') > 0)) - { +if ($action == "transfert_stock" && !$cancel) { + if (!(GETPOST("id_entrepot", 'int') > 0) || !(GETPOST("id_entrepot_destination", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; $action = 'transfert'; } - if (!GETPOST("nbpiece", 'int')) - { + if (!GETPOST("nbpiece", 'int')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors'); $error++; $action = 'transfert'; } - if (GETPOST("id_entrepot", 'int') == GETPOST("id_entrepot_destination", 'int')) - { + if (GETPOST("id_entrepot", 'int') == GETPOST("id_entrepot_destination", 'int')) { setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); $error++; $action = 'transfert'; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { $object = new Product($db); $result = $object->fetch($id); - if ($object->hasbatch() && !$batchnumber) - { + if ($object->hasbatch() && !$batchnumber) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; $action = 'transfert'; } } - if (!$error) - { - if ($id) - { + if (!$error) { + if ($id) { $object = new Product($db); $result = $object->fetch($id); @@ -339,20 +338,19 @@ if ($action == "transfert_stock" && !$cancel) // Define value of products moved $pricesrc = 0; - if (isset($object->pmp)) $pricesrc = $object->pmp; + if (isset($object->pmp)) { + $pricesrc = $object->pmp; + } $pricedest = $pricesrc; $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml')); - if ($object->hasbatch()) - { + if ($object->hasbatch()) { $pdluo = new Productbatch($db); - if ($pdluoid > 0) - { + if ($pdluoid > 0) { $result = $pdluo->fetch($pdluoid); - if ($result) - { + if ($result) { $srcwarehouseid = $pdluo->warehouseid; $batch = $pdluo->batch; $eatby = $pdluo->eatby; @@ -370,8 +368,7 @@ if ($action == "transfert_stock" && !$cancel) $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml')); - if (!$error) - { + if (!$error) { // Remove stock $result1 = $object->correct_stock_batch( $user, @@ -380,13 +377,16 @@ if ($action == "transfert_stock" && !$cancel) 1, GETPOST("label", 'alphanohtml'), $pricesrc, - $eatby, $sellby, $batch, + $eatby, + $sellby, + $batch, GETPOST('inventorycode', 'alphanohtml') ); - if ($result1 < 0) $error++; + if ($result1 < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { // Add stock $result2 = $object->correct_stock_batch( $user, @@ -395,14 +395,17 @@ if ($action == "transfert_stock" && !$cancel) 0, GETPOST("label", 'alphanohtml'), $pricedest, - $eatby, $sellby, $batch, + $eatby, + $sellby, + $batch, GETPOST('inventorycode', 'alphanohtml') ); - if ($result2 < 0) $error++; + if ($result2 < 0) { + $error++; + } } } else { - if (!$error) - { + if (!$error) { // Remove stock $result1 = $object->correct_stock( $user, @@ -413,10 +416,11 @@ if ($action == "transfert_stock" && !$cancel) $pricesrc, GETPOST('inventorycode', 'alphanohtml') ); - if ($result1 < 0) $error++; + if ($result1 < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { // Add stock $result2 = $object->correct_stock( $user, @@ -427,17 +431,17 @@ if ($action == "transfert_stock" && !$cancel) $pricedest, GETPOST('inventorycode', 'alphanohtml') ); - if ($result2 < 0) $error++; + if ($result2 < 0) { + $error++; + } } } - if (!$error && $result1 >= 0 && $result2 >= 0) - { + if (!$error && $result1 >= 0 && $result2 >= 0) { $db->commit(); - if ($backtopage) - { + if ($backtopage) { header("Location: ".$backtopage); exit; } else { @@ -454,15 +458,12 @@ if ($action == "transfert_stock" && !$cancel) } // Update batch information -if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save")) -{ +if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save")) { $pdluo = new Productbatch($db); $result = $pdluo->fetch(GETPOST('pdluoid', 'int')); - if ($result > 0) - { - if ($pdluo->id) - { + if ($result > 0) { + if ($pdluo->id) { if ((!GETPOST("sellby")) && (!GETPOST("eatby")) && (!$batchnumber)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), null, 'errors'); } else { @@ -472,8 +473,7 @@ if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save")) $pdluo->eatby = $d_eatby; $pdluo->sellby = $d_sellby; $result = $pdluo->update($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($pdluo->error, $pdluo->errors, 'errors'); } } @@ -495,10 +495,11 @@ if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save")) $form = new Form($db); $formproduct = new FormProduct($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} -if ($id > 0 || $ref) -{ +if ($id > 0 || $ref) { $object = new Product($db); $result = $object->fetch($id, $ref); @@ -509,21 +510,18 @@ if ($id > 0 || $ref) $title = $langs->trans('ProductServiceCard'); $helpurl = ''; $shortlabel = dol_trunc($object->label, 16); - if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) - { + if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock'); $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; } - if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) - { + if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock'); $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } llxHeader('', $title, $helpurl); - if ($result > 0) - { + if ($result > 0) { $head = product_prepare_head($object); $titre = $langs->trans("CardProduct".$object->type); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); @@ -535,7 +533,9 @@ if ($id > 0 || $ref) $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); @@ -566,7 +566,9 @@ if ($id > 0 || $ref) // AWP print ''; print ''; print ''; @@ -575,8 +577,11 @@ if ($id > 0 || $ref) print ''; @@ -648,7 +653,9 @@ if ($id > 0 || $ref) print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1); print ''; print ''; @@ -660,10 +667,16 @@ if ($id > 0 || $ref) $helpondiff = ''.$langs->trans("StockDiffPhysicTeoric").':
'; // Number of customer orders running if (!empty($conf->commande->enabled)) { - if ($found) $helpondiff .= '
'; else $found = 1; + if ($found) { + $helpondiff .= '
'; + } else { + $found = 1; + } $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty']; $result = $object->load_stats_commande(0, '0', 1); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } $helpondiff .= ' ('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')'; } @@ -676,31 +689,48 @@ if ($id > 0 || $ref) } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { $filterShipmentStatus = Expedition::STATUS_CLOSED; } - if ($found) $helpondiff .= '
'; else $found = 1; + if ($found) { + $helpondiff .= '
'; + } else { + $found = 1; + } $result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus); $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty']; } // Number of supplier order running - if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) - { - if ($found) $helpondiff .= '
'; else $found = 1; + if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { + if ($found) { + $helpondiff .= '
'; + } else { + $found = 1; + } $result = $object->load_stats_commande_fournisseur(0, '3,4', 1); $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty']; $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } $helpondiff .= ' ('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')'; } // Number of product from supplier order already received (partial receipt) if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { - if ($found) $helpondiff .= '
'; else $found = 1; + if ($found) { + $helpondiff .= '
'; + } else { + $found = 1; + } $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty']; } // Number of product in production if (!empty($conf->mrp->enabled)) { - if ($found) $helpondiff .= '
'; else $found = 1; + if ($found) { + $helpondiff .= '
'; + } else { + $found = 1; + } $helpondiff .= $langs->trans("ProductQtyToConsumeByMO").': '.$object->stats_mrptoconsume['qty'].'
'; $helpondiff .= $langs->trans("ProductQtyToProduceByMO").': '.$object->stats_mrptoproduce['qty']; } @@ -713,14 +743,15 @@ if ($id > 0 || $ref) print "'; print ''; // Last movement - if (!empty($user->rights->stock->mouvement->lire)) - { + if (!empty($user->rights->stock->mouvement->lire)) { $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql .= " WHERE m.fk_product = ".((int) $object->id); @@ -754,15 +785,13 @@ if ($id > 0 || $ref) } // Correct stock - if ($action == "correction") - { + if ($action == "correction") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; print '

'; } // Transfer of units - if ($action == "transfert") - { + if ($action == "transfert") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; print '

'; } @@ -776,14 +805,11 @@ if ($id > 0 || $ref) $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook -if (empty($reshook)) -{ - if (empty($action) && $object->id) - { +if (empty($reshook)) { + if (empty($action) && $object->id) { print "
\n"; - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { print ''.$langs->trans("CorrectStock").''; } else { @@ -794,8 +820,7 @@ if (empty($reshook)) } //if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch()) - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { print ''.$langs->trans("TransferStock").''; } else { @@ -888,22 +913,32 @@ if (!$variants) { print '
'; // Sell price print ''; // Value sell print ''; - else print $langs->trans("Variable"); + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print price(price2num($object->price * $obj->reel, 'MT'), 1).''; + } else { + print $langs->trans("Variable"); + } print ''; $total += $obj->reel; - if (price2num($object->pmp)) $totalwithpmp += $obj->reel; + if (price2num($object->pmp)) { + $totalwithpmp += $obj->reel; + } $totalvalue = $totalvalue + ($object->pmp * $obj->reel); $totalvaluesell = $totalvaluesell + ($object->price * $obj->reel); // Batch Detail if ((!empty($conf->productbatch->enabled)) && $object->hasbatch()) { $details = Productbatch::findAll($db, $obj->product_stock_id, 0, $object->id); - if ($details < 0) dol_print_error($db); + if ($details < 0) { + dol_print_error($db); + } foreach ($details as $pdluo) { $product_lot_static->id = $pdluo->lotid; $product_lot_static->batch = $pdluo->batch; @@ -961,7 +996,9 @@ if (!$variants) { } $i++; } - } else dol_print_error($db); + } else { + dol_print_error($db); + } // Total line print ''; @@ -974,13 +1011,19 @@ if (!$variants) { print $totalvalue ? price(price2num($totalvalue, 'MT'), 1) : ' '; print ''; print ''; // Value to sell print ''; print ""; @@ -1068,11 +1111,9 @@ if (!$variants) { fetch($currcomb->fk_product_child); $prodstatic->load_stock(); $stock_total += $prodstatic->stock_reel; diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 752b84a9ec0..6aacdca2b6c 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -76,14 +76,14 @@ $search_fk_user_creat = GETPOST('search_fk_user_creat', 'int'); $search_fk_user_modif = GETPOST('search_fk_user_modif', 'int'); $search_import_key = GETPOST('search_import_key', 'int'); -if (empty($action) && empty($id) && empty($ref)) $action = 'list'; +if (empty($action) && empty($id) && empty($ref)) { + $action = 'list'; +} // Load object //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals -if ($id || $ref) -{ - if ($ref) - { +if ($id || $ref) { + if ($ref) { $tmp = explode('_', $ref); $productid = $tmp[0]; $batch = $tmp[1]; @@ -93,8 +93,7 @@ if ($id || $ref) } // Protection if external user -if ($user->socid > 0) -{ +if ($user->socid > 0) { //accessforbidden(); } //$result = restrictedArea($user, 'mymodule', $id); @@ -133,18 +132,20 @@ if (empty($reshook)) { $backurlforlist = dol_buildpath('/product/stock/productlot_list.php', 1); - if ($action == 'seteatby' && $user->rights->stock->creer) - { + if ($action == 'seteatby' && $user->rights->stock->creer) { $newvalue = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); $result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } } - if ($action == 'setsellby' && $user->rights->stock->creer) - { + if ($action == 'setsellby' && $user->rights->stock->creer) { $newvalue = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } } $triggermodname = 'PRODUCT_LOT_MODIFY'; // Name of trigger action code to execute when we modify record @@ -274,7 +275,7 @@ if (empty($reshook)) { else setEventMessages($object->error, null, 'errors'); } } -*/ + */ // Action to build doc include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; @@ -375,7 +376,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } $morehtmlref = ''; @@ -436,7 +439,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'."\n"; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } if (empty($reshook)) { /*TODO if ($user->rights->stock->lire) @@ -453,7 +458,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'."\n"; } - } diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php index ca522f48da7..81f68487cf6 100644 --- a/htdocs/product/stock/productlot_document.php +++ b/htdocs/product/stock/productlot_document.php @@ -48,7 +48,9 @@ $confirm = GETPOST('confirm', 'alpha'); // Security check $fieldvalue = (!empty($id) ? $id : ''); $fieldtype = 'rowid'; -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service'); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -59,19 +61,23 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "position_name"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "position_name"; +} $modulepart = 'product_batch'; $object = new Productlot($db); -if ($id || $ref) -{ - if ($ref) - { +if ($id || $ref) { + if ($ref) { $tmp = explode('_', $ref); $productid = $tmp[0]; $batch = $tmp[1]; @@ -79,7 +85,9 @@ if ($id || $ref) $object->fetch($id, $productid, $batch); $object->ref = $object->batch; // For document management ( it use $object->ref) - if (!empty($conf->productbatch->enabled)) $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); + if (!empty($conf->productbatch->enabled)) { + $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); + } } @@ -89,10 +97,11 @@ if ($id || $ref) $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Action submit/delete file/link include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; } @@ -109,8 +118,7 @@ $form = new Form($db); llxHeader('', $langs->trans('ProductLot'), ''); -if ($object->id) -{ +if ($object->id) { $head = productlot_prepare_head($object); print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode'); @@ -118,14 +126,15 @@ if ($object->id) $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } // Build file list $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $totalsize = 0; - foreach ($filearray as $key => $file) - { + foreach ($filearray as $key => $file) { $totalsize += $file['size']; } @@ -133,7 +142,9 @@ if ($object->id) $linkback = ''.$langs->trans("BackToList").''; $shownav = 1; - if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; + if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; + } dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch'); diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index 6e818be629d..45dae12ce10 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -54,7 +54,9 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -72,28 +74,33 @@ $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Default sort order (if not yet defined by previous GETPOST) -if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Initialize array of search criterias $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'); $search = array(); -foreach ($object->fields as $key => $val) -{ - if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha'); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha') !== '') { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } } // List of fields to search into when doing a "search in all" $fieldstosearchall = array(); -foreach ($object->fields as $key => $val) -{ - if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; +foreach ($object->fields as $key => $val) { + if ($val['searchall']) { + $fieldstosearchall['t.'.$key] = $val['label']; + } } // Definition of array of fields for columns $arrayfields = array(); -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { // If $val['visible']==0, then we never show the field if (!empty($val['visible'])) { $visible = dol_eval($val['visible'], 1); @@ -106,10 +113,8 @@ foreach ($object->fields as $key => $val) } } // Extra fields -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) -{ - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) - { +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) { $arrayfields["ef.".$key] = array( 'label'=>$extrafields->attributes[$object->table_element]['label'][$key], @@ -134,31 +139,33 @@ $permissiontoadd = $user->rights->stock->mouvement->creer; * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { - foreach ($object->fields as $key => $val) - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + foreach ($object->fields as $key => $val) { $search[$key] = ''; } $toselect = ''; $search_array_options = array(); } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) - { + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation } @@ -187,13 +194,14 @@ $title = $langs->trans('LotSerialList'); // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $sql .= 't.'.$key.', '; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : ''); + } } // Add fields from hooks $parameters = array(); @@ -201,20 +209,32 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $obje $sql .= preg_replace('/^,/', '', $hookmanager->resPrint); $sql = preg_replace('/,\s*$/', '', $sql); $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; -if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; -else $sql .= " WHERE 1 = 1"; -foreach ($search as $key => $val) -{ - if ($key == 'status' && $search[$key] == -1) continue; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; +} +if ($object->ismultientitymanaged == 1) { + $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; +} else { + $sql .= " WHERE 1 = 1"; +} +foreach ($search as $key => $val) { + if ($key == 'status' && $search[$key] == -1) { + continue; + } $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); if (strpos($object->fields[$key]['type'], 'integer:') === 0) { - if ($search[$key] == '-1') $search[$key] = ''; + if ($search[$key] == '-1') { + $search[$key] = ''; + } $mode_search = 2; } - if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + if ($search[$key] != '') { + $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + } +} +if ($search_all) { + $sql .= natural_search(array_keys($fieldstosearchall), $search_all); } -if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all); //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear); // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -244,26 +264,24 @@ $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $resql = $db->query($sql); $nbtotalofrecords = $db->num_rows($resql); - if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } } // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. -if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) -{ +if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) { $num = $nbtotalofrecords; } else { - if ($limit) $sql .= $db->plimit($limit + 1, $offset); + if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); + } $resql = $db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($db); exit; } @@ -272,8 +290,7 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit } // Direct jump if only one record found -if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) -{ +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) { $obj = $db->fetch_object($resql); $id = $obj->rowid; header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id); @@ -289,14 +306,24 @@ llxHeader('', $title, $help_url); $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -foreach ($search as $key => $val) -{ - if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); - else $param .= '&search_'.$key.'='.urlencode($search[$key]); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +foreach ($search as $key => $val) { + if (is_array($search[$key]) && count($search[$key])) { + foreach ($search[$key] as $skey) { + $param .= '&search_'.$key.'[]='.urlencode($skey); + } + } else { + $param .= '&search_'.$key.'='.urlencode($search[$key]); + } +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); } -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -307,12 +334,18 @@ $arrayofmassactions = array( //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); -if ($permissiontodelete) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($permissiontodelete) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); +} +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); +} $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print ''."\n"; -if ($optioncss != '') print ''; +if ($optioncss != '') { + print ''; +} print ''; print ''; print ''; @@ -332,9 +365,10 @@ $objecttmp = new Productlot($db); $trackid = 'lot'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -if ($search_all) -{ - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); +if ($search_all) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'; } @@ -345,11 +379,13 @@ $moreforfilter = ''; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} -if (!empty($moreforfilter)) -{ +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -366,20 +402,26 @@ print '
'; - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); - elseif (strpos($val['type'], 'integer:') === 0 || strpos($val['type'], 'sellist:') === 0) { + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); + } elseif (strpos($val['type'], 'integer:') === 0 || strpos($val['type'], 'sellist:') === 0) { print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1); - } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print ''; + } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) { + print ''; + } print '
'.price2num($obj->stockqty, 5).''; - if (price2num($obj->estimatedvalue, 'MT')) print price(price2num($obj->estimatedvalue, 'MT'), 1); - else print ''; + if (price2num($obj->estimatedvalue, 'MT')) { + print price(price2num($obj->estimatedvalue, 'MT'), 1); + } else { + print ''; + } print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($obj->sellvalue, 'MT'), 1); - else { + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print price(price2num($obj->sellvalue, 'MT'), 1); + } else { $htmltext = $langs->trans("OptionMULTIPRICESIsOn"); print $form->textwithtooltip($langs->trans("Variable"), $htmltext); } print ''.$warehouse->LibStatut($obj->statut, 5).''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'; $filtertype = 0; -if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype = ''; +if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $filtertype = ''; +} if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) { $limit = ''; } else { @@ -372,8 +363,7 @@ if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) { $form->select_produits($id_product, 'productid', $filtertype, $limit, 0, -1, 2, '', 1, array(), 0, '1', 0, 'minwidth200imp maxwidth300', 1); print ''; print ''; print ''; -foreach ($listofdata as $key => $val) -{ +foreach ($listofdata as $key => $val) { $productstatic->fetch($val['id_product']); $warehousestatics->fetch($val['id_sw']); $warehousestatict->fetch($val['id_tw']); @@ -402,8 +391,7 @@ foreach ($listofdata as $key => $val) print ''; print $productstatic->getNomUrl(1).' - '.$productstatic->label; print ''; print $val['batch']; print '
'.$langs->trans("LastMovement").''; - if ($lastmovementdate) - { + if ($lastmovementdate) { print dol_print_date($lastmovementdate, 'dayhour'); } else { print $langs->trans("None"); @@ -622,8 +650,7 @@ if ($resql) /* * Correct stock */ - if ($action == "correction") - { + if ($action == "correction") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; print '
'; } @@ -631,8 +658,7 @@ if ($resql) /* * Transfer of units */ - if ($action == "transfert") - { + if ($action == "transfert") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; print '
'; } @@ -644,17 +670,14 @@ if ($resql) /* */ /* ************************************************************************** */ - if ((empty($action) || $action == 'list') && $id > 0) - { + if ((empty($action) || $action == 'list') && $id > 0) { print "
\n"; - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { print ''.$langs->trans("CorrectStock").''; } - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { print ''.$langs->trans("TransferStock").''; } @@ -662,18 +685,42 @@ if ($resql) } $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($id > 0) $param .= '&id='.urlencode($id); - if ($search_movement) $param .= '&search_movement='.urlencode($search_movement); - if ($search_inventorycode) $param .= '&search_inventorycode='.urlencode($search_inventorycode); - if ($search_type_mouvement) $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); - if ($search_product_ref) $param .= '&search_product_ref='.urlencode($search_product_ref); - if ($search_product) $param .= '&search_product='.urlencode($search_product); - if ($search_batch) $param .= '&search_batch='.urlencode($search_batch); - if ($search_warehouse > 0) $param .= '&search_warehouse='.urlencode($search_warehouse); - if ($search_user) $param .= '&search_user='.urlencode($search_user); - if ($idproduct > 0) $param .= '&idproduct='.urlencode($idproduct); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($id > 0) { + $param .= '&id='.urlencode($id); + } + if ($search_movement) { + $param .= '&search_movement='.urlencode($search_movement); + } + if ($search_inventorycode) { + $param .= '&search_inventorycode='.urlencode($search_inventorycode); + } + if ($search_type_mouvement) { + $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); + } + if ($search_product_ref) { + $param .= '&search_product_ref='.urlencode($search_product_ref); + } + if ($search_product) { + $param .= '&search_product='.urlencode($search_product); + } + if ($search_batch) { + $param .= '&search_batch='.urlencode($search_batch); + } + if ($search_warehouse > 0) { + $param .= '&search_warehouse='.urlencode($search_warehouse); + } + if ($search_user) { + $param .= '&search_user='.urlencode($search_user); + } + if ($idproduct > 0) { + $param .= '&idproduct='.urlencode($idproduct); + } // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -683,11 +730,15 @@ if ($resql) // 'builddoc'=>$langs->trans("PDFMerge"), ); //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); - if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + if (in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); + } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print '
'; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; @@ -695,14 +746,20 @@ if ($resql) print ''; print ''; print ''; - if ($id > 0) print ''; + if ($id > 0) { + print ''; + } - if ($id > 0) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit); - else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit); + if ($id > 0) { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit); + } else { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit); + } - if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } @@ -710,11 +767,13 @@ if ($resql) $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; - else $moreforfilter = $hookmanager->resPrint; + if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; + } else { + $moreforfilter = $hookmanager->resPrint; + } - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -728,84 +787,74 @@ if ($resql) // Fields title search print '
'; print ''; print ''; print ''; - if (empty($conf->productbatch->enabled)) print ' '; + if (empty($conf->productbatch->enabled)) { + print ' '; + } //else print '
'; $syear = $year ? $year : -1; print ''; //print $formother->selectyear($syear,'year',1, 20, 5); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; @@ -821,22 +870,19 @@ if ($resql) // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); print ''; print '  '; print ''; print ''; print ''; print '  '; @@ -852,14 +898,12 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['m.datec']['checked'])) - { + if (!empty($arrayfields['m.datec']['checked'])) { print ''; print ''; print '
'.$objp->mid.''.dol_print_date($db->jdate($objp->datem), 'dayhour').''; print $productstatic->getNomUrl(1, 'stock', 16); print "'; /*$productstatic->id=$objp->rowid; - $productstatic->ref=$objp->produit; - $productstatic->type=$objp->type; - print $productstatic->getNomUrl(1,'',16);*/ + $productstatic->ref=$objp->produit; + $productstatic->type=$objp->type; + print $productstatic->getNomUrl(1,'',16);*/ print $productstatic->label; print "'; - if ($productlot->id > 0) print $productlot->getNomUrl(1); - else print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. + if ($productlot->id > 0) { + print $productlot->getNomUrl(1); + } else { + print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. + } print ''.dol_print_date($objp->eatby, 'day').''.dol_print_date($objp->sellby, 'day').''; print $warehousestatic->getNomUrl(1); print "'; print $userstatic->getNomUrl(-1); print "'.$objp->label.''.$origin.''; - if ($objp->qt > 0) print '+'; + if ($objp->qt > 0) { + print '+'; + } print $objp->qty; print ''; - if ($objp->price != 0) print price($objp->price); + if ($objp->price != 0) { + print price($objp->price); + } print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'.$langs->trans("LastMovement").''; - if ($lastmovementdate) - { + if ($lastmovementdate) { print dol_print_date($lastmovementdate, 'dayhour'); } else { print $langs->trans("None"); @@ -681,8 +726,7 @@ if ($resql) /* * Correct stock */ - if ($action == "correction") - { + if ($action == "correction") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; print '
'; } @@ -690,8 +734,7 @@ if ($resql) /* * Transfer of units */ - if ($action == "transfert") - { + if ($action == "transfert") { include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; print '
'; } @@ -703,17 +746,14 @@ if ($resql) /* */ /* ************************************************************************** */ - if ((empty($action) || $action == 'list') && $id > 0) - { + if ((empty($action) || $action == 'list') && $id > 0) { print "
\n"; - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { print ''.$langs->trans("CorrectStock").''; } - if ($user->rights->stock->mouvement->creer) - { + if ($user->rights->stock->mouvement->creer) { print ''.$langs->trans("TransferStock").''; } @@ -721,24 +761,60 @@ if ($resql) } $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($id > 0) $param .= '&id='.urlencode($id); - if ($search_date_startday) $param .= '&search_date_startday='.urlencode($search_date_startday); - if ($search_date_startmonth) $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); - if ($search_date_startyear) $param .= '&search_date_startyear='.urlencode($search_date_startyear); - if ($search_date_endday) $param .= '&search_date_endday='.urlencode($search_date_endday); - if ($search_date_endmonth) $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); - if ($search_date_endyear) $param .= '&search_date_endyear='.urlencode($search_date_endyear); - if ($search_movement) $param .= '&search_movement='.urlencode($search_movement); - if ($search_inventorycode) $param .= '&search_inventorycode='.urlencode($search_inventorycode); - if ($search_type_mouvement) $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); - if ($search_product_ref) $param .= '&search_product_ref='.urlencode($search_product_ref); - if ($search_product) $param .= '&search_product='.urlencode($search_product); - if ($search_batch) $param .= '&search_batch='.urlencode($search_batch); - if ($search_warehouse > 0) $param .= '&search_warehouse='.urlencode($search_warehouse); - if ($search_user) $param .= '&search_user='.urlencode($search_user); - if ($idproduct > 0) $param .= '&idproduct='.urlencode($idproduct); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($id > 0) { + $param .= '&id='.urlencode($id); + } + if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode($search_date_startday); + } + if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); + } + if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode($search_date_startyear); + } + if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode($search_date_endday); + } + if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); + } + if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode($search_date_endyear); + } + if ($search_movement) { + $param .= '&search_movement='.urlencode($search_movement); + } + if ($search_inventorycode) { + $param .= '&search_inventorycode='.urlencode($search_inventorycode); + } + if ($search_type_mouvement) { + $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); + } + if ($search_product_ref) { + $param .= '&search_product_ref='.urlencode($search_product_ref); + } + if ($search_product) { + $param .= '&search_product='.urlencode($search_product); + } + if ($search_batch) { + $param .= '&search_batch='.urlencode($search_batch); + } + if ($search_warehouse > 0) { + $param .= '&search_warehouse='.urlencode($search_warehouse); + } + if ($search_user) { + $param .= '&search_user='.urlencode($search_user); + } + if ($idproduct > 0) { + $param .= '&idproduct='.urlencode($idproduct); + } // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -748,12 +824,18 @@ if ($resql) // 'builddoc'=>$langs->trans("PDFMerge"), ); // By default, we should never accept deletion of stock movement. - if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); - if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); + } + if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); + } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print '
'; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; @@ -761,10 +843,15 @@ if ($resql) print ''; print ''; print ''; - if ($id > 0) print ''; + if ($id > 0) { + print ''; + } - if ($id > 0) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); - else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); + if ($id > 0) { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); + } else { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); + } // Add code for pre mass action (confirmation or email presend form) $topicmail = "SendStockMovement"; @@ -773,9 +860,10 @@ if ($resql) $trackid = 'mov'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } @@ -783,11 +871,13 @@ if ($resql) $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; - else $moreforfilter = $hookmanager->resPrint; + if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; + } else { + $moreforfilter = $hookmanager->resPrint; + } - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -801,15 +891,13 @@ if ($resql) // Fields title search print '
'; print ''; print ''; print '
'; print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel'); @@ -819,66 +907,56 @@ if ($resql) print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; @@ -894,29 +972,25 @@ if ($resql) // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); print ''; print '  '; print ''; print ''; print ''; print '  '; print ''; print '  '; @@ -932,14 +1006,12 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['m.datec']['checked'])) - { + if (!empty($arrayfields['m.datec']['checked'])) { print ''; print ''; print '
'.$objp->mid.''.dol_print_date($db->jdate($objp->datem), 'dayhour', 'tzuserrel').''; print $productstatic->getNomUrl(1, 'stock', 16); print "'; print $productstatic->label; print "'; - if ($productlot->id > 0) print $productlot->getNomUrl(1); - else print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. + if ($productlot->id > 0) { + print $productlot->getNomUrl(1); + } else { + print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. + } print ''.dol_print_date($objp->eatby, 'day').''.dol_print_date($objp->sellby, 'day').''; print $warehousestatic->getNomUrl(1); print "'; print $userstatic->getNomUrl(-1); print "'.$objp->inventorycode.''.$objp->label.''.$origin.''; - if ($objp->qt > 0) print '+'; + if ($objp->qt > 0) { + print '+'; + } print $objp->qty; print ''; - if ($objp->price != 0) print price($objp->price); + if ($objp->price != 0) { + print price($objp->price); + } print ''; - if ($objp->fk_project != 0) print $movement->get_origin($objp->fk_project, 'project'); + if ($objp->fk_project != 0) { + print $movement->get_origin($objp->fk_project, 'project'); + } print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($objp->mid, $arrayofselected)) $selected = 1; + if (in_array($objp->mid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).''; - if ($object->pmp > 0) print price($object->pmp).' '.$langs->trans("HT"); + if ($object->pmp > 0) { + print price($object->pmp).' '.$langs->trans("HT"); + } print '
'; $product_fourn = new ProductFournisseur($db); if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) { - if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(); - else print $langs->trans("NotDefined"); + if ($product_fourn->product_fourn_price_id > 0) { + print $product_fourn->display_price_product_fournisseur(); + } else { + print $langs->trans("NotDefined"); + } } print '
'.price2num($object->stock_reel, 'MS'); - if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); + if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) { + print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); + } print '    '.$langs->trans("StockAtDate").''; print '"; //print (empty($stocktheo)?0:$stocktheo); print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff); - if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); + if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) { + print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte)); + } print '    '.$langs->trans("VirtualStockAtDate").''; print '
'.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price, 'MU'), 1); - else print $langs->trans("Variable"); + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print price(price2num($object->price, 'MU'), 1); + } else { + print $langs->trans("Variable"); + } print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($object->price * $obj->reel, 'MT'), 1).'
'.$langs->trans("Total").':'; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print ($total ? price($totalvaluesell / $total, 1) : ' '); - else print $langs->trans("Variable"); + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print ($total ? price($totalvaluesell / $total, 1) : ' '); + } else { + print $langs->trans("Variable"); + } print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($totalvaluesell, 'MT'), 1); - else print $langs->trans("Variable"); + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print price(price2num($totalvaluesell, 'MT'), 1); + } else { + print $langs->trans("Variable"); + } print '
'; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; } } @@ -401,15 +443,18 @@ print ''."\n"; // Fields title label // -------------------------------------------------------------------- print ''; -foreach ($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } + if (!empty($arrayfields['t.'.$key]['checked'])) { print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n"; } } @@ -426,11 +471,11 @@ print ''."\n"; // Detect if we need a fetch on each output line $needToFetchEachLine = 0; -if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) -{ - foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) - { - if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object +if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) { + foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) { + if (preg_match('/\$object/', $val)) { + $needToFetchEachLine++; // There is at least one compute field that use $object + } } } @@ -439,34 +484,43 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co // -------------------------------------------------------------------- $i = 0; $totalarray = array(); -while ($i < ($limit ? min($num, $limit) : $num)) -{ +while ($i < ($limit ? min($num, $limit) : $num)) { $obj = $db->fetch_object($resql); - if (empty($obj)) break; // Should not happen + if (empty($obj)) { + break; // Should not happen + } // Store properties in $object $object->setVarsFromFetchObj($obj); // Show here line of result print ''; - foreach ($object->fields as $key => $val) - { + foreach ($object->fields as $key => $val) { $cssforfield = (empty($val['css']) ? '' : $val['css']); - if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; - elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; + if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } elseif ($key == 'status') { + $cssforfield .= ($cssforfield ? ' ' : '').'center'; + } - if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; - elseif ($key == 'ref' || $key == 'batch') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + if (in_array($val['type'], array('timestamp'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } elseif ($key == 'ref' || $key == 'batch') { + $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; + } - if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status'))) $cssforfield .= ($cssforfield ? ' ' : '').'right'; + if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status'))) { + $cssforfield .= ($cssforfield ? ' ' : '').'right'; + } //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100'; - if (!empty($arrayfields['t.'.$key]['checked'])) - { + if (!empty($arrayfields['t.'.$key]['checked'])) { print ''; - if ($key == 'status') print $object->getLibStatut(5); - elseif ($key == 'rowid') print $object->id; - else { + if ($key == 'status') { + print $object->getLibStatut(5); + } elseif ($key == 'rowid') { + print $object->id; + } else { if ($key == 'batch') { print $object->getNomUrl(1); } else { @@ -474,10 +528,13 @@ while ($i < ($limit ? min($num, $limit) : $num)) } } print ''; - if (!$i) $totalarray['nbfield']++; - if (!empty($val['isameasure'])) - { - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + if (!$i) { + $totalarray['nbfield']++; + } + if (!empty($val['isameasure'])) { + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; + } $totalarray['val']['t.'.$key] += $object->$key; } } @@ -490,14 +547,17 @@ while ($i < ($limit ? min($num, $limit) : $num)) print $hookmanager->resPrint; // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print ''."\n"; @@ -508,10 +568,13 @@ while ($i < ($limit ? min($num, $limit) : $num)) include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; // If no record found -if ($num == 0) -{ +if ($num == 0) { $colspan = 1; - foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } print ''; } @@ -527,10 +590,11 @@ print ''."\n"; print ''."\n"; -if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) -{ +if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $formfile = new FormFile($db); diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 64dd485671d..904fa9b7e94 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -68,7 +68,9 @@ $texte = ''; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; @@ -86,8 +88,7 @@ if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) - || !empty($conf->mrp->enabled)) -{ + || !empty($conf->mrp->enabled)) { $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs. } @@ -96,20 +97,25 @@ if ($virtualdiffersfromphysical) { } else { $usevirtualstock = 0; } -if ($mode == 'physical') $usevirtualstock = 0; -if ($mode == 'virtual') $usevirtualstock = 1; +if ($mode == 'physical') { + $usevirtualstock = 0; +} +if ($mode == 'virtual') { + $usevirtualstock = 1; +} $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} /* * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('valid')) // Both test are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('valid')) { // Both test are required to be compatible with all browsers $search_ref = ''; $search_label = ''; $sall = ''; @@ -117,26 +123,24 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $includeproductswithoutdesiredqty = ''; $draftorder = ''; } -if ($draftorder == 'on') $draftchecked = "checked"; +if ($draftorder == 'on') { + $draftchecked = "checked"; +} // Create orders -if ($action == 'order' && GETPOST('valid')) -{ +if ($action == 'order' && GETPOST('valid')) { $linecount = GETPOST('linecount', 'int'); $box = 0; $errorQty = 0; unset($_POST['linecount']); - if ($linecount > 0) - { + if ($linecount > 0) { $db->begin(); $suppliers = array(); require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $productsupplier = new ProductFournisseur($db); - for ($i = 0; $i < $linecount; $i++) - { - if (GETPOST('choose'.$i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) - { + for ($i = 0; $i < $linecount; $i++) { + if (GETPOST('choose'.$i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) { //one line $box = $i; $supplierpriceid = GETPOST('fourn'.$i, 'int'); @@ -144,10 +148,8 @@ if ($action == 'order' && GETPOST('valid')) $qty = GETPOST('tobuy'.$i, 'int'); $idprod = $productsupplier->get_buyprice($supplierpriceid, $qty); $res = $productsupplier->fetch($idprod); - if ($res && $idprod > 0) - { - if ($qty) - { + if ($res && $idprod > 0) { + if ($qty) { //might need some value checks $line = new CommandeFournisseurLigne($db); $line->qty = $qty; @@ -155,8 +157,7 @@ if ($action == 'order' && GETPOST('valid')) //$product = new Product($db); //$product->fetch($obj->fk_product); - if (!empty($conf->global->MAIN_MULTILANGS)) - { + if (!empty($conf->global->MAIN_MULTILANGS)) { $productsupplier->getMultiLangs(); } @@ -167,8 +168,7 @@ if ($action == 'order' && GETPOST('valid')) $desc = $productsupplier->description; } $line->desc = $desc; - if (!empty($conf->global->MAIN_MULTILANGS)) - { + if (!empty($conf->global->MAIN_MULTILANGS)) { // TODO Get desc in language of thirdparty } @@ -184,8 +184,7 @@ if ($action == 'order' && GETPOST('valid')) $line->fk_unit = $productsupplier->fk_unit; $suppliers[$productsupplier->fourn_socid]['lines'][] = $line; } - } elseif ($idprod == -1) - { + } elseif ($idprod == -1) { $errorQty++; } else { $error = $db->lasterror(); @@ -202,8 +201,7 @@ if ($action == 'order' && GETPOST('valid')) $fail = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach ($suppliers as $supplier) - { + foreach ($suppliers as $supplier) { $order = new CommandeFournisseur($db); // Check if an order for the supplier exists $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur"; @@ -267,10 +265,11 @@ if ($action == 'order' && GETPOST('valid')) } } - if ($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings'); + if ($errorQty) { + setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings'); + } - if (!$fail && $id) - { + if (!$fail && $id) { $db->commit(); setEventMessages($langs->trans('OrderCreated'), null, 'mesgs'); @@ -280,8 +279,7 @@ if ($action == 'order' && GETPOST('valid')) $db->rollback(); } } - if ($box == 0) - { + if ($box == 0) { setEventMessages($langs->trans('SelectProductWithNotNullQty'), null, 'warnings'); } } @@ -340,7 +338,9 @@ $reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Not $sql .= $hookmanager->resPrint; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; -if ($sall) $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +if ($sall) { + $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); +} // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type)) { if ($type == 1) { @@ -349,8 +349,12 @@ if (dol_strlen($type)) { $sql .= ' AND p.fk_product_type <> 1'; } } -if ($search_ref) $sql .= natural_search('p.ref', $search_ref); -if ($search_label) $sql .= natural_search('p.label', $search_label); +if ($search_ref) { + $sql .= natural_search('p.ref', $search_ref); +} +if ($search_label) { + $sql .= natural_search('p.label', $search_label); +} $sql .= ' AND p.tobuy = 1'; if (empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) { // Add test to exclude products that has variants $sql .= ' AND p.rowid NOT IN (SELECT pac.fk_product_parent FROM '.MAIN_DB_PREFIX.'product_attribute_combination as pac WHERE pac.entity IN ('.getEntity('product').'))'; @@ -366,8 +370,7 @@ if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entre } $sql .= ', s.fk_product'; -if ($usevirtualstock) -{ +if ($usevirtualstock) { if (!empty($conf->commande->enabled)) { $sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd1.qty) IS NULL", "0", "SUM(cd1.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL $sqlCommandesCli .= " FROM ".MAIN_DB_PREFIX."commandedet as cd1, ".MAIN_DB_PREFIX."commande as c1"; @@ -446,8 +449,7 @@ if ($usevirtualstock) $sql .= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.') + ('.$sqlProductionToProduce.' - '.$sqlProductionToConsume.')))'; $sql .= ')'; - if ($salert == 'on') // Option to see when stock is lower than alert - { + if ($salert == 'on') { // Option to see when stock is lower than alert $sql .= ' AND ('; if ($includeproductswithoutdesiredqty == 'on') { $sql .= '('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; @@ -469,8 +471,7 @@ if ($usevirtualstock) } $sql .= ')'; - if ($salert == 'on') // Option to see when stock is lower than alert - { + if ($salert == 'on') { // Option to see when stock is lower than alert $sql .= ' AND ('; if ($includeproductswithoutdesiredqty == 'on') { $sql .= ' ('.$sqlalertstock.' >= 0 OR '.$sqlalertstock.' IS NULL) AND ('.$db->ifsql("$sqlalertstock IS NULL", "0", $sqlalertstock).' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))'; @@ -507,8 +508,7 @@ $sql .= $db->plimit($limit + 1, $offset); //print $sql; $resql = $db->query($sql); -if (empty($resql)) -{ +if (empty($resql)) { dol_print_error($db); exit; } @@ -541,15 +541,13 @@ if (empty($fk_warhouse) && !empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_ print ''.$langs->trans("ReplenishmentStatusDescPerWarehouse").''."\n"; } print '

'; -if ($usevirtualstock == 1) -{ +if ($usevirtualstock == 1) { print $langs->trans("CurentSelectionMode").': '; print ''.$langs->trans("UseVirtualStock").''; print ' 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UsePhysicalStock").''; print '
'; } -if ($usevirtualstock == 0) -{ +if ($usevirtualstock == 0) { print $langs->trans("CurentSelectionMode").': '; print ' 0 ? '&fk_supplier='.$fk_supplier : '').($fk_entrepot > 0 ? '&fk_entrepot='.$fk_entrepot : '').'">'.$langs->trans("UseVirtualStock").''; print ' '.$langs->trans("UsePhysicalStock").''; @@ -569,8 +567,7 @@ print ''; if ($limit > 0 && $limit != $conf->liste_limit) { print ''; } -if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) -{ +if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) { print '
'; print $langs->trans('Warehouse').' '.$formproduct->selectWarehouses($fk_entrepot, 'fk_entrepot', '', 1); print '
'; @@ -581,7 +578,9 @@ print ''; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) print $hookmanager->resPrint; +if (empty($reshook)) { + print $hookmanager->resPrint; +} print '
'; print ''; @@ -607,8 +606,12 @@ if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST(' $filters .= '&salert='.urlencode($salert); $filters .= '&draftorder='.urlencode($draftorder); $filters .= '&mode='.urlencode($mode); - if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier); - if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot); + if ($fk_supplier > 0) { + $filters .= '&fk_supplier='.urlencode($fk_supplier); + } + if ($fk_entrepot > 0) { + $filters .= '&fk_entrepot='.urlencode($fk_entrepot); + } } else { $filters = '&search_ref='.urlencode($search_ref).'&search_label='.urlencode($search_label); $filters .= '&fourn_id='.urlencode($fourn_id); @@ -616,8 +619,12 @@ if ($search_ref || $search_label || $sall || $salert || $draftorder || GETPOST(' $filters .= '&='.urlencode($salert); $filters .= '&draftorder='.urlencode($draftorder); $filters .= '&mode='.urlencode($mode); - if ($fk_supplier > 0) $filters .= '&fk_supplier='.urlencode($fk_supplier); - if ($fk_entrepot > 0) $filters .= '&fk_entrepot='.urlencode($fk_entrepot); + if ($fk_supplier > 0) { + $filters .= '&fk_supplier='.urlencode($fk_supplier); + } + if ($fk_entrepot > 0) { + $filters .= '&fk_entrepot='.urlencode($fk_entrepot); + } } if ($limit > 0 && $limit != $conf->liste_limit) { $filters .= '&limit='.urlencode($limit); @@ -632,10 +639,13 @@ $param .= '&fk_entrepot='.urlencode($fk_entrepot); $stocklabel = $langs->trans('Stock'); $stocklabelbis = $langs->trans('Stock'); -if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock'); -if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock'); -if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) -{ +if ($usevirtualstock == 1) { + $stocklabel = $langs->trans('VirtualStock'); +} +if ($usevirtualstock == 0) { + $stocklabel = $langs->trans('PhysicalStock'); +} +if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { $stocklabelbis = $stocklabel.' (Selected warehouse)'; $stocklabel .= ' ('.$langs->trans("AllWarehouses").')'; } @@ -684,12 +694,13 @@ print '
'; print ''; print ''; print ''; -if (!empty($conf->service->enabled) && $type == 1) print ''; +if (!empty($conf->service->enabled) && $type == 1) { + print ''; +} print ''; print ''; print ''; -if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) -{ +if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { print ''; } print ''; print_liste_field_titre('', $_SERVER["PHP_SELF"], ''); print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', $param, '', '', $sortfield, $sortorder); print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', $param, '', '', $sortfield, $sortorder); -if (!empty($conf->service->enabled) && $type == 1) print_liste_field_titre('Duration', $_SERVER["PHP_SELF"], 'p.duration', $param, '', '', $sortfield, $sortorder, 'center '); +if (!empty($conf->service->enabled) && $type == 1) { + print_liste_field_titre('Duration', $_SERVER["PHP_SELF"], 'p.duration', $param, '', '', $sortfield, $sortorder, 'center '); +} print_liste_field_titre('DesiredStock', $_SERVER["PHP_SELF"], 'p.desiredstock', $param, '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre('StockLimitShort', $_SERVER["PHP_SELF"], 'p.seuil_stock_alerte', $param, '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre($stocklabel, $_SERVER["PHP_SELF"], 'stock_physique', $param, '', '', $sortfield, $sortorder, 'right '); -if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) -{ +if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { print_liste_field_titre($stocklabelbis, $_SERVER["PHP_SELF"], 'stock_real_warehouse', $param, '', '', $sortfield, $sortorder, 'right '); } print_liste_field_titre('Ordered', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); @@ -733,18 +745,15 @@ print $hookmanager->resPrint; print "\n"; -while ($i < ($limit ? min($num, $limit) : $num)) -{ +while ($i < ($limit ? min($num, $limit) : $num)) { $objp = $db->fetch_object($resql); - if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) - { + if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) { $prod->fetch($objp->rowid); $prod->load_stock('warehouseopen, warehouseinternal', $draftchecked); // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) - { + if (!empty($conf->global->MAIN_MULTILANGS)) { $sql = 'SELECT label,description'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product_lang'; $sql .= ' WHERE fk_product = '.$objp->rowid; @@ -752,17 +761,19 @@ while ($i < ($limit ? min($num, $limit) : $num)) $sql .= ' LIMIT 1'; $resqlm = $db->query($sql); - if ($resqlm) - { + if ($resqlm) { $objtp = $db->fetch_object($resqlm); - if (!empty($objtp->description)) $objp->description = $objtp->description; - if (!empty($objtp->label)) $objp->label = $objtp->label; + if (!empty($objtp->description)) { + $objp->description = $objtp->description; + } + if (!empty($objtp->label)) { + $objp->label = $objtp->label; + } } } $stockwarehouse = 0; - if ($usevirtualstock) - { + if ($usevirtualstock) { // If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock. $stock = $prod->stock_theorique; //TODO $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->; @@ -790,27 +801,30 @@ while ($i < ($limit ? min($num, $limit) : $num)) $alertstockwarehouse = ($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : 0); $warning = ''; - if ($alertstock && ($stock < $alertstock)) - { + if ($alertstock && ($stock < $alertstock)) { $warning = img_warning($langs->trans('StockTooLow')).' '; } $warningwarehouse = ''; - if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse)) - { + if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse)) { $warningwarehouse = img_warning($langs->trans('StockTooLow')).' '; } //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value - if (empty($usevirtualstock)) $stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0); - else $stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0); //ordered is already in $stock in virtual mode - if (empty($usevirtualstock)) $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0); - else $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0); //ordered is already in $stock in virtual mode + if (empty($usevirtualstock)) { + $stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0); + } else { + $stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0); //ordered is already in $stock in virtual mode + } + if (empty($usevirtualstock)) { + $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0); + } else { + $stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0); //ordered is already in $stock in virtual mode + } $picto = ''; - if ($ordered > 0) - { + if ($ordered > 0) { $stockforcompare = ($usevirtualstock ? $stock : $stock + $ordered); /*if ($stockforcompare >= $desiredstock) { @@ -833,8 +847,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) print ''; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST print ''; - if (!empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { $regs = array(); if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { $duration = $regs[1].' '.$langs->trans('DurationYear'); @@ -858,8 +871,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) print ''; // Current stock (warehouse selected only) - if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) - { + if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) { print ''; } diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index c73c7b1ca39..f5978313a1e 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -38,7 +38,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->loadLangs(array('products', 'stocks', 'orders')); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'produit|service'); $sall = GETPOST('search_all', 'alphanohtml'); @@ -56,10 +58,16 @@ $search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_d $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (!$sortorder) $sortorder = 'DESC'; -if (!$sortfield) $sortfield = 'cf.date_creation'; +if (!$sortorder) { + $sortorder = 'DESC'; +} +if (!$sortfield) { + $sortfield = 'cf.date_creation'; +} $page = GETPOST('page', 'int') ? GETPOST('page', 'int') : 0; -if ($page < 0) $page = 0; +if ($page < 0) { + $page = 0; +} $offset = $limit * $page; @@ -67,8 +75,7 @@ $offset = $limit * $page; * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers $sall = ""; $sref = ""; $snom = ""; @@ -130,13 +137,25 @@ if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { if (!$user->rights->societe->client->voir && !$socid) { $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.$user->id; } -if ($sref) $sql .= natural_search('cf.ref', $sref); -if ($snom) $sql .= natural_search('s.nom', $snom); -if ($suser) $sql .= natural_search('u.login', $suser); -if ($sttc) $sql .= natural_search('cf.total_ttc', $sttc, 1); +if ($sref) { + $sql .= natural_search('cf.ref', $sref); +} +if ($snom) { + $sql .= natural_search('s.nom', $snom); +} +if ($suser) { + $sql .= natural_search('u.login', $suser); +} +if ($sttc) { + $sql .= natural_search('cf.total_ttc', $sttc, 1); +} $sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear); -if ($sall) $sql .= natural_search(array('cf.ref', 'cf.note'), $sall); -if (!empty($socid)) $sql .= ' AND s.rowid = '.$socid; +if ($sall) { + $sql .= natural_search(array('cf.ref', 'cf.note'), $sall); +} +if (!empty($socid)) { + $sql .= ' AND s.rowid = '.$socid; +} if (GETPOST('statut', 'int')) { $sql .= ' AND fk_statut = '.GETPOST('statut', 'int'); } @@ -148,8 +167,7 @@ if (!$search_product) { } $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -160,16 +178,36 @@ if ($resql) print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, ''); $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sref) $param .= '&search_ref='.urlencode($sref); - if ($snom) $param .= '&search_nom='.urlencode($snom); - if ($suser) $param .= '&search_user='.urlencode($suser); - if ($sttc) $param .= '&search_ttc='.urlencode($sttc); - if ($search_dateyear) $param .= '&search_dateyear='.urlencode($search_dateyear); - if ($search_datemonth) $param .= '&search_datemonth='.urlencode($search_datemonth); - if ($search_dateday) $param .= '&search_dateday='.urlencode($search_dateday); - if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sref) { + $param .= '&search_ref='.urlencode($sref); + } + if ($snom) { + $param .= '&search_nom='.urlencode($snom); + } + if ($suser) { + $param .= '&search_user='.urlencode($suser); + } + if ($sttc) { + $param .= '&search_ttc='.urlencode($sttc); + } + if ($search_dateyear) { + $param .= '&search_dateyear='.urlencode($search_dateyear); + } + if ($search_datemonth) { + $param .= '&search_datemonth='.urlencode($search_datemonth); + } + if ($search_dateday) { + $param .= '&search_dateday='.urlencode($search_dateday); + } + if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); + } print '
'; - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); - elseif (strpos($val['type'], 'integer:') === 0) { + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1); + } elseif (strpos($val['type'], 'integer:') === 0) { print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1); - } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print ''; + } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) { + print ''; + } print '
'; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($object->id, $arrayofselected)) $selected = 1; + if (in_array($object->id, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'.$langs->trans("NoRecordFound").'
   '.$form->textwithpicto($langs->trans('IncludeEmptyDesiredStock'), $langs->trans('IncludeProductWithUndefinedAlerts')).' '.$langs->trans('AlertOnly').'  '; @@ -714,12 +725,13 @@ print '
'.$warning.$stock.''.$warningwarehouse.$stockwarehouse.'
'; @@ -261,14 +299,12 @@ if ($resql) $userstatic = new User($db); - while ($i < min($num, $search_product ? $num : $conf->liste_limit)) - { + while ($i < min($num, $search_product ? $num : $conf->liste_limit)) { $obj = $db->fetch_object($resql); $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid))); - if ($showline) - { + if ($showline) { $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid; print ''; diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index 0b80ab3a36b..cbdaa62014b 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -71,7 +71,9 @@ $fk_warehouse = GETPOST('fk_warehouse', 'int'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; if (!$sortfield) { @@ -83,7 +85,9 @@ if (!$sortorder) { $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} $dateIsValid = true; if ($mode == 'future') { @@ -103,8 +107,7 @@ if ($mode == 'future') { * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers $date = ''; $productid = 0; $fk_warehouse = 0; @@ -142,8 +145,7 @@ if ($date && $dateIsValid) { // Avoid heavy sql if mandatory date is not defined //print $sql; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -197,8 +199,7 @@ if ($date && $dateIsValid) { $sql .= " GROUP BY sm.fk_product, sm.fk_entrepot"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -270,7 +271,9 @@ if ($productid > 0) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $sql .= " AND p.fk_product_type = 0"; } -if (!empty($canvas)) $sql .= ' AND p.canvas = "'.$db->escape($canvas).'"'; +if (!empty($canvas)) { + $sql .= ' AND p.canvas = "'.$db->escape($canvas).'"'; +} if ($fk_warehouse > 0) { $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price, p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,'; $sql .= ' p.tms, p.duration, p.tobuy, p.stock'; @@ -293,12 +296,10 @@ $sql .= $db->order($sortfield, $sortorder); if ($date && $dateIsValid) { // We avoid a heavy sql if mandatory parameter date not yet defined $nbtotalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -308,8 +309,7 @@ if ($date && $dateIsValid) { // We avoid a heavy sql if mandatory parameter date //print $sql; $resql = $db->query($sql); - if (empty($resql)) - { + if (empty($resql)) { dol_print_error($db); exit; } @@ -341,7 +341,9 @@ print load_fiche_titre($langs->trans('StockAtDate'), '', 'stock'); print dol_get_fiche_head($head, ($mode == 'future' ? 'stockatdatefuture' : 'stockatdatepast'), '', -1, ''); $desc = $langs->trans("StockAtDatePastDesc"); -if ($mode == 'future') $desc = $langs->trans("StockAtDateFutureDesc"); +if ($mode == 'future') { + $desc = $langs->trans("StockAtDateFutureDesc"); +} print ''.$desc.'
'."\n"; print '
'."\n"; @@ -366,7 +368,9 @@ print ''; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) print $hookmanager->resPrint; +if (empty($reshook)) { + print $hookmanager->resPrint; +} print '
'; print ''; @@ -375,14 +379,28 @@ print '
'; //print ''; $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} $param .= '&mode='.$mode; -if ($fk_warehouse > 0) $param .= '&fk_warehouse='.$fk_warehouse; -if ($productid > 0) $param .= '&productid='.$productid; -if (GETPOST('dateday', 'int') > 0) $param .= '&dateday='.GETPOST('dateday', 'int'); -if (GETPOST('datemonth', 'int') > 0) $param .= '&datemonth='.GETPOST('datemonth', 'int'); -if (GETPOST('dateyear', 'int') > 0) $param .= '&dateyear='.GETPOST('dateyear', 'int'); +if ($fk_warehouse > 0) { + $param .= '&fk_warehouse='.$fk_warehouse; +} +if ($productid > 0) { + $param .= '&productid='.$productid; +} +if (GETPOST('dateday', 'int') > 0) { + $param .= '&dateday='.GETPOST('dateday', 'int'); +} +if (GETPOST('datemonth', 'int') > 0) { + $param .= '&datemonth='.GETPOST('datemonth', 'int'); +} +if (GETPOST('dateyear', 'int') > 0) { + $param .= '&dateyear='.GETPOST('dateyear', 'int'); +} // TODO Move this into the title line ? print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); @@ -391,7 +409,9 @@ print '
'; // You can use div-table-responsive- print '
'; $stocklabel = $langs->trans('StockAtDate'); -if ($mode == 'future') $stocklabel = $langs->trans("VirtualStockAtDate"); +if ($mode == 'future') { + $stocklabel = $langs->trans("VirtualStockAtDate"); +} //print ''; print ''; @@ -456,12 +476,10 @@ print $hookmanager->resPrint; print "\n"; $i = 0; -while ($i < ($limit ? min($num, $limit) : $num)) -{ +while ($i < ($limit ? min($num, $limit) : $num)) { $objp = $db->fetch_object($resql); - if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) - { + if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) { $prod->fetch($objp->rowid); // Multilangs @@ -483,8 +501,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) }*/ $currentstock = ''; - if ($fk_warehouse > 0) - { + if ($fk_warehouse > 0) { //if ($productid > 0) { $currentstock = $stock_prod_warehouse[$objp->rowid][$fk_warehouse]; //} else { @@ -545,14 +562,18 @@ while ($i < ($limit ? min($num, $limit) : $num)) // PMP value print ''; // Selling value print ''; } diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 4f88b448239..6e2ab53dd0e 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -30,12 +30,16 @@ if (empty($conf) || !is_object($conf)) { element == 'product') $productref = $object->ref; +if ($object->element == 'product') { + $productref = $object->ref; +} $langs->load("productbatch"); -if (empty($id)) $id = $object->id; +if (empty($id)) { + $id = $object->id; +} print '
'; - if (price2num($objp->estimatedvalue, 'MT')) print price(price2num($objp->estimatedvalue, 'MT'), 1); - else print ''; + if (price2num($objp->estimatedvalue, 'MT')) { + print price(price2num($objp->estimatedvalue, 'MT'), 1); + } else { + print ''; + } print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($objp->sellvalue, 'MT'), 1); - else { + if (empty($conf->global->PRODUIT_MULTIPRICES)) { + print price(price2num($objp->sellvalue, 'MT'), 1); + } else { $htmltext = $langs->trans("OptionMULTIPRICESIsOn"); print $form->textwithtooltip($langs->trans("Variable"), $htmltext); } @@ -588,7 +609,9 @@ print $hookmanager->resPrint; if (empty($date) || ! $dateIsValid) { $colspan = 8; - if ($mode == 'future') $colspan++; + if ($mode == 'future') { + $colspan++; + } print '
'.$langs->trans("EnterADateCriteria").'