diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f0c05ec7986..889eb036ab4 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -60,9 +60,15 @@ if (!empty($conf->variants->enabled)) { // Load translation files required by the page $langs->loadLangs(array('orders', 'sendings', 'companies', 'bills', 'propal', 'deliveries', 'products', 'other')); -if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); -if (!empty($conf->margin->enabled)) $langs->load('margins'); -if (!empty($conf->productbatch->enabled)) $langs->load("productbatch"); +if (!empty($conf->incoterm->enabled)) { + $langs->load('incoterm'); +} +if (!empty($conf->margin->enabled)) { + $langs->load('margins'); +} +if (!empty($conf->productbatch->enabled)) { + $langs->load("productbatch"); +} $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('orderid', 'int')); $ref = GETPOST('ref', 'alpha'); @@ -82,8 +88,9 @@ $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($ $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); // Security check -if (!empty($user->socid)) +if (!empty($user->socid)) { $socid = $user->socid; +} $result = restrictedArea($user, 'commande', $id); $object = new Commande($db); @@ -125,14 +132,13 @@ $date_delivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int' $parameters = array('socid' => $socid); // Note that $action and $object may be modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if ($cancel) - { - if (!empty($backtopage)) - { +if (empty($reshook)) { + if ($cancel) { + if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } @@ -146,20 +152,16 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) - { - if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) - { + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { + if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { - if ($object->id > 0) - { + if ($object->id > 0) { // Because createFromClone modifies the object, we must clone it so that we can restore it later $orig = clone $object; $result = $object->createFromClone($user, $socid); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit; } else { @@ -169,49 +171,38 @@ if (empty($reshook)) } } } - } - - // Reopen a closed order - elseif ($action == 'reopen' && $usercancreate) - { - if ($object->statut == Commande::STATUS_CANCELED || $object->statut == Commande::STATUS_CLOSED) - { + } elseif ($action == 'reopen' && $usercancreate) { + // Reopen a closed order + if ($object->statut == Commande::STATUS_CANCELED || $object->statut == Commande::STATUS_CLOSED) { $result = $object->set_reopen($user); - if ($result > 0) - { + if ($result > 0) { setEventMessages($langs->trans('OrderReopened', $object->ref), null); } else { setEventMessages($object->error, $object->errors, 'errors'); } } - } - - // Remove order - elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) - { + } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { + // Remove order $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { header('Location: list.php?restore_lastsearch_values=1'); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Remove a product line - elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) - { + } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { + // Remove a product line $result = $object->deleteline($user, $lineid); - if ($result > 0) - { + if ($result > 0) { // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -226,17 +217,11 @@ if (empty($reshook)) } else { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Link to a project - elseif ($action == 'classin' && $usercancreate) - { + } elseif ($action == 'classin' && $usercancreate) { + // Link to a project $object->setProject(GETPOST('projectid', 'int')); - } - - // Add order - elseif ($action == 'add' && $usercancreate) - { + } elseif ($action == 'add' && $usercancreate) { + // Add order $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $date_delivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $selectedLines = GETPOST('toselect', 'array'); @@ -282,15 +267,15 @@ if (empty($reshook)) $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); // Fill array 'array_options' with data from add form - if (!$error) - { + if (!$error) { $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } } // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid)) - { + if (!empty($origin) && !empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { @@ -320,12 +305,10 @@ if (empty($reshook)) $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects); } - if (!$error) - { + if (!$error) { $object_id = $object->create($user); - if ($object_id > 0) - { + if ($object_id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); @@ -333,11 +316,9 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); $result = $srcobject->fetch($object->origin_id); - if ($result > 0) - { + if ($result > 0) { $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject, 'fetch_lines')) - { + if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { $srcobject->fetch_lines(); $lines = $srcobject->lines; } @@ -345,9 +326,10 @@ if (empty($reshook)) $fk_parent_line = 0; $num = count($lines); - for ($i = 0; $i < $num; $i++) - { - if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines + for ($i = 0; $i < $num; $i++) { + if (!in_array($lines[$i]->id, $selectedLines)) { + continue; // Skip unselected lines + } $label = (!empty($lines[$i]->label) ? $lines[$i]->label : ''); $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : ''); @@ -356,15 +338,19 @@ if (empty($reshook)) // Dates // TODO mutualiser $date_start = $lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) + if ($lines[$i]->date_debut_reel) { $date_start = $lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) + } + if ($lines[$i]->date_start) { $date_start = $lines[$i]->date_start; + } $date_end = $lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) + if ($lines[$i]->date_fin_reel) { $date_end = $lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) + } + if ($lines[$i]->date_end) { $date_end = $lines[$i]->date_end; + } // Reset fk_parent_line for no child products and special product if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) { @@ -372,20 +358,42 @@ if (empty($reshook)) } // Extrafields - if (method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if trigger used - { + if (method_exists($lines[$i], 'fetch_optionals')) { // For avoid conflicts if trigger used $lines[$i]->fetch_optionals(); $array_options = $lines[$i]->array_options; } $tva_tx = $lines[$i]->tva_tx; - if (!empty($lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')'; + if (!empty($lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) { + $tva_tx .= ' ('.$lines[$i]->vat_src_code.')'; + } $result = $object->addline( - $desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, - $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, - $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, - $lines[$i]->fk_unit, $object->origin, $lines[$i]->rowid + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $date_start, + $date_end, + $product_type, + $lines[$i]->rang, + $lines[$i]->special_code, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $label, + $array_options, + $lines[$i]->fk_unit, + $object->origin, + $lines[$i]->rowid ); if ($result < 0) { @@ -407,26 +415,26 @@ if (empty($reshook)) /* Useless, already into the create if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) { - $originforcontact = $object->origin; - $originidforcontact = $object->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order - { - $originforcontact=$srcobject->origin; - $originidforcontact=$srcobject->origin_id; - } - $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$db->escape($originforcontact)."'"; + $originforcontact = $object->origin; + $originidforcontact = $object->origin_id; + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order + { + $originforcontact=$srcobject->origin; + $originidforcontact=$srcobject->origin_id; + } + $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$db->escape($originforcontact)."'"; - $resqlcontact = $db->query($sqlcontact); - if ($resqlcontact) - { - while($objcontact = $db->fetch_object($resqlcontact)) - { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; - $object->add_contact($objcontact->fk_socpeople, $objcontact->code); - } - } - else dol_print_error($resqlcontact); + $resqlcontact = $db->query($sqlcontact); + if ($resqlcontact) + { + while($objcontact = $db->fetch_object($resqlcontact)) + { + //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; + $object->add_contact($objcontact->fk_socpeople, $objcontact->code); + } + } + else dol_print_error($resqlcontact); }*/ // Hooks @@ -445,15 +453,13 @@ if (empty($reshook)) $action = 'create'; } } else { - if (!$error) - { + if (!$error) { $object_id = $object->create($user); } } // Insert default contacts if defined - if ($object_id > 0) - { + if ($object_id > 0) { if (GETPOST('contactid', 'int')) { $result = $object->add_contact(GETPOST('contactid', 'int'), 'CUSTOMER', 'external'); if ($result < 0) { @@ -467,8 +473,7 @@ if (empty($reshook)) } // End of object creation, we show it - if ($object_id > 0 && !$error) - { + if ($object_id > 0 && !$error) { $db->commit(); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object_id); exit(); @@ -478,32 +483,26 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'classifybilled' && $usercancreate) - { + } elseif ($action == 'classifybilled' && $usercancreate) { $ret = $object->classifyBilled($user); if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'classifyunbilled' && $usercancreate) - { + } elseif ($action == 'classifyunbilled' && $usercancreate) { $ret = $object->classifyUnBilled(); if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Positionne ref commande client - elseif ($action == 'setref_client' && $usercancreate) { + } elseif ($action == 'setref_client' && $usercancreate) { + // Positionne ref commande client $result = $object->set_ref_client($user, GETPOST('ref_client')); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'setremise' && $usercancreate) { $result = $object->setDiscount($user, GETPOST('remise')); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'setabsolutediscount' && $usercancreate) { @@ -533,26 +532,25 @@ if (empty($reshook)) } } elseif ($action == 'setmode' && $usercancreate) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); - } - - // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $usercancreate) { + } + } elseif ($action == 'setmulticurrencycode' && $usercancreate) { + // Multicurrency Code $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } - - // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + } elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + // Multicurrency rate $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx'))); } elseif ($action == 'setavailability' && $usercancreate) { $result = $object->availability(GETPOST('availability_id')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } elseif ($action == 'setdemandreason' && $usercancreate) { $result = $object->demand_reason(GETPOST('demand_reason_id')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } elseif ($action == 'setconditions' && $usercancreate) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); if ($result < 0) { @@ -562,8 +560,9 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = GETPOST('lang_id', 'alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -573,35 +572,26 @@ if (empty($reshook)) $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - } - - // Set incoterm - elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { + } elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { + // Set incoterm $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // bank account - elseif ($action == 'setbankaccount' && $usercancreate) { + } elseif ($action == 'setbankaccount' && $usercancreate) { + // bank account $result = $object->setBankAccount(GETPOST('fk_account', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // shipping method - elseif ($action == 'setshippingmethod' && $usercancreate) { + } elseif ($action == 'setshippingmethod' && $usercancreate) { + // shipping method $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // warehouse - elseif ($action == 'setwarehouse' && $usercancreate) { + } elseif ($action == 'setwarehouse' && $usercancreate) { + // warehouse $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -619,8 +609,7 @@ if (empty($reshook)) foreach ($object->lines as $line) { $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); } - } elseif ($action == 'addline' && $usercancreate) // Add a new line - { + } elseif ($action == 'addline' && $usercancreate) { // Add a new line $langs->load('errors'); $error = 0; @@ -630,8 +619,7 @@ if (empty($reshook)) $price_ht = price2num(GETPOST('price_ht'), 'MU'); $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU'); $prod_entry_mode = GETPOST('prod_entry_mode'); - if ($prod_entry_mode == 'free') - { + if ($prod_entry_mode == 'free') { $idprod = 0; $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { @@ -665,8 +653,7 @@ if (empty($reshook)) setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); $error++; } - if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '' && $price_ht_devise == '') // Unit price can be 0 but not ''. Also price can be negative for order. - { + if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '' && $price_ht_devise == '') { // Unit price can be 0 but not ''. Also price can be negative for order. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); $error++; } @@ -712,7 +699,9 @@ if (empty($reshook)) // Update if prices fields are defined $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; @@ -720,21 +709,21 @@ if (empty($reshook)) $price_base_type = $prod->price_base_type; // If price per segment - if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) - { + if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) { $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; - if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility - { - if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level]; - if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility + if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) { + $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level]; + } + if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) { + $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + } } - } - // If price per customer - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { + } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + // If price per customer require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; $prodcustprice = new Productcustomerprice($db); @@ -742,38 +731,37 @@ if (empty($reshook)) $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id); $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); - if ($result >= 0) - { - if (count($prodcustprice->lines) > 0) - { + if ($result >= 0) { + if (count($prodcustprice->lines) > 0) { $pu_ht = price($prodcustprice->lines[0]->price); $pu_ttc = price($prodcustprice->lines[0]->price_ttc); $price_min = price($prodcustprice->lines[0]->price_min); $price_base_type = $prodcustprice->lines[0]->price_base_type; $tva_tx = $prodcustprice->lines[0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + } $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } } } else { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } - } - // If price per quantity - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) - { - if ($prod->prices_by_qty[0]) // yes, this product has some prices per quantity - { + } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { + // If price per quantity + if ($prod->prices_by_qty[0]) { // yes, this product has some prices per quantity // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp']. $pqp = GETPOST('pbq', 'int'); // Search price into product_price_by_qty from $prod->id - foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) - { - if ($priceforthequantityarray['rowid'] != $pqp) continue; + foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) { + if ($priceforthequantityarray['rowid'] != $pqp) { + continue; + } // We found the price - if ($priceforthequantityarray['price_base_type'] == 'HT') - { + if ($priceforthequantityarray['price_base_type'] == 'HT') { $pu_ht = $priceforthequantityarray['unitprice']; } else { $pu_ttc = $priceforthequantityarray['unitprice']; @@ -782,21 +770,18 @@ if (empty($reshook)) break; } } - } - // If price per quantity and customer - elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { - if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity - { + } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + // If price per quantity and customer + if ($prod->prices_by_qty[$object->thirdparty->price_level]) { // yes, this product has some prices per quantity // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp']. $pqp = GETPOST('pbq', 'int'); // Search price into product_price_by_qty from $prod->id - foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) - { - if ($priceforthequantityarray['rowid'] != $pqp) continue; + foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) { + if ($priceforthequantityarray['rowid'] != $pqp) { + continue; + } // We found the price - if ($priceforthequantityarray['price_base_type'] == 'HT') - { + if ($priceforthequantityarray['price_base_type'] == 'HT') { $pu_ht = $priceforthequantityarray['unitprice']; } else { $pu_ttc = $priceforthequantityarray['unitprice']; @@ -814,10 +799,9 @@ if (empty($reshook)) if (!empty($price_ht) || $price_ht === '0') { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - elseif ($tmpvat != $tmpprodvat) { + } elseif ($tmpvat != $tmpprodvat) { + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); } else { @@ -831,16 +815,18 @@ if (empty($reshook)) if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'aZ09')) + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); - if (empty($newlang)) + } + if (empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; + $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description; } else { $desc = $prod->description; } @@ -850,8 +836,11 @@ if (empty($reshook)) $product_desc=''; } - if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; - else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) { + $desc = $product_desc; + } else { + $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + } // Add custom code and origin country into description if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) { @@ -860,28 +849,36 @@ if (empty($reshook)) if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'alpha')) + if (empty($newlang) && GETPOST('lang_id', 'alpha')) { $newlang = GETPOST('lang_id', 'alpha'); - if (empty($newlang)) + } + if (empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - if (!empty($prod->customcode)) + if (!empty($prod->customcode)) { $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode; - if (!empty($prod->customcode) && !empty($prod->country_code)) + } + if (!empty($prod->customcode) && !empty($prod->country_code)) { $tmptxt .= ' - '; - if (!empty($prod->country_code)) + } + if (!empty($prod->country_code)) { $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $outputlangs, 0); + } } else { - if (!empty($prod->customcode)) + if (!empty($prod->customcode)) { $tmptxt .= $langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode; - if (!empty($prod->customcode) && !empty($prod->country_code)) + } + if (!empty($prod->customcode) && !empty($prod->country_code)) { $tmptxt .= ' - '; - if (!empty($prod->country_code)) + } + if (!empty($prod->country_code)) { $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $langs, 0); + } } $tmptxt .= ')'; $desc = dol_concatdesc($desc, $tmptxt); @@ -912,8 +909,9 @@ if (empty($reshook)) $desc = dol_htmlcleanlastbr($desc); $info_bits = 0; - if ($tva_npr) + if ($tva_npr) { $info_bits |= 0x01; + } if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); @@ -930,8 +928,9 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = GETPOST('lang_id', 'alpha'); - if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) + if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -977,13 +976,8 @@ if (empty($reshook)) } } } - } - - /* - * Update a line - */ - elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) - { + } elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) { + // Update a line // Clean parameters $date_start = ''; $date_end = ''; @@ -996,8 +990,9 @@ if (empty($reshook)) // Define info_bits $info_bits = 0; - if (preg_match('/\*/', $vat_rate)) + if (preg_match('/\*/', $vat_rate)) { $info_bits |= 0x01; + } // Define vat_rate $vat_rate = str_replace('*', '', $vat_rate); @@ -1020,7 +1015,9 @@ if (empty($reshook)) // Define special_code for special lines $special_code = GETPOST('special_code'); - if (!GETPOST('qty')) $special_code = 3; + if (!GETPOST('qty')) { + $special_code = 3; + } // Check minimum price $productid = GETPOST('productid', 'int'); @@ -1031,8 +1028,9 @@ if (empty($reshook)) $type = $product->type; $price_min = $product->price_min; - if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) + if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) { $price_min = $product->multiprices_min[$object->thirdparty->price_level]; + } $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); @@ -1052,12 +1050,9 @@ if (empty($reshook)) } if (!$error) { - if (empty($user->rights->margins->creer)) - { - foreach ($object->lines as &$line) - { - if ($line->id == GETPOST('lineid')) - { + if (empty($user->rights->margins->creer)) { + foreach ($object->lines as &$line) { + if ($line->id == GETPOST('lineid')) { $fournprice = $line->fk_fournprice; $buyingprice = $line->pa_ht; break; @@ -1071,10 +1066,12 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -1117,23 +1114,19 @@ if (empty($reshook)) } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition exit(); - } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) - { + } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse', 'int'); $qualified_for_stock_change = 0; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - $qualified_for_stock_change = $object->hasProductsOrServices(2); + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); + $qualified_for_stock_change = $object->hasProductsOrServices(1); } // Check parameters - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) - { - if (!$idwarehouse || $idwarehouse == -1) - { + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) { + if (!$idwarehouse || $idwarehouse == -1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $action = ''; @@ -1142,15 +1135,17 @@ if (empty($reshook)) if (!$error) { $result = $object->valid($user, $idwarehouse); - if ($result >= 0) - { + if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -1164,25 +1159,20 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - } - - // Go back to draft status - elseif ($action == 'confirm_modif' && $usercancreate) { + } elseif ($action == 'confirm_modif' && $usercancreate) { + // Go back to draft status $idwarehouse = GETPOST('idwarehouse'); $qualified_for_stock_change = 0; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - $qualified_for_stock_change = $object->hasProductsOrServices(2); + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); + $qualified_for_stock_change = $object->hasProductsOrServices(1); } // Check parameters - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) - { - if (!$idwarehouse || $idwarehouse == -1) - { + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) { + if (!$idwarehouse || $idwarehouse == -1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $action = ''; @@ -1191,15 +1181,17 @@ if (empty($reshook)) if (!$error) { $result = $object->setDraft($user, $idwarehouse); - if ($result >= 0) - { + if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -1216,23 +1208,19 @@ if (empty($reshook)) if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanvalidate) - { + } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse', 'int'); $qualified_for_stock_change = 0; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - $qualified_for_stock_change = $object->hasProductsOrServices(2); + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); + $qualified_for_stock_change = $object->hasProductsOrServices(1); } // Check parameters - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) - { - if (!$idwarehouse || $idwarehouse == -1) - { + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) { + if (!$idwarehouse || $idwarehouse == -1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $action = ''; @@ -1248,58 +1236,53 @@ if (empty($reshook)) } } - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // 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) - { + if (!$error) { // Actions on extra fields $result = $object->insertExtraFields('ORDER_MODIFY'); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } - if ($error) $action = 'edit_extras'; + if ($error) { + $action = 'edit_extras'; + } } // add lines from objectlinked if ($action == 'import_lines_from_object' && $usercancreate && $object->statut == Commande::STATUS_DRAFT - ) - { + ) { $fromElement = GETPOST('fromelement'); $fromElementid = GETPOST('fromelementid'); $importLines = GETPOST('line_checkbox'); - if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) - { - if ($fromElement == 'commande') - { + if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) { + if ($fromElement == 'commande') { dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); $lineClassName = 'OrderLine'; - } elseif ($fromElement == 'propal') - { + } elseif ($fromElement == 'propal') { dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); $lineClassName = 'PropaleLigne'; } $nextRang = count($object->lines) + 1; $importCount = 0; $error = 0; - foreach ($importLines as $lineId) - { + foreach ($importLines as $lineId) { $lineId = intval($lineId); $originLine = new $lineClassName($db); - if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) - { + if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) { $originLine->fetch_optionals(); $desc = $originLine->desc; $pu_ht = $originLine->subprice; @@ -1343,8 +1326,7 @@ if (empty($reshook)) } } - if ($error) - { + if ($error) { setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); } } @@ -1366,10 +1348,8 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) - { - if ($action == 'addcontact') - { + if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) { + if ($action == 'addcontact') { if ($object->id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); @@ -1387,21 +1367,15 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - } - - // bascule du statut d'un contact - elseif ($action == 'swapstatut') - { + } elseif ($action == 'swapstatut') { + // bascule du statut d'un contact if ($object->id > 0) { $result = $object->swapContactStatus(GETPOST('ligne')); } else { dol_print_error($db); } - } - - // Efface un contact - elseif ($action == 'deletecontact') - { + } elseif ($action == 'deletecontact') { + // Efface un contact $result = $object->delete_contact($lineid); if ($result >= 0) { @@ -1425,16 +1399,18 @@ $form = new Form($db); $formfile = new FormFile($db); $formorder = new FormOrder($db); $formmargin = new FormMargin($db); -if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} // Mode creation -if ($action == 'create' && $usercancreate) -{ +if ($action == 'create' && $usercancreate) { print load_fiche_titre($langs->trans('CreateOrder'), '', 'order'); $soc = new Societe($db); - if ($socid > 0) + if ($socid > 0) { $res = $soc->fetch($socid); + } $remise_absolue = 0; @@ -1481,8 +1457,9 @@ if ($action == 'create' && $usercancreate) $classname = ucfirst($subelement); $objectsrc = new $classname($db); $objectsrc->fetch($originid); - if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) + if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { $objectsrc->fetch_lines(); + } $objectsrc->fetch_thirdparty(); // Replicate extrafields @@ -1505,12 +1482,17 @@ if ($action == 'create' && $usercancreate) $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 : ''; $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : ''); - if (empty($date_delivery)) $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : ''); + if (empty($date_delivery)) { + $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : ''); + } - if (!empty($conf->multicurrency->enabled)) - { - if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; + if (!empty($conf->multicurrency->enabled)) { + if (!empty($objectsrc->multicurrency_code)) { + $currency_code = $objectsrc->multicurrency_code; + } + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) { + $currency_tx = $objectsrc->multicurrency_tx; + } } $note_private = $object->getDefaultCreateValueFor('note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null)); @@ -1531,18 +1513,25 @@ if ($action == 'create' && $usercancreate) $remise_absolue = 0; $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 : ''; - if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; + if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) { + $currency_code = $soc->multicurrency_code; + } $note_private = $object->getDefaultCreateValueFor('note_private'); $note_public = $object->getDefaultCreateValueFor('note_public'); } //Warehouse default if null - if ($soc->fk_warehouse > 0) $warehouse_id = $soc->fk_warehouse; - if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) - { - if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE; - if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) $warehouse_id = $user->fk_warehouse; + if ($soc->fk_warehouse > 0) { + $warehouse_id = $soc->fk_warehouse; + } + if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { + if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) { + $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE; + } + if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) { + $warehouse_id = $user->fk_warehouse; + } } print '