47 const TRIGGER_PREFIX =
'';
83 public $errors = array();
88 private $validateFieldsErrors = array();
104 public $element_for_permission;
109 public $table_element;
114 public $table_element_line =
'';
119 public $ismultientitymanaged;
129 public $array_options = array();
134 public $fields = array();
139 public $array_languages =
null;
144 public $contacts_ids;
149 public $linked_objects;
154 public $linkedObjectsIds;
159 public $linkedObjects;
164 private $linkedObjectsFullLoaded = array();
178 protected $table_ref_field =
'';
183 public $restrictiononfksoc = 0;
191 public $context = array();
272 public $ref_previous;
313 public $country_code;
356 public $barcode_type;
362 public $barcode_type_code;
368 public $barcode_type_label;
374 public $barcode_type_coder;
380 public $mode_reglement_id;
386 public $cond_reglement_id;
391 public $demand_reason_id;
397 public $transport_mode_id;
404 public $cond_reglement;
411 public $fk_delivery_address;
417 public $shipping_method_id;
423 public $shipping_method;
428 public $multicurrency_code;
433 public $multicurrency_tx;
452 public $last_main_doc;
482 public $note_private;
506 public $total_localtax1;
512 public $total_localtax2;
529 public $comments = array();
555 public $date_creation;
560 public $date_validation;
575 public $date_cloture;
586 public $user_creation;
590 public $user_creation_id;
601 public $user_validation;
605 public $user_validation_id;
609 public $user_closing_id;
615 public $user_modification;
619 public $user_modification_id;
622 public $next_prev_filter;
627 public $specimen = 0;
641 protected $labelStatusShort;
646 public $showphoto_on_popup;
651 public $nb = array();
661 public $extraparams = array();
666 protected $childtables = array();
673 protected $childtablesoncascade = array();
693 $sql =
"SELECT rowid, ref, ref_ext";
694 $sql .=
" FROM ".$db->prefix().$element;
695 $sql .=
" WHERE entity IN (".getEntity($element).
")";
698 $sql .=
" AND rowid = ".((int) $id);
700 $sql .=
" AND ref = '".$db->escape($ref).
"'";
701 } elseif ($ref_ext) {
702 $sql .=
" AND ref_ext = '".$db->escape($ref_ext).
"'";
704 $error =
'ErrorWrongParameters';
708 if ($ref || $ref_ext) {
709 $sql .=
" AND entity = ".((int) $conf->entity);
712 dol_syslog(get_class().
"::isExistingObject", LOG_DEBUG);
713 $resql = $db->query(
$sql);
715 $num = $db->num_rows($resql);
733 if (!empty($object->error)) {
734 $this->error = $object->error;
736 if (!empty($object->errors)) {
737 $this->errors = array_merge($this->errors, $object->errors);
762 global $action, $extrafields, $langs, $hookmanager;
765 $MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP =
getDolGlobalInt(
'MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP', 3);
771 if (!empty($extrafields->attributes[$this->table_element][
'label'])) {
772 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
773 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
776 if ($count >= abs($MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP)) {
777 $datas[
'more_extrafields'] =
'<br>...';
781 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
782 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
784 if ($enabled && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
785 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
788 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
789 $perms =
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
791 if (empty($enabled)) {
794 if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
800 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
801 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
803 $labelextra = $langs->trans((
string) $extrafields->attributes[$this->table_element][
'label'][$key]);
804 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
805 $datas[$key]=
'<br><b><u>'. $labelextra .
'</u></b>';
807 $value = (empty($this->array_options[
'options_' . $key]) ?
'' : $this->array_options[
'options_' . $key]);
808 $datas[$key]=
'<br><b>'. $labelextra .
':</b> ' . $extrafields->showOutputField($key, $value,
'', $this->table_element);
814 $hookmanager->initHooks(array($this->element .
'dao'));
816 'tooltipcontentarray' => &$datas,
820 $hookmanager->executeHooks(
'getTooltipContent', $parameters, $this, $action);
823 $label = implode($datas);
836 return $this->error.(is_array($this->errors) ? (($this->error !=
'' ?
', ' :
'').join(
', ', $this->errors)) :
'');
850 $parameters = array(
'objref'=>$objref);
852 $reshook = $hookmanager->executeHooks(
'getFormatedCustomerRef', $parameters, $this, $action);
854 return $hookmanager->resArray[
'objref'];
856 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
869 $parameters = array(
'objref'=>$objref);
871 $reshook = $hookmanager->executeHooks(
'getFormatedSupplierRef', $parameters, $this, $action);
873 return $hookmanager->resArray[
'objref'];
875 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
887 public function getFullAddress($withcountry = 0, $sep =
"\n", $withregion = 0, $extralangcode =
'')
889 if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
890 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
891 $tmparray =
getCountry($this->country_id,
'all');
892 $this->country_code = $tmparray[
'code'];
893 $this->country = $tmparray[
'label'];
896 if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) {
897 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
898 $tmparray =
getState($this->state_id,
'all', 0, 1);
899 $this->state_code = $tmparray[
'code'];
900 $this->state = $tmparray[
'label'];
901 $this->region_code = $tmparray[
'region_code'];
902 $this->region = $tmparray[
'region'];
919 global $user, $dolibarr_main_url_root;
921 if (empty($this->last_main_doc)) {
925 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
927 $result = $ecmfile->fetch(0,
'', $this->last_main_doc);
929 $this->error = $ecmfile->error;
930 $this->errors = $ecmfile->errors;
934 if (empty($ecmfile->id)) {
937 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
959 } elseif (empty($ecmfile->share)) {
962 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
964 $ecmfile->update($user);
970 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
974 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
983 if (!empty($ecmfile->share)) {
984 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$ecmfile->share;
986 if ($forcedownload) {
987 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
991 $linktoreturn =
'document.php'.($paramlink ?
'?'.$paramlink :
'');
993 $linktoreturn = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
997 return $linktoreturn;
1011 public function add_contact($fk_socpeople, $type_contact, $source =
'external', $notrigger = 0)
1014 global $user, $langs;
1017 dol_syslog(get_class($this).
"::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
1020 if ($fk_socpeople <= 0) {
1021 $langs->load(
"errors");
1022 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"1");
1023 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1026 if (!$type_contact) {
1027 $langs->load(
"errors");
1028 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"2");
1029 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1033 $id_type_contact = 0;
1034 if (is_numeric($type_contact)) {
1035 $id_type_contact = $type_contact;
1038 $sql =
"SELECT tc.rowid";
1039 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1040 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1041 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1042 $sql .=
" AND tc.code='".$this->db->escape($type_contact).
"' AND tc.active=1";
1044 $resql = $this->db->query(
$sql);
1046 $obj = $this->db->fetch_object($resql);
1048 $id_type_contact = $obj->rowid;
1053 if ($id_type_contact == 0) {
1054 $this->error =
'CODE_NOT_VALID_FOR_THIS_ELEMENT';
1055 dol_syslog(
"CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact.
"' does not exists or is not active for element ".$this->element.
", we can ignore it");
1063 $already_added =
false;
1064 if (is_array($TListeContacts) && !empty($TListeContacts)) {
1065 foreach ($TListeContacts as $array_contact) {
1066 if ($array_contact[
'status'] == 4 && $array_contact[
'id'] == $fk_socpeople && $array_contact[
'fk_c_type_contact'] == $id_type_contact) {
1067 $already_added =
true;
1073 if (!$already_added) {
1077 $sql =
"INSERT INTO ".$this->db->prefix().
"element_contact";
1078 $sql .=
" (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1079 $sql .=
" VALUES (".$this->id.
", ".((int) $fk_socpeople).
" , ";
1080 $sql .=
"'".$this->db->idate($datecreate).
"'";
1081 $sql .=
", 4, ".((int) $id_type_contact);
1084 $resql = $this->db->query(
$sql);
1087 $result = $this->
call_trigger(strtoupper($this->element).
'_ADD_CONTACT', $user);
1089 $this->db->rollback();
1094 $this->db->commit();
1097 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1098 $this->error = $this->db->errno();
1099 $this->db->rollback();
1102 $this->error = $this->db->lasterror();
1103 $this->db->rollback();
1123 $contacts = $objFrom->liste_contact(-1, $source);
1124 foreach ($contacts as $contact) {
1125 if ($this->
add_contact($contact[
'id'], $contact[
'fk_c_type_contact'], $contact[
'source']) < 0) {
1142 public function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0)
1146 $sql =
"UPDATE ".$this->db->prefix().
"element_contact set";
1147 $sql .=
" statut = ".$statut;
1148 if ($type_contact_id) {
1149 $sql .=
", fk_c_type_contact = ".((int) $type_contact_id);
1151 if ($fk_socpeople) {
1152 $sql .=
", fk_socpeople = ".((int) $fk_socpeople);
1154 $sql .=
" where rowid = ".((int) $rowid);
1155 $resql = $this->db->query(
$sql);
1159 $this->error = $this->db->lasterror();
1180 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1181 $sql .=
" WHERE rowid = ".((int) $rowid);
1183 dol_syslog(get_class($this).
"::delete_contact", LOG_DEBUG);
1184 if ($this->db->query(
$sql)) {
1186 $result = $this->
call_trigger(strtoupper($this->element).
'_DELETE_CONTACT', $user);
1188 $this->db->rollback();
1193 $this->db->commit();
1196 $this->error = $this->db->lasterror();
1197 $this->db->rollback();
1217 if (!empty($typeContact)) {
1218 foreach ($typeContact as $key => $value) {
1219 array_push($temp, $key);
1221 $listId = implode(
",", $temp);
1226 if (empty($listId)) {
1230 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1231 $sql .=
" WHERE element_id = ".((int) $this->
id);
1232 $sql .=
" AND fk_c_type_contact IN (".$this->db->sanitize($listId).
")";
1234 dol_syslog(get_class($this).
"::delete_linked_contact", LOG_DEBUG);
1235 if ($this->db->query(
$sql)) {
1238 $this->error = $this->db->lasterror();
1255 public function liste_contact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1, $arrayoftcids = array())
1262 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
1263 if ($source ==
'internal') {
1264 $sql .=
", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1266 if ($source ==
'external' || $source ==
'thirdparty') {
1267 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
1269 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1270 $sql .=
", tc.source, tc.element, tc.code, tc.libelle";
1271 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc,";
1272 $sql .=
" ".$this->db->prefix().
"element_contact ec";
1273 if ($source ==
'internal') {
1274 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user t on ec.fk_socpeople = t.rowid";
1276 if ($source ==
'external' || $source ==
'thirdparty') {
1277 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on ec.fk_socpeople = t.rowid";
1279 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
1280 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1281 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1283 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1285 if ($source ==
'internal') {
1286 $sql .=
" AND tc.source = 'internal'";
1288 $sql .=
" AND t.statut = ".((int) $status);
1291 if ($source ==
'external' || $source ==
'thirdparty') {
1292 $sql .=
" AND tc.source = 'external'";
1294 $sql .=
" AND t.statut = ".((int) $status);
1297 $sql .=
" AND tc.active = 1";
1298 if ($statusoflink >= 0) {
1299 $sql .=
" AND ec.statut = ".((int) $statusoflink);
1301 $sql .=
" ORDER BY t.lastname ASC";
1303 dol_syslog(get_class($this).
"::liste_contact", LOG_DEBUG);
1304 $resql = $this->db->query(
$sql);
1306 $num = $this->db->num_rows($resql);
1309 $obj = $this->db->fetch_object($resql);
1312 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1313 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1315 'parentId' => $this->
id,
1316 'source' => $obj->source,
1317 'socid' => $obj->socid,
1319 'nom' => $obj->lastname,
1320 'civility' => $obj->civility,
1321 'lastname' => $obj->lastname,
1322 'firstname' => $obj->firstname,
1323 'email'=>$obj->email,
1324 'login'=> (empty($obj->login) ?
'' : $obj->login),
1325 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
1326 'statuscontact' => $obj->statuscontact,
1327 'rowid' => $obj->rowid,
1328 'code' => $obj->code,
1329 'libelle' => $libelle_type,
1330 'status' => $obj->statuslink,
1331 'fk_c_type_contact' => $obj->fk_c_type_contact
1334 $tab[$i] = $obj->id;
1342 $this->error = $this->db->lasterror();
1357 $sql =
"SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1358 $sql .=
" tc.code, tc.libelle";
1359 $sql .=
" FROM (".$this->db->prefix().
"element_contact as ec, ".$this->db->prefix().
"c_type_contact as tc)";
1360 $sql .=
" WHERE ec.rowid =".((int) $rowid);
1361 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1362 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1364 dol_syslog(get_class($this).
"::swapContactStatus", LOG_DEBUG);
1365 $resql = $this->db->query(
$sql);
1367 $obj = $this->db->fetch_object($resql);
1368 $newstatut = ($obj->statut == 4) ? 5 : 4;
1370 $this->db->free($resql);
1373 $this->error = $this->db->error();
1390 public function liste_type_contact($source =
'internal', $order =
'position', $option = 0, $activeonly = 0, $code =
'')
1395 if (empty($order)) {
1396 $order =
'position';
1398 if ($order ==
'position') {
1403 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
1404 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1405 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1406 if ($activeonly == 1) {
1407 $sql .=
" AND tc.active=1";
1409 if (!empty($source) && $source !=
'all') {
1410 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1412 if (!empty($code)) {
1413 $sql .=
" AND tc.code='".$this->db->escape($code).
"'";
1415 $sql .= $this->db->order($order,
'ASC');
1418 $resql = $this->db->query(
$sql);
1420 $num = $this->db->num_rows($resql);
1423 $obj = $this->db->fetch_object($resql);
1425 $transkey =
"TypeContact_".$this->element.
"_".$source.
"_".$obj->code;
1426 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1427 if (empty($option)) {
1428 $tab[$obj->rowid] = $libelle_type;
1430 $tab[$obj->code] = $libelle_type;
1436 $this->error = $this->db->lasterror();
1453 public function listeTypeContacts($source =
'internal', $option = 0, $activeonly = 0, $code =
'', $element =
'', $excludeelement =
'')
1455 global $langs, $conf;
1457 $langs->loadLangs(array(
'bills',
'contracts',
'interventions',
'orders',
'projects',
'propal',
'ticket',
'agenda'));
1461 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element";
1462 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1464 $sqlWhere = array();
1465 if (!empty($element)) {
1466 $sqlWhere[] =
" tc.element='".$this->db->escape($element).
"'";
1468 if (!empty($excludeelement)) {
1469 $sqlWhere[] =
" tc.element <> '".$this->db->escape($excludeelement).
"'";
1472 if ($activeonly == 1) {
1473 $sqlWhere[] =
" tc.active=1";
1476 if (!empty($source) && $source !=
'all') {
1477 $sqlWhere[] =
" tc.source='".$this->db->escape($source).
"'";
1480 if (!empty($code)) {
1481 $sqlWhere[] =
" tc.code='".$this->db->escape($code).
"'";
1484 if (count($sqlWhere) > 0) {
1485 $sql .=
" WHERE ".implode(
' AND ', $sqlWhere);
1488 $sql .= $this->db->order(
'tc.element, tc.position',
'ASC');
1491 $resql = $this->db->query(
$sql);
1493 $num = $this->db->num_rows($resql);
1495 $langs->loadLangs(array(
"propal",
"orders",
"bills",
"suppliers",
"contracts",
"supplier_proposal"));
1497 while ($obj = $this->db->fetch_object($resql)) {
1498 $modulename = $obj->element;
1499 if (strpos($obj->element,
'project') !==
false) {
1500 $modulename =
'projet';
1501 } elseif ($obj->element ==
'contrat') {
1502 $element =
'contract';
1503 } elseif ($obj->element ==
'action') {
1504 $modulename =
'agenda';
1505 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1506 $modulename =
'fournisseur';
1507 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1508 $modulename =
'fournisseur';
1510 if (!empty($conf->{$modulename}->enabled)) {
1511 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1512 $tmpelement = $obj->element;
1513 $transkey =
"TypeContact_".$tmpelement.
"_".$source.
"_".$obj->code;
1514 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1515 if (empty($option)) {
1516 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1518 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1525 $this->error = $this->db->lasterror();
1548 if ($this->element ==
'shipping' && $this->origin_id != 0) {
1549 $id = $this->origin_id;
1550 $element =
'commande';
1551 } elseif ($this->element ==
'reception' && $this->origin_id != 0) {
1552 $id = $this->origin_id;
1553 $element =
'order_supplier';
1556 $element = $this->element;
1559 $sql =
"SELECT ec.fk_socpeople";
1560 $sql .=
" FROM ".$this->db->prefix().
"element_contact as ec,";
1561 if ($source ==
'internal') {
1562 $sql .=
" ".$this->db->prefix().
"user as c,";
1564 if ($source ==
'external') {
1565 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
1567 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc";
1568 $sql .=
" WHERE ec.element_id = ".((int) $id);
1569 $sql .=
" AND ec.fk_socpeople = c.rowid";
1570 if ($source ==
'internal') {
1571 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
1573 if ($source ==
'external') {
1574 $sql .=
" AND c.entity IN (".getEntity(
'societe').
")";
1576 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1577 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1578 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1580 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1582 $sql .=
" AND tc.active = 1";
1584 $sql .=
" AND ec.statut = ".((int) $status);
1587 dol_syslog(get_class($this).
"::getIdContact", LOG_DEBUG);
1588 $resql = $this->db->query(
$sql);
1590 while ($obj = $this->db->fetch_object($resql)) {
1591 $result[$i] = $obj->fk_socpeople;
1595 $this->error = $this->db->error();
1612 if (empty($contactid)) {
1613 $contactid = $this->contact_id;
1616 if (empty($contactid)) {
1620 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1621 $contact =
new Contact($this->db);
1622 $result = $contact->fetch($contactid);
1623 $this->contact = $contact;
1639 if (empty($this->socid) && empty($this->fk_soc) && empty($force_thirdparty_id)) {
1643 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1645 $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : 0);
1646 if ($force_thirdparty_id) {
1647 $idtofetch = $force_thirdparty_id;
1651 $thirdparty =
new Societe($this->db);
1652 $result = $thirdparty->fetch($idtofetch);
1654 $this->errors=array_merge($this->errors, $thirdparty->errors);
1656 $this->thirdparty = $thirdparty;
1659 if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
1660 $this->thirdparty->price_level = 1;
1679 if (!$this->table_ref_field) {
1683 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element.
" WHERE ".$this->table_ref_field.
" LIKE '".$this->db->escape($ref).
"' LIMIT 1";
1685 $query = $this->db->query(
$sql);
1687 if (!$this->db->num_rows($query)) {
1691 $result = $this->db->fetch_object($query);
1693 return $this->fetch($result->rowid);
1709 dol_syslog(get_class($this).
'::fetch_barcode this->element='.$this->element.
' this->barcode_type='.$this->barcode_type);
1711 $idtype = $this->barcode_type;
1712 if (empty($idtype) && $idtype !=
'0') {
1713 if ($this->element ==
'product' && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
1714 $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1715 } elseif ($this->element ==
'societe') {
1716 $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1718 dol_syslog(
'Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1723 if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1724 $sql =
"SELECT rowid, code, libelle as label, coder";
1725 $sql .=
" FROM ".$this->db->prefix().
"c_barcode_type";
1726 $sql .=
" WHERE rowid = ".((int) $idtype);
1727 dol_syslog(get_class($this).
'::fetch_barcode', LOG_DEBUG);
1728 $resql = $this->db->query(
$sql);
1730 $obj = $this->db->fetch_object($resql);
1731 $this->barcode_type = $obj->rowid;
1732 $this->barcode_type_code = $obj->code;
1733 $this->barcode_type_label = $obj->label;
1734 $this->barcode_type_coder = $obj->coder;
1754 return $this->fetch_projet();
1766 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1768 if (empty($this->fk_project) && !empty($this->fk_projet)) {
1769 $this->fk_project = $this->fk_projet;
1771 if (empty($this->fk_project)) {
1775 $project =
new Project($this->db);
1776 $result = $project->fetch($this->fk_project);
1778 $this->projet = $project;
1779 $this->project = $project;
1792 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1794 if (empty($this->fk_product)) {
1798 $product =
new Product($this->db);
1799 $result = $product->fetch($this->fk_product);
1801 $this->product = $product;
1815 $user =
new User($this->db);
1816 $result = $user->fetch($userid);
1817 $this->
user = $user;
1830 if ($this->origin ==
'shipping') {
1831 $this->origin =
'expedition';
1833 if ($this->origin ==
'delivery') {
1834 $this->origin =
'livraison';
1836 if ($this->origin ==
'order_supplier') {
1837 $this->origin =
'commandeFournisseur';
1840 $origin = $this->origin;
1842 $classname = ucfirst($origin);
1843 $this->$origin =
new $classname($this->db);
1844 $this->$origin->fetch($this->origin_id);
1862 $sql =
"SELECT rowid FROM ".$this->db->prefix().$table;
1863 $sql .=
" WHERE ".$field.
" = '".$this->db->escape($key).
"'";
1864 if (!empty($element)) {
1865 $sql .=
" AND entity IN (".getEntity($element).
")";
1867 $sql .=
" AND entity = ".((int) $conf->entity);
1870 dol_syslog(get_class($this).
'::fetchObjectFrom', LOG_DEBUG);
1871 $resql = $this->db->query(
$sql);
1873 $row = $this->db->fetch_row($resql);
1876 $result = $this->fetch($row[0]);
1894 if (!empty($id) && !empty($field) && !empty($table)) {
1895 $sql =
"SELECT ".$field.
" FROM ".$this->db->prefix().$table;
1896 $sql .=
" WHERE rowid = ".((int) $id);
1898 dol_syslog(get_class($this).
'::getValueFrom', LOG_DEBUG);
1899 $resql = $this->db->query(
$sql);
1901 $row = $this->db->fetch_row($resql);
1924 public function setValueFrom($field, $value, $table =
'', $id =
null, $format =
'', $id_field =
'', $fuser =
null, $trigkey =
'', $fk_user_field =
'fk_user_modif')
1926 global $user, $langs, $conf;
1928 if (empty($table)) {
1929 $table = $this->table_element;
1934 if (empty($format)) {
1937 if (empty($id_field)) {
1938 $id_field =
'rowid';
1942 if ($table ==
'product' && $field ==
'note_private') {
1945 if (in_array($table, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
1946 $fk_user_field =
'fk_user_mod';
1952 $sql =
"SELECT " . $field;
1953 $sql .=
" FROM " . MAIN_DB_PREFIX . $table;
1954 $sql .=
" WHERE " . $id_field .
" = " . ((int) $id);
1956 $resql = $this->db->query(
$sql);
1958 if ($obj = $this->db->fetch_object($resql)) {
1959 if ($format ==
'date') {
1960 $oldvalue = $this->db->jdate($obj->$field);
1962 $oldvalue = $obj->$field;
1966 $this->error = $this->db->lasterror();
1977 $sql =
"UPDATE ".$this->db->prefix().$table.
" SET ";
1979 if ($format ==
'text') {
1980 $sql .= $field.
" = '".$this->db->escape($value).
"'";
1981 } elseif ($format ==
'int') {
1982 $sql .= $field.
" = ".((int) $value);
1983 } elseif ($format ==
'date') {
1984 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value).
"'" :
"null");
1985 } elseif ($format ==
'dategmt') {
1986 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value,
'gmt').
"'" :
"null");
1989 if ($fk_user_field) {
1990 if (!empty($fuser) && is_object($fuser)) {
1991 $sql .=
", ".$fk_user_field.
" = ".((int) $fuser->id);
1992 } elseif (empty($fuser) || $fuser !=
'none') {
1993 $sql .=
", ".$fk_user_field.
" = ".((int) $user->id);
1997 $sql .=
" WHERE ".$id_field.
" = ".((int) $id);
1999 $resql = $this->db->query(
$sql);
2003 if (method_exists($this,
'fetch')) {
2004 $result = $this->fetch($id);
2006 $result = $this->fetchCommon($id);
2008 $this->oldcopy = clone $this;
2009 if (property_exists($this->oldcopy, $field)) {
2010 $this->oldcopy->$field = $oldvalue;
2014 $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
2022 if (property_exists($this, $field)) {
2023 $this->$field = $value;
2025 $this->db->commit();
2028 $this->db->rollback();
2032 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2033 $this->error =
'DB_ERROR_RECORD_ALREADY_EXISTS';
2035 $this->error = $this->db->lasterror();
2037 $this->db->rollback();
2054 global $conf, $user;
2056 if (!$this->table_element) {
2057 dol_print_error(
'', get_class($this).
"::load_previous_next_ref was called on objet with property table_element not defined");
2060 if ($fieldid ==
'none') {
2065 if ($this->table_element ==
'facture_rec' && $fieldid ==
'title') {
2071 if ($user->socid > 0) {
2072 $socid = $user->socid;
2077 $aliastablesociete =
's';
2078 if ($this->element ==
'societe') {
2079 $aliastablesociete =
'te';
2081 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2082 $sql =
"SELECT MAX(te.".$fieldid.
")";
2083 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2084 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2085 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
2087 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2088 $tmparray = explode(
'@', $this->ismultientitymanaged);
2089 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2090 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2091 $sql .=
", ".$this->db->prefix().
"societe as s";
2092 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2093 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2095 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2096 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2098 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($fieldid ==
'rowid' ? $this->
id : $this->
ref).
"'";
2099 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2100 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2102 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2103 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2105 if (!empty($filter)) {
2106 if (!preg_match(
'/^\s*AND/i', $filter)) {
2111 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2112 $tmparray = explode(
'@', $this->ismultientitymanaged);
2113 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2114 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2115 $sql .=
' AND te.fk_soc = s.rowid';
2117 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2118 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2119 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2120 $sql .=
" AND te.entity IS NOT NULL";
2122 $sql .=
" AND ug.fk_user = te.rowid";
2123 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2126 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2129 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2130 $tmparray = explode(
'@', $this->ismultientitymanaged);
2131 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2133 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2134 $sql .=
' AND te.fk_soc = '.((int) $socid);
2136 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2137 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2139 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2140 $sql .=
' AND te.rowid = '.((int) $socid);
2144 $result = $this->db->query(
$sql);
2146 $this->error = $this->db->lasterror();
2149 $row = $this->db->fetch_row($result);
2150 $this->ref_previous = $row[0];
2152 $sql =
"SELECT MIN(te.".$fieldid.
")";
2153 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2154 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2155 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
2157 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2158 $tmparray = explode(
'@', $this->ismultientitymanaged);
2159 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2160 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2161 $sql .=
", ".$this->db->prefix().
"societe as s";
2162 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2163 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2165 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2166 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2168 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($fieldid ==
'rowid' ? $this->
id : $this->ref).
"'";
2169 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2170 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2172 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2173 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2175 if (!empty($filter)) {
2176 if (!preg_match(
'/^\s*AND/i', $filter)) {
2181 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2182 $tmparray = explode(
'@', $this->ismultientitymanaged);
2183 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2184 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2185 $sql .=
' AND te.fk_soc = s.rowid';
2187 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2188 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2189 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2190 $sql .=
" AND te.entity IS NOT NULL";
2192 $sql .=
" AND ug.fk_user = te.rowid";
2193 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2196 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2199 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2200 $tmparray = explode(
'@', $this->ismultientitymanaged);
2201 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2203 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2204 $sql .=
' AND te.fk_soc = '.((int) $socid);
2206 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2207 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2209 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2210 $sql .=
' AND te.rowid = '.((int) $socid);
2215 $result = $this->db->query(
$sql);
2217 $this->error = $this->db->lasterror();
2220 $row = $this->db->fetch_row($result);
2221 $this->ref_next = $row[0];
2236 $contactAlreadySelected = array();
2237 $tab = $this->liste_contact(-1, $source);
2241 if ($source ==
'thirdparty') {
2242 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
2244 $contactAlreadySelected[$i] = $tab[$i][
'id'];
2248 return $contactAlreadySelected;
2264 if (!$this->table_element) {
2265 dol_syslog(get_class($this).
"::setProject was called on objet with property table_element not defined", LOG_ERR);
2269 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2270 if (!empty($this->fields[
'fk_project'])) {
2272 $sql .=
" SET fk_project = ".((int) $projectid);
2274 $sql .=
" SET fk_project = NULL";
2276 $sql .=
' WHERE rowid = '.((int) $this->
id);
2277 } elseif ($this->table_element ==
'actioncomm') {
2279 $sql .=
" SET fk_project = ".((int) $projectid);
2281 $sql .=
" SET fk_project = NULL";
2283 $sql .=
' WHERE id = '.((int) $this->
id);
2287 $sql .=
' SET fk_projet = '.((int) $projectid);
2289 $sql .=
' SET fk_projet = NULL';
2291 $sql .=
" WHERE rowid = ".((int) $this->
id);
2296 dol_syslog(get_class($this).
"::setProject", LOG_DEBUG);
2297 if ($this->db->query(
$sql)) {
2298 $this->fk_project = ((int) $projectid);
2305 if (!$error && !$notrigger) {
2307 $result = $this->call_trigger(strtoupper($this->element) .
'_MODIFY', $user);
2316 $this->db->rollback();
2319 $this->db->commit();
2334 $error = 0; $notrigger = 0;
2336 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2338 if ($this->statut >= 0 || $this->element ==
'societe') {
2340 $fieldname =
'fk_mode_reglement';
2341 if ($this->element ==
'societe') {
2342 $fieldname =
'mode_reglement';
2344 if (get_class($this) ==
'Fournisseur') {
2345 $fieldname =
'mode_reglement_supplier';
2347 if (get_class($this) ==
'Tva') {
2348 $fieldname =
'fk_typepayment';
2350 if (get_class($this) ==
'Salary') {
2351 $fieldname =
'fk_typepayment';
2354 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2355 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2356 $sql .=
' WHERE rowid='.((int) $this->
id);
2358 if ($this->db->query(
$sql)) {
2359 $this->mode_reglement_id = $id;
2361 if (get_class($this) ==
'Fournisseur') {
2362 $this->mode_reglement_supplier_id = $id;
2365 if (!$error && !$notrigger) {
2367 if (get_class($this) ==
'Commande') {
2368 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2370 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
2379 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2380 $this->error = $this->db->error();
2384 dol_syslog(get_class($this).
'::setPaymentMethods, status of the object is incompatible');
2385 $this->error =
'Status of the object is incompatible '.$this->statut;
2398 dol_syslog(get_class($this).
'::setMulticurrencyCode('.$code.
')');
2399 if ($this->statut >= 0 || $this->element ==
'societe') {
2400 $fieldname =
'multicurrency_code';
2402 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2403 $sql .=
" SET ".$fieldname.
" = '".$this->db->escape($code).
"'";
2404 $sql .=
' WHERE rowid='.((int) $this->
id);
2406 if ($this->db->query(
$sql)) {
2407 $this->multicurrency_code = $code;
2411 $this->setMulticurrencyRate($rate, 2);
2416 dol_syslog(get_class($this).
'::setMulticurrencyCode Error '.
$sql.
' - '.$this->db->error());
2417 $this->error = $this->db->error();
2421 dol_syslog(get_class($this).
'::setMulticurrencyCode, status of the object is incompatible');
2422 $this->error =
'Status of the object is incompatible '.$this->statut;
2434 public function setMulticurrencyRate($rate, $mode = 1)
2436 dol_syslog(get_class($this).
'::setMulticurrencyRate('.$rate.
','.$mode.
')');
2437 if ($this->statut >= 0 || $this->element ==
'societe') {
2438 $fieldname =
'multicurrency_tx';
2440 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2441 $sql .=
" SET ".$fieldname.
" = ".((
float) $rate);
2442 $sql .=
' WHERE rowid='.((int) $this->
id);
2444 if ($this->db->query(
$sql)) {
2445 $this->multicurrency_tx = $rate;
2448 if (!empty($this->lines)) {
2449 foreach ($this->lines as &$line) {
2452 $line->subprice = 0;
2457 $line->multicurrency_subprice = 0;
2460 switch ($this->element) {
2468 $line->remise_percent,
2470 $line->localtax1_tx,
2471 $line->localtax2_tx,
2472 ($line->description ? $line->description : $line->desc),
2475 $line->special_code,
2476 $line->fk_parent_line,
2477 $line->skip_update_total,
2478 $line->fk_fournprice,
2481 $line->product_type,
2484 $line->array_options,
2486 $line->multicurrency_subprice
2494 ($line->description ? $line->description : $line->desc),
2497 $line->remise_percent,
2499 $line->localtax1_tx,
2500 $line->localtax2_tx,
2505 $line->product_type,
2506 $line->fk_parent_line,
2507 $line->skip_update_total,
2508 $line->fk_fournprice,
2511 $line->special_code,
2512 $line->array_options,
2514 $line->multicurrency_subprice
2522 ($line->description ? $line->description : $line->desc),
2525 $line->remise_percent,
2529 $line->localtax1_tx,
2530 $line->localtax2_tx,
2533 $line->product_type,
2534 $line->fk_parent_line,
2535 $line->skip_update_total,
2536 $line->fk_fournprice,
2539 $line->special_code,
2540 $line->array_options,
2541 $line->situation_percent,
2543 $line->multicurrency_subprice
2546 case 'supplier_proposal':
2553 $line->remise_percent,
2555 $line->localtax1_tx,
2556 $line->localtax2_tx,
2557 ($line->description ? $line->description : $line->desc),
2560 $line->special_code,
2561 $line->fk_parent_line,
2562 $line->skip_update_total,
2563 $line->fk_fournprice,
2566 $line->product_type,
2567 $line->array_options,
2569 $line->multicurrency_subprice
2572 case 'order_supplier':
2577 ($line->description ? $line->description : $line->desc),
2580 $line->remise_percent,
2582 $line->localtax1_tx,
2583 $line->localtax2_tx,
2586 $line->product_type,
2590 $line->array_options,
2592 $line->multicurrency_subprice,
2596 case 'invoice_supplier':
2601 ($line->description ? $line->description : $line->desc),
2604 $line->localtax1_tx,
2605 $line->localtax2_tx,
2610 $line->product_type,
2611 $line->remise_percent,
2615 $line->array_options,
2617 $line->multicurrency_subprice,
2622 dol_syslog(get_class($this).
'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
2630 dol_syslog(get_class($this).
'::setMulticurrencyRate Error '.
$sql.
' - '.$this->db->error());
2631 $this->error = $this->db->error();
2635 dol_syslog(get_class($this).
'::setMulticurrencyRate, status of the object is incompatible');
2636 $this->error =
'Status of the object is incompatible '.$this->statut;
2650 dol_syslog(get_class($this).
'::setPaymentTerms('.$id.
', '.var_export($deposit_percent,
true).
')');
2651 if ($this->statut >= 0 || $this->element ==
'societe') {
2653 $fieldname =
'fk_cond_reglement';
2654 if ($this->element ==
'societe') {
2655 $fieldname =
'cond_reglement';
2657 if (get_class($this) ==
'Fournisseur') {
2658 $fieldname =
'cond_reglement_supplier';
2661 if (empty($deposit_percent) || $deposit_percent < 0) {
2665 if ($deposit_percent > 100) {
2666 $deposit_percent = 100;
2669 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2670 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2671 if (in_array($this->table_element, array(
'propal',
'commande',
'societe'))) {
2672 $sql .=
" , deposit_percent = " . (empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape($deposit_percent).
"'");
2674 $sql .=
' WHERE rowid='.((int) $this->
id);
2676 if ($this->db->query(
$sql)) {
2677 $this->cond_reglement_id = $id;
2679 if (get_class($this) ==
'Fournisseur') {
2680 $this->cond_reglement_supplier_id = $id;
2682 $this->cond_reglement = $id;
2683 $this->deposit_percent = $deposit_percent;
2686 dol_syslog(get_class($this).
'::setPaymentTerms Error '.
$sql.
' - '.$this->db->error());
2687 $this->error = $this->db->error();
2691 dol_syslog(get_class($this).
'::setPaymentTerms, status of the object is incompatible');
2692 $this->error =
'Status of the object is incompatible '.$this->statut;
2705 dol_syslog(get_class($this).
'::setTransportMode('.$id.
')');
2706 if ($this->statut >= 0 || $this->element ==
'societe') {
2707 $fieldname =
'fk_transport_mode';
2708 if ($this->element ==
'societe') {
2709 $fieldname =
'transport_mode';
2711 if (get_class($this) ==
'Fournisseur') {
2712 $fieldname =
'transport_mode_supplier';
2715 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2716 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2717 $sql .=
' WHERE rowid='.((int) $this->
id);
2719 if ($this->db->query(
$sql)) {
2720 $this->transport_mode_id = $id;
2722 if (get_class($this) ==
'Fournisseur') {
2723 $this->transport_mode_supplier_id = $id;
2727 dol_syslog(get_class($this).
'::setTransportMode Error '.
$sql.
' - '.$this->db->error());
2728 $this->error = $this->db->error();
2732 dol_syslog(get_class($this).
'::setTransportMode, status of the object is incompatible');
2733 $this->error =
'Status of the object is incompatible '.$this->statut;
2746 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms('.$id.
')');
2747 if ($this->statut >= 0 || $this->element ==
'societe') {
2748 $fieldname =
'retained_warranty_fk_cond_reglement';
2750 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2751 $sql .=
" SET ".$fieldname.
" = ".((int) $id);
2752 $sql .=
' WHERE rowid='.((int) $this->
id);
2754 if ($this->db->query(
$sql)) {
2755 $this->retained_warranty_fk_cond_reglement = $id;
2758 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms Error '.
$sql.
' - '.$this->db->error());
2759 $this->error = $this->db->error();
2763 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
2764 $this->error =
'Status of the object is incompatible '.$this->statut;
2778 $fieldname =
'fk_delivery_address';
2779 if ($this->element ==
'delivery' || $this->element ==
'shipping') {
2780 $fieldname =
'fk_address';
2783 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ".$fieldname.
" = ".((int) $id);
2784 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
2786 if ($this->db->query(
$sql)) {
2787 $this->fk_delivery_address = $id;
2790 $this->error = $this->db->error();
2791 dol_syslog(get_class($this).
'::setDeliveryAddress Error '.$this->error);
2810 if (empty($userused)) {
2816 if (!$this->table_element) {
2817 dol_syslog(get_class($this).
"::setShippingMethod was called on objet with property table_element not defined", LOG_ERR);
2823 if ($shipping_method_id < 0) {
2824 $shipping_method_id =
'NULL';
2826 dol_syslog(get_class($this).
'::setShippingMethod('.$shipping_method_id.
')');
2828 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2829 $sql .=
" SET fk_shipping_method = ".((int) $shipping_method_id);
2830 $sql .=
" WHERE rowid=".((int) $this->
id);
2831 $resql = $this->db->query(
$sql);
2833 dol_syslog(get_class($this).
'::setShippingMethod Error ', LOG_DEBUG);
2834 $this->error = $this->db->lasterror();
2839 $this->context = array(
'shippingmethodupdate'=>1);
2840 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2848 $this->db->rollback();
2851 $this->shipping_method_id = ($shipping_method_id ==
'NULL') ?
null:$shipping_method_id;
2852 $this->db->commit();
2866 if (!$this->table_element) {
2867 dol_syslog(get_class($this).
"::setWarehouse was called on objet with property table_element not defined", LOG_ERR);
2870 if ($warehouse_id < 0) {
2871 $warehouse_id =
'NULL';
2873 dol_syslog(get_class($this).
'::setWarehouse('.$warehouse_id.
')');
2875 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2876 $sql .=
" SET fk_warehouse = ".((int) $warehouse_id);
2877 $sql .=
" WHERE rowid=".((int) $this->
id);
2879 if ($this->db->query(
$sql)) {
2880 $this->warehouse_id = ($warehouse_id ==
'NULL') ?
null:$warehouse_id;
2883 dol_syslog(get_class($this).
'::setWarehouse Error ', LOG_DEBUG);
2884 $this->error = $this->db->error();
2899 if (!$this->table_element) {
2900 dol_syslog(get_class($this).
"::setDocModel was called on objet with property table_element not defined", LOG_ERR);
2904 $newmodelpdf =
dol_trunc($modelpdf, 255);
2906 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2907 $sql .=
" SET model_pdf = '".$this->db->escape($newmodelpdf).
"'";
2908 $sql .=
" WHERE rowid = ".((int) $this->
id);
2910 dol_syslog(get_class($this).
"::setDocModel", LOG_DEBUG);
2911 $resql = $this->db->query(
$sql);
2913 $this->model_pdf = $modelpdf;
2914 $this->modelpdf = $modelpdf;
2935 if (empty($userused)) {
2941 if (!$this->table_element) {
2942 dol_syslog(get_class($this).
"::setBankAccount was called on objet with property table_element not defined", LOG_ERR);
2947 if ($fk_account < 0) {
2948 $fk_account =
'NULL';
2950 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
2952 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2953 $sql .=
" SET fk_account = ".((int) $fk_account);
2954 $sql .=
" WHERE rowid=".((int) $this->
id);
2956 $resql = $this->db->query(
$sql);
2958 dol_syslog(get_class($this).
'::setBankAccount Error '.
$sql.
' - '.$this->db->error());
2959 $this->error = $this->db->lasterror();
2964 $this->context = array(
'bankaccountupdate'=>1);
2965 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2973 $this->db->rollback();
2976 $this->fk_account = ($fk_account ==
'NULL') ?
null:$fk_account;
2977 $this->db->commit();
2995 public function line_order($renum =
false, $rowidorder =
'ASC', $fk_parent_line =
true)
2998 if (!$this->table_element_line) {
2999 dol_syslog(get_class($this).
"::line_order was called on objet with property table_element_line not defined", LOG_ERR);
3002 if (!$this->fk_element) {
3003 dol_syslog(get_class($this).
"::line_order was called on objet with property fk_element not defined", LOG_ERR);
3007 $fieldposition =
'rang';
3008 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3009 $fieldposition =
'position';
3014 $sql =
"SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
3015 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3017 $sql .=
" AND " . $fieldposition .
" = 0";
3020 $sql .=
" AND " . $fieldposition .
" <> 0";
3023 dol_syslog(get_class($this).
"::line_order", LOG_DEBUG);
3024 $resql = $this->db->query(
$sql);
3026 $row = $this->db->fetch_row($resql);
3036 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3037 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3038 if ($fk_parent_line) {
3039 $sql .=
' AND fk_parent_line IS NULL';
3041 $sql .=
" ORDER BY " . $fieldposition .
" ASC, rowid " . $rowidorder;
3043 dol_syslog(get_class($this).
"::line_order search all parent lines", LOG_DEBUG);
3044 $resql = $this->db->query(
$sql);
3047 $num = $this->db->num_rows($resql);
3049 $row = $this->db->fetch_row($resql);
3051 $childrens = $this->getChildrenOfLine($row[0]);
3052 if (!empty($childrens)) {
3053 foreach ($childrens as $child) {
3054 array_push($rows, $child);
3061 if (!empty($rows)) {
3062 foreach ($rows as $key => $row) {
3063 $this->updateRangOfLine($row, ($key + 1));
3082 $fieldposition =
'rang';
3083 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3084 $fieldposition =
'position';
3089 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3090 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3091 $sql .=
' AND fk_parent_line = '.((int) $id);
3092 $sql .=
" ORDER BY " . $fieldposition .
" ASC";
3094 dol_syslog(get_class($this).
"::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
3095 $resql = $this->db->query(
$sql);
3097 if ($this->db->num_rows($resql) > 0) {
3098 while ($row = $this->db->fetch_row($resql)) {
3100 if (!empty($includealltree)) {
3101 $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
3117 public function line_up($rowid, $fk_parent_line =
true)
3120 $this->line_order(
false,
'ASC', $fk_parent_line);
3123 $rang = $this->getRangOfLine($rowid);
3126 $this->updateLineUp($rowid, $rang);
3140 $this->line_order(
false,
'ASC', $fk_parent_line);
3143 $rang = $this->getRangOfLine($rowid);
3146 $max = $this->line_max();
3149 $this->updateLineDown($rowid, $rang, $max);
3161 global $hookmanager;
3162 $fieldposition =
'rang';
3163 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3164 $fieldposition =
'position';
3167 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3168 $sql .=
' WHERE rowid = '.((int) $rowid);
3170 dol_syslog(get_class($this).
"::updateRangOfLine", LOG_DEBUG);
3171 if (!$this->db->query(
$sql)) {
3175 $parameters=array(
'rowid'=>$rowid,
'rang'=>$rang,
'fieldposition' => $fieldposition);
3177 $reshook = $hookmanager->executeHooks(
'afterRankOfLineUpdate', $parameters, $this, $action);
3192 $num = count($rows);
3193 for ($i = 0; $i < $num; $i++) {
3194 $this->updateRangOfLine($rows[$i], ($i + 1));
3208 $fieldposition =
'rang';
3209 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3210 $fieldposition =
'position';
3213 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3214 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3215 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang - 1));
3216 if ($this->db->query(
$sql)) {
3217 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang - 1));
3218 $sql .=
' WHERE rowid = '.((int) $rowid);
3219 if (!$this->db->query(
$sql)) {
3239 $fieldposition =
'rang';
3240 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3241 $fieldposition =
'position';
3244 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3245 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3246 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang + 1));
3247 if ($this->db->query(
$sql)) {
3248 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang + 1));
3249 $sql .=
' WHERE rowid = '.((int) $rowid);
3250 if (!$this->db->query(
$sql)) {
3267 $fieldposition =
'rang';
3268 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3269 $fieldposition =
'position';
3272 $sql =
"SELECT " . $fieldposition .
" FROM ".$this->db->prefix().$this->table_element_line;
3273 $sql .=
" WHERE rowid = ".((int) $rowid);
3275 dol_syslog(get_class($this).
"::getRangOfLine", LOG_DEBUG);
3276 $resql = $this->db->query(
$sql);
3278 $row = $this->db->fetch_row($resql);
3293 $fieldposition =
'rang';
3294 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3295 $fieldposition =
'position';
3298 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3299 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3300 $sql .=
" AND " . $fieldposition .
" = ".((int) $rang);
3301 $resql = $this->db->query(
$sql);
3303 $row = $this->db->fetch_row($resql);
3320 $positionfield =
'rang';
3321 if (in_array($this->table_element, array(
'bom_bom',
'product_attribute'))) {
3322 $positionfield =
'position';
3326 if ($fk_parent_line) {
3327 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3328 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3329 $sql .=
" AND fk_parent_line = ".((int) $fk_parent_line);
3331 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3332 $resql = $this->db->query(
$sql);
3334 $row = $this->db->fetch_row($resql);
3335 if (!empty($row[0])) {
3338 return $this->getRangOfLine($fk_parent_line);
3343 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3344 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3346 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3347 $resql = $this->db->query(
$sql);
3349 $row = $this->db->fetch_row($resql);
3367 if (!$this->table_element) {
3368 dol_syslog(get_class($this).
"::update_ref_ext was called on objet with property table_element not defined", LOG_ERR);
3372 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3373 $sql .=
" SET ref_ext = '".$this->db->escape($ref_ext).
"'";
3374 $sql .=
" WHERE ".(isset($this->table_rowid) ? $this->table_rowid :
'rowid').
" = ".((
int) $this->id);
3376 dol_syslog(get_class($this).
"::update_ref_ext", LOG_DEBUG);
3377 if ($this->db->query(
$sql)) {
3378 $this->ref_ext = $ref_ext;
3381 $this->error = $this->db->error();
3399 if (!$this->table_element) {
3400 $this->error =
'update_note was called on objet with property table_element not defined';
3401 dol_syslog(get_class($this).
"::update_note was called on objet with property table_element not defined", LOG_ERR);
3404 if (!in_array($suffix, array(
'',
'_public',
'_private'))) {
3405 $this->error =
'update_note Parameter suffix must be empty, \'_private\' or \'_public\'';
3406 dol_syslog(get_class($this).
"::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
3410 $newsuffix = $suffix;
3413 if ($this->table_element ==
'product' && $newsuffix ==
'_private') {
3416 if (in_array($this->table_element, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
3417 $fieldusermod =
"fk_user_mod";
3418 } elseif ($this->table_element ==
'ecm_files') {
3419 $fieldusermod =
"fk_user_m";
3421 $fieldusermod =
"fk_user_modif";
3423 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3424 $sql .=
" SET note".$newsuffix.
" = ".(!empty($note) ? (
"'".$this->db->escape($note).
"'") :
"NULL");
3425 $sql .=
", ".$fieldusermod.
" = ".((int) $user->id);
3426 $sql .=
" WHERE rowid = ".((int) $this->
id);
3428 dol_syslog(get_class($this).
"::update_note", LOG_DEBUG);
3429 if ($this->db->query(
$sql)) {
3430 if ($suffix ==
'_public') {
3431 $this->note_public = $note;
3432 } elseif ($suffix ==
'_private') {
3433 $this->note_private = $note;
3435 $this->note = $note;
3436 $this->note_private = $note;
3440 $this->error = $this->db->lasterror();
3457 return $this->update_note($note,
'_public');
3471 public function update_price($exclspec = 0, $roundingadjust =
'none', $nodatabaseupdate = 0, $seller =
null)
3474 global $conf, $hookmanager, $action;
3476 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3477 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3480 } elseif ($reshook < 0) {
3486 if ($this->element ==
'propal') {
3487 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3488 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3489 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3490 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3491 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3492 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3493 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3494 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3495 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3496 } elseif ($this->element ==
'supplier_proposal') {
3497 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3500 if (!empty($MODULE)) {
3501 if (!empty($conf->global->$MODULE)) {
3502 $modsactivated = explode(
',', $conf->global->$MODULE);
3503 foreach ($modsactivated as $mod) {
3511 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3513 $forcedroundingmode = $roundingadjust;
3514 if ($forcedroundingmode ==
'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3516 } elseif ($forcedroundingmode ==
'auto') {
3517 $forcedroundingmode =
'0';
3522 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3525 $fieldtva =
'total_tva';
3526 $fieldlocaltax1 =
'total_localtax1';
3527 $fieldlocaltax2 =
'total_localtax2';
3528 $fieldup =
'subprice';
3529 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3533 if ($this->element ==
'invoice_supplier_rec') {
3536 if ($this->element ==
'expensereport') {
3537 $fieldup =
'value_unit';
3540 $sql =
"SELECT rowid, qty, ".$fieldup.
" as up, remise_percent, total_ht, ".$fieldtva.
" as total_tva, total_ttc, ".$fieldlocaltax1.
" as total_localtax1, ".$fieldlocaltax2.
" as total_localtax2,";
3541 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3542 if ($this->table_element_line ==
'facturedet') {
3543 $sql .=
', situation_percent';
3545 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
3546 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
3547 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3549 $product_field =
'product_type';
3550 if ($this->table_element_line ==
'contratdet') {
3551 $product_field =
'';
3553 if ($product_field) {
3554 $sql .=
" AND ".$product_field.
" <> 9";
3557 $sql .=
' ORDER by rowid';
3559 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3561 $resql = $this->db->query(
$sql);
3563 $this->total_ht = 0;
3564 $this->total_tva = 0;
3565 $this->total_localtax1 = 0;
3566 $this->total_localtax2 = 0;
3567 $this->total_ttc = 0;
3568 $total_ht_by_vats = array();
3569 $total_tva_by_vats = array();
3570 $total_ttc_by_vats = array();
3571 $this->multicurrency_total_ht = 0;
3572 $this->multicurrency_total_tva = 0;
3573 $this->multicurrency_total_ttc = 0;
3577 $num = $this->db->num_rows($resql);
3580 $obj = $this->db->fetch_object($resql);
3583 $parameters = array(
'fk_element' => $obj->rowid);
3584 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
3586 if (empty($reshook) && $forcedroundingmode ==
'0') {
3588 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3589 $tmpcal =
calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0,
'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx);
3591 $diff_when_using_price_ht =
price2num($tmpcal[1] - $obj->total_tva,
'MT', 1);
3592 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
3596 if ($diff_on_current_total) {
3598 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]).
" WHERE rowid = ".((int) $obj->rowid);
3599 dol_syslog(
'We found unconsistent data into detailed line (diff_on_current_total = '.$diff_on_current_total.
') for line rowid = '.$obj->rowid.
" (ht=".$obj->total_ht.
" vat=".$obj->total_tva.
" tax1=".$obj->total_localtax1.
" tax2=".$obj->total_localtax2.
" ttc=".$obj->total_ttc.
"). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix, LOG_WARNING);
3600 $resqlfix = $this->db->query($sqlfix);
3604 $obj->total_tva = $tmpcal[1];
3605 $obj->total_ttc = $tmpcal[2];
3606 } elseif ($diff_when_using_price_ht && $roundingadjust ==
'0') {
3609 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]).
" WHERE rowid = ".((int) $obj->rowid);
3610 dol_syslog(
'We found a line with different rounding data into detailed line (diff_when_using_price_ht = '.$diff_when_using_price_ht.
' and diff_on_current_total = '.$diff_on_current_total.
') for line rowid = '.$obj->rowid.
" (total vat of line calculated=".$tmpcal[1].
", database=".$obj->total_tva.
"). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
3611 $resqlfix = $this->db->query($sqlfix);
3615 $obj->total_tva = $tmpcal[1];
3616 $obj->total_ttc = $tmpcal[2];
3620 $this->total_ht += $obj->total_ht;
3621 $this->total_tva += $obj->total_tva;
3622 $this->total_localtax1 += $obj->total_localtax1;
3623 $this->total_localtax2 += $obj->total_localtax2;
3624 $this->total_ttc += $obj->total_ttc;
3625 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
3626 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
3627 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
3629 if (!isset($total_ht_by_vats[$obj->vatrate])) {
3630 $total_ht_by_vats[$obj->vatrate] = 0;
3632 if (!isset($total_tva_by_vats[$obj->vatrate])) {
3633 $total_tva_by_vats[$obj->vatrate] = 0;
3635 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3636 $total_ttc_by_vats[$obj->vatrate] = 0;
3638 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
3639 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3640 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3642 if ($forcedroundingmode ==
'1') {
3643 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
3644 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat,
'MT', 1);
3647 if (abs($diff) > (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)))) {
3649 $errmsg =
'A rounding difference was detected into TOTAL but is too high to be corrected. Some data in your lines may be corrupted. Try to edit each line manually to fix this before restarting.';
3651 $this->error = $errmsg;
3655 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num($obj->total_tva - $diff).
", total_ttc = ".
price2num($obj->total_ttc - $diff).
" WHERE rowid = ".((int) $obj->rowid);
3656 dol_syslog(
'We found a difference of '.$diff.
' for line rowid = '.$obj->rowid.
". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
3658 $resqlfix = $this->db->query($sqlfix);
3664 $this->total_tva = (
float)
price2num($this->total_tva - $diff,
'', 1);
3665 $this->total_ttc = (
float)
price2num($this->total_ttc - $diff,
'', 1);
3666 $total_tva_by_vats[$obj->vatrate] = (
float)
price2num($total_tva_by_vats[$obj->vatrate] - $diff,
'', 1);
3667 $total_ttc_by_vats[$obj->vatrate] = (
float)
price2num($total_ttc_by_vats[$obj->vatrate] - $diff,
'', 1);
3675 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
3676 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
3679 if (!empty($this->situation_cycle_ref) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits') && $this->
type != $this::TYPE_CREDIT_NOTE) {
3680 $prev_sits = $this->get_prev_sits();
3682 foreach ($prev_sits as $sit) {
3683 $this->total_ht -= $sit->total_ht;
3684 $this->total_tva -= $sit->total_tva;
3685 $this->total_localtax1 -= $sit->total_localtax1;
3686 $this->total_localtax2 -= $sit->total_localtax2;
3687 $this->total_ttc -= $sit->total_ttc;
3688 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
3689 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
3690 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
3697 $this->total_localtax1 = (
float)
price2num($this->total_localtax1);
3698 $this->total_localtax2 = (
float)
price2num($this->total_localtax2);
3701 $this->db->free($resql);
3704 $fieldht =
'total_ht';
3706 $fieldlocaltax1 =
'localtax1';
3707 $fieldlocaltax2 =
'localtax2';
3708 $fieldttc =
'total_ttc';
3710 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
3711 $fieldtva =
'total_tva';
3714 if (!$error && empty($nodatabaseupdate)) {
3715 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
3718 $sql .=
" ".$fieldlocaltax1.
" = ".((
float)
price2num($this->total_localtax1,
'MT', 1)).
",";
3719 $sql .=
" ".$fieldlocaltax2.
" = ".((
float)
price2num($this->total_localtax2,
'MT', 1)).
",";
3721 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
3722 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
3723 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
3724 $sql .=
" WHERE rowid = ".((int) $this->
id);
3726 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3727 $resql = $this->db->query(
$sql);
3731 $this->error = $this->db->lasterror();
3732 $this->errors[] = $this->db->lasterror();
3737 $this->db->commit();
3740 $this->db->rollback();
3760 public function add_object_linked($origin =
null, $origin_id =
null, $f_user =
null, $notrigger = 0)
3763 global $user, $hookmanager, $action;
3764 $origin = (!empty($origin) ? $origin : $this->origin);
3765 $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
3766 $f_user = isset($f_user) ? $f_user : $user;
3769 if ($origin ==
'order') {
3770 $origin =
'commande';
3772 if ($origin ==
'invoice') {
3773 $origin =
'facture';
3775 if ($origin ==
'invoice_template') {
3776 $origin =
'facturerec';
3778 if ($origin ==
'supplierorder') {
3779 $origin =
'order_supplier';
3784 $coremodule = array(
'knowledgemanagement',
'partnership',
'workstation',
'ticket',
'recruitment',
'eventorganization',
'asset');
3786 $targettype = ((!empty($this->module) && ! in_array($this->module, $coremodule)) ? $this->module.
'_' :
'').$this->element;
3788 $parameters = array(
'targettype'=>$targettype);
3790 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3792 if (!empty($hookmanager->resArray[
'targettype'])) $targettype = $hookmanager->resArray[
'targettype'];
3798 $sql =
"INSERT INTO " . $this->db->prefix() .
"element_element (";
3799 $sql .=
"fk_source";
3800 $sql .=
", sourcetype";
3801 $sql .=
", fk_target";
3802 $sql .=
", targettype";
3803 $sql .=
") VALUES (";
3804 $sql .= ((int) $origin_id);
3805 $sql .=
", '" . $this->db->escape($origin) .
"'";
3806 $sql .=
", " . ((int) $this->
id);
3807 $sql .=
", '" . $this->db->escape($targettype) .
"'";
3810 dol_syslog(get_class($this) .
"::add_object_linked", LOG_DEBUG);
3811 if ($this->db->query(
$sql)) {
3814 $this->context[
'link_origin'] = $origin;
3815 $this->context[
'link_origin_id'] = $origin_id;
3816 $result = $this->call_trigger(
'OBJECT_LINK_INSERT', $f_user);
3823 $this->error = $this->db->lasterror();
3828 $this->db->commit();
3831 $this->db->rollback();
3858 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
3860 global $conf, $hookmanager, $action;
3864 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
3868 $this->linkedObjectsIds = array();
3869 $this->linkedObjects = array();
3871 $justsource =
false;
3872 $justtarget =
false;
3873 $withtargettype =
false;
3874 $withsourcetype =
false;
3876 $parameters = array(
'sourcetype'=>$sourcetype,
'sourceid'=>$sourceid,
'targettype'=>$targettype,
'targetid'=>$targetid);
3878 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3880 if (!empty($hookmanager->resArray[
'sourcetype'])) $sourcetype = $hookmanager->resArray[
'sourcetype'];
3881 if (!empty($hookmanager->resArray[
'sourceid'])) $sourceid = $hookmanager->resArray[
'sourceid'];
3882 if (!empty($hookmanager->resArray[
'targettype'])) $targettype = $hookmanager->resArray[
'targettype'];
3883 if (!empty($hookmanager->resArray[
'targetid'])) $targetid = $hookmanager->resArray[
'targetid'];
3886 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
3888 if (!empty($targettype)) {
3889 $withtargettype =
true;
3892 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
3894 if (!empty($sourcetype)) {
3895 $withsourcetype =
true;
3899 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
3900 $targetid = (!empty($targetid) ? $targetid : $this->id);
3901 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
3902 $targettype = (!empty($targettype) ? $targettype : $this->element);
3911 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
3912 $sql .=
" FROM ".$this->db->prefix().
"element_element";
3914 if ($justsource || $justtarget) {
3916 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3917 if ($withtargettype) {
3918 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
3920 } elseif ($justtarget) {
3921 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
3922 if ($withsourcetype) {
3923 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3927 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
3928 $sql .=
" ".$clause.
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
3929 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
3930 $this->linkedObjectsFullLoaded[$this->id] =
true;
3933 $sql .=
" ORDER BY ".$orderby;
3935 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
3936 $resql = $this->db->query(
$sql);
3938 $num = $this->db->num_rows($resql);
3941 $obj = $this->db->fetch_object($resql);
3942 if ($justsource || $justtarget) {
3944 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
3945 } elseif ($justtarget) {
3946 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
3949 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
3950 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
3952 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
3953 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
3959 if (!empty($this->linkedObjectsIds)) {
3960 $tmparray = $this->linkedObjectsIds;
3961 foreach ($tmparray as $objecttype => $objectids) {
3963 $module = $element = $subelement = $objecttype;
3965 if ($objecttype !=
'supplier_proposal' && $objecttype !=
'order_supplier' && $objecttype !=
'invoice_supplier'
3966 && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
3967 $module = $element = $regs[1];
3968 $subelement = $regs[2];
3971 $classpath = $element.
'/class';
3973 if ($objecttype ==
'facture') {
3974 $classpath =
'compta/facture/class';
3975 } elseif ($objecttype ==
'facturerec') {
3976 $classpath =
'compta/facture/class';
3977 $module =
'facture';
3978 } elseif ($objecttype ==
'propal') {
3979 $classpath =
'comm/propal/class';
3980 } elseif ($objecttype ==
'supplier_proposal') {
3981 $classpath =
'supplier_proposal/class';
3982 } elseif ($objecttype ==
'shipping') {
3983 $classpath =
'expedition/class';
3984 $subelement =
'expedition';
3985 $module =
'expedition';
3986 } elseif ($objecttype ==
'delivery') {
3987 $classpath =
'delivery/class';
3988 $subelement =
'delivery';
3989 $module =
'delivery_note';
3990 } elseif ($objecttype ==
'invoice_supplier' || $objecttype ==
'order_supplier') {
3991 $classpath =
'fourn/class';
3992 $module =
'fournisseur';
3993 } elseif ($objecttype ==
'fichinter') {
3994 $classpath =
'fichinter/class';
3995 $subelement =
'fichinter';
3996 $module =
'ficheinter';
3997 } elseif ($objecttype ==
'subscription') {
3998 $classpath =
'adherents/class';
3999 $module =
'adherent';
4000 } elseif ($objecttype ==
'contact') {
4001 $module =
'societe';
4004 $classfile = strtolower($subelement);
4005 $classname = ucfirst($subelement);
4007 if ($objecttype ==
'order') {
4008 $classfile =
'commande';
4009 $classname =
'Commande';
4010 } elseif ($objecttype ==
'invoice_supplier') {
4011 $classfile =
'fournisseur.facture';
4012 $classname =
'FactureFournisseur';
4013 } elseif ($objecttype ==
'order_supplier') {
4014 $classfile =
'fournisseur.commande';
4015 $classname =
'CommandeFournisseur';
4016 } elseif ($objecttype ==
'supplier_proposal') {
4017 $classfile =
'supplier_proposal';
4018 $classname =
'SupplierProposal';
4019 } elseif ($objecttype ==
'facturerec') {
4020 $classfile =
'facture-rec';
4021 $classname =
'FactureRec';
4022 } elseif ($objecttype ==
'subscription') {
4023 $classfile =
'subscription';
4024 $classname =
'Subscription';
4025 } elseif ($objecttype ==
'project' || $objecttype ==
'projet') {
4026 $classpath =
'projet/class';
4027 $classfile =
'project';
4028 $classname =
'Project';
4029 } elseif ($objecttype ==
'conferenceorboothattendee') {
4030 $classpath =
'eventorganization/class';
4031 $classfile =
'conferenceorboothattendee';
4032 $classname =
'ConferenceOrBoothAttendee';
4033 $module =
'eventorganization';
4034 } elseif ($objecttype ==
'conferenceorbooth') {
4035 $classpath =
'eventorganization/class';
4036 $classfile =
'conferenceorbooth';
4037 $classname =
'ConferenceOrBooth';
4038 $module =
'eventorganization';
4039 } elseif ($objecttype ==
'mo') {
4040 $classpath =
'mrp/class';
4047 if (
isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4048 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4051 if (class_exists($classname)) {
4052 foreach ($objectids as $i => $objectid) {
4053 $object =
new $classname($this->db);
4054 $ret = $object->fetch($objectid);
4056 $this->linkedObjects[$objecttype][$i] = $object;
4062 unset($this->linkedObjectsIds[$objecttype]);
4081 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4082 unset($this->linkedObjectsFullLoaded[$this->
id]);
4100 public function updateObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $f_user =
null, $notrigger = 0)
4103 $updatesource =
false;
4104 $updatetarget =
false;
4105 $f_user = isset($f_user) ? $f_user : $user;
4107 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4108 $updatesource =
true;
4109 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4110 $updatetarget =
true;
4116 $sql =
"UPDATE " . $this->db->prefix() .
"element_element SET ";
4117 if ($updatesource) {
4118 $sql .=
"fk_source = " . ((int) $sourceid);
4119 $sql .=
", sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4120 $sql .=
" WHERE fk_target = " . ((int) $this->
id);
4121 $sql .=
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4122 } elseif ($updatetarget) {
4123 $sql .=
"fk_target = " . ((int) $targetid);
4124 $sql .=
", targettype = '" . $this->db->escape($targettype) .
"'";
4125 $sql .=
" WHERE fk_source = " . ((int) $this->
id);
4126 $sql .=
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4129 dol_syslog(get_class($this) .
"::updateObjectLinked", LOG_DEBUG);
4130 if ($this->db->query(
$sql)) {
4133 $this->context[
'link_source_id'] = $sourceid;
4134 $this->context[
'link_source_type'] = $sourcetype;
4135 $this->context[
'link_target_id'] = $targetid;
4136 $this->context[
'link_target_type'] = $targettype;
4137 $result = $this->call_trigger(
'OBJECT_LINK_MODIFY', $f_user);
4144 $this->error = $this->db->lasterror();
4149 $this->db->commit();
4152 $this->db->rollback();
4170 public function deleteObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $rowid =
'', $f_user =
null, $notrigger = 0)
4173 $deletesource =
false;
4174 $deletetarget =
false;
4175 $f_user = isset($f_user) ? $f_user : $user;
4177 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4178 $deletesource =
true;
4179 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4180 $deletetarget =
true;
4183 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4184 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
4185 $targetid = (!empty($targetid) ? $targetid : $this->id);
4186 $targettype = (!empty($targettype) ? $targettype : $this->element);
4192 $this->context[
'link_id'] = $rowid;
4193 $this->context[
'link_source_id'] = $sourceid;
4194 $this->context[
'link_source_type'] = $sourcetype;
4195 $this->context[
'link_target_id'] = $targetid;
4196 $this->context[
'link_target_type'] = $targettype;
4197 $result = $this->call_trigger(
'OBJECT_LINK_DELETE', $f_user);
4205 $sql =
"DELETE FROM " . $this->db->prefix() .
"element_element";
4208 $sql .=
" rowid = " . ((int) $rowid);
4210 if ($deletesource) {
4211 $sql .=
" fk_source = " . ((int) $sourceid) .
" AND sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4212 $sql .=
" AND fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4213 } elseif ($deletetarget) {
4214 $sql .=
" fk_target = " . ((int) $targetid) .
" AND targettype = '" . $this->db->escape($targettype) .
"'";
4215 $sql .=
" AND fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4217 $sql .=
" (fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"')";
4219 $sql .=
" (fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"')";
4223 dol_syslog(get_class($this) .
"::deleteObjectLinked", LOG_DEBUG);
4224 if (!$this->db->query(
$sql)) {
4225 $this->error = $this->db->lasterror();
4226 $this->errors[] = $this->error;
4232 $this->db->commit();
4235 $this->db->rollback();
4251 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4257 $sql =
"SELECT ".$field_select.
" FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4258 $resql = $db->query(
$sql);
4261 if (!empty($resql)) {
4262 while ($res = $db->fetch_object($resql)) {
4263 $TRes[] = $res->{$field_select};
4280 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4286 $sql =
"DELETE FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4287 $resql = $db->query(
$sql);
4289 if (empty($resql)) {
4306 public function setStatut($status, $elementId =
null, $elementType =
'', $trigkey =
'', $fieldstatus =
'fk_statut')
4308 global $user, $langs, $conf;
4310 $savElementId = $elementId;
4312 $elementId = (!empty($elementId) ? $elementId : $this->id);
4313 $elementTable = (!empty($elementType) ? $elementType : $this->table_element);
4317 if ($elementTable ==
'facture_rec') {
4318 $fieldstatus =
"suspended";
4320 if ($elementTable ==
'mailing') {
4321 $fieldstatus =
"statut";
4323 if ($elementTable ==
'cronjob') {
4324 $fieldstatus =
"status";
4326 if ($elementTable ==
'user') {
4327 $fieldstatus =
"statut";
4329 if ($elementTable ==
'expensereport') {
4330 $fieldstatus =
"fk_statut";
4332 if ($elementTable ==
'commande_fournisseur_dispatch') {
4333 $fieldstatus =
"status";
4335 if (isset($this->fields) && is_array($this->fields) && array_key_exists(
'status', $this->fields)) {
4336 $fieldstatus =
'status';
4339 $sql =
"UPDATE ".$this->db->prefix().$elementTable;
4340 $sql .=
" SET ".$fieldstatus.
" = ".((int) $status);
4343 if ($status == 1 && in_array($elementTable, array(
'expensereport',
'inventory'))) {
4344 $sql .=
", fk_user_valid = ".((int) $user->id);
4346 if ($status == 1 && in_array($elementTable, array(
'expensereport'))) {
4347 $sql .=
", date_valid = '".$this->db->idate(
dol_now()).
"'";
4349 if ($status == 1 && in_array($elementTable, array(
'inventory'))) {
4350 $sql .=
", date_validation = '".$this->db->idate(
dol_now()).
"'";
4352 $sql .=
" WHERE rowid = ".((int) $elementId);
4353 $sql .=
" AND ".$fieldstatus.
" <> ".((int) $status);
4355 dol_syslog(get_class($this).
"::setStatut", LOG_DEBUG);
4356 $resql = $this->db->query(
$sql);
4360 $nb_rows_affected = $this->db->affected_rows($resql);
4362 if ($nb_rows_affected > 0) {
4363 if (empty($trigkey)) {
4365 if ($this->element ==
'supplier_proposal' && $status == 2) {
4366 $trigkey =
'SUPPLIER_PROPOSAL_SIGN';
4368 if ($this->element ==
'supplier_proposal' && $status == 3) {
4369 $trigkey =
'SUPPLIER_PROPOSAL_REFUSE';
4371 if ($this->element ==
'supplier_proposal' && $status == 4) {
4372 $trigkey =
'SUPPLIER_PROPOSAL_CLOSE';
4374 if ($this->element ==
'fichinter' && $status == 3) {
4375 $trigkey =
'FICHINTER_CLASSIFY_DONE';
4377 if ($this->element ==
'fichinter' && $status == 2) {
4378 $trigkey =
'FICHINTER_CLASSIFY_BILLED';
4380 if ($this->element ==
'fichinter' && $status == 1) {
4381 $trigkey =
'FICHINTER_CLASSIFY_UNBILLED';
4387 $result = $this->call_trigger($trigkey, $user);
4398 $this->db->commit();
4400 if (empty($savElementId)) {
4402 if ($fieldstatus ==
'tosell') {
4403 $this->status = $status;
4404 } elseif ($fieldstatus ==
'tobuy') {
4405 $this->status_buy = $status;
4407 $this->statut = $status;
4408 $this->status = $status;
4414 $this->db->rollback();
4415 dol_syslog(get_class($this).
"::setStatut ".$this->error, LOG_ERR);
4419 $this->error = $this->db->lasterror();
4420 $this->db->rollback();
4437 if (empty($id) && empty($ref)) {
4440 if (!empty($conf->global->MAIN_DISABLE_CANVAS)) {
4447 $sql =
"SELECT rowid, canvas";
4448 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
4449 $sql .=
" WHERE entity IN (".getEntity($this->element).
")";
4451 $sql .=
" AND rowid = ".((int) $id);
4454 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
4457 $resql = $this->db->query(
$sql);
4459 $obj = $this->db->fetch_object($resql);
4461 $this->canvas = $obj->canvas;
4481 $sql =
"SELECT special_code FROM ".$this->db->prefix().$this->table_element_line;
4482 $sql .=
" WHERE rowid = ".((int) $lineid);
4483 $resql = $this->db->query(
$sql);
4485 $row = $this->db->fetch_row($resql);
4509 if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
4510 dol_print_error(
'Called isObjectUsed on a class with property this->childtables not defined');
4514 $arraytoscan = $this->childtables;
4516 $tmparray = array_keys($this->childtables);
4517 if (is_numeric($tmparray[0])) {
4518 $arraytoscan = array_flip($this->childtables);
4523 foreach ($arraytoscan as $table => $element) {
4526 $sql =
"SELECT COUNT(*) as nb";
4527 $sql.=
" FROM ".$this->db->prefix().$table.
" as c";
4528 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4529 $sql.=
", ".$this->db->prefix().$element[
'parent'].
" as p";
4531 if (!empty($element[
'fk_element'])) {
4532 $sql.=
" WHERE c.".$element[
'fk_element'].
" = ".((int) $id);
4534 $sql.=
" WHERE c.".$this->fk_element.
" = ".((int) $id);
4536 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4537 $sql.=
" AND c.".$element[
'parentkey'].
" = p.rowid";
4539 if (!empty($element[
'parent']) && !empty($element[
'parenttypefield']) && !empty($element[
'parenttypevalue'])) {
4540 $sql.=
" AND c.".$element[
'parenttypefield'].
" = '".$this->db->escape($element[
'parenttypevalue']).
"'";
4542 if (!empty($entity)) {
4543 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4544 $sql.=
" AND p.entity = ".((int) $entity);
4546 $sql.=
" AND c.entity = ".((int) $entity);
4550 $resql = $this->db->query(
$sql);
4552 $obj = $this->db->fetch_object($resql);
4554 $langs->load(
"errors");
4556 $haschild += $obj->nb;
4557 if (is_numeric($element)) {
4558 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
4559 } elseif (is_string($element)) {
4560 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->
ref, $langs->transnoentitiesnoconv($element));
4562 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->
ref, $langs->transnoentitiesnoconv($element[
'name']));
4567 $this->errors[] = $this->db->lasterror();
4571 if ($haschild > 0) {
4572 $this->errors[] =
"ErrorRecordHasChildren";
4589 foreach ($this->lines as $key => $val) {
4591 if ($predefined == -1) {
4594 if ($predefined == 1 && $val->fk_product > 0) {
4597 if ($predefined == 0 && $val->fk_product <= 0) {
4600 if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
4603 if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
4610 dol_syslog(get_class($this).
'::hasProductsOrServices we found '.$nb.
' qualified lines of products/servcies');
4621 if (!empty($this->table_element_line) ) {
4622 $total_discount = 0.00;
4624 $sql =
"SELECT subprice as pu_ht, qty, remise_percent, total_ht";
4625 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
4626 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
4628 dol_syslog(get_class($this).
'::getTotalDiscount', LOG_DEBUG);
4629 $resql = $this->db->query(
$sql);
4631 $num = $this->db->num_rows($resql);
4634 $obj = $this->db->fetch_object($resql);
4636 $pu_ht = $obj->pu_ht;
4638 $total_ht = $obj->total_ht;
4640 $total_discount_line = floatval(
price2num(($pu_ht * $qty) - $total_ht,
'MT'));
4641 $total_discount += $total_discount_line;
4670 foreach ($this->lines as $line) {
4671 if (isset($line->qty_asked)) {
4672 if (empty($totalOrdered)) {
4675 $totalOrdered += $line->qty_asked;
4677 if (isset($line->qty_shipped)) {
4678 if (empty($totalToShip)) {
4681 $totalToShip += $line->qty_shipped;
4682 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
4683 if (empty($totalToShip)) {
4686 $totalToShip += $line->qty;
4690 if ($this->element ==
'shipping') {
4692 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
4694 $qty = $line->qty ? $line->qty : 0;
4697 $weight = !empty($line->weight) ? $line->weight : 0;
4698 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
4699 $volume = !empty($line->volume) ? $line->volume : 0;
4700 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
4702 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
4703 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
4704 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
4705 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
4709 if (!empty($weight_units)) {
4710 $weightUnit = $weight_units;
4712 if (!empty($volume_units)) {
4713 $volumeUnit = $volume_units;
4716 if (empty($totalWeight)) {
4719 if (empty($totalVolume)) {
4724 if ($weight_units < 50) {
4725 $trueWeightUnit = pow(10, $weightUnit);
4726 $totalWeight += $weight * $qty * $trueWeightUnit;
4728 if ($weight_units == 99) {
4730 $trueWeightUnit = 0.45359237;
4731 $totalWeight += $weight * $qty * $trueWeightUnit;
4732 } elseif ($weight_units == 98) {
4734 $trueWeightUnit = 0.0283495;
4735 $totalWeight += $weight * $qty * $trueWeightUnit;
4737 $totalWeight += $weight * $qty;
4740 if ($volume_units < 50) {
4742 $trueVolumeUnit = pow(10, $volumeUnit);
4744 $totalVolume += $volume * $qty * $trueVolumeUnit;
4746 $totalVolume += $volume * $qty;
4750 return array(
'weight'=>$totalWeight,
'volume'=>$totalVolume,
'ordered'=>$totalOrdered,
'toship'=>$totalToShip);
4763 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
4765 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
4766 $sql .=
" SET extraparams = ".(!empty($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null");
4767 $sql .=
" WHERE rowid = ".((int) $this->
id);
4769 dol_syslog(get_class($this).
"::setExtraParameters", LOG_DEBUG);
4770 $resql = $this->db->query(
$sql);
4772 $this->error = $this->db->lasterror();
4773 $this->db->rollback();
4776 $this->db->commit();
4799 global $conf, $user, $langs, $object, $hookmanager, $extrafields;
4803 if (!is_object($extrafields)) {
4804 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
4807 $extrafields->fetch_name_optionals_label($this->table_element_line);
4812 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4813 foreach ($dirtpls as $module => $reldir) {
4814 if (!empty($module)) {
4817 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_create.tpl.php';
4820 if (empty($conf->file->strict_mode)) {
4821 $res = @include $tpl;
4823 $res = include $tpl;
4850 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
4852 global $conf, $hookmanager, $langs, $user,
$form, $extrafields, $object;
4854 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
4858 if (
isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
4862 $num = count($this->lines);
4865 if (!is_object($extrafields)) {
4866 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
4869 $extrafields->fetch_name_optionals_label($this->table_element_line);
4871 $parameters = array(
'num'=>$num,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$this->table_element_line);
4872 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
4873 if (empty($reshook)) {
4877 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4878 foreach ($dirtpls as $module => $reldir) {
4880 if (!empty($module)) {
4883 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
4885 if (file_exists($tpl)) {
4886 if (empty($conf->file->strict_mode)) {
4887 $res = @include $tpl;
4889 $res = include $tpl;
4900 print
"<!-- begin printObjectLines() --><tbody>\n";
4901 foreach ($this->lines as $line) {
4903 $line->fetch_optionals();
4906 if (is_object($hookmanager)) {
4907 if (empty($line->fk_parent_line)) {
4908 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element);
4909 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
4911 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element,
'fk_parent_line'=>$line->fk_parent_line);
4912 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
4915 if (empty($reshook)) {
4916 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
4921 print
"</tbody><!-- end printObjectLines() -->\n";
4941 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
4943 global $conf, $langs, $user, $object, $hookmanager;
4945 global $object_rights, $disableedit, $disablemove, $disableremove;
4947 $object_rights = $this->getRights();
4953 if ($action !=
'editline' || $selected != $line->id) {
4955 if (!empty($line->fk_product) && $line->fk_product > 0) {
4956 $product_static =
new Product($this->db);
4957 $product_static->fetch($line->fk_product);
4959 $product_static->ref = $line->ref;
4960 $product_static->label = !empty($line->label) ? $line->label :
"";
4962 $text = $product_static->getNomUrl(1);
4966 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
4967 dol_print_error(
'',
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
4971 $prod =
new Product($this->db);
4972 $prod->fetch($line->fk_product);
4974 $outputlangs = $langs;
4976 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
4977 $newlang =
GETPOST(
'lang_id',
'aZ09');
4979 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
4980 $newlang = $this->thirdparty->default_lang;
4982 if (!empty($newlang)) {
4983 $outputlangs =
new Translate(
"", $conf);
4984 $outputlangs->setDefaultLang($newlang);
4987 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
4989 $label = $line->product_label;
4992 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
4993 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
4996 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5001 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5002 foreach ($dirtpls as $module => $reldir) {
5004 if (!empty($module)) {
5007 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5009 if (file_exists($tpl)) {
5010 if (empty($conf->file->strict_mode)) {
5011 $res = @include $tpl;
5013 $res = include $tpl;
5023 if ($this->statut == 0 && $action ==
'editline' && $selected == $line->id) {
5024 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5026 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5031 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5032 foreach ($dirtpls as $module => $reldir) {
5033 if (!empty($module)) {
5036 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5039 if (empty($conf->file->strict_mode)) {
5040 $res = @include $tpl;
5042 $res = include $tpl;
5067 global $langs, $hookmanager, $conf,
$form, $action;
5069 print
'<tr class="liste_titre">';
5070 print
'<td class="linecolref">'.$langs->trans(
'Ref').
'</td>';
5071 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
5072 print
'<td class="linecolvat right">'.$langs->trans(
'VATRate').
'</td>';
5073 print
'<td class="linecoluht right">'.$langs->trans(
'PriceUHT').
'</td>';
5075 print
'<td class="linecoluht_currency right">'.$langs->trans(
'PriceUHTCurrency').
'</td>';
5077 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
5079 print
'<td class="linecoluseunit left">'.$langs->trans(
'Unit').
'</td>';
5081 print
'<td class="linecoldiscount right">'.$langs->trans(
'ReductionShort').
'</td>';
5082 print
'<td class="linecolht right">'.$langs->trans(
'TotalHT').
'</td>';
5083 print
'<td class="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
5087 if (!empty($this->lines)) {
5088 foreach ($this->lines as $line) {
5091 if (is_object($hookmanager)) {
5092 $parameters = array(
'line'=>$line,
'i'=>$i,
'restrictlist'=>$restrictlist,
'selectedLines'=> $selectedLines);
5093 if (!empty($line->fk_parent_line)) { $parameters[
'fk_parent_line'] = $line->fk_parent_line; }
5094 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
5096 if (empty($reshook)) {
5097 $this->printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
5118 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5120 global $langs, $conf;
5123 if (!empty($line->date_start)) {
5124 $date_start = $line->date_start;
5126 $date_start = $line->date_debut_prevue;
5127 if ($line->date_debut_reel) {
5128 $date_start = $line->date_debut_reel;
5131 if (!empty($line->date_end)) {
5132 $date_end = $line->date_end;
5134 $date_end = $line->date_fin_prevue;
5135 if ($line->date_fin_reel) {
5136 $date_end = $line->date_fin_reel;
5140 $this->tpl[
'id'] = $line->id;
5142 $this->tpl[
'label'] =
'';
5143 if (!empty($line->fk_parent_line)) {
5144 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5147 if (($line->info_bits & 2) == 2) {
5149 $discount->fk_soc = $this->socid;
5150 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5151 } elseif (!empty($line->fk_product)) {
5152 $productstatic =
new Product($this->db);
5153 $productstatic->id = $line->fk_product;
5154 $productstatic->ref = $line->ref;
5155 $productstatic->type = $line->fk_product_type;
5156 if (empty($productstatic->ref)) {
5157 $line->fetch_product();
5158 $productstatic = $line->product;
5161 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
5162 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5164 if ($line->product_type == 1 && ($date_start || $date_end)) {
5168 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
''),
'service') :
img_object($langs->trans(
''),
'product')));
5169 if (!empty($line->desc)) {
5170 $this->tpl[
'label'] .= $line->desc;
5172 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5176 if ($line->product_type == 1 && ($date_start || $date_end)) {
5181 if (!empty($line->desc)) {
5182 if ($line->desc ==
'(CREDIT_NOTE)') {
5184 $discount->fetch($line->fk_remise_except);
5185 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5186 } elseif ($line->desc ==
'(DEPOSIT)') {
5188 $discount->fetch($line->fk_remise_except);
5189 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5190 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5192 $discount->fetch($line->fk_remise_except);
5193 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5194 } elseif ($line->desc ==
'(EXCESS PAID)') {
5196 $discount->fetch($line->fk_remise_except);
5197 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5199 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5202 $this->tpl[
'description'] =
' ';
5206 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5207 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5208 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5209 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5212 $this->tpl[
'price'] =
price($line->subprice);
5213 $this->tpl[
'total_ht'] =
price($line->total_ht);
5214 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5215 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5217 $this->tpl[
'unit'] = $langs->transnoentities($line->getLabelOfUnit(
'long'));
5219 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate($line->remise_percent,
true) :
' ';
5222 $this->tpl[
'strike'] = 0;
5224 $this->tpl[
'strike'] = 1;
5229 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5230 foreach ($dirtpls as $module => $reldir) {
5231 if (!empty($module)) {
5234 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5237 if (empty($conf->file->strict_mode)) {
5238 $res = @include $tpl;
5240 $res = include $tpl;
5265 $sql =
"INSERT INTO ".$this->db->prefix().
"element_resources (";
5266 $sql .=
"resource_id";
5267 $sql .=
", resource_type";
5268 $sql .=
", element_id";
5269 $sql .=
", element_type";
5271 $sql .=
", mandatory";
5272 $sql .=
") VALUES (";
5273 $sql .= ((int) $resource_id);
5274 $sql .=
", '".$this->db->escape($resource_type).
"'";
5275 $sql .=
", '".$this->db->escape($this->
id).
"'";
5276 $sql .=
", '".$this->db->escape($this->element).
"'";
5277 $sql .=
", '".$this->db->escape($busy).
"'";
5278 $sql .=
", '".$this->db->escape($mandatory).
"'";
5281 dol_syslog(get_class($this).
"::add_element_resource", LOG_DEBUG);
5282 if ($this->db->query(
$sql)) {
5283 $this->db->commit();
5286 $this->error = $this->db->lasterror();
5287 $this->db->rollback();
5308 $sql =
"DELETE FROM ".$this->db->prefix().
"element_resources";
5309 $sql .=
" WHERE rowid = ".((int) $rowid);
5311 dol_syslog(get_class($this).
"::delete_resource", LOG_DEBUG);
5313 $resql = $this->db->query(
$sql);
5315 $this->error = $this->db->lasterror();
5316 $this->db->rollback();
5320 $result = $this->call_trigger(strtoupper($element).
'_DELETE_RESOURCE', $user);
5322 $this->db->rollback();
5326 $this->db->commit();
5340 if (isset($this->lines) && is_array($this->lines)) {
5341 $nboflines = count($this->lines);
5342 for ($i = 0; $i < $nboflines; $i++) {
5343 $this->lines[$i] = clone $this->lines[$i];
5361 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5363 global $conf, $langs, $user, $hookmanager, $action;
5365 $srctemplatepath =
'';
5367 $parameters = array(
'modelspath'=>$modelspath,
'modele'=>$modele,
'outputlangs'=>$outputlangs,
'hidedetails'=>$hidedetails,
'hidedesc'=>$hidedesc,
'hideref'=>$hideref,
'moreparams'=>$moreparams);
5368 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5370 if (!empty($reshook)) {
5374 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5376 if (empty($modele)) {
5377 $this->error =
'BadValueForParameterModele';
5382 $err = error_reporting();
5384 @set_time_limit(120);
5385 error_reporting($err);
5388 $tmp = explode(
':', $modele, 2);
5389 if (!empty($tmp[1])) {
5391 $srctemplatepath = $tmp[1];
5398 $dirmodels = array(
'/');
5399 if (is_array($conf->modules_parts[
'models'])) {
5400 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
5402 foreach ($dirmodels as $reldir) {
5403 foreach (array(
'doc',
'pdf') as $prefix) {
5404 if (in_array(get_class($this), array(
'Adherent'))) {
5406 $file = $prefix.
"_".$modele.
".class.php";
5409 $file = $prefix.
"_".$modele.
".modules.php";
5414 if (file_exists($file)) {
5416 $classname = $prefix.
'_'.$modele;
5426 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5427 $this->errors[] = $this->error;
5437 $obj =
new $classname($this->db);
5440 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5441 $varfortemplatedir = $obj->scandir;
5442 if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) {
5443 $dirtoscan = $conf->global->$varfortemplatedir;
5445 $listoffiles = array();
5448 $listofdir = explode(
',', $dirtoscan);
5449 foreach ($listofdir as $key => $tmpdir) {
5450 $tmpdir = trim($tmpdir);
5451 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5453 unset($listofdir[$key]);
5456 if (is_dir($tmpdir)) {
5457 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
5458 if (count($tmpfiles)) {
5459 $listoffiles = array_merge($listoffiles, $tmpfiles);
5464 if (count($listoffiles)) {
5465 foreach ($listoffiles as $record) {
5466 $srctemplatepath = $record[
'fullname'];
5472 if (empty($srctemplatepath)) {
5473 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
5478 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
5480 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
5481 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
5488 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
5490 if (in_array(get_class($this), array(
'Adherent'))) {
5491 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards', $moreparams);
5493 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
5497 if ($resultwritefile > 0) {
5498 $outputlangs->charset_output = $sav_charset_output;
5501 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5505 if (!empty($obj->result[
'fullpath'])) {
5506 $destfull = $obj->result[
'fullpath'];
5509 $update_main_doc_field = 0;
5510 if (!empty($obj->update_main_doc_field)) {
5511 $update_main_doc_field = 1;
5517 $this->indexFile($destfull, $update_main_doc_field);
5520 dol_syslog(
'Method ->write_file was called on object '.get_class($obj).
' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
5528 $outputlangs->charset_output = $sav_charset_output;
5529 $this->error = $obj->error;
5530 $this->errors = $obj->errors;
5531 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
5545 public function indexFile($destfull, $update_main_doc_field)
5547 global $conf, $user;
5549 $upload_dir = dirname($destfull);
5550 $destfile = basename($destfull);
5551 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
5553 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5554 $filename = basename($destfile);
5555 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
5556 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
5558 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
5559 $ecmfile =
new EcmFiles($this->db);
5560 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
5563 $setsharekey =
false;
5564 if ($this->element ==
'propal' || $this->element ==
'proposal') {
5565 if (!isset($conf->global->PROPOSAL_ALLOW_ONLINESIGN) || !empty($conf->global->PROPOSAL_ALLOW_ONLINESIGN)) {
5566 $setsharekey =
true;
5568 if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5569 $setsharekey =
true;
5572 if ($this->element ==
'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
5573 $setsharekey =
true;
5575 if ($this->element ==
'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
5576 $setsharekey =
true;
5578 if ($this->element ==
'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
5579 $setsharekey =
true;
5581 if ($this->element ==
'product' && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) {
5582 $setsharekey =
true;
5584 if ($this->element ==
'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) {
5585 $setsharekey =
true;
5587 if ($this->element ==
'fichinter' && !empty($conf->global->FICHINTER_ALLOW_EXTERNAL_DOWNLOAD)) {
5588 $setsharekey =
true;
5590 if ($this->element ==
'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5591 $setsharekey =
true;
5595 if (empty($ecmfile->share)) {
5596 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5603 $ecmfile->fullpath_orig =
'';
5604 $ecmfile->gen_or_uploaded =
'generated';
5605 $ecmfile->description =
'';
5606 $ecmfile->keywords =
'';
5607 $result = $ecmfile->update($user);
5613 $ecmfile->entity = $conf->entity;
5614 $ecmfile->filepath = $rel_dir;
5615 $ecmfile->filename = $filename;
5617 $ecmfile->fullpath_orig =
'';
5618 $ecmfile->gen_or_uploaded =
'generated';
5619 $ecmfile->description =
'';
5620 $ecmfile->keywords =
'';
5621 $ecmfile->src_object_type = $this->table_element;
5622 $ecmfile->src_object_id = $this->id;
5624 $result = $ecmfile->create($user);
5636 if ($update_main_doc_field && !empty($this->table_element)) {
5637 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
5638 $sql .=
" WHERE rowid = ".((int) $this->
id);
5640 $resql = $this->db->query(
$sql);
5645 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
5664 if (file_exists($file_osencoded)) {
5665 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5668 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
5669 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
5670 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
5671 $maxheightmini = $tmparraysize[
'maxheightmini'];
5677 vignette($file_osencoded, $maxwidthsmall, $maxheightsmall,
'_small', $quality);
5681 vignette($file_osencoded, $maxwidthmini, $maxheightmini,
'_mini', $quality);
5720 global $conf, $_POST;
5724 return GETPOST($fieldname, $type, 3);
5727 if (isset($alternatevalue)) {
5728 return $alternatevalue;
5731 $newelement = $this->element;
5732 if ($newelement ==
'facture') {
5733 $newelement =
'invoice';
5735 if ($newelement ==
'commande') {
5736 $newelement =
'order';
5738 if (empty($newelement)) {
5739 dol_syslog(
"Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
5743 $keyforfieldname = strtoupper($newelement.
'_DEFAULT_'.$fieldname);
5745 if (isset($conf->global->$keyforfieldname)) {
5746 return $conf->global->$keyforfieldname;
5773 global $langs, $conf;
5774 if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX .
'_') !== 0) {
5775 dol_print_error(
'',
'The trigger "' . $triggerName .
'" does not start with "' . self::TRIGGER_PREFIX .
'_" as required.');
5778 if (!is_object($langs)) {
5779 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5783 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5785 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
5788 if (!empty($this->errors)) {
5789 $this->errors = array_unique(array_merge($this->errors, $interface->errors));
5791 $this->errors = $interface->errors;
5811 if (!$this->element) {
5814 if (!($this->
id > 0)) {
5817 if (is_array($this->array_languages)) {
5821 $this->array_languages = array();
5823 $element = $this->element;
5824 if ($element ==
'categorie') {
5825 $element =
'categories';
5829 $sql =
"SELECT rowid, property, lang , value";
5830 $sql .=
" FROM ".$this->db->prefix().
"object_lang";
5831 $sql .=
" WHERE type_object = '".$this->db->escape($element).
"'";
5832 $sql .=
" AND fk_object = ".((int) $this->
id);
5835 $resql = $this->db->query(
$sql);
5837 $numrows = $this->db->num_rows($resql);
5840 while ($i < $numrows) {
5841 $obj = $this->db->fetch_object($resql);
5842 $key = $obj->property;
5843 $value = $obj->value;
5844 $codelang = $obj->lang;
5845 $type = $this->fields[$key][
'type'];
5848 if (preg_match(
'/date/', $type)) {
5849 $this->array_languages[$key][$codelang] = $this->db->jdate($value);
5851 $this->array_languages[$key][$codelang] = $value;
5858 $this->db->free($resql);
5879 global $_POST, $langs;
5882 foreach ($_POST as $postfieldkey => $postfieldvalue) {
5883 $tmparray = explode(
'-', $postfieldkey);
5884 if ($tmparray[0] !=
'field') {
5888 $element = $tmparray[1];
5889 $key = $tmparray[2];
5890 $codelang = $tmparray[3];
5893 if (!empty($onlykey) && $key != $onlykey) {
5896 if ($element != $this->element) {
5900 $key_type = $this->fields[$key][
'type'];
5903 if (isset($this->fields[$key][
'enabled'])) {
5904 $enabled =
dol_eval($this->fields[$key][
'enabled'], 1, 1,
'1');
5911 if (empty($enabled)) {
5916 if (in_array($key_type, array(
'date'))) {
5920 } elseif (in_array($key_type, array(
'datetime'))) {
5923 $value_key =
dol_mktime(
GETPOST($postfieldkey.
"hour",
'int'),
GETPOST($postfieldkey.
"min",
'int'), 0,
GETPOST($postfieldkey.
"month",
'int'),
GETPOST($postfieldkey.
"day",
'int'),
GETPOST($postfieldkey.
"year",
'int'));
5924 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
5925 $value_arr =
GETPOST($postfieldkey,
'array');
5926 if (!empty($value_arr)) {
5927 $value_key = implode(
',', $value_arr);
5931 } elseif (in_array($key_type, array(
'price',
'double'))) {
5932 $value_arr =
GETPOST($postfieldkey,
'alpha');
5935 $value_key =
GETPOST($postfieldkey);
5936 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
5941 $this->array_languages[$key][$codelang] = $value_key;
5966 $savDisableCompute = $conf->disable_compute;
5967 $conf->disable_compute = 1;
5969 $ret = $this->fetch($id);
5971 $conf->disable_compute = $savDisableCompute;
5989 global $conf, $extrafields;
5991 if (empty($rowid)) {
5994 if (empty($rowid) && isset($this->
rowid)) {
5995 $rowid = $this->rowid;
5999 if (!$this->table_element) {
6003 $this->array_options = array();
6005 if (!is_array($optionsArray)) {
6007 if (!isset($extrafields) || !is_object($extrafields)) {
6008 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6013 if (empty($extrafields->attributes[$this->table_element][
'loaded'])) {
6014 $extrafields->fetch_name_optionals_label($this->table_element);
6016 $optionsArray = (!empty($extrafields->attributes[$this->table_element][
'label']) ? $extrafields->attributes[$this->table_element][
'label'] :
null);
6018 global $extrafields;
6019 dol_syslog(
"Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
6022 $table_element = $this->table_element;
6023 if ($table_element ==
'categorie') {
6024 $table_element =
'categories';
6028 if (is_array($optionsArray) && count($optionsArray) > 0) {
6029 $sql =
"SELECT rowid";
6030 foreach ($optionsArray as $name => $label) {
6031 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] !=
'separate') {
6035 $sql .=
" FROM ".$this->db->prefix().$table_element.
"_extrafields";
6036 $sql .=
" WHERE fk_object = ".((int) $rowid);
6039 $resql = $this->db->query(
$sql);
6041 $numrows = $this->db->num_rows($resql);
6043 $tab = $this->db->fetch_array($resql);
6045 foreach ($tab as $key => $value) {
6047 if ($key !=
'rowid' && $key !=
'tms' && $key !=
'fk_member' && !is_int($key)) {
6049 if (!empty($extrafields->attributes[$this->table_element]) && in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date',
'datetime'))) {
6051 $this->array_options[
"options_".$key] = $this->db->jdate($value);
6053 $this->array_options[
"options_".$key] = $value;
6063 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6064 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6065 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'computed'][$key])) {
6067 if (empty($conf->disable_compute)) {
6068 global $objectoffield;
6069 $objectoffield = $this;
6070 $this->array_options[
'options_' . $key] =
dol_eval($extrafields->attributes[$this->table_element][
'computed'][$key], 1, 0,
'');
6076 $this->db->free($resql);
6084 $this->errors[]=$this->db->lasterror;
6101 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6107 $table_element = $this->table_element;
6108 if ($table_element ==
'categorie') {
6109 $table_element =
'categories';
6112 dol_syslog(get_class($this).
"::deleteExtraFields delete", LOG_DEBUG);
6114 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6116 $resql = $this->db->query($sql_del);
6118 $this->error = $this->db->lasterror();
6119 $this->db->rollback();
6122 $this->db->commit();
6139 global $conf, $langs, $user;
6141 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6145 if (empty($userused)) {
6151 if (!empty($this->array_options)) {
6153 $langs->load(
'admin');
6154 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6156 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6159 $new_array_options = array();
6160 foreach ($this->array_options as $key => $value) {
6161 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6162 $new_array_options[$key] = $value;
6163 } elseif (in_array($key, array_keys($target_extrafields))) {
6164 $new_array_options[
'options_'.$key] = $value;
6168 foreach ($new_array_options as $key => $value) {
6169 $attributeKey = substr($key, 8);
6170 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6171 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$attributeKey];
6172 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6173 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6174 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6175 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6179 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6180 $new_array_options[$key] =
null;
6184 if ($attributeRequired) {
6185 $mandatorypb =
false;
6186 if ($attributeType ==
'link' && $this->array_options[$key] ==
'-1') {
6187 $mandatorypb =
true;
6189 if ($this->array_options[$key] ===
'') {
6190 $mandatorypb =
true;
6192 if ($attributeType ==
'sellist' && $this->array_options[$key] ==
'0') {
6193 $mandatorypb =
true;
6196 $langs->load(
"errors");
6197 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6198 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6206 if (!empty($attrfieldcomputed)) {
6207 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6208 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6209 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6210 $new_array_options[$key] = $value;
6212 $new_array_options[$key] =
null;
6216 switch ($attributeType) {
6218 if (!is_numeric($value) && $value !=
'') {
6219 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6221 } elseif ($value ==
'') {
6222 $new_array_options[$key] =
null;
6228 if (!is_numeric($value) && $value !=
'') {
6229 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6230 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6232 } elseif ($value ==
'') {
6236 $new_array_options[$key] = $value;
6246 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6248 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6249 $algo = reset($tmparrays);
6254 if (is_object($this->oldcopy)) {
6256 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6257 $new_array_options[$key] = $this->array_options[$key];
6260 $newvalue =
dol_hash($this->array_options[$key], $algo);
6261 $new_array_options[$key] = $newvalue;
6264 $new_array_options[$key] = $this->array_options[$key];
6269 $new_array_options[$key] = $this->array_options[$key];
6275 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6276 $this->array_options[$key] = strtotime($this->array_options[$key]);
6278 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6282 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6283 $this->array_options[$key] = strtotime($this->array_options[$key]);
6285 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6288 $param_list = array_keys($attributeParam[
'options']);
6291 $InfoFieldList = explode(
":", $param_list[0]);
6293 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6294 if ($value ==
'-1') {
6295 $new_array_options[$key] =
'';
6297 $object =
new $InfoFieldList[0]($this->db);
6298 if (is_numeric($value)) {
6299 $res = $object->fetch($value);
6301 $res = $object->fetch(
'', $value);
6305 $new_array_options[$key] = $object->id;
6307 $this->error =
"Id/Ref '".$value.
"' for object '".$object->element.
"' not found";
6312 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6317 if (is_array($this->array_options[$key])) {
6318 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6320 $new_array_options[$key] = $this->array_options[$key];
6328 $table_element = $this->table_element;
6329 if ($table_element ==
'categorie') {
6330 $table_element =
'categories';
6333 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
6335 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6336 $this->db->query($sql_del);
6338 $sql =
"INSERT INTO ".$this->db->prefix().$table_element.
"_extrafields (fk_object";
6339 foreach ($new_array_options as $key => $value) {
6340 $attributeKey = substr($key, 8);
6342 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6343 $sql .=
",".$attributeKey;
6347 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6348 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6349 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6350 $sql .=
",".$tmpkey;
6354 $sql .=
") VALUES (".$this->id;
6356 foreach ($new_array_options as $key => $value) {
6357 $attributeKey = substr($key, 8);
6359 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6360 if ($new_array_options[$key] !=
'' || $new_array_options[$key] ==
'0') {
6361 $sql .=
",'".$this->db->escape($new_array_options[$key]).
"'";
6368 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6369 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6370 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6371 if (in_array($tmpval, array(
'int',
'double',
'price'))) {
6382 $resql = $this->db->query(
$sql);
6384 $this->error = $this->db->lasterror();
6388 if (!$error && $trigger) {
6390 $this->context = array(
'extrafieldaddupdate'=>1);
6391 $result = $this->call_trigger($trigger, $userused);
6399 $this->db->rollback();
6402 $this->db->commit();
6422 global $conf, $langs, $user;
6424 if (empty($userused)) {
6430 if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6434 if (is_array($this->array_languages)) {
6435 $new_array_languages = $this->array_languages;
6437 foreach ($new_array_languages as $key => $value) {
6438 $attributeKey = $key;
6439 $attributeType = $this->fields[$attributeKey][
'type'];
6440 $attributeLabel = $this->fields[$attributeKey][
'label'];
6445 switch ($attributeType) {
6447 if (!is_numeric($value) && $value !=
'') {
6448 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6450 } elseif ($value ==
'') {
6451 $new_array_languages[$key] =
null;
6456 if (!is_numeric($value) && $value !=
'') {
6457 dol_syslog($langs->trans(
"ExtraLanguageHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6458 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6460 } elseif ($value ==
'') {
6461 $new_array_languages[$key] =
null;
6463 $new_array_languages[$key] = $value;
6477 $table_element = $this->table_element;
6478 if ($table_element ==
'categorie') {
6479 $table_element =
'categories';
6482 dol_syslog(get_class($this).
"::insertExtraLanguages delete then insert", LOG_DEBUG);
6484 foreach ($new_array_languages as $key => $langcodearray) {
6485 foreach ($langcodearray as $langcode => $value) {
6486 $sql_del =
"DELETE FROM ".$this->db->prefix().
"object_lang";
6487 $sql_del .=
" WHERE fk_object = ".((int) $this->
id).
" AND property = '".$this->db->escape($key).
"' AND type_object = '".$this->db->escape($table_element).
"'";
6488 $sql_del .=
" AND lang = '".$this->db->escape($langcode).
"'";
6489 $this->db->query($sql_del);
6491 if ($value !==
'') {
6492 $sql =
"INSERT INTO ".$this->db->prefix().
"object_lang (fk_object, property, type_object, lang, value";
6493 $sql .=
") VALUES (".$this->id.
", '".$this->db->escape($key).
"', '".$this->db->escape($table_element).
"', '".$this->db->escape($langcode).
"', '".$this->db->escape($value).
"'";
6496 $resql = $this->db->query(
$sql);
6498 $this->error = $this->db->lasterror();
6506 if (!$error && $trigger) {
6508 $this->context = array(
'extralanguagesaddupdate'=>1);
6509 $result = $this->call_trigger($trigger, $userused);
6517 $this->db->rollback();
6520 $this->db->commit();
6540 global $conf, $langs, $user;
6542 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6546 if (empty($userused)) {
6552 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
6554 $langs->load(
'admin');
6555 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6557 $extrafields->fetch_name_optionals_label($this->table_element);
6559 $value = $this->array_options[
"options_".$key];
6561 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
6562 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
6563 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
6564 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
6565 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
6568 if ($attributeRequired) {
6569 $mandatorypb =
false;
6570 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
6571 $mandatorypb =
true;
6573 if ($this->array_options[
"options_".$key] ===
'') {
6574 $mandatorypb =
true;
6577 $langs->load(
"errors");
6578 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
6579 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6587 if (!empty($attrfieldcomputed)) {
6588 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6589 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6590 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6591 $this->array_options[
"options_".$key] = $value;
6593 $this->array_options[
"options_".$key] =
null;
6597 switch ($attributeType) {
6599 if (!is_numeric($value) && $value !=
'') {
6600 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6602 } elseif ($value ===
'') {
6603 $this->array_options[
"options_".$key] =
null;
6608 if (!is_numeric($value) && $value !=
'') {
6609 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6610 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6612 } elseif ($value ===
'') {
6616 $this->array_options[
"options_".$key] = $value;
6625 $this->array_options[
"options_".$key] =
price2num($this->array_options[
"options_".$key]);
6629 if (empty($this->array_options[
"options_".$key])) {
6630 $this->array_options[
"options_".$key] =
null;
6632 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
6636 if (empty($this->array_options[
"options_".$key])) {
6637 $this->array_options[
"options_".$key] =
null;
6639 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
6643 if (empty($this->array_options[
"options_".$key])) {
6644 $this->array_options[
"options_".$key] =
null;
6648 if ($this->array_options[
"options_".$key] ===
'') {
6649 $this->array_options[
"options_".$key] =
null;
6683 if (is_array($this->array_options[$key])) {
6684 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6686 $new_array_options[$key] = $this->array_options[$key];
6693 $linealreadyfound = 0;
6696 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6697 $resql = $this->db->query(
$sql);
6699 $tmpobj = $this->db->fetch_object($resql);
6701 $linealreadyfound = $tmpobj->nb;
6705 if ($linealreadyfound) {
6706 if ($this->array_options[
"options_".$key] ===
null) {
6707 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = null";
6709 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($this->array_options[
"options_".$key]).
"'";
6711 $sql .=
" WHERE fk_object = ".((int) $this->
id);
6713 $result = $this->insertExtraFields(
'', $user);
6719 $resql = $this->db->query(
$sql);
6722 $this->error = $this->db->lasterror();
6724 if (!$error && $trigger) {
6726 $this->context = array(
'extrafieldupdate'=>1);
6727 $result = $this->call_trigger($trigger, $userused);
6735 dol_syslog(__METHOD__.$this->error, LOG_ERR);
6736 $this->db->rollback();
6739 $this->db->commit();
6759 global $conf, $langs, $user;
6761 if (empty($userused)) {
6767 if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6789 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
6791 global $conf, $langs,
$form;
6793 if (!is_object(
$form)) {
6794 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
6798 if (!empty($this->fields)) {
6799 $val = $this->fields[$key];
6803 $fieldValidationErrorMsg =
'';
6804 $validationClass =
'';
6805 $fieldValidationErrorMsg = $this->getFieldError($key);
6806 if (!empty($fieldValidationErrorMsg)) {
6807 $validationClass =
' --error';
6809 $validationClass =
' --success';
6816 $param[
'options'] = array();
6818 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
6820 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6821 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6823 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6824 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6826 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
6827 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6829 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6830 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6832 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6833 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6835 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
6836 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6838 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
6839 $param[
'options'] = array($reg[1] =>
'N');
6841 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
6842 $param[
'options'] = array();
6845 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
6846 $param[
'options'] = array();
6849 $param[
'options'] = array();
6850 $type = $this->fields[$key][
'type'];
6854 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
6855 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
6859 $label = $this->fields[$key][
'label'];
6861 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
6862 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
6863 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
6864 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
6865 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
6867 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
6868 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
6869 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
6871 $objectid = $this->id;
6874 if (!preg_match(
'/^search_/', $keyprefix)) {
6875 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
6882 if (empty($morecss) && !empty($val[
'css'])) {
6883 $morecss = $val[
'css'];
6884 } elseif (empty($morecss)) {
6885 if ($type ==
'date') {
6886 $morecss =
'minwidth100imp';
6887 } elseif ($type ==
'datetime' || $type ==
'link') {
6888 $morecss =
'minwidth200imp';
6889 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
6890 $morecss =
'maxwidth75';
6891 } elseif ($type ==
'url') {
6892 $morecss =
'minwidth400';
6893 } elseif ($type ==
'boolean') {
6896 if (round($size) < 12) {
6897 $morecss =
'minwidth100';
6898 } elseif (round($size) <= 48) {
6899 $morecss =
'minwidth200';
6901 $morecss =
'minwidth400';
6907 if (!empty($validationClass)) {
6908 $morecss.= $validationClass;
6911 if (in_array($type, array(
'date'))) {
6912 $tmp = explode(
',', $size);
6917 if (!$required && $value ==
'') {
6922 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
6923 } elseif (in_array($type, array(
'datetime'))) {
6924 $tmp = explode(
',', $size);
6929 if (!$required && $value ==
'') $value =
'-1';
6932 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
6933 } elseif (in_array($type, array(
'duration'))) {
6934 $out =
$form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
6935 } elseif (in_array($type, array(
'int',
'integer'))) {
6936 $tmp = explode(
',', $size);
6938 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"'.($newsize > 0 ?
' maxlength="'.$newsize.
'"' :
'').
' value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6939 } elseif (in_array($type, array(
'real'))) {
6940 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6941 } elseif (preg_match(
'/varchar/', $type)) {
6942 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"'.($size > 0 ?
' maxlength="'.$size.
'"' :
'').
' value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6943 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
6944 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6945 } elseif (preg_match(
'/^text/', $type)) {
6946 if (!preg_match(
'/search_/', $keyprefix)) {
6947 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
6948 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
6949 $out = $doleditor->Create(1);
6951 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
6953 } elseif (preg_match(
'/^html/', $type)) {
6954 if (!preg_match(
'/search_/', $keyprefix)) {
6955 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
6956 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
6957 $out = $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
6959 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
6961 } elseif ($type ==
'boolean') {
6963 if (!empty($value)) {
6964 $checked =
' checked value="1" ';
6966 $checked =
' value="1" ';
6968 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
6969 } elseif ($type ==
'price') {
6970 if (!empty($value)) {
6971 $value =
price($value);
6973 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
6974 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
6975 if (!empty($value)) {
6976 $value =
price($value);
6978 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
6979 } elseif ($type ==
'select') {
6981 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
6982 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
6983 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
6986 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
6987 if ((!isset($this->fields[$key][
'default'])) || ($this->fields[$key][
'notnull'] != 1)) {
6988 $out .=
'<option value="0"> </option>';
6990 foreach ($param[
'options'] as $keyb => $valb) {
6991 if ((
string) $keyb ==
'') {
6994 if (strpos($valb,
"|") !==
false) {
6995 list($valb, $parent) = explode(
'|', $valb);
6997 $out .=
'<option value="'.$keyb.
'"';
6998 $out .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
6999 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7000 $out .=
'>'.$valb.
'</option>';
7002 $out .=
'</select>';
7003 } elseif ($type ==
'sellist') {
7005 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
7006 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7007 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7010 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7011 if (is_array($param[
'options'])) {
7012 $param_list = array_keys($param[
'options']);
7013 $InfoFieldList = explode(
":", $param_list[0]);
7023 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7025 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7026 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7027 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7029 $keyList = $InfoFieldList[2].
' as rowid';
7032 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7033 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7034 $keyList .=
', '.$parentField;
7037 $filter_categorie =
false;
7038 if (count($InfoFieldList) > 5) {
7039 if ($InfoFieldList[0] ==
'categorie') {
7040 $filter_categorie =
true;
7044 if ($filter_categorie ===
false) {
7045 $fields_label = explode(
'|', $InfoFieldList[1]);
7046 if (is_array($fields_label)) {
7048 $keyList .= implode(
', ', $fields_label);
7052 $sql =
"SELECT " . $keyList;
7053 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7054 if (!empty($InfoFieldList[4])) {
7056 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7057 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7061 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7062 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7064 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7068 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7069 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
7070 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7072 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7075 $sqlwhere .=
' WHERE 1=1';
7078 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7079 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7084 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
7086 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
7087 $resql = $this->db->query(
$sql);
7089 $out .=
'<option value="0"> </option>';
7090 $num = $this->db->num_rows($resql);
7094 $obj = $this->db->fetch_object($resql);
7098 $fields_label = explode(
'|', $InfoFieldList[1]);
7099 if (count($fields_label) > 1) {
7101 foreach ($fields_label as $field_toshow) {
7102 $labeltoshow .= $obj->$field_toshow .
' ';
7105 $labeltoshow = $obj->{$InfoFieldList[1]};
7107 $labeltoshow =
dol_trunc($labeltoshow, 45);
7109 if ($value == $obj->rowid) {
7110 foreach ($fields_label as $field_toshow) {
7111 $translabel = $langs->trans($obj->$field_toshow);
7112 if ($translabel != $obj->$field_toshow) {
7113 $labeltoshow =
dol_trunc($translabel) .
' ';
7115 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
7118 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7121 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7122 if ($translabel != $obj->{$InfoFieldList[1]}) {
7123 $labeltoshow =
dol_trunc($translabel, 18);
7125 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
7128 if (empty($labeltoshow)) {
7129 $labeltoshow =
'(not defined)';
7131 if ($value == $obj->rowid) {
7132 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7135 if (!empty($InfoFieldList[3]) && $parentField) {
7136 $parent = $parentName .
':' . $obj->{$parentField};
7140 $out .=
'<option value="' . $obj->rowid .
'"';
7141 $out .= ($value == $obj->rowid ?
' selected' :
'');
7142 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
7143 $out .=
'>' . $labeltoshow .
'</option>';
7148 $this->db->free($resql);
7150 print
'Error in request ' .
$sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7153 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7154 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7155 $out .=
'<option value="0"> </option>';
7156 foreach ($data as $data_key => $data_value) {
7157 $out .=
'<option value="' . $data_key .
'"';
7158 $out .= ($value == $data_key ?
' selected' :
'');
7159 $out .=
'>' . $data_value .
'</option>';
7163 $out .=
'</select>';
7164 } elseif ($type ==
'checkbox') {
7165 $value_arr = explode(
',', $value);
7166 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0, $morecss, 0,
'100%');
7167 } elseif ($type ==
'radio') {
7169 foreach ($param[
'options'] as $keyopt => $valopt) {
7170 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
7171 $out .=
' value="'.$keyopt.
'"';
7172 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
7173 $out .= ($value == $keyopt ?
'checked' :
'');
7174 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
7176 } elseif ($type ==
'chkbxlst') {
7177 if (is_array($value)) {
7178 $value_arr = $value;
7180 $value_arr = explode(
',', $value);
7183 if (is_array($param[
'options'])) {
7184 $param_list = array_keys($param[
'options']);
7185 $InfoFieldList = explode(
":", $param_list[0]);
7195 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7197 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7198 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7199 $keyList .=
', '.$parentField;
7201 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7202 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7203 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7205 $keyList = $InfoFieldList[2].
' as rowid';
7209 $filter_categorie =
false;
7210 if (count($InfoFieldList) > 5) {
7211 if ($InfoFieldList[0] ==
'categorie') {
7212 $filter_categorie =
true;
7216 if ($filter_categorie ===
false) {
7217 $fields_label = explode(
'|', $InfoFieldList[1]);
7218 if (is_array($fields_label)) {
7220 $keyList .= implode(
', ', $fields_label);
7224 $sql =
"SELECT " . $keyList;
7225 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
7226 if (!empty($InfoFieldList[4])) {
7228 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7229 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7233 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7234 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7236 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7240 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7241 $sql .=
' as main, ' . $this->db->prefix() . $InfoFieldList[0] .
'_extrafields as extra';
7242 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7244 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7247 $sqlwhere .=
' WHERE 1=1';
7250 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7251 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7257 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
7258 $resql = $this->db->query(
$sql);
7260 $num = $this->db->num_rows($resql);
7267 $obj = $this->db->fetch_object($resql);
7271 $fields_label = explode(
'|', $InfoFieldList[1]);
7272 if (count($fields_label) > 1) {
7274 foreach ($fields_label as $field_toshow) {
7275 $labeltoshow .= $obj->$field_toshow .
' ';
7278 $labeltoshow = $obj->{$InfoFieldList[1]};
7280 $labeltoshow =
dol_trunc($labeltoshow, 45);
7282 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7283 foreach ($fields_label as $field_toshow) {
7284 $translabel = $langs->trans($obj->$field_toshow);
7285 if ($translabel != $obj->$field_toshow) {
7286 $labeltoshow =
dol_trunc($translabel, 18) .
' ';
7288 $labeltoshow =
dol_trunc($obj->$field_toshow, 18) .
' ';
7292 $data[$obj->rowid] = $labeltoshow;
7295 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7296 if ($translabel != $obj->{$InfoFieldList[1]}) {
7297 $labeltoshow =
dol_trunc($translabel, 18);
7299 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
7302 if (empty($labeltoshow)) {
7303 $labeltoshow =
'(not defined)';
7306 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7307 $data[$obj->rowid] = $labeltoshow;
7310 if (!empty($InfoFieldList[3]) && $parentField) {
7311 $parent = $parentName .
':' . $obj->{$parentField};
7315 $data[$obj->rowid] = $labeltoshow;
7320 $this->db->free($resql);
7322 $out =
$form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr,
'', 0, $morecss, 0,
'100%');
7324 print
'Error in request ' .
$sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7327 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7328 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7329 $out =
$form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr,
'', 0, $morecss, 0,
'100%');
7332 } elseif ($type ==
'link') {
7333 $param_list = array_keys($param[
'options']);
7334 $param_list_array = explode(
&