39require 
'../../main.inc.php';
 
   40require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
 
   41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
 
   42require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
 
   43require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
 
   44require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
 
   45require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
 
   46require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
 
   47require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
 
   48require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
 
   50if (isModEnabled(
'supplier_proposal')) {
 
   51  require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
 
   53if (isModEnabled(
"product")) {
 
   54  require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
 
   56if (isModEnabled(
'project')) {
 
   57  require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
 
   58  require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
 
   60require_once NUSOAP_PATH.
'/nusoap.php'; 
 
   62if (isModEnabled(
'variants')) {
 
   63  require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
 
   68$langs->loadLangs(array(
'admin', 
'orders', 
'sendings', 
'companies', 
'bills', 
'propal', 
'receptions', 
'supplier_proposal', 
'deliveries', 
'products', 
'stocks', 
'productbatch'));
 
   69if (isModEnabled(
'incoterm')) {
 
   70  $langs->load(
'incoterm');
 
   77$action      = 
GETPOST(
'action', 
'alpha');
 
   78$confirm     = 
GETPOST(
'confirm', 
'alpha');
 
   79$contextpage = 
GETPOST(
'contextpage', 
'aZ') ? 
GETPOST(
'contextpage', 
'aZ') : 
'purchaseordercard'; 
 
   80$backtopage = 
GETPOST(
'backtopage', 
'alpha');
 
   81$backtopageforcancel = 
GETPOST(
'backtopageforcancel', 
'alpha');
 
   83$socid     = 
GETPOST(
'socid', 
'int');
 
   84$projectid = 
GETPOST(
'projectid', 
'int');
 
   85$cancel    = 
GETPOST(
'cancel', 
'alpha');
 
   86$lineid    = 
GETPOST(
'lineid', 
'int');
 
   87$origin    = 
GETPOST(
'origin', 
'alpha');
 
   92$hidedetails = (
GETPOST(
'hidedetails', 
'int') ? 
GETPOST(
'hidedetails', 
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
 
   93$hidedesc = (
GETPOST(
'hidedesc', 
'int') ? 
GETPOST(
'hidedesc', 
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
 
   94$hideref = (
GETPOST(
'hideref', 
'int') ? 
GETPOST(
'hideref', 
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
 
   96$datelivraison = 
dol_mktime(
GETPOST(
'liv_hour', 
'int'), 
GETPOST(
'liv_min', 
'int'), 
GETPOST(
'liv_sec', 
'int'), 
GETPOST(
'liv_month', 
'int'), 
GETPOST(
'liv_day', 
'int'), 
GETPOST(
'liv_year', 
'int'));
 
  100if (!empty($user->socid)) {
 
  101  $socid = $user->socid;
 
  105$hookmanager->initHooks(array(
'ordersuppliercard', 
'globalcard'));
 
  111$extrafields->fetch_name_optionals_label($object->table_element);
 
  114  $socid = $user->socid;
 
  118if ($id > 0 || !empty($ref)) {
 
  119  $ret = $object->fetch($id, $ref);
 
  123  $ret = $object->fetch_thirdparty();
 
  127} elseif (!empty($socid) && $socid > 0) {
 
  128  $object->socid = $socid;
 
  129  $ret = $object->fetch_thirdparty();
 
  136$isdraft = (isset($object->statut) && ($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
 
  137$result = 
restrictedArea($user, 
'fournisseur', $object, 
'commande_fournisseur', 
'commande', 
'fk_soc', 
'rowid', $isdraft);
 
  140$usercanread  = ($user->hasRight(
"fournisseur", 
"commande", 
"lire") || $user->hasRight(
"supplier_order", 
"lire"));
 
  141$usercancreate  = ($user->hasRight(
"fournisseur", 
"commande", 
"creer") || $user->hasRight(
"supplier_order", 
"creer"));
 
  142$usercandelete  = (($user->hasRight(
"fournisseur", 
"commande", 
"supprimer") || $user->hasRight(
"supplier_order", 
"supprimer")) || ($usercancreate && isset($object->statut) && $object->statut == $object::STATUS_DRAFT));
 
  145$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
"fournisseur", 
"supplier_order_advance", 
"validate")));
 
  148$usercanapprove     = $user->hasRight(
"fournisseur", 
"commande", 
"approuver");
 
  149$usercanapprovesecond = $user->hasRight(
"fournisseur", 
"commande", 
"approve2");
 
  150$usercanorder     = $user->hasRight(
"fournisseur", 
"commande", 
"commander");
 
  151if (empty($conf->reception->enabled)) {
 
  152  $usercanreceive = $user->hasRight(
"fournisseur", 
"commande", 
"receptionner");
 
  154  $usercanreceive = $user->hasRight(
"reception", 
"creer");
 
  158$permissionnote   = $usercancreate; 
 
  159$permissiondellink  = $usercancreate; 
 
  160$permissiontoedit = $usercancreate; 
 
  161$permissiontoadd  = $usercancreate; 
 
  164$caneditproject = 
false;
 
  165if (isModEnabled(
'project')) {
 
  166  $caneditproject = empty($conf->global->SUPPLIER_ORDER_FORBID_EDIT_PROJECT) || ($object->statut == 
CommandeFournisseur::STATUS_DRAFT && preg_match(
'/^[\(]?PROV/i', $object->ref));
 
  176$parameters = array(
'socid'=>$socid);
 
  177$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action); 
 
  182if (empty($reshook)) {
 
  183  $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ? 
'?socid='.((int) $socid)  : 
'');
 
  185  if (empty($backtopage) || ($cancel && empty($id))) {
 
  186    if (empty($backtopage) || ($cancel && strpos($backtopage, 
'__ID__'))) {
 
  187      if (empty($id) && (($action != 
'add' && $action != 
'create') || $cancel)) {
 
  188        $backtopage = $backurlforlist;
 
  190        $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) && $id > 0) ? $id : 
'__ID__');
 
  196    if (!empty($backtopageforcancel)) {
 
  197      header(
"Location: ".$backtopageforcancel);
 
  199    } elseif (!empty($backtopage)) {
 
  200      header(
"Location: ".$backtopage);
 
  206  include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php'; 
 
  208  include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php'; 
 
  210  include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php'; 
 
  212  if ($action == 
'setref_supplier' && $usercancreate) {
 
  213    $result = $object->setValueFrom(
'ref_supplier', 
GETPOST(
'ref_supplier', 
'alpha'), 
'', 
null, 
'text', 
'', $user, 
'ORDER_SUPPLIER_MODIFY');
 
  220  if ($action == 
'set_incoterms' && $usercancreate) {
 
  221    $result = $object->setIncoterms(
GETPOST(
'incoterm_id', 
'int'), 
GETPOST(
'location_incoterms', 
'alpha'));
 
  228  if ($action == 
'setconditions' && $usercancreate) {
 
  229    $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id', 
'int'));
 
  236  if ($action == 
'setmode' && $usercancreate) {
 
  237    $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id', 
'int'));
 
  241  } elseif ($action == 
'setmulticurrencycode' && $usercancreate) {
 
  243    $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code', 
'alpha'));
 
  244  } elseif ($action == 
'setmulticurrencyrate' && $usercancreate) {
 
  246    $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')), 
GETPOST(
'calculation_mode', 
'int'));
 
  250  if ($action == 
'setbankaccount' && $usercancreate) {
 
  251    $result = $object->setBankAccount(
GETPOST(
'fk_account', 
'int'));
 
  258  if ($action == 
'setdate_livraison' && $usercancreate) {
 
  259    $result = $object->setDeliveryDate($user, $datelivraison);
 
  266  if ($action == 
'classin' && $usercancreate && $caneditproject) {
 
  267    $result = $object->setProject($projectid);
 
  274  if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action == 
'set_thirdparty' && $usercancreate && $object->statut == 
CommandeFournisseur::STATUS_DRAFT) {
 
  275    $new_socid = 
GETPOST(
'new_socid', 
'int');
 
  276    if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
 
  280      $sql = 
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
 
  281      $sql .= 
' SET fk_soc = '.((int) $new_socid);
 
  282      $sql .= 
' WHERE fk_soc = '.((int) $object->thirdparty->id);
 
  283      $sql .= 
' AND rowid = '.((int) $object->id);
 
  285      $res = $db->query($sql);
 
  293        foreach ($object->lines as $l) {
 
  294          $sql = 
'SELECT price, unitprice, tva_tx, ref_fourn';
 
  295          $sql .= 
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
 
  296          $sql .= 
' WHERE fk_product = '.((int) $l->fk_product);
 
  297          $sql .= 
' AND fk_soc = '.((int) $new_socid);
 
  298          $sql .= 
' ORDER BY unitprice ASC';
 
  300          $resql = $db->query($sql);
 
  302            $num_row = $db->num_rows($resql);
 
  303            if (empty($num_row)) {
 
  309              $l->ref_supplier = 
'';
 
  313              $obj = $db->fetch_object($resql);
 
  314              $l->subprice = $obj->unitprice;
 
  315              $l->total_ht = $obj->price;
 
  316              $l->tva_tx = $obj->tva_tx;
 
  317              $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
 
  318              $l->total_ttc = $l->total_ht + $l->total_tva;
 
  319              $l->ref_supplier = $obj->ref_fourn;
 
  327        $object->update_price();
 
  330    header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
 
  334  if ($action == 
'setremisepercent' && $usercancreate) {
 
  341  if ($action == 
'reopen') {  
 
  342    if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) {
 
  343      if ($object->statut == 1) {
 
  345      } elseif ($object->statut == 2) {
 
  347      } elseif ($object->statut == 3) {
 
  349      } elseif ($object->statut == 4) {
 
  351      } elseif ($object->statut == 5) {
 
  357      } elseif ($object->statut == 6) {
 
  359      } elseif ($object->statut == 7) {
 
  361      } elseif ($object->statut == 9) {
 
  370      $result = $object->setStatus($user, $newstatus);
 
  373        $sql = 
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
 
  374        $sql .= 
' SET billed = 0';
 
  375        $sql .= 
' WHERE rowid = '.((int) $object->id);
 
  377        $resql = $db->query($sql);
 
  379        if ($newstatus == 0) {
 
  380          $sql = 
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
 
  381          $sql .= 
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
 
  382          $sql .= 
' WHERE rowid = '.((int) $object->id);
 
  384          $resql = $db->query($sql);
 
  389        header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
 
  402  if ($action == 
'classifybilled' && $usercancreate) {
 
  403    $ret = $object->classifyBilled($user);
 
  410  if ($action == 
'addline' && 
GETPOST(
'submitforalllines', 
'aZ09') && 
GETPOST(
'vatforalllines', 
'alpha') !== 
'' && $usercancreate) {
 
  412    $vat_rate = (
GETPOST(
'vatforalllines') ? 
GETPOST(
'vatforalllines') : 0);
 
  413    $vat_rate = str_replace(
'*', 
'', $vat_rate);
 
  414    $localtax1_rate = 
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
 
  415    $localtax2_rate = 
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
 
  416    foreach ($object->lines as $line) {
 
  417      $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->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
 
  419  } elseif ($action == 
'addline' && $usercancreate) {
 
  422    $langs->load(
'errors');
 
  427    $product_desc = (GETPOSTISSET(
'dp_desc') ? 
GETPOST(
'dp_desc', 
'restricthtml') : 
'');
 
  431    $prod_entry_mode = 
GETPOST(
'prod_entry_mode');
 
  432    if ($prod_entry_mode == 
'free') {
 
  435      $idprod = 
GETPOST(
'idprod', 
'int');
 
  446    $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ? 
price2num(
GETPOST(
'remise_percent'.$predef, 
'alpha'), 
'', 2) : 0);
 
  447    if (empty($remise_percent)) {
 
  452    $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
 
  453    $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
 
  455    if (is_array($extralabelsline)) {
 
  457      foreach ($extralabelsline as $key => $value) {
 
  458        unset($_POST[
"options_".$key]);
 
  462    if ($prod_entry_mode == 
'free' && 
GETPOST(
'price_ht') < 0 && $qty < 0) {
 
  463      setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')), 
null, 
'errors');
 
  466    if ($prod_entry_mode == 
'free' && !
GETPOST(
'idprodfournprice') && 
GETPOST(
'type') < 0) {
 
  467      setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), 
null, 
'errors');
 
  470    if ($prod_entry_mode == 
'free' && 
GETPOST(
'price_ht') === 
'' && 
GETPOST(
'price_ttc') === 
'' && $price_ht_devise === 
'') { 
 
  471      setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')), 
null, 
'errors');
 
  474    if ($prod_entry_mode == 
'free' && !
GETPOST(
'dp_desc')) {
 
  475      setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), 
null, 
'errors');
 
  478    if (
GETPOST(
'qty', 
'alpha') == 
'') {  
 
  479      setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), 
null, 
'errors');
 
  483    if (!$error && isModEnabled(
'variants') && $prod_entry_mode != 
'free') {
 
  484      if ($combinations = 
GETPOST(
'combinations', 
'array')) {
 
  488        if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
 
  489          $idprod = $res->fk_product_child;
 
  491          setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), 
null, 
'errors');
 
  497    if ($prod_entry_mode != 
'free' && empty($error)) {  
 
  501      if (
GETPOST(
'idprodfournprice', 
'alpha') == -1 || 
GETPOST(
'idprodfournprice', 
'alpha') == 
'') {
 
  506      if (preg_match(
'/^idprod_([0-9]+)$/', 
GETPOST(
'idprodfournprice', 
'alpha'), $reg)) {
 
  508        $res = $productsupplier->fetch($idprod); 
 
  511        if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
 
  513          $productsupplier->get_buyprice(0, -1, $idprod, 
'none', $fksoctosearch); 
 
  514          if ($productsupplier->fourn_socid != $socid) {  
 
  515            $productsupplier->ref_supplier = 
'';
 
  518          $fksoctosearch = $object->thirdparty->id;
 
  519          $productsupplier->get_buyprice(0, -1, $idprod, 
'none', $fksoctosearch); 
 
  521      } elseif (
GETPOST(
'idprodfournprice', 
'alpha') > 0) {
 
  524        $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice', 
'alpha'), $qtytosearch);
 
  525        $res = $productsupplier->fetch($idprod);
 
  529        $label = $productsupplier->label;
 
  532        if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
 
  533          $outputlangs = $langs;
 
  535          if (empty($newlang) && 
GETPOST(
'lang_id', 
'aZ09')) {
 
  536            $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
  538          if (empty($newlang)) {
 
  539            $newlang = $object->thirdparty->default_lang;
 
  541          if (!empty($newlang)) {
 
  543            $outputlangs->setDefaultLang($newlang);
 
  545          $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
 
  547          $desc = $productsupplier->description;
 
  550        if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
 
  551          $desc = $productsupplier->desc_supplier;
 
  555        if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
 
  559        if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
 
  560          $desc = $product_desc;
 
  562        if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
 
  563          $desc = 
dol_concatdesc($desc, $product_desc, 
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
 
  566        $ref_supplier = $productsupplier->ref_supplier;
 
  570        if (!GETPOSTISSET(
'tva_tx')) {  
 
  571          $tva_tx = 
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, 
GETPOST(
'idprodfournprice', 
'alpha'));
 
  572          $tva_npr = 
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, 
GETPOST(
'idprodfournprice', 
'alpha'));
 
  573          if (empty($tva_tx)) {
 
  578        $localtax1_tx = 
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
 
  579        $localtax2_tx = 
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
 
  581        $type = $productsupplier->type;
 
  582        if (
GETPOST(
'price_ht') != 
'' || 
GETPOST(
'multicurrency_price_ht') != 
'') {
 
  583          $price_base_type = 
'HT';
 
  585          $pu_devise = 
price2num($price_ht_devise, 
'CU');
 
  586        } elseif (
GETPOST(
'price_ttc') != 
'' || 
GETPOST(
'multicurrency_price_ttc') != 
'') {
 
  587          $price_base_type = 
'TTC';
 
  589          $pu_devise = 
price2num($price_ttc_devise, 
'CU');
 
  591          $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 
'HT');
 
  592          if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {  
 
  593            $pu = $productsupplier->fourn_pu;
 
  596            $pu = $productsupplier->fourn_pu;
 
  597            $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
 
  605        $result = $object->addline(
 
  607          ($price_base_type == 
'HT' ? $pu : 0),
 
  613          $productsupplier->product_fourn_price_id,
 
  617          ($price_base_type == 
'TTC' ? $pu : 0),
 
  624          $productsupplier->fk_unit,
 
  628          min($rank, count($object->lines) + 1)
 
  631      if ($idprod == -99 || $idprod == 0) {
 
  634        $langs->load(
"errors");
 
  635        setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")), 
null, 
'errors');
 
  640        $langs->load(
"errors");
 
  641        setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), 
null, 
'errors');
 
  643    } elseif (empty($error)) { 
 
  644      $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
 
  645      $tva_tx = str_replace(
'*', 
'', $tva_tx);
 
  646      $label = (
GETPOST(
'product_label') ? 
GETPOST(
'product_label') : 
'');
 
  647      $desc = $product_desc;
 
  649      $ref_supplier = 
GETPOST(
'fourn_ref', 
'alpha');
 
  651      $fk_unit = 
GETPOST(
'units', 
'alpha');
 
  653      if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
 
  658      $localtax1_tx = 
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
 
  659      $localtax2_tx = 
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
 
  661      if (
GETPOST(
'price_ht') != 
'' || 
GETPOST(
'multicurrency_price_ht') != 
'') {
 
  665        $pu_ht = 
price2num($pu_ttc / (1 + ($tva_tx / 100)), 
'MU'); 
 
  667      $price_base_type = 
'HT';
 
  668      $pu_ht_devise = 
price2num($price_ht_devise, 
'CU');
 
  670      $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, 
'', 
'', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
 
  674    if (!$error && $result > 0) {
 
  677      $ret = $object->fetch($object->id); 
 
  680      if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
  681        $outputlangs = $langs;
 
  684          $newlang = $object->thirdparty->default_lang;
 
  685          if (
GETPOST(
'lang_id', 
'aZ09'))
 
  686            $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
  688        if (!empty($newlang)) {
 
  690          $outputlangs->setDefaultLang($newlang);
 
  692        $model = $object->model_pdf;
 
  693        $ret = $object->fetch($id); 
 
  695        $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
  701      unset($_POST [
'prod_entry_mode']);
 
  703      unset($_POST[
'qty']);
 
  704      unset($_POST[
'type']);
 
  705      unset($_POST[
'remise_percent']);
 
  707      unset($_POST[
'price_ht']);
 
  708      unset($_POST[
'multicurrency_price_ht']);
 
  709      unset($_POST[
'price_ttc']);
 
  710      unset($_POST[
'fourn_ref']);
 
  711      unset($_POST[
'tva_tx']);
 
  712      unset($_POST[
'label']);
 
  713      unset($localtax1_tx);
 
  714      unset($localtax2_tx);
 
  715      unset($_POST[
'np_marginRate']);
 
  716      unset($_POST[
'np_markRate']);
 
  717      unset($_POST[
'dp_desc']);
 
  718      unset($_POST[
'idprodfournprice']);
 
  719      unset($_POST[
'units']);
 
  721      unset($_POST[
'date_starthour']);
 
  722      unset($_POST[
'date_startmin']);
 
  723      unset($_POST[
'date_startsec']);
 
  724      unset($_POST[
'date_startday']);
 
  725      unset($_POST[
'date_startmonth']);
 
  726      unset($_POST[
'date_startyear']);
 
  727      unset($_POST[
'date_endhour']);
 
  728      unset($_POST[
'date_endmin']);
 
  729      unset($_POST[
'date_endsec']);
 
  730      unset($_POST[
'date_endday']);
 
  731      unset($_POST[
'date_endmonth']);
 
  732      unset($_POST[
'date_endyear']);
 
  744  if ($action == 
'updateline' && $usercancreate && !
GETPOST(
'cancel', 
'alpha')) {
 
  751      $res = $line->fetch($lineid);
 
  758    if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
 
  759      if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, 
price2num(
GETPOST(
'qty', 
'int')), $line->fk_product, 
'none', 
GETPOST(
'socid', 
'int')) < 0) {
 
  760        setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), 
null, 
'warnings');
 
  769    if (preg_match(
'/\*/', $vat_rate)) {
 
  774    $vat_rate = str_replace(
'*', 
'', $vat_rate);
 
  775    $localtax1_rate = 
get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
 
  776    $localtax2_rate = 
get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
 
  778    if (
GETPOST(
'price_ht') != 
'') {
 
  779      $price_base_type = 
'HT';
 
  783      $vatratecleaned = $vat_rate;
 
  784      if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {      
 
  785        $vatratecleaned = trim($reg[1]);
 
  786        $vatratecode = $reg[2];
 
  790      $ht = (float) $ttc / (1 + ($vatratecleaned / 100));
 
  791      $price_base_type = 
'HT';
 
  797    $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
 
  798    $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
 
  800    if (is_array($extralabelsline)) {
 
  801      foreach ($extralabelsline as $key => $value) {
 
  802        unset($_POST[
"options_".$key]);
 
  806    $result = $object->updateline(
 
  808      GETPOST(
'product_desc', 
'restricthtml'),
 
  817      GETPOSTISSET(
"type") ? 
GETPOST(
"type") : $line->product_type,
 
  826    unset($_POST[
'qty']);
 
  827    unset($_POST[
'type']);
 
  828    unset($_POST[
'idprodfournprice']);
 
  829    unset($_POST[
'remmise_percent']);
 
  830    unset($_POST[
'dp_desc']);
 
  831    unset($_POST[
'np_desc']);
 
  833    unset($_POST[
'fourn_ref']);
 
  834    unset($_POST[
'tva_tx']);
 
  835    unset($_POST[
'date_start']);
 
  836    unset($_POST[
'date_end']);
 
  837    unset($_POST[
'units']);
 
  838    unset($localtax1_tx);
 
  839    unset($localtax2_tx);
 
  841    unset($_POST[
'date_starthour']);
 
  842    unset($_POST[
'date_startmin']);
 
  843    unset($_POST[
'date_startsec']);
 
  844    unset($_POST[
'date_startday']);
 
  845    unset($_POST[
'date_startmonth']);
 
  846    unset($_POST[
'date_startyear']);
 
  847    unset($_POST[
'date_endhour']);
 
  848    unset($_POST[
'date_endmin']);
 
  849    unset($_POST[
'date_endsec']);
 
  850    unset($_POST[
'date_endday']);
 
  851    unset($_POST[
'date_endmonth']);
 
  852    unset($_POST[
'date_endyear']);
 
  856      if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
  857        $outputlangs = $langs;
 
  860          $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
  863          $newlang = $object->thirdparty->default_lang;
 
  865        if (!empty($newlang)) {
 
  867          $outputlangs->setDefaultLang($newlang);
 
  869        $model = $object->model_pdf;
 
  870        $ret = $object->fetch($id); 
 
  872        $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
  887  if ($action == 
'confirm_deleteline' && $confirm == 
'yes' && $usercancreate) {
 
  890    $result = $object->deleteline($lineid);
 
  893      $object->line_order(
true);
 
  895      $outputlangs = $langs;
 
  898        $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
  901        $newlang = $object->thirdparty->default_lang;
 
  903      if (!empty($newlang)) {
 
  905        $outputlangs->setDefaultLang($newlang);
 
  907      if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
  908        $ret = $object->fetch($object->id); 
 
  909        $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
  931      header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
 
  939  if ($action == 
'confirm_valid' && $confirm == 
'yes' && $usercanvalidate) {
 
  942    $object->date_commande = 
dol_now();
 
  943    $result = $object->valid($user);
 
  946      if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
  947        $outputlangs = $langs;
 
  950          $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
  953          $newlang = $object->thirdparty->default_lang;
 
  955        if (!empty($newlang)) {
 
  957          $outputlangs->setDefaultLang($newlang);
 
  959        $model = $object->model_pdf;
 
  960        $ret = $object->fetch($id); 
 
  962        $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
  974    if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) {
 
  975      $action = 
'confirm_approve'; 
 
  985  if (($action == 
'confirm_approve' || $action == 
'confirm_approve2') && $confirm == 
'yes' && $usercanapprove) {
 
  988    $idwarehouse = 
GETPOST(
'idwarehouse', 
'int');
 
  990    $qualified_for_stock_change = 0;
 
  991    if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
 
  992      $qualified_for_stock_change = $object->hasProductsOrServices(2);
 
  994      $qualified_for_stock_change = $object->hasProductsOrServices(1);
 
  998    if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {  
 
  999      if (!$idwarehouse || $idwarehouse == -1) {
 
 1001        setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), 
null, 
'errors');
 
 1007      $result = $object->approve($user, $idwarehouse, ($action == 
'confirm_approve2' ? 1 : 0));
 
 1009        if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
 1010          $outputlangs = $langs;
 
 1013            $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
 1016            $newlang = $object->thirdparty->default_lang;
 
 1018          if (!empty($newlang)) {
 
 1019            $outputlangs = 
new Translate(
"", $conf);
 
 1020            $outputlangs->setDefaultLang($newlang);
 
 1022          $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
 1033      header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
 
 1040  if ($action == 
'confirm_refuse' && $confirm == 
'yes' && $usercanapprove) {
 
 1042      $object->refuse_note = 
GETPOST(
'refuse_note');
 
 1044    $result = $object->refuse($user);
 
 1046      header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
 
 1054  if ($action == 
'commande') {
 
 1055    $methodecommande = 
GETPOST(
'methodecommande', 
'int');
 
 1059    } elseif ($methodecommande <= 0) {
 
 1060      setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")), 
null, 
'errors');
 
 1061      $action = 
'createorder';
 
 1065  if ($action == 
'confirm_commande' && $confirm == 
'yes' && $usercanorder) {
 
 1068    $result = $object->commande($user, 
GETPOST(
"datecommande"), 
GETPOST(
"methode", 
'int'), 
GETPOST(
'comment', 
'alphanohtml'));
 
 1070      if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
 
 1071        $outputlangs = $langs;
 
 1074          $newlang = 
GETPOST(
'lang_id', 
'aZ09');
 
 1077          $newlang = $object->thirdparty->default_lang;
 
 1079        if (!empty($newlang)) {
 
 1080          $outputlangs = 
new Translate(
"", $conf);
 
 1081          $outputlangs->setDefaultLang($newlang);
 
 1083        $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 
 1094      header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
 
 1102  if ($action == 
'confirm_delete' && $confirm == 
'yes' && $usercandelete) {
 
 1103    $result = $object->delete($user);
 
 1105      header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
 
 1113  if ($action == 
'confirm_clone' && $confirm == 
'yes' && $usercancreate) {
 
 1114    if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
 
 1115      setEventMessages($langs->trans(
"NoCloneOptionsSpecified"), 
null, 
'errors');
 
 1117      if ($object->id > 0) {
 
 1118        $orig = clone $object;
 
 1120        $result = $object->createFromClone($user, $socid);
 
 1122          header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
 
 1134  if ($action == 
'livraison' && $usercanreceive) {
 
 1143        $result = $object->Livraison($user, $date_liv, 
GETPOST(
"type"), 
GETPOST(
"comment")); 
 
 1145          $langs->load(
"deliveries");
 
 1148        } elseif ($result == -3) {
 
 1157        setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")), 
null, 
'errors');
 
 1168  if ($action == 
'confirm_cancel' && $confirm == 
'yes' && $usercanorder) {
 
 1170      $object->cancel_note = 
GETPOST(
'cancel_note');
 
 1172    $result = $object->cancel($user);
 
 1174      header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
 
 1182  include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
 
 1185  $triggersendname = 
'ORDER_SUPPLIER_SENTBYMAIL';
 
 1186  $autocopy = 
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
 
 1187  $trackid = 
'sord'.$object->id;
 
 1188  include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
 
 1191  $upload_dir = $conf->fournisseur->commande->dir_output;
 
 1192  $permissiontoadd = $usercancreate;
 
 1193  include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
 
 1196  if ($action == 
'update_extras') {
 
 1200    $ret = $extrafields->setOptionalsFromPost(
null, $object, 
GETPOST(
'attribute', 
'restricthtml'));
 
 1208        $result = $object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
 
 1217      $action = 
'edit_extras';
 
 1224  if ($action == 
'add' && $usercancreate) {
 
 1226    $selectedLines = 
GETPOST(
'toselect', 
'array');
 
 1228      setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')), 
null, 
'errors');
 
 1237      $object->ref_supplier   = 
GETPOST(
'refsupplier');
 
 1238      $object->socid          = $socid;
 
 1239      $object->cond_reglement_id = 
GETPOST(
'cond_reglement_id', 
'int');
 
 1240      $object->mode_reglement_id = 
GETPOST(
'mode_reglement_id', 
'int');
 
 1241      $object->fk_account        = 
GETPOST(
'fk_account', 
'int');
 
 1242      $object->note_private = 
GETPOST(
'note_private', 
'restricthtml');
 
 1243      $object->note_public    = 
GETPOST(
'note_public', 
'restricthtml');
 
 1244      $object->date_livraison = $datelivraison; 
 
 1245      $object->delivery_date = $datelivraison;
 
 1246      $object->fk_incoterms = 
GETPOST(
'incoterm_id', 
'int');
 
 1247      $object->location_incoterms = 
GETPOST(
'location_incoterms', 
'alpha');
 
 1248      $object->multicurrency_code = 
GETPOST(
'multicurrency_code', 
'alpha');
 
 1249      $object->multicurrency_tx = 
price2num(
GETPOST(
'originmulticurrency_tx', 
'alpha'));
 
 1250      $object->fk_project       = 
GETPOST(
'projectid', 
'int');
 
 1254        $ret = $extrafields->setOptionalsFromPost(
null, $object);
 
 1262        if (!empty($origin) && !empty($originid)) {
 
 1263          $element = $subelement = $origin;
 
 1264          $classname = ucfirst($subelement);
 
 1265          if ($origin == 
'propal' || $origin == 
'proposal') {
 
 1266            $element = 
'comm/propal'; $subelement = 
'propal';
 
 1267            $classname = 
'Propal';
 
 1269          if ($origin == 
'order' || $origin == 
'commande') {
 
 1270            $element = $subelement = 
'commande';
 
 1271            $classname = 
'Commande';
 
 1273          if ($origin == 
'supplier_proposal') {
 
 1274            $classname = 
'SupplierProposal';
 
 1275            $element = 
'supplier_proposal';
 
 1276            $subelement = 
'supplier_proposal';
 
 1279          $object->origin = $origin;
 
 1280          $object->origin_id = $originid;
 
 1283          $object->linked_objects [$object->origin] = $object->origin_id;
 
 1284          $other_linked_objects = 
GETPOST(
'other_linked_objects', 
'array');
 
 1285          if (!empty($other_linked_objects)) {
 
 1286            $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
 
 1289          $id = $object->create($user);
 
 1293            $srcobject = 
new $classname($db);
 
 1295            dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
 
 1296            $result = $srcobject->fetch($object->origin_id);
 
 1298              $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
 
 1299              $object->setDeliveryDate($user, $tmpdate);
 
 1300              $object->set_id_projet($user, $srcobject->fk_project);
 
 1302              $lines = $srcobject->lines;
 
 1303              if (empty($lines) && method_exists($srcobject, 
'fetch_lines')) {
 
 1304                $srcobject->fetch_lines();
 
 1305                $lines = $srcobject->lines;
 
 1308              $fk_parent_line = 0;
 
 1309              $num = count($lines);
 
 1311              for ($i = 0; $i < $num; $i++) {
 
 1312                if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines)) {
 
 1316                $label = (!empty($lines[$i]->label) ? $lines[$i]->label : 
'');
 
 1317                $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
 
 1318                $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
 
 1321                if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
 
 1322                  $fk_parent_line = 0;
 
 1326                if (method_exists($lines[$i], 
'fetch_optionals')) {               
 
 1327                  $lines[$i]->fetch_optionals();
 
 1328                  $array_option = $lines[$i]->array_options;
 
 1332                $product_fourn_price_id = 0;
 
 1333                if ($origin == 
"commande") {
 
 1335                  $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
 
 1337                    $ref_supplier = $productsupplier->ref_supplier;
 
 1338                    $product_fourn_price_id = $productsupplier->product_fourn_price_id;
 
 1341                  $ref_supplier = $lines[$i]->ref_fourn;
 
 1342                  $product_fourn_price_id = 0;
 
 1345                $tva_tx = $lines[$i]->tva_tx;
 
 1347                if ($origin == 
"commande") {
 
 1349                  $soc->fetch($socid);
 
 1350                  $tva_tx = 
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
 
 1353                $result = $object->addline(
 
 1355                  $lines[$i]->subprice,
 
 1358                  $lines[$i]->localtax1_tx,
 
 1359                  $lines[$i]->localtax2_tx,
 
 1360                  $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
 
 1361                  $product_fourn_price_id,
 
 1363                  $lines[$i]->remise_percent,
 
 1366                  $lines[$i]->product_type,
 
 1372                  $lines[$i]->fk_unit,
 
 1375                  !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->
rowid,
 
 1377                  $lines[$i]->special_code
 
 1387                if ($result > 0 && $lines[$i]->product_type == 9) {
 
 1388                  $fk_parent_line = $result;
 
 1396              $parameters = array(
'objFrom' => $srcobject);
 
 1397              $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action); 
 
 1412          $id = $object->create($user);
 
 1421        $langs->load(
"errors");
 
 1424        $_GET[
'socid'] = $_POST[
'socid'];
 
 1427        header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode($id));
 
 1433  if ($action == 
'webservice' && 
GETPOST(
'mode', 
'alpha') == 
"send" && !
GETPOST(
'cancel', 
'alpha')) {
 
 1434    $ws_url         = $object->thirdparty->webservices_url;
 
 1435    $ws_key         = $object->thirdparty->webservices_key;
 
 1436    $ws_user        = 
GETPOST(
'ws_user', 
'alpha');
 
 1437    $ws_password    = 
GETPOST(
'ws_password', 
'alpha');
 
 1438    $ws_entity      = 
GETPOST(
'ws_entity', 
'int');
 
 1439    $ws_thirdparty  = 
GETPOST(
'ws_thirdparty', 
'int');
 
 1442    $ws_ns = 
'http://www.dolibarr.org/ns/';
 
 1443    $ws_authentication = array(
 
 1444      'dolibarrkey'=>$ws_key,
 
 1445      'sourceapplication'=>
'DolibarrWebServiceClient',
 
 1447      'password'=>$ws_password,
 
 1448      'entity'=>$ws_entity
 
 1452    if (empty($conf->syncsupplierwebservices->enabled)) {
 
 1453      setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2650Name")), 
null, 
'mesgs');
 
 1454    } elseif (empty($ws_url) || empty($ws_key)) {
 
 1455      setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), 
null, 
'errors');
 
 1456    } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
 
 1460      $soapclient_order = 
new nusoap_client($ws_url.
"/webservices/server_order.php");
 
 1461      $soapclient_order->soap_defencoding = 
'UTF-8';
 
 1462      $soapclient_order->decodeUTF8(
false);
 
 1465      $soapclient_product = 
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
 
 1466      $soapclient_product->soap_defencoding = 
'UTF-8';
 
 1467      $soapclient_product->decodeUTF8(
false);
 
 1470      $order_lines = array();
 
 1471      foreach ($object->lines as $line) {
 
 1472        $ws_parameters = array(
'authentication' => $ws_authentication, 
'id' => 
'', 
'ref' => $line->ref_supplier);
 
 1473        $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns, 
'');
 
 1475        if ($result_product[
"result"][
"result_code"] == 
"OK") {
 
 1476          $order_lines[] = array(
 
 1477            'desc'          => $line->product_desc,
 
 1478            'type'          => $line->product_type,
 
 1479            'product_id'    => $result_product[
"product"][
"id"],
 
 1480            'vat_rate'      => $line->tva_tx,
 
 1481            'qty'           => $line->qty,
 
 1482            'price'         => $line->price,
 
 1483            'unitprice'     => $line->subprice,
 
 1484            'total_net'     => $line->total_ht,
 
 1485            'total_vat'     => $line->total_tva,
 
 1486            'total'         => $line->total_ttc,
 
 1487            'date_start'    => $line->date_start,
 
 1488            'date_end'      => $line->date_end,
 
 1495        'thirdparty_id' => $ws_thirdparty,
 
 1497        'total_net'     => $object->total_ht,
 
 1498        'total_var'     => $object->total_tva,
 
 1499        'total'         => $object->total_ttc,
 
 1500        'lines'         => $order_lines
 
 1503      $ws_parameters = array(
'authentication'=>$ws_authentication, 
'order' => $order);
 
 1504      $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns, 
'');
 
 1506      if (empty($result_order[
"result"][
"result_code"])) { 
 
 1507        setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", 
null, 
'errors');
 
 1508      } elseif ($result_order[
"result"][
"result_code"] != 
"OK") { 
 
 1509        setEventMessages($langs->trans(
"SOAPError").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'", 
null, 
'errors');
 
 1511        setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"], 
null, 
'mesgs');
 
 1516  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
 
 1517    if ($action == 
'addcontact') {
 
 1518      if ($object->id > 0) {
 
 1521        $result = $object->add_contact($contactid, $typeid, 
GETPOST(
"source", 
'aZ09'));
 
 1525        header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
 
 1528        if ($object->error == 
'DB_ERROR_RECORD_ALREADY_EXISTS') {
 
 1529          $langs->load(
"errors");
 
 1530          setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), 
null, 
'errors');
 
 1535    } elseif ($action == 
'swapstatut' && $object->id > 0) {
 
 1537      $result = $object->swapContactStatus(
GETPOST(
'ligne', 
'int'));
 
 1538    } elseif ($action == 
'deletecontact' && $object->id > 0) {
 
 1540      $result = $object->delete_contact(
GETPOST(
"lineid", 
'int'));
 
 1543        header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
 
 1557$form = 
new Form($db);
 
 1560$productstatic = 
new Product($db);
 
 1561if (isModEnabled(
'project')) {
 
 1565$title = $object->ref.
" - ".$langs->trans(
'Card');
 
 1566if ($action == 
'create') {
 
 1567  $title = $langs->trans(
"NewOrderSupplier");
 
 1569$help_url = 
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
 
 1574if ($action == 
'create') {
 
 1575  print 
load_fiche_titre($langs->trans(
'NewOrderSupplier'), 
'', 
'supplier_order');
 
 1579  $currency_code = $conf->currency;
 
 1584    $societe->fetch($socid);
 
 1587  if (!empty($origin) && !empty($originid)) {
 
 1589    $element = $subelement = $origin;
 
 1590    $classname = ucfirst($subelement);
 
 1592    if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
 
 1593      $element = $regs[1];
 
 1594      $subelement = $regs[2];
 
 1597    if ($origin == 
'propal' || $origin == 
'proposal') {
 
 1598      $classname = 
'Propal';
 
 1599      $element = 
'comm/propal'; $subelement = 
'propal';
 
 1601    if ($origin == 
'order' || $origin == 
'commande') {
 
 1602      $classname = 
'Commande';
 
 1603      $element = $subelement = 
'commande';
 
 1605    if ($origin == 
'supplier_proposal') {
 
 1606      $classname = 
'SupplierProposal';
 
 1607      $element = 
'supplier_proposal';
 
 1608      $subelement = 
'supplier_proposal';
 
 1614    $objectsrc = 
new $classname($db);
 
 1615    $objectsrc->fetch($originid);
 
 1616    if (empty($objectsrc->lines) && method_exists($objectsrc, 
'fetch_lines')) {
 
 1617      $objectsrc->fetch_lines();
 
 1619    $objectsrc->fetch_thirdparty();
 
 1622    $objectsrc->fetch_optionals();
 
 1623    $object->array_options = $objectsrc->array_options;
 
 1625    $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 
'');
 
 1626    $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : 
'');
 
 1628    $soc = $objectsrc->thirdparty;
 
 1630    $cond_reglement_id  = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
 
 1631    $mode_reglement_id  = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
 
 1632    $fk_account         = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
 
 1633    $availability_id  = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
 
 1634    $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
 
 1635    $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
 
 1636    $remise_percent   = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
 
 1637    $remise_absolue   = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
 
 1638    $dateinvoice    = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : 
'';
 
 1640    $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : 
''));
 
 1642    if (isModEnabled(
"multicurrency")) {
 
 1643      if (!empty($objectsrc->multicurrency_code)) {
 
 1644        $currency_code = $objectsrc->multicurrency_code;
 
 1646      if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
 
 1647        $currency_tx = $objectsrc->multicurrency_tx;
 
 1651    $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
 
 1652    $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
 
 1655    $srccontactslist = $objectsrc->liste_contact(-1, 
'external', 1);
 
 1657    $cond_reglement_id  = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
 
 1658    $mode_reglement_id  = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
 
 1660    if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
 
 1661      $currency_code = $societe->multicurrency_code;
 
 1664    $note_private = $object->getDefaultCreateValueFor(
'note_private');
 
 1665    $note_public = $object->getDefaultCreateValueFor(
'note_public');
 
 1669  if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) {
 
 1670    $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
 
 1672  if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) {
 
 1673    $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
 
 1676  print 
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
 
 1677  print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 1678  print 
'<input type="hidden" name="action" value="add">';
 
 1679  print 
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ? 
'' : $soc->remise_supplier_percent).
'">';
 
 1680  print 
'<input type="hidden" name="origin" value="'.$origin.
'">';
 
 1681  print 
'<input type="hidden" name="originid" value="'.$originid.
'">';
 
 1683    print 
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
 
 1685  if ($backtopageforcancel) {
 
 1686    print 
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
 
 1689  if (!empty($currency_tx)) {
 
 1690    print 
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
 
 1695  print 
'<table class="border centpercent">';
 
 1698  print 
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
 
 1701  print 
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
 
 1704  if (!empty($societe->id) && $societe->id > 0) {
 
 1705    print $societe->getNomUrl(1, 
'supplier');
 
 1706    print 
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
 
 1708    $filter = 
'((s.fournisseur:=:1) AND (s.status:=:1))';
 
 1709    print 
img_picto(
'', 
'company', 
'class="pictofixedwidth"').$form->select_company((empty($socid) ? 
'' : $socid), 
'socid', $filter, 
'SelectThirdParty', 1, 0, null, 0, 
'minwidth175 maxwidth500 widthcentpercentminusxx');
 
 1711    if (empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED)) {
 
 1713      $(document).ready(function() { 
 1714        $("#socid").change(function() { 
 1715          console.log("We have changed the company - Reload page"); 
 1717          $("input[name=action]").val("create"); 
 1718          $("form[name=add]").submit(); 
 1723    print 
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
 
 1727  if (!empty($societe->id) && $societe->id > 0) {
 
 1729    print 
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
 
 1731    $absolute_discount = $societe->getAvailableDiscounts(
'', 
'', 0, 1);
 
 1733    $thirdparty = $societe;
 
 1735    $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
 
 1736    include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
 
 1742  print 
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
 
 1746  print 
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
 
 1747  print 
img_picto(
'', 
'payment', 
'class="pictofixedwidth"');
 
 1748  print $form->getSelectConditionsPaiements((GETPOSTISSET(
'cond_reglement_id') &&  
GETPOST(
'cond_reglement_id') != 0) ? 
GETPOST(
'cond_reglement_id') : $cond_reglement_id, 
'cond_reglement_id', -1, 1);
 
 1752  print 
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
 
 1753  print 
img_picto(
'', 
'bank', 
'class="pictofixedwidth"');
 
 1754  $form->select_types_paiements((GETPOSTISSET(
'mode_reglement_id') && 
GETPOST(
'mode_reglement_id') != 0) ? 
GETPOST(
'mode_reglement_id') : $mode_reglement_id, 
'mode_reglement_id');
 
 1759  print $langs->trans(
'DateDeliveryPlanned');
 
 1763  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
 
 1766  print 
img_picto(
'', 
'action', 
'class="pictofixedwidth"');
 
 1767  print $form->selectDate($datelivraison ? $datelivraison : -1, 
'liv_', $usehourmin, $usehourmin, 
'', 
"set");
 
 1771  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && isModEnabled(
"banque")) {
 
 1772    $langs->load(
"bank");
 
 1773    print 
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
 
 1774    print 
img_picto(
'', 
'bank_account', 
'class="pictofixedwidth"');
 
 1775    $form->select_comptes($fk_account, 
'fk_account', 0, 
'', 1);
 
 1780  if (isModEnabled(
'project')) {
 
 1783    $langs->load(
'projects');
 
 1784    print 
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
 
 1785    print 
img_picto(
'', 
'project', 
'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 
'projectid', 0, 0, 1, 1, 0, 0, 0, 
'', 1, 0, 
'maxwidth500');
 
 1786    print 
'   <a href="'.DOL_URL_ROOT.
'/projet/card.php?action=create&status=1'.(!empty($societe->id) ? 
'&socid='.$societe->id : 
"").
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create'.(!empty($societe->id) ? 
'&socid='.$societe->id : 
"")).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
 
 1791  if (isModEnabled(
'incoterm')) {
 
 1792    $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms : 
''));
 
 1793    $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms : 
''));
 
 1795    print 
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $object->label_incoterms, 1).
'</label></td>';
 
 1796    print 
'<td class="maxwidthonsmartphone">';
 
 1797    print 
img_picto(
'', 
'incoterm', 
'class="pictofixedwidth"');
 
 1798    print $form->select_incoterms($fkincoterms, $locincoterms);
 
 1803  if (isModEnabled(
"multicurrency")) {
 
 1805    print 
'<td>'.$form->editfieldkey(
'Currency', 
'multicurrency_code', 
'', $object, 0).
'</td>';
 
 1806    print 
'<td class="maxwidthonsmartphone">';
 
 1807    print 
img_picto(
'', 
'currency', 
'class="pictofixedwidth"');
 
 1808    print $form->selectMultiCurrency($currency_code, 
'multicurrency_code');
 
 1812  print 
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
 
 1814  $doleditor = 
new DolEditor(
'note_public', isset($note_public) ? $note_public : 
GETPOST(
'note_public', 
'restricthtml'), 
'', 80, 
'dolibarr_notes', 
'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, 
'90%');
 
 1815  print $doleditor->Create(1);
 
 1820  print 
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
 
 1822  $doleditor = 
new DolEditor(
'note_private', isset($note_private) ? $note_private : 
GETPOST(
'note_private', 
'restricthtml'), 
'', 80, 
'dolibarr_notes', 
'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, 
'90%');
 
 1823  print $doleditor->Create(1);
 
 1828  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
 
 1829    print 
"\n<!-- ".$classname.
" info -->";
 
 1831    print 
'<input type="hidden" name="amount"         value="'.$objectsrc->total_ht.
'">'.
"\n";
 
 1832    print 
'<input type="hidden" name="total"          value="'.$objectsrc->total_ttc.
'">'.
"\n";
 
 1833    print 
'<input type="hidden" name="tva"            value="'.$objectsrc->total_tva.
'">'.
"\n";
 
 1834    print 
'<input type="hidden" name="origin"         value="'.$objectsrc->element.
'">';
 
 1835    print 
'<input type="hidden" name="originid"       value="'.$objectsrc->id.
'">';
 
 1837    $newclassname = $classname;
 
 1838    print 
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1, 
'supplier').
'</td></tr>';
 
 1839    print 
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
 
 1840    print 
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
 
 1841    if ($mysoc->localtax1_assuj == 
"1" || $objectsrc->total_localtax1 != 0) {     
 
 1842      print 
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
 
 1845    if ($mysoc->localtax2_assuj == 
"1" || $objectsrc->total_localtax2 != 0) {     
 
 1846      print 
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
 
 1849    print 
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
 
 1851    if (isModEnabled(
"multicurrency")) {
 
 1852      print 
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
 
 1853      print 
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
 
 1854      print 
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
 
 1859  $parameters = array();
 
 1860  $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action); 
 
 1861  print $hookmanager->resPrint;
 
 1863  if (empty($reshook)) {
 
 1864    print $object->showOptionals($extrafields, 
'create');
 
 1872  print $form->buttonsSaveCancel(
"CreateDraft");
 
 1875  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
 
 1876    $title = $langs->trans(
'ProductsAndServices');
 
 1879    print 
'<div class="div-table-responsive-no-min">';
 
 1880    print 
'<table class="noborder centpercent">';
 
 1882    $selectedLines = array();
 
 1884    $objectsrc->printOriginLinesList(
'', $selectedLines);
 
 1890} elseif (!empty($object->id)) {
 
 1892  $result = $object->fetch($id, $ref);
 
 1893  $object->fetch_thirdparty();
 
 1895  $societe = $object->thirdparty;
 
 1897  $author = 
new User($db);
 
 1898  $author->fetch($object->user_author_id);
 
 1902  $title = $langs->trans(
"SupplierOrder");
 
 1909  if ($action == 
'delete') {
 
 1910    $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'), 
'confirm_delete', 
'', 0, 2);
 
 1914  if ($action == 
'clone') {
 
 1915    $filter = 
'(s.fournisseur:=:1)';
 
 1917    $formquestion = array(
 
 1918      array(
'type' => 
'other', 
'name' => 
'socid', 
'label' => $langs->trans(
"SelectThirdParty"), 
'value' => $form->select_company(
GETPOST(
'socid', 
'int'), 
'socid', $filter))
 
 1921    $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref), 
'confirm_clone', $formquestion, 
'yes', 1);
 
 1925  if ($action == 
'valid') {
 
 1926    $object->date_commande = 
dol_now();
 
 1929    if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) { 
 
 1930      $newref = $object->getNextNumRef($object->thirdparty);
 
 1932      $newref = $object->ref;
 
 1939      $text = $langs->trans(
'ConfirmValidateOrder', $newref);
 
 1940      if (isModEnabled(
'notification')) {
 
 1941        require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
 
 1942        $notify = 
new Notify($db);
 
 1944        $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
 
 1947      $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text, 
'confirm_valid', 
'', 0, 1);
 
 1952  if ($action == 
'approve' || $action == 
'approve2') {
 
 1953    $qualified_for_stock_change = 0;
 
 1954    if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
 
 1955      $qualified_for_stock_change = $object->hasProductsOrServices(2);
 
 1957      $qualified_for_stock_change = $object->hasProductsOrServices(1);
 
 1960    $formquestion = array();
 
 1961    if (isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
 
 1962      $langs->load(
"stocks");
 
 1963      require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
 
 1966      if ($conf->browser->name == 
'ie') {
 
 1969      $formquestion = array(
 
 1973        array(
'type' => 
'other', 
'name' => 
'idwarehouse', 
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"), 
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse', 
'int'), 
'idwarehouse', 
'', 1, 0, 0, 
'', 0, $forcecombo))
 
 1976    $text = $langs->trans(
"ConfirmApproveThisOrder", $object->ref);
 
 1977    if (isModEnabled(
'notification')) {
 
 1978      require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
 
 1979      $notify = 
new Notify($db);
 
 1981      $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE', $object->socid, $object);
 
 1984    $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ApproveThisOrder"), $text, 
"confirm_".$action, $formquestion, 1, 1, 240);
 
 1988  if ($action == 
'refuse') {
 
 1989    $formquestion = array(
 
 1992        'name' => 
'refuse_note',
 
 1993        'label' => $langs->trans(
"Reason"),
 
 1995        'morecss' => 
'minwidth300' 
 1998    $formconfirm  = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder", $object->ref), 
"confirm_refuse", $formquestion, 0, 1);
 
 2002  if ($action == 
'cancel') {
 
 2003    $formquestion = array(
 
 2006        'name' => 
'cancel_note',
 
 2007        'label' => $langs->trans(
"Reason"),
 
 2009        'morecss' => 
'minwidth300' 
 2012    $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder", $object->ref), 
"confirm_cancel", $formquestion, 0, 1);
 
 2016  if ($action == 
'commande') {
 
 2018    $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id.
"&datecommande=".$date_com.
"&methode=".
GETPOST(
"methodecommande").
"&comment=".urlencode(
GETPOST(
"comment")), $langs->trans(
"MakeOrder"), $langs->trans(
"ConfirmMakeOrder", 
dol_print_date($date_com, 
'day')), 
"confirm_commande", 
'', 0, 2);
 
 2022  if ($action == 
'ask_deleteline') {
 
 2023     $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'), 
'confirm_deleteline', 
'', 0, 1);
 
 2026  $parameters = array(
'formConfirm' => $formconfirm, 
'lineid'=>$lineid);
 
 2027  $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action); 
 
 2028  if (empty($reshook)) {
 
 2029    $formconfirm .= $hookmanager->resPrint;
 
 2030  } elseif ($reshook > 0) {
 
 2031    $formconfirm = $hookmanager->resPrint;
 
 2040  $linkback = 
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? 
'&socid='.$socid : 
'').
'">'.$langs->trans(
"BackToList").
'</a>';
 
 2042  $morehtmlref = 
'<div class="refidno">';
 
 2044  $morehtmlref .= $form->editfieldkey(
"RefSupplier", 
'ref_supplier', $object->ref_supplier, $object, $usercancreate, 
'string', 
'', 0, 1);
 
 2045  $morehtmlref .= $form->editfieldval(
"RefSupplier", 
'ref_supplier', $object->ref_supplier, $object, $usercancreate, 
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? 
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : 
''), 
'', null, null, 
'', 1);
 
 2047  $morehtmlref .= 
'<br>';
 
 2048  if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action == 
'edit_thirdparty') {
 
 2049    $morehtmlref .= 
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
 
 2050    $morehtmlref .= 
'<input type="hidden" name="action" value="set_thirdparty">';
 
 2051    $morehtmlref .= 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2052    $filter = 
'(s.fournisseur:=:1)';
 
 2053    $morehtmlref .= $form->select_company($object->thirdparty->id, 
'new_socid', $filter, 
'', 0, 0, array(), 0, 
'minwidth300');
 
 2054    $morehtmlref .= 
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
 
 2055    $morehtmlref .= 
'</form>';
 
 2057  if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action != 
'edit_thirdparty') {
 
 2059      $morehtmlref .= 
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
 
 2061    $morehtmlref .= $object->thirdparty->getNomUrl(1, 
'supplier');
 
 2062    if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
 
 2063      $morehtmlref .= 
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
 
 2068  if (isModEnabled(
'project')) {
 
 2069    $langs->load(
"projects");
 
 2070    $morehtmlref .= 
'<br>';
 
 2071    if ($permissiontoadd) {
 
 2072      $morehtmlref .= 
img_picto($langs->trans(
"Project"), 
'project', 
'class="pictofixedwidth"');
 
 2073      if ($action != 
'classify' && $caneditproject) {
 
 2074        $morehtmlref .= 
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
 
 2076      $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 
'classify' ? 
'projectid' : 
'none'), 0, 0, 0, 1, 
'', 
'maxwidth300');
 
 2078      if (!empty($object->fk_project)) {
 
 2080        $proj->fetch($object->fk_project);
 
 2081        $morehtmlref .= $proj->getNomUrl(1);
 
 2083          $morehtmlref .= 
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
 
 2088  $morehtmlref .= 
'</div>';
 
 2091  dol_banner_tab($object, 
'ref', $linkback, 1, 
'ref', 
'ref', $morehtmlref);
 
 2094  print 
'<div class="fichecenter">';
 
 2095  print 
'<div class="fichehalfleft">';
 
 2096  print 
'<div class="underbanner clearboth"></div>';
 
 2098  print 
'<table class="border tableforfield centpercent">';
 
 2101  if ($object->methode_commande_id > 0) {
 
 2103    if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
 
 2106    print 
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
 
 2107    print $object->date_commande ? 
dol_print_date($object->date_commande, $usehourmin ? 
'dayhour' : 
'day') : 
'';
 
 2108    if ($object->hasDelay() && !empty($object->delivery_date) && !empty($object->date_commande)) {
 
 2109      print 
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(), 
"warning");
 
 2113    if ($object->methode_commande) {
 
 2114      print 
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
 
 2119  print 
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
 
 2120  print 
'<td>'.$author->getNomUrl(1, 
'', 0, 0, 0).
'</td>';
 
 2124  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
 
 2125    $filterabsolutediscount = 
"fk_invoice_supplier_source IS NULL"; 
 
 2126    $filtercreditnote = 
"fk_invoice_supplier_source IS NOT NULL"; 
 
 2128    $filterabsolutediscount = 
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
 
 2129    $filtercreditnote = 
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
 
 2132  $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
 
 2133  $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
 
 2134  $absolute_discount = 
price2num($absolute_discount, 
'MT');
 
 2135  $absolute_creditnote = 
price2num($absolute_creditnote, 
'MT');
 
 2137  print 
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
 
 2139  $thirdparty = $societe;
 
 2141  $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
 
 2142  include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
 
 2147  $langs->load(
'bills');
 
 2148  print 
'<tr><td class="nowrap">';
 
 2149  print 
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
 
 2150  print $langs->trans(
'PaymentConditions');
 
 2152  if ($action != 
'editconditions') {
 
 2153    print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
 
 2155  print 
'</tr></table>';
 
 2157  if ($action == 
'editconditions') {
 
 2158    $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id, 
'cond_reglement_id');
 
 2160    $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id, 
'none');
 
 2166  $langs->load(
'bills');
 
 2167  print 
'<tr><td class="nowrap">';
 
 2168  print 
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
 
 2169  print $langs->trans(
'PaymentMode');
 
 2171  if ($action != 
'editmode') {
 
 2172    print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
 
 2174  print 
'</tr></table>';
 
 2176  if ($action == 
'editmode') {
 
 2177    $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id, 
'mode_reglement_id', 
'DBIT', 1, 1);
 
 2179    $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id, 
'none');
 
 2184  if (isModEnabled(
"multicurrency")) {
 
 2188    print 
'<table class="nobordernopadding centpercent"><tr><td>';
 
 2189    print $form->editfieldkey(
'Currency', 
'multicurrency_code', 
'', $object, 0);
 
 2191    if ($action != 
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
 
 2192      print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
 
 2194    print 
'</tr></table>';
 
 2196    if ($action == 
'editmulticurrencycode') {
 
 2197      $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, 
'multicurrency_code');
 
 2199      $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code, 
'none');
 
 2204    if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
 
 2207      print 
'<table class="nobordernopadding centpercent"><tr>';
 
 2209      print $form->editfieldkey(
'CurrencyRate', 
'multicurrency_tx', 
'', $object, 0);
 
 2211      if ($action != 
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
 
 2212        print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
 
 2214      print 
'</tr></table>';
 
 2216      if ($action == 
'editmulticurrencyrate' || $action == 
'actualizemulticurrencyrate') {
 
 2217        if ($action == 
'actualizemulticurrencyrate') {
 
 2220        $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, 
'multicurrency_tx', $object->multicurrency_code);
 
 2222        $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx, 
'none', $object->multicurrency_code);
 
 2223        if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
 
 2224          print 
'<div class="inline-block">         ';
 
 2225          print 
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
 
 2234  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && isModEnabled(
"banque")) {
 
 2235    print 
'<tr><td class="nowrap">';
 
 2236    print 
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
 
 2237    print $langs->trans(
'BankAccount');
 
 2239    if ($action != 
'editbankaccount' && $usercancreate) {
 
 2240      print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
 
 2242    print 
'</tr></table>';
 
 2244    if ($action == 
'editbankaccount') {
 
 2245      $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account, 
'fk_account', 1);
 
 2247      $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account, 
'none');
 
 2255  print 
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'), 
'info', 
'style="cursor:help"').
'</td>';
 
 2256  print 
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
 
 2261  print 
'<table class="nobordernopadding centpercent"><tr><td>';
 
 2262  print $langs->trans(
'DateDeliveryPlanned');
 
 2264  if ($action != 
'editdate_livraison') {
 
 2265    print 
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_livraison&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetDeliveryDate'), 1).
'</a></td>';
 
 2267  print 
'</tr></table>';
 
 2269  if ($action == 
'editdate_livraison') {
 
 2270    print 
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
 
 2271    print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2272    print 
'<input type="hidden" name="action" value="setdate_livraison">';
 
 2274    if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
 
 2277    print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 
'liv_', $usehourmin, $usehourmin, 
'', 
"setdate_livraison");
 
 2278    print 
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
 
 2281    $usehourmin = 
'day';
 
 2282    if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
 
 2283      $usehourmin = 
'dayhour';
 
 2285    print $object->delivery_date ? 
dol_print_date($object->delivery_date, $usehourmin) : 
' ';
 
 2286    if ($object->hasDelay() && !empty($object->delivery_date) && ($object->statut == $object::STATUS_ORDERSENT || $object->statut == $object::STATUS_RECEIVED_PARTIALLY)) {
 
 2287      print 
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(), 
"warning");
 
 2293  if (isModEnabled(
'incoterm')) {
 
 2295    print 
'<table class="nobordernopadding centpercent"><tr><td>';
 
 2296    print $langs->trans(
'IncotermLabel');
 
 2297    print 
'<td><td class="right">';
 
 2298    if ($usercancreate) {
 
 2299      print 
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$object->id.
'&action=editincoterm&token='.newToken().
'">'.
img_edit().
'</a>';
 
 2303    print 
'</td></tr></table>';
 
 2306    if ($action != 
'editincoterm') {
 
 2307      print $form->textwithpicto(
dol_escape_htmltag($object->display_incoterms()), $object->label_incoterms, 1);
 
 2309      print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : 
''), (!empty($object->location_incoterms) ? $object->location_incoterms : 
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
 
 2315  include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
 
 2320  print 
'<div class="fichehalfright">';
 
 2321  print 
'<div class="underbanner clearboth"></div>';
 
 2323  print 
'<table class="border tableforfield centpercent">';
 
 2327  print 
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') . 
'</td>';
 
 2328  print 
'<td class="nowrap amountcard right">' . 
price($object->total_ht, 
'', $langs, 0, -1, -1, $conf->currency) . 
'</td>';
 
 2329  if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
 
 2331    print 
'<td class="nowrap amountcard right">' . 
price($object->multicurrency_total_ht, 
'', $langs, 0, -1, -1, $object->multicurrency_code) . 
'</td>';
 
 2337  print 
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') . 
'</td>';
 
 2338  print 
'<td class="nowrap amountcard right">' . 
price($object->total_tva, 
'', $langs, 0, -1, -1, $conf->currency) . 
'</td>';
 
 2339  if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
 
 2341    print 
'<td class="nowrap amountcard right">' . 
price($object->multicurrency_total_tva, 
'', $langs, 0, -1, -1, $object->multicurrency_code) . 
'</td>';
 
 2346  if ($mysoc->localtax1_assuj == 
"1" || $object->total_localtax1 != 0) {
 
 2348    print 
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) . 
'</td>';
 
 2349    print 
'<td class="nowrap amountcard right">' . 
price($object->total_localtax1, 
'', $langs, 0, -1, -1, $conf->currency) . 
'</td>';
 
 2350    if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
 
 2351      print 
'<td class="nowrap amountcard right">' . 
price($object->total_localtax1, 
'', $langs, 0, -1, -1, $object->multicurrency_code) . 
'</td>';
 
 2355    if ($mysoc->localtax2_assuj == 
"1" || $object->total_localtax2 != 0) {
 
 2357      print 
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) . 
'</td>';
 
 2358      print 
'<td class="nowrap amountcard right">' . 
price($object->total_localtax2, 
'', $langs, 0, -1, -1, $conf->currency) . 
'</td>';
 
 2359      if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
 
 2360        print 
'<td class="nowrap amountcard right">' . 
price($object->total_localtax2, 
'', $langs, 0, -1, -1, $object->multicurrency_code) . 
'</td>';
 
 2367  if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
 
 2368    $alert = 
' ' . 
img_warning($langs->trans(
'OrderMinAmount') . 
': ' . 
price($object->thirdparty->supplier_order_min_amount));
 
 2373  print 
'<td>' . $langs->trans(
'AmountTTC') . 
'</td>';
 
 2374  print 
'<td class="nowrap amountcard right">' . 
price($object->total_ttc, 
'', $langs, 0, -1, -1, $conf->currency) . $alert . 
'</td>';
 
 2375  if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
 
 2377    print 
'<td class="nowrap amountcard right">' . 
price($object->multicurrency_total_ttc, 
'', $langs, 0, -1, -1, $object->multicurrency_code) . 
'</td>';
 
 2392  print 
'<div class="clearboth"></div><br>';
 
 2394  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
 
 2395    $blocname = 
'contacts';
 
 2396    $title = $langs->trans(
'ContactsAddresses');
 
 2397    include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
 
 2400  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
 
 2401    $blocname = 
'notes';
 
 2402    $title = $langs->trans(
'Notes');
 
 2403    include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
 
 2412  print 
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action != 
'editline') ? 
'' : 
'#line_'.
GETPOST(
'lineid', 
'int')).
'" method="POST"> 
 2413  <input type="hidden" name="token" value="'.newToken().
'"> 
 2414  <input type="hidden" name="action" value="' . (($action != 
'editline') ? 
'addline' : 
'updateline').
'"> 
 2415  <input type="hidden" name="mode" value=""> 
 2416  <input type="hidden" name="page_y" value=""> 
 2417  <input type="hidden" name="id" value="'.$object->id.
'"> 
 2418    <input type="hidden" name="socid" value="'.$societe->id.
'"> 
 2421  if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
 
 2422    include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
 
 2425  print 
'<div class="div-table-responsive-no-min">';
 
 2426  print 
'<table id="tablelines" class="noborder noshadow centpercent">';
 
 2429  global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
 
 2430  $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
 
 2431  $senderissupplier = 2; 
 
 2432  if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
 
 2433    $senderissupplier = 1;
 
 2437  if (!empty($object->lines)) {
 
 2438    $object->printObjectLines($action, $object->thirdparty, $mysoc, $lineid, 1);
 
 2441  $num = count($object->lines);
 
 2445    if ($action != 
'editline') {
 
 2448      $parameters = array();
 
 2449      $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action); 
 
 2450      if ($reshook < 0) 
setEventMessages($hookmanager->error, $hookmanager->errors, 
'errors');
 
 2451      if (empty($reshook))
 
 2452        $object->formAddObjectLine(1, $societe, $mysoc);
 
 2465  if ($user->socid == 0 && $action != 
'delete') {
 
 2466    if ($action != 
'createorder' && $action != 
'presend' && $action != 
'editline') {
 
 2467      print 
'<div class="tabsAction">';
 
 2469      $parameters = array();
 
 2470      $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action); 
 
 2472      if (empty($reshook)) {
 
 2473        $object->fetchObjectLinked(); 
 
 2476        if ($object->statut == 0 && $num > 0) {
 
 2477          if ($usercanvalidate) {
 
 2478            $tmpbuttonlabel = $langs->trans(
'Validate');
 
 2479            if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
 
 2480              $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
 
 2483            print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid">';
 
 2484            print $tmpbuttonlabel;
 
 2496          if ($usercanorder) {
 
 2497            print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
"Modify").
'</a>';
 
 2503          if ($usercanapprove) {
 
 2504            if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED && !empty($object->user_approve_id)) {
 
 2505              print 
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
 
 2507              print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
 
 2510            print 
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
 
 2515        if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
 
 2517            if ($usercanapprovesecond) {
 
 2518              if (!empty($object->user_approve_id2)) {
 
 2519                print 
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
 
 2521                print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
 
 2524              print 
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
 
 2531          if ($usercanapprove || $usercanapprovesecond) {
 
 2532            print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
 
 2534            print 
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
 
 2539        if (empty($user->socid)) {
 
 2541            if ($usercanorder) {
 
 2542              print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
 
 2550          if (!$buttonshown && $usercanapprove) {
 
 2551            if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
 
 2552              || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) {
 
 2553              print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
 
 2557          if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
 
 2558            if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
 
 2559              || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) {
 
 2560              print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
 
 2564        if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) {
 
 2565          if ($usercanorder) {
 
 2566            print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
 
 2572        if (isModEnabled(
'stock') && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) {
 
 2573          $labelofbutton = $langs->trans(
'ReceiveProducts');
 
 2574          if ($conf->reception->enabled) {
 
 2575            $labelofbutton = $langs->trans(
"CreateReception");
 
 2576            if (!empty($object->linkedObjects[
'reception'])) {
 
 2577              foreach ($object->linkedObjects[
'reception'] as $element) {
 
 2578                if ($element->statut >= 0) {
 
 2586          if (in_array($object->statut, array(3, 4, 5))) {
 
 2587            if (isModEnabled(
"supplier_order") && $usercanreceive) {
 
 2588              print 
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.$object->id.
'">'.$labelofbutton.
'</a></div>';
 
 2590              print 
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
 
 2596          if ($usercanorder) {
 
 2597            print 
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=createorder#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
 
 2599            print 
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
 
 2605          if ($usercanreceive) {
 
 2606            print 
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&token='.newToken().
'&action=classifyreception#classifyreception">'.$langs->trans(
"ClassifyReception").
'</a></div>';
 
 2613        if (isModEnabled(
"supplier_invoice") && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1)) {  
 
 2614          if ($user->hasRight(
'fournisseur', 
'facture', 
'creer') || $user->hasRight(
"supplier_invoice", 
"creer")) {
 
 2615            print 
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid.
'">'.$langs->trans(
"CreateBill").
'</a>';
 
 2621        if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1) {  
 
 2622          if (!isModEnabled(
'facture')) {
 
 2623            print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
 
 2625            if (!empty($object->linkedObjectsIds[
'invoice_supplier'])) {
 
 2626              if ($user->hasRight(
'fournisseur', 
'facture', 
'creer') || $user->hasRight(
"supplier_invoice", 
"creer")) {
 
 2627                print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
 
 2630              print 
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
 
 2636        if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2) { 
 
 2637          print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=webservice&token='.newToken().
'&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
 
 2641        if ($usercancreate) {
 
 2642          print 
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=order">'.$langs->trans(
"ToClone").
'</a>';
 
 2647          if ($usercanorder) {
 
 2648            print 
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel">'.$langs->trans(
"CancelOrder").
'</a>';
 
 2653        if (!empty($usercandelete)) {
 
 2654          if ($hasreception) {
 
 2655            print 
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
 
 2657            print 
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken().
'">'.$langs->trans(
"Delete").
'</a>';
 
 2667      print 
'<!-- form to record supplier order -->'.
"\n";
 
 2668      print 
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
 
 2670      print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2671      print 
'<input type="hidden" name="action" value="commande">';
 
 2673      print 
'<table class="noborder centpercent">';
 
 2675      print 
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
 
 2676      $date_com = 
dol_mktime(
GETPOST(
'rehour', 
'int'), 
GETPOST(
'remin', 
'int'), 
GETPOST(
'resec', 
'int'), 
GETPOST(
'remonth', 
'int'), 
GETPOST(
'reday', 
'int'), 
GETPOST(
'reyear', 
'int'));
 
 2677      print $form->selectDate($date_com ?: 
'', 
'', 0, 0, 
'', 
"commande", 1, 1);
 
 2681      print 
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
 
 2682      $formorder->selectInputMethod(
GETPOST(
'methodecommande'), 
"methodecommande", 1);
 
 2685      print 
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
 
 2687      print 
'<tr><td class="center" colspan="2">';
 
 2688      print 
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
 
 2689      print 
'     ';
 
 2690      print 
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
 
 2699    if (
GETPOST(
'modelselected')) {
 
 2700      $action = 
'presend';
 
 2703    if ($action != 
'createorder' && $action != 
'presend' ) {
 
 2704      print 
'<div class="fichecenter"><div class="fichehalfleft">';
 
 2708      $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
 
 2709      $relativepath = $objref.
'/'.$objref.
'.pdf';
 
 2710      $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
 
 2711      $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
 
 2712      $genallowed = $usercanread;
 
 2713      $delallowed = $usercancreate;
 
 2714      $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) ? 
'' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
 
 2716      print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0, 
'', 
'', 
'', $object->thirdparty->default_lang, 
'', $object);
 
 2717      $somethingshown = $formfile->numoffiles;
 
 2720      $linktoelem = $form->showLinkToObjectBlock($object, 
null, array(
'supplier_order', 
'order_supplier'));
 
 2721      $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
 
 2723      print 
'</div><div class="fichehalfright">';
 
 2725      if ($action == 
'classifyreception') {
 
 2728          print 
'<!-- form to record purchase order received -->'.
"\n";
 
 2729          print 
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
 
 2730          print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2731          print 
'<input type="hidden" name="action" value="livraison">';
 
 2734          print 
'<table class="noborder centpercent">';
 
 2736          print 
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
 
 2738          print $form->selectDate($datepreselected, 
'', 1, 1, 
'', 
"commande", 1, 1);
 
 2739          print 
"</td></tr>\n";
 
 2741          print 
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
 
 2743          $liv[
''] = 
' ';
 
 2744          $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
 
 2745          $liv[
'par'] = $langs->trans(
"PartialWoman");
 
 2746          $liv[
'nev'] = $langs->trans(
"NeverReceived");
 
 2747          $liv[
'can'] = $langs->trans(
"Canceled");
 
 2749          print $form->selectarray(
"type", $liv);
 
 2752          print 
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
 
 2753          print 
'<tr><td class="center" colspan="2">';
 
 2754          print 
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
 
 2755          print 
'     ';
 
 2756          print 
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
 
 2765      include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
 
 2767      $somethingshown = 
$formactions->showactions($object, 
'order_supplier', $socid, 1, 
'listaction'.($genallowed ? 
'largetitle' : 
''));
 
 2769      print 
'</div></div>';
 
 2775    if ($action == 
'webservice' && 
GETPOST(
'mode', 
'alpha') != 
"send" && !
GETPOST(
'cancel', 
'alpha')) {
 
 2776      $mode        = 
GETPOST(
'mode', 
'alpha');
 
 2777      $ws_url      = $object->thirdparty->webservices_url;
 
 2778      $ws_key      = $object->thirdparty->webservices_key;
 
 2779      $ws_user     = 
GETPOST(
'ws_user', 
'alpha');
 
 2780      $ws_password = 
GETPOST(
'ws_password', 
'alpha');
 
 2783      $ws_ns = 
'http://www.dolibarr.org/ns/';
 
 2784      $ws_authentication = array(
 
 2785      'dolibarrkey'=>$ws_key,
 
 2786      'sourceapplication'=>
'DolibarrWebServiceClient',
 
 2788      'password'=>$ws_password,
 
 2795      if (empty($ws_url) || empty($ws_key)) {
 
 2796        setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), 
null, 
'errors');
 
 2798        $error_occurred = 
true; 
 
 2799      } elseif ($mode != 
"init" && (empty($ws_user) || empty($ws_password))) {
 
 2804      if ($mode == 
"init") {
 
 2806        print 
'<table class="border centpercent">';
 
 2807        print 
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
 
 2808        print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2809        print 
'<input type="hidden" name="action" value="webservice">';
 
 2810        print 
'<input type="hidden" name="mode" value="check">';
 
 2812        if ($error_occurred) {
 
 2813          print 
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
 
 2814          print 
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
 
 2817          print 
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
 
 2819          print 
'<tr><td>'.$langs->trans(
"User").
'</td><td><input class="width100" type="text" name="ws_user"></td></tr>';
 
 2821          print 
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input class="width100" type="text" name="ws_password"></td></tr>';
 
 2823          print 
'<tr><td class="center" colspan="2">';
 
 2824          print 
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
 
 2825          print 
'     ';
 
 2827          print 
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
 
 2834      } elseif ($mode == 
"check") {
 
 2836        $ws_thirdparty = 
'';
 
 2837        $error_occurred = 
false;
 
 2840        $soapclient_user = 
new nusoap_client($ws_url.
"/webservices/server_user.php");
 
 2841        $soapclient_user->soap_defencoding = 
'UTF-8';
 
 2842        $soapclient_user->decodeUTF8(
false);
 
 2845        $ws_parameters = array(
'authentication'=>$ws_authentication, 
'id' => 
'', 
'ref'=>$ws_user);
 
 2846        $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns, 
'');
 
 2847        $user_status_code = $result_user[
"result"][
"result_code"];
 
 2849        if ($user_status_code == 
"OK") {
 
 2851          $ws_entity = $result_user[
"user"][
"entity"];
 
 2852          $ws_authentication[
'entity'] = $ws_entity;
 
 2853          $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
 
 2854          if (empty($ws_thirdparty)) {
 
 2855            setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"), 
null, 
'errors');
 
 2856            $error_occurred = 
true;
 
 2859            $soapclient_product = 
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
 
 2860            $soapclient_product->soap_defencoding = 
'UTF-8';
 
 2861            $soapclient_product->decodeUTF8(
false);
 
 2865            foreach ($object->lines as $line) {
 
 2867              $ref_supplier = $line->ref_supplier;
 
 2868              $line_id = $i.
"º) ".$line->product_ref.
": ";
 
 2869              if (empty($ref_supplier)) {
 
 2872              $ws_parameters = array(
'authentication' => $ws_authentication, 
'id' => 
'', 
'ref' => $ref_supplier);
 
 2873              $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns, 
'');
 
 2874              if (!$result_product) {
 
 2875                setEventMessages($line_id.$langs->trans(
"SOAPError").
" ".$soapclient_product->error_str.
" - ".$soapclient_product->response, 
null, 
'errors');
 
 2876                $error_occurred = 
true;
 
 2881              $status_code = $result_product[
"result"][
"result_code"];
 
 2882              if (empty($status_code)) { 
 
 2883                setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", 
null, 
'errors');
 
 2884              } elseif ($status_code != 
"OK") { 
 
 2885                if ($status_code == 
"NOT_FOUND") {
 
 2886                  setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'", 
null, 
'warnings');
 
 2888                  setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'", 
null, 
'errors');
 
 2889                  $error_occurred = 
true;
 
 2896              $supplier_price = 
price($result_product[
"product"][
"price_net"]); 
 
 2897              $local_price = 
null; 
 
 2900              $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
 
 2901              if (count($product_fourn_list) > 0) {
 
 2902                foreach ($product_fourn_list as $product_fourn_line) {
 
 2904                  if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
 
 2905                    $local_price = 
price($product_fourn_line->fourn_price);
 
 2910              if ($local_price != 
null && $local_price != $supplier_price) {
 
 2911                setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price, 
null, 
'warnings');
 
 2915              if (empty($result_product[
"product"][
"status_tosell"])) {
 
 2916                setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'", 
null, 
'warnings');
 
 2920        } elseif ($user_status_code == 
"PERMISSION_DENIED") {
 
 2921          setEventMessages($langs->trans(
"RemoteUserNotPermission"), 
null, 
'errors');
 
 2922          $error_occurred = 
true;
 
 2923        } elseif ($user_status_code == 
"BAD_CREDENTIALS") {
 
 2924          setEventMessages($langs->trans(
"RemoteUserBadCredentials"), 
null, 
'errors');
 
 2925          $error_occurred = 
true;
 
 2927          setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'", 
null, 
'errors');
 
 2928          $error_occurred = 
true;
 
 2932        print 
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
 
 2933        print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
 2934        print 
'<input type="hidden" name="action" value="webservice">';
 
 2935        print 
'<input type="hidden" name="mode" value="send">';
 
 2936        print 
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
 
 2937        print 
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
 
 2938        print 
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
 
 2939        print 
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
 
 2940        if ($error_occurred) {
 
 2941          print 
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
 
 2943          print 
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
 
 2944          print 
'     ';
 
 2946        print 
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
 
 2952    $modelmail = 
'order_supplier_send';
 
 2953    $defaulttopic = 
'SendOrderRef';
 
 2954    $diroutput = $conf->fournisseur->commande->dir_output;
 
 2955    $autocopy = 
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
 
 2956    $trackid = 
'sord'.$object->id;
 
 2958    include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
 
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
 
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
 
Class to manage predefined suppliers products.
 
const STATUS_RECEIVED_PARTIALLY
Received partially.
 
const STATUS_VALIDATED
Validated status.
 
const STATUS_RECEIVED_COMPLETELY
Received completely.
 
const STATUS_DRAFT
Draft status.
 
const STATUS_ACCEPTED
Accepted.
 
const STATUS_ORDERSENT
Order sent, shipment on process.
 
Class to manage line orders.
 
Class to manage a WYSIWYG editor.
 
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
 
Class to manage notifications.
 
Class ProductCombination Used to represent a product combination.
 
Class to manage predefined suppliers products.
 
Class to manage products or services.
 
Class to manage projects.
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
Class to manage translations.
 
Class to manage Dolibarr users.
 
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
 
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
 
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
 
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
 
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
 
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
 
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
 
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
 
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
dol_get_fiche_end($notab=0)
Return tab footer of a card.
 
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
 
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
 
dol_now($mode='auto')
Return date for now.
 
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
 
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
 
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
 
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
 
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
 
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='float')
Show Url link.
 
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
 
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
 
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
 
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
 
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
 
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.