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();
276 public $ref_previous;
318 public $country_code;
361 public $barcode_type;
367 public $barcode_type_code;
373 public $barcode_type_label;
379 public $barcode_type_coder;
385 public $mode_reglement_id;
391 public $cond_reglement_id;
396 public $demand_reason_id;
402 public $transport_mode_id;
409 public $cond_reglement;
416 public $fk_delivery_address;
422 public $shipping_method_id;
428 public $shipping_method;
433 public $multicurrency_code;
438 public $multicurrency_tx;
457 public $last_main_doc;
487 public $note_private;
511 public $total_localtax1;
517 public $total_localtax2;
534 public $comments = array();
560 public $date_creation;
565 public $date_validation;
581 public $date_cloture;
593 public $user_creation;
598 public $user_creation_id;
610 public $user_validation;
615 public $user_validation_id;
620 public $user_closing_id;
626 public $user_modification;
631 public $user_modification_id;
634 public $next_prev_filter;
639 public $specimen = 0;
653 protected $labelStatusShort;
658 public $showphoto_on_popup;
663 public $nb = array();
673 public $extraparams = array();
678 protected $childtables = array();
685 protected $childtablesoncascade = array();
705 $sql =
"SELECT rowid, ref, ref_ext";
706 $sql .=
" FROM ".$db->prefix().$element;
707 $sql .=
" WHERE entity IN (".getEntity($element).
")";
710 $sql .=
" AND rowid = ".((int) $id);
712 $sql .=
" AND ref = '".$db->escape($ref).
"'";
713 } elseif ($ref_ext) {
714 $sql .=
" AND ref_ext = '".$db->escape($ref_ext).
"'";
716 $error =
'ErrorWrongParameters';
720 if ($ref || $ref_ext) {
721 $sql .=
" AND entity = ".((int) $conf->entity);
724 dol_syslog(get_class().
"::isExistingObject", LOG_DEBUG);
725 $resql = $db->query(
$sql);
727 $num = $db->num_rows($resql);
745 if (!empty($object->error)) {
746 $this->error = $object->error;
748 if (!empty($object->errors)) {
749 $this->errors = array_merge($this->errors, $object->errors);
774 global $action, $extrafields, $langs, $hookmanager;
777 $MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP =
getDolGlobalInt(
'MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP', 3);
783 if (!empty($extrafields->attributes[$this->table_element][
'label'])) {
784 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
785 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
788 if ($count >= abs($MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP)) {
789 $datas[
'more_extrafields'] =
'<br>...';
793 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
794 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
796 if ($enabled && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
797 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
800 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
801 $perms =
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
803 if (empty($enabled)) {
806 if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
812 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
813 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
815 $labelextra = $langs->trans((
string) $extrafields->attributes[$this->table_element][
'label'][$key]);
816 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
817 $datas[$key]=
'<br><b><u>'. $labelextra .
'</u></b>';
819 $value = (empty($this->array_options[
'options_' . $key]) ?
'' : $this->array_options[
'options_' . $key]);
820 $datas[$key]=
'<br><b>'. $labelextra .
':</b> ' . $extrafields->showOutputField($key, $value,
'', $this->table_element);
826 $hookmanager->initHooks(array($this->element .
'dao'));
828 'tooltipcontentarray' => &$datas,
832 $hookmanager->executeHooks(
'getTooltipContent', $parameters, $this, $action);
835 $label = implode($datas);
848 return $this->error.(is_array($this->errors) ? (($this->error !=
'' ?
', ' :
'').join(
', ', $this->errors)) :
'');
862 $parameters = array(
'objref'=>$objref);
864 $reshook = $hookmanager->executeHooks(
'getFormatedCustomerRef', $parameters, $this, $action);
866 return $hookmanager->resArray[
'objref'];
868 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
881 $parameters = array(
'objref'=>$objref);
883 $reshook = $hookmanager->executeHooks(
'getFormatedSupplierRef', $parameters, $this, $action);
885 return $hookmanager->resArray[
'objref'];
887 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
899 public function getFullAddress($withcountry = 0, $sep =
"\n", $withregion = 0, $extralangcode =
'')
901 if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
902 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
903 $tmparray =
getCountry($this->country_id,
'all');
904 $this->country_code = $tmparray[
'code'];
905 $this->country = $tmparray[
'label'];
908 if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) {
909 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
910 $tmparray =
getState($this->state_id,
'all', 0, 1);
911 $this->state_code = $tmparray[
'code'];
912 $this->state = $tmparray[
'label'];
913 $this->region_code = $tmparray[
'region_code'];
914 $this->region = $tmparray[
'region'];
931 global $user, $dolibarr_main_url_root;
933 if (empty($this->last_main_doc)) {
937 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
939 $result = $ecmfile->fetch(0,
'', $this->last_main_doc);
941 $this->error = $ecmfile->error;
942 $this->errors = $ecmfile->errors;
946 if (empty($ecmfile->id)) {
949 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
971 } elseif (empty($ecmfile->share)) {
974 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
976 $ecmfile->update($user);
982 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
986 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
995 if (!empty($ecmfile->share)) {
996 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$ecmfile->share;
998 if ($forcedownload) {
999 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
1002 if ($relativelink) {
1003 $linktoreturn =
'document.php'.($paramlink ?
'?'.$paramlink :
'');
1005 $linktoreturn = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
1009 return $linktoreturn;
1023 public function add_contact($fk_socpeople, $type_contact, $source =
'external', $notrigger = 0)
1026 global $user, $langs;
1029 dol_syslog(get_class($this).
"::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
1032 if ($fk_socpeople <= 0) {
1033 $langs->load(
"errors");
1034 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"1");
1035 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1038 if (!$type_contact) {
1039 $langs->load(
"errors");
1040 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"2");
1041 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1045 $id_type_contact = 0;
1046 if (is_numeric($type_contact)) {
1047 $id_type_contact = $type_contact;
1050 $sql =
"SELECT tc.rowid";
1051 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1052 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1053 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1054 $sql .=
" AND tc.code='".$this->db->escape($type_contact).
"' AND tc.active=1";
1056 $resql = $this->db->query(
$sql);
1058 $obj = $this->db->fetch_object($resql);
1060 $id_type_contact = $obj->rowid;
1065 if ($id_type_contact == 0) {
1066 $this->error =
'CODE_NOT_VALID_FOR_THIS_ELEMENT';
1067 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");
1075 $already_added =
false;
1076 if (is_array($TListeContacts) && !empty($TListeContacts)) {
1077 foreach ($TListeContacts as $array_contact) {
1078 if ($array_contact[
'status'] == 4 && $array_contact[
'id'] == $fk_socpeople && $array_contact[
'fk_c_type_contact'] == $id_type_contact) {
1079 $already_added =
true;
1085 if (!$already_added) {
1089 $sql =
"INSERT INTO ".$this->db->prefix().
"element_contact";
1090 $sql .=
" (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1091 $sql .=
" VALUES (".$this->id.
", ".((int) $fk_socpeople).
" , ";
1092 $sql .=
"'".$this->db->idate($datecreate).
"'";
1093 $sql .=
", 4, ".((int) $id_type_contact);
1096 $resql = $this->db->query(
$sql);
1099 $result = $this->
call_trigger(strtoupper($this->element).
'_ADD_CONTACT', $user);
1101 $this->db->rollback();
1106 $this->db->commit();
1109 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1110 $this->error = $this->db->errno();
1111 $this->db->rollback();
1114 $this->error = $this->db->lasterror();
1115 $this->db->rollback();
1135 $contacts = $objFrom->liste_contact(-1, $source);
1136 foreach ($contacts as $contact) {
1137 if ($this->
add_contact($contact[
'id'], $contact[
'fk_c_type_contact'], $contact[
'source']) < 0) {
1154 public function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0)
1158 $sql =
"UPDATE ".$this->db->prefix().
"element_contact set";
1159 $sql .=
" statut = ".$statut;
1160 if ($type_contact_id) {
1161 $sql .=
", fk_c_type_contact = ".((int) $type_contact_id);
1163 if ($fk_socpeople) {
1164 $sql .=
", fk_socpeople = ".((int) $fk_socpeople);
1166 $sql .=
" where rowid = ".((int) $rowid);
1167 $resql = $this->db->query(
$sql);
1171 $this->error = $this->db->lasterror();
1192 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1193 $sql .=
" WHERE rowid = ".((int) $rowid);
1195 dol_syslog(get_class($this).
"::delete_contact", LOG_DEBUG);
1196 if ($this->db->query(
$sql)) {
1198 $result = $this->
call_trigger(strtoupper($this->element).
'_DELETE_CONTACT', $user);
1200 $this->db->rollback();
1205 $this->db->commit();
1208 $this->error = $this->db->lasterror();
1209 $this->db->rollback();
1229 if (!empty($typeContact)) {
1230 foreach ($typeContact as $key => $value) {
1231 array_push($temp, $key);
1233 $listId = implode(
",", $temp);
1238 if (empty($listId)) {
1242 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1243 $sql .=
" WHERE element_id = ".((int) $this->
id);
1244 $sql .=
" AND fk_c_type_contact IN (".$this->db->sanitize($listId).
")";
1246 dol_syslog(get_class($this).
"::delete_linked_contact", LOG_DEBUG);
1247 if ($this->db->query(
$sql)) {
1250 $this->error = $this->db->lasterror();
1267 public function liste_contact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1, $arrayoftcids = array())
1274 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
1275 if ($source ==
'internal') {
1276 $sql .=
", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1278 if ($source ==
'external' || $source ==
'thirdparty') {
1279 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
1281 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1282 $sql .=
", tc.source, tc.element, tc.code, tc.libelle";
1283 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc,";
1284 $sql .=
" ".$this->db->prefix().
"element_contact ec";
1285 if ($source ==
'internal') {
1286 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user t on ec.fk_socpeople = t.rowid";
1288 if ($source ==
'external' || $source ==
'thirdparty') {
1289 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on ec.fk_socpeople = t.rowid";
1291 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
1292 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1293 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1295 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1297 if ($source ==
'internal') {
1298 $sql .=
" AND tc.source = 'internal'";
1300 $sql .=
" AND t.statut = ".((int) $status);
1303 if ($source ==
'external' || $source ==
'thirdparty') {
1304 $sql .=
" AND tc.source = 'external'";
1306 $sql .=
" AND t.statut = ".((int) $status);
1309 $sql .=
" AND tc.active = 1";
1310 if ($statusoflink >= 0) {
1311 $sql .=
" AND ec.statut = ".((int) $statusoflink);
1313 $sql .=
" ORDER BY t.lastname ASC";
1315 dol_syslog(get_class($this).
"::liste_contact", LOG_DEBUG);
1316 $resql = $this->db->query(
$sql);
1318 $num = $this->db->num_rows($resql);
1321 $obj = $this->db->fetch_object($resql);
1324 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1325 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1327 'parentId' => $this->
id,
1328 'source' => $obj->source,
1329 'socid' => $obj->socid,
1331 'nom' => $obj->lastname,
1332 'civility' => $obj->civility,
1333 'lastname' => $obj->lastname,
1334 'firstname' => $obj->firstname,
1335 'email'=>$obj->email,
1336 'login'=> (empty($obj->login) ?
'' : $obj->login),
1337 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
1338 'statuscontact' => $obj->statuscontact,
1339 'rowid' => $obj->rowid,
1340 'code' => $obj->code,
1341 'libelle' => $libelle_type,
1342 'status' => $obj->statuslink,
1343 'fk_c_type_contact' => $obj->fk_c_type_contact
1346 $tab[$i] = $obj->id;
1354 $this->error = $this->db->lasterror();
1369 $sql =
"SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1370 $sql .=
" tc.code, tc.libelle";
1371 $sql .=
" FROM (".$this->db->prefix().
"element_contact as ec, ".$this->db->prefix().
"c_type_contact as tc)";
1372 $sql .=
" WHERE ec.rowid =".((int) $rowid);
1373 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1374 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1376 dol_syslog(get_class($this).
"::swapContactStatus", LOG_DEBUG);
1377 $resql = $this->db->query(
$sql);
1379 $obj = $this->db->fetch_object($resql);
1380 $newstatut = ($obj->statut == 4) ? 5 : 4;
1382 $this->db->free($resql);
1385 $this->error = $this->db->error();
1402 public function liste_type_contact($source =
'internal', $order =
'position', $option = 0, $activeonly = 0, $code =
'')
1407 if (empty($order)) {
1408 $order =
'position';
1410 if ($order ==
'position') {
1415 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
1416 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1417 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1418 if ($activeonly == 1) {
1419 $sql .=
" AND tc.active=1";
1421 if (!empty($source) && $source !=
'all') {
1422 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1424 if (!empty($code)) {
1425 $sql .=
" AND tc.code='".$this->db->escape($code).
"'";
1427 $sql .= $this->db->order($order,
'ASC');
1430 $resql = $this->db->query(
$sql);
1432 $num = $this->db->num_rows($resql);
1435 $obj = $this->db->fetch_object($resql);
1437 $transkey =
"TypeContact_".$this->element.
"_".$source.
"_".$obj->code;
1438 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1439 if (empty($option)) {
1440 $tab[$obj->rowid] = $libelle_type;
1442 $tab[$obj->code] = $libelle_type;
1448 $this->error = $this->db->lasterror();
1465 public function listeTypeContacts($source =
'internal', $option = 0, $activeonly = 0, $code =
'', $element =
'', $excludeelement =
'')
1467 global $langs, $conf;
1469 $langs->loadLangs(array(
'bills',
'contracts',
'interventions',
'orders',
'projects',
'propal',
'ticket',
'agenda'));
1473 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element";
1474 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1476 $sqlWhere = array();
1477 if (!empty($element)) {
1478 $sqlWhere[] =
" tc.element='".$this->db->escape($element).
"'";
1480 if (!empty($excludeelement)) {
1481 $sqlWhere[] =
" tc.element <> '".$this->db->escape($excludeelement).
"'";
1484 if ($activeonly == 1) {
1485 $sqlWhere[] =
" tc.active=1";
1488 if (!empty($source) && $source !=
'all') {
1489 $sqlWhere[] =
" tc.source='".$this->db->escape($source).
"'";
1492 if (!empty($code)) {
1493 $sqlWhere[] =
" tc.code='".$this->db->escape($code).
"'";
1496 if (count($sqlWhere) > 0) {
1497 $sql .=
" WHERE ".implode(
' AND ', $sqlWhere);
1500 $sql .= $this->db->order(
'tc.element, tc.position',
'ASC');
1503 $resql = $this->db->query(
$sql);
1505 $num = $this->db->num_rows($resql);
1507 $langs->loadLangs(array(
"propal",
"orders",
"bills",
"suppliers",
"contracts",
"supplier_proposal"));
1509 while ($obj = $this->db->fetch_object($resql)) {
1510 $modulename = $obj->element;
1511 if (strpos($obj->element,
'project') !==
false) {
1512 $modulename =
'projet';
1513 } elseif ($obj->element ==
'contrat') {
1514 $element =
'contract';
1515 } elseif ($obj->element ==
'action') {
1516 $modulename =
'agenda';
1517 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1518 $modulename =
'fournisseur';
1519 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1520 $modulename =
'fournisseur';
1522 if (!empty($conf->{$modulename}->enabled)) {
1523 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1524 $tmpelement = $obj->element;
1525 $transkey =
"TypeContact_".$tmpelement.
"_".$source.
"_".$obj->code;
1526 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1527 if (empty($option)) {
1528 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1530 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1537 $this->error = $this->db->lasterror();
1560 if ($this->element ==
'shipping' && $this->origin_id != 0) {
1561 $id = $this->origin_id;
1562 $element =
'commande';
1563 } elseif ($this->element ==
'reception' && $this->origin_id != 0) {
1564 $id = $this->origin_id;
1565 $element =
'order_supplier';
1568 $element = $this->element;
1571 $sql =
"SELECT ec.fk_socpeople";
1572 $sql .=
" FROM ".$this->db->prefix().
"element_contact as ec,";
1573 if ($source ==
'internal') {
1574 $sql .=
" ".$this->db->prefix().
"user as c,";
1576 if ($source ==
'external') {
1577 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
1579 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc";
1580 $sql .=
" WHERE ec.element_id = ".((int) $id);
1581 $sql .=
" AND ec.fk_socpeople = c.rowid";
1582 if ($source ==
'internal') {
1583 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
1585 if ($source ==
'external') {
1586 $sql .=
" AND c.entity IN (".getEntity(
'societe').
")";
1588 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1589 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1590 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1592 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1594 $sql .=
" AND tc.active = 1";
1596 $sql .=
" AND ec.statut = ".((int) $status);
1599 dol_syslog(get_class($this).
"::getIdContact", LOG_DEBUG);
1600 $resql = $this->db->query(
$sql);
1602 while ($obj = $this->db->fetch_object($resql)) {
1603 $result[$i] = $obj->fk_socpeople;
1607 $this->error = $this->db->error();
1624 if (empty($contactid)) {
1625 $contactid = $this->contact_id;
1628 if (empty($contactid)) {
1632 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1633 $contact =
new Contact($this->db);
1634 $result = $contact->fetch($contactid);
1635 $this->contact = $contact;
1651 if (empty($this->socid) && empty($this->fk_soc) && empty($force_thirdparty_id)) {
1655 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1657 $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : 0);
1658 if ($force_thirdparty_id) {
1659 $idtofetch = $force_thirdparty_id;
1663 $thirdparty =
new Societe($this->db);
1664 $result = $thirdparty->fetch($idtofetch);
1666 $this->errors=array_merge($this->errors, $thirdparty->errors);
1668 $this->thirdparty = $thirdparty;
1671 if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
1672 $this->thirdparty->price_level = 1;
1691 if (!$this->table_ref_field) {
1695 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element.
" WHERE ".$this->table_ref_field.
" LIKE '".$this->db->escape($ref).
"' LIMIT 1";
1697 $query = $this->db->query(
$sql);
1699 if (!$this->db->num_rows($query)) {
1703 $result = $this->db->fetch_object($query);
1705 return $this->fetch($result->rowid);
1721 dol_syslog(get_class($this).
'::fetch_barcode this->element='.$this->element.
' this->barcode_type='.$this->barcode_type);
1723 $idtype = $this->barcode_type;
1724 if (empty($idtype) && $idtype !=
'0') {
1725 if ($this->element ==
'product' && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
1726 $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1727 } elseif ($this->element ==
'societe') {
1728 $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1730 dol_syslog(
'Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1735 if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1736 $sql =
"SELECT rowid, code, libelle as label, coder";
1737 $sql .=
" FROM ".$this->db->prefix().
"c_barcode_type";
1738 $sql .=
" WHERE rowid = ".((int) $idtype);
1739 dol_syslog(get_class($this).
'::fetch_barcode', LOG_DEBUG);
1740 $resql = $this->db->query(
$sql);
1742 $obj = $this->db->fetch_object($resql);
1743 $this->barcode_type = $obj->rowid;
1744 $this->barcode_type_code = $obj->code;
1745 $this->barcode_type_label = $obj->label;
1746 $this->barcode_type_coder = $obj->coder;
1766 return $this->fetch_projet();
1778 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1780 if (empty($this->fk_project) && !empty($this->fk_projet)) {
1781 $this->fk_project = $this->fk_projet;
1783 if (empty($this->fk_project)) {
1787 $project =
new Project($this->db);
1788 $result = $project->fetch($this->fk_project);
1790 $this->projet = $project;
1791 $this->project = $project;
1804 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1806 if (empty($this->fk_product)) {
1810 $product =
new Product($this->db);
1811 $result = $product->fetch($this->fk_product);
1813 $this->product = $product;
1827 $user =
new User($this->db);
1828 $result = $user->fetch($userid);
1829 $this->
user = $user;
1842 if ($this->origin ==
'shipping') {
1843 $this->origin =
'expedition';
1845 if ($this->origin ==
'delivery') {
1846 $this->origin =
'livraison';
1848 if ($this->origin ==
'order_supplier') {
1849 $this->origin =
'commandeFournisseur';
1852 $origin = $this->origin;
1854 $classname = ucfirst($origin);
1855 $this->$origin =
new $classname($this->db);
1856 $this->$origin->fetch($this->origin_id);
1874 $sql =
"SELECT rowid FROM ".$this->db->prefix().$table;
1875 $sql .=
" WHERE ".$field.
" = '".$this->db->escape($key).
"'";
1876 if (!empty($element)) {
1877 $sql .=
" AND entity IN (".getEntity($element).
")";
1879 $sql .=
" AND entity = ".((int) $conf->entity);
1882 dol_syslog(get_class($this).
'::fetchObjectFrom', LOG_DEBUG);
1883 $resql = $this->db->query(
$sql);
1885 $row = $this->db->fetch_row($resql);
1888 $result = $this->fetch($row[0]);
1906 if (!empty($id) && !empty($field) && !empty($table)) {
1907 $sql =
"SELECT ".$field.
" FROM ".$this->db->prefix().$table;
1908 $sql .=
" WHERE rowid = ".((int) $id);
1910 dol_syslog(get_class($this).
'::getValueFrom', LOG_DEBUG);
1911 $resql = $this->db->query(
$sql);
1913 $row = $this->db->fetch_row($resql);
1936 public function setValueFrom($field, $value, $table =
'', $id =
null, $format =
'', $id_field =
'', $fuser =
null, $trigkey =
'', $fk_user_field =
'fk_user_modif')
1938 global $user, $langs, $conf;
1940 if (empty($table)) {
1941 $table = $this->table_element;
1946 if (empty($format)) {
1949 if (empty($id_field)) {
1950 $id_field =
'rowid';
1954 if ($table ==
'product' && $field ==
'note_private') {
1957 if (in_array($table, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
1958 $fk_user_field =
'fk_user_mod';
1964 $sql =
"SELECT " . $field;
1965 $sql .=
" FROM " . MAIN_DB_PREFIX . $table;
1966 $sql .=
" WHERE " . $id_field .
" = " . ((int) $id);
1968 $resql = $this->db->query(
$sql);
1970 if ($obj = $this->db->fetch_object($resql)) {
1971 if ($format ==
'date') {
1972 $oldvalue = $this->db->jdate($obj->$field);
1974 $oldvalue = $obj->$field;
1978 $this->error = $this->db->lasterror();
1989 $sql =
"UPDATE ".$this->db->prefix().$table.
" SET ";
1991 if ($format ==
'text') {
1992 $sql .= $field.
" = '".$this->db->escape($value).
"'";
1993 } elseif ($format ==
'int') {
1994 $sql .= $field.
" = ".((int) $value);
1995 } elseif ($format ==
'date') {
1996 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value).
"'" :
"null");
1997 } elseif ($format ==
'dategmt') {
1998 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value,
'gmt').
"'" :
"null");
2001 if ($fk_user_field) {
2002 if (!empty($fuser) && is_object($fuser)) {
2003 $sql .=
", ".$fk_user_field.
" = ".((int) $fuser->id);
2004 } elseif (empty($fuser) || $fuser !=
'none') {
2005 $sql .=
", ".$fk_user_field.
" = ".((int) $user->id);
2009 $sql .=
" WHERE ".$id_field.
" = ".((int) $id);
2011 $resql = $this->db->query(
$sql);
2015 if (method_exists($this,
'fetch')) {
2016 $result = $this->fetch($id);
2018 $result = $this->fetchCommon($id);
2020 $this->oldcopy = clone $this;
2021 if (property_exists($this->oldcopy, $field)) {
2022 $this->oldcopy->$field = $oldvalue;
2026 $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
2034 if (property_exists($this, $field)) {
2035 $this->$field = $value;
2037 $this->db->commit();
2040 $this->db->rollback();
2044 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2045 $this->error =
'DB_ERROR_RECORD_ALREADY_EXISTS';
2047 $this->error = $this->db->lasterror();
2049 $this->db->rollback();
2066 global $conf, $user;
2068 if (!$this->table_element) {
2069 dol_print_error(
'', get_class($this).
"::load_previous_next_ref was called on objet with property table_element not defined");
2072 if ($fieldid ==
'none') {
2077 if ($this->table_element ==
'facture_rec' && $fieldid ==
'title') {
2083 if ($user->socid > 0) {
2084 $socid = $user->socid;
2089 $aliastablesociete =
's';
2090 if ($this->element ==
'societe') {
2091 $aliastablesociete =
'te';
2093 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2094 $sql =
"SELECT MAX(te.".$fieldid.
")";
2095 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2096 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2097 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
2099 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2100 $tmparray = explode(
'@', $this->ismultientitymanaged);
2101 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2102 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2103 $sql .=
", ".$this->db->prefix().
"societe as s";
2104 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2105 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2107 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2108 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2110 if ($fieldid ==
'rowid') {
2111 $sql .=
" WHERE te.".$fieldid.
" < ".((int) $this->
id);
2113 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($this->
ref).
"'";
2115 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2116 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2118 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2119 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2121 if (!empty($filter)) {
2122 if (!preg_match(
'/^\s*AND/i', $filter)) {
2127 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2128 $tmparray = explode(
'@', $this->ismultientitymanaged);
2129 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2130 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2131 $sql .=
' AND te.fk_soc = s.rowid';
2133 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2134 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2135 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2136 $sql .=
" AND te.entity IS NOT NULL";
2138 $sql .=
" AND ug.fk_user = te.rowid";
2139 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2142 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2145 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2146 $tmparray = explode(
'@', $this->ismultientitymanaged);
2147 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2149 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2150 $sql .=
' AND te.fk_soc = '.((int) $socid);
2152 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2153 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2155 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2156 $sql .=
' AND te.rowid = '.((int) $socid);
2160 $result = $this->db->query(
$sql);
2162 $this->error = $this->db->lasterror();
2165 $row = $this->db->fetch_row($result);
2166 $this->ref_previous = $row[0];
2168 $sql =
"SELECT MIN(te.".$fieldid.
")";
2169 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2170 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2171 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
2173 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2174 $tmparray = explode(
'@', $this->ismultientitymanaged);
2175 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2176 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2177 $sql .=
", ".$this->db->prefix().
"societe as s";
2178 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2179 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2181 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2182 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2184 if ($fieldid ==
'rowid') {
2185 $sql .=
" WHERE te.".$fieldid.
" > ".((int) $this->
id);
2187 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($this->
ref).
"'";
2189 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2190 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2192 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2193 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2195 if (!empty($filter)) {
2196 if (!preg_match(
'/^\s*AND/i', $filter)) {
2201 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2202 $tmparray = explode(
'@', $this->ismultientitymanaged);
2203 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2204 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2205 $sql .=
' AND te.fk_soc = s.rowid';
2207 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2208 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2209 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2210 $sql .=
" AND te.entity IS NOT NULL";
2212 $sql .=
" AND ug.fk_user = te.rowid";
2213 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2216 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2219 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2220 $tmparray = explode(
'@', $this->ismultientitymanaged);
2221 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2223 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2224 $sql .=
' AND te.fk_soc = '.((int) $socid);
2226 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2227 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2229 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2230 $sql .=
' AND te.rowid = '.((int) $socid);
2235 $result = $this->db->query(
$sql);
2237 $this->error = $this->db->lasterror();
2240 $row = $this->db->fetch_row($result);
2241 $this->ref_next = $row[0];
2256 $contactAlreadySelected = array();
2257 $tab = $this->liste_contact(-1, $source);
2261 if ($source ==
'thirdparty') {
2262 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
2264 $contactAlreadySelected[$i] = $tab[$i][
'id'];
2268 return $contactAlreadySelected;
2284 if (!$this->table_element) {
2285 dol_syslog(get_class($this).
"::setProject was called on objet with property table_element not defined", LOG_ERR);
2289 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2290 if (!empty($this->fields[
'fk_project'])) {
2292 $sql .=
" SET fk_project = ".((int) $projectid);
2294 $sql .=
" SET fk_project = NULL";
2296 $sql .=
' WHERE rowid = '.((int) $this->
id);
2297 } elseif ($this->table_element ==
'actioncomm') {
2299 $sql .=
" SET fk_project = ".((int) $projectid);
2301 $sql .=
" SET fk_project = NULL";
2303 $sql .=
' WHERE id = '.((int) $this->
id);
2307 $sql .=
' SET fk_projet = '.((int) $projectid);
2309 $sql .=
' SET fk_projet = NULL';
2311 $sql .=
" WHERE rowid = ".((int) $this->
id);
2316 dol_syslog(get_class($this).
"::setProject", LOG_DEBUG);
2317 if ($this->db->query(
$sql)) {
2318 $this->fk_project = ((int) $projectid);
2325 if (!$error && !$notrigger) {
2327 $result = $this->call_trigger(strtoupper($this->element) .
'_MODIFY', $user);
2336 $this->db->rollback();
2339 $this->db->commit();
2354 $error = 0; $notrigger = 0;
2356 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2358 if ($this->statut >= 0 || $this->element ==
'societe') {
2360 $fieldname =
'fk_mode_reglement';
2361 if ($this->element ==
'societe') {
2362 $fieldname =
'mode_reglement';
2364 if (get_class($this) ==
'Fournisseur') {
2365 $fieldname =
'mode_reglement_supplier';
2367 if (get_class($this) ==
'Tva') {
2368 $fieldname =
'fk_typepayment';
2370 if (get_class($this) ==
'Salary') {
2371 $fieldname =
'fk_typepayment';
2374 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2375 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2376 $sql .=
' WHERE rowid='.((int) $this->
id);
2378 if ($this->db->query(
$sql)) {
2379 $this->mode_reglement_id = $id;
2381 if (get_class($this) ==
'Fournisseur') {
2382 $this->mode_reglement_supplier_id = $id;
2385 if (!$error && !$notrigger) {
2387 if (get_class($this) ==
'Commande') {
2388 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2390 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
2399 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2400 $this->error = $this->db->error();
2404 dol_syslog(get_class($this).
'::setPaymentMethods, status of the object is incompatible');
2405 $this->error =
'Status of the object is incompatible '.$this->statut;
2418 dol_syslog(get_class($this).
'::setMulticurrencyCode('.$code.
')');
2419 if ($this->statut >= 0 || $this->element ==
'societe') {
2420 $fieldname =
'multicurrency_code';
2422 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2423 $sql .=
" SET ".$fieldname.
" = '".$this->db->escape($code).
"'";
2424 $sql .=
' WHERE rowid='.((int) $this->
id);
2426 if ($this->db->query(
$sql)) {
2427 $this->multicurrency_code = $code;
2431 $this->setMulticurrencyRate($rate, 2);
2436 dol_syslog(get_class($this).
'::setMulticurrencyCode Error '.
$sql.
' - '.$this->db->error());
2437 $this->error = $this->db->error();
2441 dol_syslog(get_class($this).
'::setMulticurrencyCode, status of the object is incompatible');
2442 $this->error =
'Status of the object is incompatible '.$this->statut;
2454 public function setMulticurrencyRate($rate, $mode = 1)
2456 dol_syslog(get_class($this).
'::setMulticurrencyRate('.$rate.
','.$mode.
')');
2457 if ($this->statut >= 0 || $this->element ==
'societe') {
2458 $fieldname =
'multicurrency_tx';
2460 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2461 $sql .=
" SET ".$fieldname.
" = ".((
float) $rate);
2462 $sql .=
' WHERE rowid='.((int) $this->
id);
2464 if ($this->db->query(
$sql)) {
2465 $this->multicurrency_tx = $rate;
2468 if (!empty($this->lines)) {
2469 foreach ($this->lines as &$line) {
2472 $line->subprice = 0;
2477 $line->multicurrency_subprice = 0;
2480 switch ($this->element) {
2488 $line->remise_percent,
2490 $line->localtax1_tx,
2491 $line->localtax2_tx,
2492 ($line->description ? $line->description : $line->desc),
2495 $line->special_code,
2496 $line->fk_parent_line,
2497 $line->skip_update_total,
2498 $line->fk_fournprice,
2501 $line->product_type,
2504 $line->array_options,
2506 $line->multicurrency_subprice
2514 ($line->description ? $line->description : $line->desc),
2517 $line->remise_percent,
2519 $line->localtax1_tx,
2520 $line->localtax2_tx,
2525 $line->product_type,
2526 $line->fk_parent_line,
2527 $line->skip_update_total,
2528 $line->fk_fournprice,
2531 $line->special_code,
2532 $line->array_options,
2534 $line->multicurrency_subprice
2542 ($line->description ? $line->description : $line->desc),
2545 $line->remise_percent,
2549 $line->localtax1_tx,
2550 $line->localtax2_tx,
2553 $line->product_type,
2554 $line->fk_parent_line,
2555 $line->skip_update_total,
2556 $line->fk_fournprice,
2559 $line->special_code,
2560 $line->array_options,
2561 $line->situation_percent,
2563 $line->multicurrency_subprice
2566 case 'supplier_proposal':
2573 $line->remise_percent,
2575 $line->localtax1_tx,
2576 $line->localtax2_tx,
2577 ($line->description ? $line->description : $line->desc),
2580 $line->special_code,
2581 $line->fk_parent_line,
2582 $line->skip_update_total,
2583 $line->fk_fournprice,
2586 $line->product_type,
2587 $line->array_options,
2589 $line->multicurrency_subprice
2592 case 'order_supplier':
2597 ($line->description ? $line->description : $line->desc),
2600 $line->remise_percent,
2602 $line->localtax1_tx,
2603 $line->localtax2_tx,
2606 $line->product_type,
2610 $line->array_options,
2612 $line->multicurrency_subprice,
2616 case 'invoice_supplier':
2621 ($line->description ? $line->description : $line->desc),
2624 $line->localtax1_tx,
2625 $line->localtax2_tx,
2630 $line->product_type,
2631 $line->remise_percent,
2635 $line->array_options,
2637 $line->multicurrency_subprice,
2642 dol_syslog(get_class($this).
'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
2650 dol_syslog(get_class($this).
'::setMulticurrencyRate Error '.
$sql.
' - '.$this->db->error());
2651 $this->error = $this->db->error();
2655 dol_syslog(get_class($this).
'::setMulticurrencyRate, status of the object is incompatible');
2656 $this->error =
'Status of the object is incompatible '.$this->statut;
2670 dol_syslog(get_class($this).
'::setPaymentTerms('.$id.
', '.var_export($deposit_percent,
true).
')');
2671 if ($this->statut >= 0 || $this->element ==
'societe') {
2673 $fieldname =
'fk_cond_reglement';
2674 if ($this->element ==
'societe') {
2675 $fieldname =
'cond_reglement';
2677 if (get_class($this) ==
'Fournisseur') {
2678 $fieldname =
'cond_reglement_supplier';
2681 if (empty($deposit_percent) || $deposit_percent < 0) {
2685 if ($deposit_percent > 100) {
2686 $deposit_percent = 100;
2689 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2690 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2691 if (in_array($this->table_element, array(
'propal',
'commande',
'societe'))) {
2692 $sql .=
" , deposit_percent = " . (empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape($deposit_percent).
"'");
2694 $sql .=
' WHERE rowid='.((int) $this->
id);
2696 if ($this->db->query(
$sql)) {
2697 $this->cond_reglement_id = $id;
2699 if (get_class($this) ==
'Fournisseur') {
2700 $this->cond_reglement_supplier_id = $id;
2702 $this->cond_reglement = $id;
2703 $this->deposit_percent = $deposit_percent;
2706 dol_syslog(get_class($this).
'::setPaymentTerms Error '.
$sql.
' - '.$this->db->error());
2707 $this->error = $this->db->error();
2711 dol_syslog(get_class($this).
'::setPaymentTerms, status of the object is incompatible');
2712 $this->error =
'Status of the object is incompatible '.$this->statut;
2725 dol_syslog(get_class($this).
'::setTransportMode('.$id.
')');
2726 if ($this->statut >= 0 || $this->element ==
'societe') {
2727 $fieldname =
'fk_transport_mode';
2728 if ($this->element ==
'societe') {
2729 $fieldname =
'transport_mode';
2731 if (get_class($this) ==
'Fournisseur') {
2732 $fieldname =
'transport_mode_supplier';
2735 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2736 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2737 $sql .=
' WHERE rowid='.((int) $this->
id);
2739 if ($this->db->query(
$sql)) {
2740 $this->transport_mode_id = $id;
2742 if (get_class($this) ==
'Fournisseur') {
2743 $this->transport_mode_supplier_id = $id;
2747 dol_syslog(get_class($this).
'::setTransportMode Error '.
$sql.
' - '.$this->db->error());
2748 $this->error = $this->db->error();
2752 dol_syslog(get_class($this).
'::setTransportMode, status of the object is incompatible');
2753 $this->error =
'Status of the object is incompatible '.$this->statut;
2766 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms('.$id.
')');
2767 if ($this->statut >= 0 || $this->element ==
'societe') {
2768 $fieldname =
'retained_warranty_fk_cond_reglement';
2770 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2771 $sql .=
" SET ".$fieldname.
" = ".((int) $id);
2772 $sql .=
' WHERE rowid='.((int) $this->
id);
2774 if ($this->db->query(
$sql)) {
2775 $this->retained_warranty_fk_cond_reglement = $id;
2778 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms Error '.
$sql.
' - '.$this->db->error());
2779 $this->error = $this->db->error();
2783 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
2784 $this->error =
'Status of the object is incompatible '.$this->statut;
2798 $fieldname =
'fk_delivery_address';
2799 if ($this->element ==
'delivery' || $this->element ==
'shipping') {
2800 $fieldname =
'fk_address';
2803 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ".$fieldname.
" = ".((int) $id);
2804 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
2806 if ($this->db->query(
$sql)) {
2807 $this->fk_delivery_address = $id;
2810 $this->error = $this->db->error();
2811 dol_syslog(get_class($this).
'::setDeliveryAddress Error '.$this->error);
2830 if (empty($userused)) {
2836 if (!$this->table_element) {
2837 dol_syslog(get_class($this).
"::setShippingMethod was called on objet with property table_element not defined", LOG_ERR);
2843 if ($shipping_method_id < 0) {
2844 $shipping_method_id =
'NULL';
2846 dol_syslog(get_class($this).
'::setShippingMethod('.$shipping_method_id.
')');
2848 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2849 $sql .=
" SET fk_shipping_method = ".((int) $shipping_method_id);
2850 $sql .=
" WHERE rowid=".((int) $this->
id);
2851 $resql = $this->db->query(
$sql);
2853 dol_syslog(get_class($this).
'::setShippingMethod Error ', LOG_DEBUG);
2854 $this->error = $this->db->lasterror();
2859 $this->context = array(
'shippingmethodupdate'=>1);
2860 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2868 $this->db->rollback();
2871 $this->shipping_method_id = ($shipping_method_id ==
'NULL') ?
null:$shipping_method_id;
2872 $this->db->commit();
2886 if (!$this->table_element) {
2887 dol_syslog(get_class($this).
"::setWarehouse was called on objet with property table_element not defined", LOG_ERR);
2890 if ($warehouse_id < 0) {
2891 $warehouse_id =
'NULL';
2893 dol_syslog(get_class($this).
'::setWarehouse('.$warehouse_id.
')');
2895 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2896 $sql .=
" SET fk_warehouse = ".((int) $warehouse_id);
2897 $sql .=
" WHERE rowid=".((int) $this->
id);
2899 if ($this->db->query(
$sql)) {
2900 $this->warehouse_id = ($warehouse_id ==
'NULL') ?
null:$warehouse_id;
2903 dol_syslog(get_class($this).
'::setWarehouse Error ', LOG_DEBUG);
2904 $this->error = $this->db->error();
2919 if (!$this->table_element) {
2920 dol_syslog(get_class($this).
"::setDocModel was called on objet with property table_element not defined", LOG_ERR);
2924 $newmodelpdf =
dol_trunc($modelpdf, 255);
2926 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2927 $sql .=
" SET model_pdf = '".$this->db->escape($newmodelpdf).
"'";
2928 $sql .=
" WHERE rowid = ".((int) $this->
id);
2930 dol_syslog(get_class($this).
"::setDocModel", LOG_DEBUG);
2931 $resql = $this->db->query(
$sql);
2933 $this->model_pdf = $modelpdf;
2934 $this->modelpdf = $modelpdf;
2955 if (empty($userused)) {
2961 if (!$this->table_element) {
2962 dol_syslog(get_class($this).
"::setBankAccount was called on objet with property table_element not defined", LOG_ERR);
2967 if ($fk_account < 0) {
2968 $fk_account =
'NULL';
2970 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
2972 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2973 $sql .=
" SET fk_account = ".((int) $fk_account);
2974 $sql .=
" WHERE rowid=".((int) $this->
id);
2976 $resql = $this->db->query(
$sql);
2978 dol_syslog(get_class($this).
'::setBankAccount Error '.
$sql.
' - '.$this->db->error());
2979 $this->error = $this->db->lasterror();
2984 $this->context = array(
'bankaccountupdate'=>1);
2985 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2993 $this->db->rollback();
2996 $this->fk_account = ($fk_account ==
'NULL') ?
null:$fk_account;
2997 $this->db->commit();
3015 public function line_order($renum =
false, $rowidorder =
'ASC', $fk_parent_line =
true)
3018 if (!$this->table_element_line) {
3019 dol_syslog(get_class($this).
"::line_order was called on objet with property table_element_line not defined", LOG_ERR);
3022 if (!$this->fk_element) {
3023 dol_syslog(get_class($this).
"::line_order was called on objet with property fk_element not defined", LOG_ERR);
3027 $fieldposition =
'rang';
3028 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3029 $fieldposition =
'position';
3034 $sql =
"SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
3035 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3037 $sql .=
" AND " . $fieldposition .
" = 0";
3040 $sql .=
" AND " . $fieldposition .
" <> 0";
3043 dol_syslog(get_class($this).
"::line_order", LOG_DEBUG);
3044 $resql = $this->db->query(
$sql);
3046 $row = $this->db->fetch_row($resql);
3056 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3057 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3058 if ($fk_parent_line) {
3059 $sql .=
' AND fk_parent_line IS NULL';
3061 $sql .=
" ORDER BY " . $fieldposition .
" ASC, rowid " . $rowidorder;
3063 dol_syslog(get_class($this).
"::line_order search all parent lines", LOG_DEBUG);
3064 $resql = $this->db->query(
$sql);
3067 $num = $this->db->num_rows($resql);
3069 $row = $this->db->fetch_row($resql);
3071 $childrens = $this->getChildrenOfLine($row[0]);
3072 if (!empty($childrens)) {
3073 foreach ($childrens as $child) {
3074 array_push($rows, $child);
3081 if (!empty($rows)) {
3082 foreach ($rows as $key => $row) {
3083 $this->updateRangOfLine($row, ($key + 1));
3102 $fieldposition =
'rang';
3103 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3104 $fieldposition =
'position';
3109 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3110 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3111 $sql .=
' AND fk_parent_line = '.((int) $id);
3112 $sql .=
" ORDER BY " . $fieldposition .
" ASC";
3114 dol_syslog(get_class($this).
"::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
3115 $resql = $this->db->query(
$sql);
3117 if ($this->db->num_rows($resql) > 0) {
3118 while ($row = $this->db->fetch_row($resql)) {
3120 if (!empty($includealltree)) {
3121 $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
3137 public function line_up($rowid, $fk_parent_line =
true)
3140 $this->line_order(
false,
'ASC', $fk_parent_line);
3143 $rang = $this->getRangOfLine($rowid);
3146 $this->updateLineUp($rowid, $rang);
3160 $this->line_order(
false,
'ASC', $fk_parent_line);
3163 $rang = $this->getRangOfLine($rowid);
3166 $max = $this->line_max();
3169 $this->updateLineDown($rowid, $rang, $max);
3181 global $hookmanager;
3182 $fieldposition =
'rang';
3183 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3184 $fieldposition =
'position';
3187 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3188 $sql .=
' WHERE rowid = '.((int) $rowid);
3190 dol_syslog(get_class($this).
"::updateRangOfLine", LOG_DEBUG);
3191 if (!$this->db->query(
$sql)) {
3195 $parameters=array(
'rowid'=>$rowid,
'rang'=>$rang,
'fieldposition' => $fieldposition);
3197 $reshook = $hookmanager->executeHooks(
'afterRankOfLineUpdate', $parameters, $this, $action);
3212 $num = count($rows);
3213 for ($i = 0; $i < $num; $i++) {
3214 $this->updateRangOfLine($rows[$i], ($i + 1));
3228 $fieldposition =
'rang';
3229 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3230 $fieldposition =
'position';
3233 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3234 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3235 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang - 1));
3236 if ($this->db->query(
$sql)) {
3237 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang - 1));
3238 $sql .=
' WHERE rowid = '.((int) $rowid);
3239 if (!$this->db->query(
$sql)) {
3259 $fieldposition =
'rang';
3260 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3261 $fieldposition =
'position';
3264 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3265 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3266 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang + 1));
3267 if ($this->db->query(
$sql)) {
3268 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang + 1));
3269 $sql .=
' WHERE rowid = '.((int) $rowid);
3270 if (!$this->db->query(
$sql)) {
3287 $fieldposition =
'rang';
3288 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3289 $fieldposition =
'position';
3292 $sql =
"SELECT " . $fieldposition .
" FROM ".$this->db->prefix().$this->table_element_line;
3293 $sql .=
" WHERE rowid = ".((int) $rowid);
3295 dol_syslog(get_class($this).
"::getRangOfLine", LOG_DEBUG);
3296 $resql = $this->db->query(
$sql);
3298 $row = $this->db->fetch_row($resql);
3313 $fieldposition =
'rang';
3314 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3315 $fieldposition =
'position';
3318 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3319 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3320 $sql .=
" AND " . $fieldposition .
" = ".((int) $rang);
3321 $resql = $this->db->query(
$sql);
3323 $row = $this->db->fetch_row($resql);
3340 $positionfield =
'rang';
3341 if (in_array($this->table_element, array(
'bom_bom',
'product_attribute'))) {
3342 $positionfield =
'position';
3346 if ($fk_parent_line) {
3347 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3348 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3349 $sql .=
" AND fk_parent_line = ".((int) $fk_parent_line);
3351 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3352 $resql = $this->db->query(
$sql);
3354 $row = $this->db->fetch_row($resql);
3355 if (!empty($row[0])) {
3358 return $this->getRangOfLine($fk_parent_line);
3363 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3364 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3366 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3367 $resql = $this->db->query(
$sql);
3369 $row = $this->db->fetch_row($resql);
3387 if (!$this->table_element) {
3388 dol_syslog(get_class($this).
"::update_ref_ext was called on objet with property table_element not defined", LOG_ERR);
3392 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3393 $sql .=
" SET ref_ext = '".$this->db->escape($ref_ext).
"'";
3394 $sql .=
" WHERE ".(isset($this->table_rowid) ? $this->table_rowid :
'rowid').
" = ".((
int) $this->id);
3396 dol_syslog(get_class($this).
"::update_ref_ext", LOG_DEBUG);
3397 if ($this->db->query(
$sql)) {
3398 $this->ref_ext = $ref_ext;
3401 $this->error = $this->db->error();
3419 if (!$this->table_element) {
3420 $this->error =
'update_note was called on objet with property table_element not defined';
3421 dol_syslog(get_class($this).
"::update_note was called on objet with property table_element not defined", LOG_ERR);
3424 if (!in_array($suffix, array(
'',
'_public',
'_private'))) {
3425 $this->error =
'update_note Parameter suffix must be empty, \'_private\' or \'_public\'';
3426 dol_syslog(get_class($this).
"::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
3430 $newsuffix = $suffix;
3433 if ($this->table_element ==
'product' && $newsuffix ==
'_private') {
3436 if (in_array($this->table_element, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
3437 $fieldusermod =
"fk_user_mod";
3438 } elseif ($this->table_element ==
'ecm_files') {
3439 $fieldusermod =
"fk_user_m";
3441 $fieldusermod =
"fk_user_modif";
3443 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3444 $sql .=
" SET note".$newsuffix.
" = ".(!empty($note) ? (
"'".$this->db->escape($note).
"'") :
"NULL");
3445 $sql .=
", ".$fieldusermod.
" = ".((int) $user->id);
3446 $sql .=
" WHERE rowid = ".((int) $this->
id);
3448 dol_syslog(get_class($this).
"::update_note", LOG_DEBUG);
3449 if ($this->db->query(
$sql)) {
3450 if ($suffix ==
'_public') {
3451 $this->note_public = $note;
3452 } elseif ($suffix ==
'_private') {
3453 $this->note_private = $note;
3455 $this->note = $note;
3456 $this->note_private = $note;
3460 $this->error = $this->db->lasterror();
3477 return $this->update_note($note,
'_public');
3491 public function update_price($exclspec = 0, $roundingadjust =
'none', $nodatabaseupdate = 0, $seller =
null)
3494 global $conf, $hookmanager, $action;
3496 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3497 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3500 } elseif ($reshook < 0) {
3506 if ($this->element ==
'propal') {
3507 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3508 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3509 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3510 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3511 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3512 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3513 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3514 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3515 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3516 } elseif ($this->element ==
'supplier_proposal') {
3517 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3520 if (!empty($MODULE)) {
3521 if (!empty($conf->global->$MODULE)) {
3522 $modsactivated = explode(
',', $conf->global->$MODULE);
3523 foreach ($modsactivated as $mod) {
3531 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3533 $forcedroundingmode = $roundingadjust;
3534 if ($forcedroundingmode ==
'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3536 } elseif ($forcedroundingmode ==
'auto') {
3537 $forcedroundingmode =
'0';
3542 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3545 $fieldtva =
'total_tva';
3546 $fieldlocaltax1 =
'total_localtax1';
3547 $fieldlocaltax2 =
'total_localtax2';
3548 $fieldup =
'subprice';
3549 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3553 if ($this->element ==
'invoice_supplier_rec') {
3556 if ($this->element ==
'expensereport') {
3557 $fieldup =
'value_unit';
3560 $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,";
3561 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3562 if ($this->table_element_line ==
'facturedet') {
3563 $sql .=
', situation_percent';
3565 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
3566 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
3567 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3569 $product_field =
'product_type';
3570 if ($this->table_element_line ==
'contratdet') {
3571 $product_field =
'';
3573 if ($product_field) {
3574 $sql .=
" AND ".$product_field.
" <> 9";
3577 $sql .=
' ORDER by rowid';
3579 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3581 $resql = $this->db->query(
$sql);
3583 $this->total_ht = 0;
3584 $this->total_tva = 0;
3585 $this->total_localtax1 = 0;
3586 $this->total_localtax2 = 0;
3587 $this->total_ttc = 0;
3588 $total_ht_by_vats = array();
3589 $total_tva_by_vats = array();
3590 $total_ttc_by_vats = array();
3591 $this->multicurrency_total_ht = 0;
3592 $this->multicurrency_total_tva = 0;
3593 $this->multicurrency_total_ttc = 0;
3597 $num = $this->db->num_rows($resql);
3600 $obj = $this->db->fetch_object($resql);
3603 $parameters = array(
'fk_element' => $obj->rowid);
3604 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
3606 if (empty($reshook) && $forcedroundingmode ==
'0') {
3608 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3609 $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);
3611 $diff_when_using_price_ht =
price2num($tmpcal[1] - $obj->total_tva,
'MT', 1);
3612 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
3616 if ($diff_on_current_total) {
3618 $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);
3619 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);
3620 $resqlfix = $this->db->query($sqlfix);
3624 $obj->total_tva = $tmpcal[1];
3625 $obj->total_ttc = $tmpcal[2];
3626 } elseif ($diff_when_using_price_ht && $roundingadjust ==
'0') {
3629 $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);
3630 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);
3631 $resqlfix = $this->db->query($sqlfix);
3635 $obj->total_tva = $tmpcal[1];
3636 $obj->total_ttc = $tmpcal[2];
3640 $this->total_ht += $obj->total_ht;
3641 $this->total_tva += $obj->total_tva;
3642 $this->total_localtax1 += $obj->total_localtax1;
3643 $this->total_localtax2 += $obj->total_localtax2;
3644 $this->total_ttc += $obj->total_ttc;
3645 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
3646 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
3647 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
3649 if (!isset($total_ht_by_vats[$obj->vatrate])) {
3650 $total_ht_by_vats[$obj->vatrate] = 0;
3652 if (!isset($total_tva_by_vats[$obj->vatrate])) {
3653 $total_tva_by_vats[$obj->vatrate] = 0;
3655 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3656 $total_ttc_by_vats[$obj->vatrate] = 0;
3658 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
3659 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3660 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3662 if ($forcedroundingmode ==
'1') {
3663 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
3664 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat,
'MT', 1);
3667 if (abs($diff) > (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)))) {
3669 $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.';
3671 $this->error = $errmsg;
3675 $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);
3676 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);
3678 $resqlfix = $this->db->query($sqlfix);
3684 $this->total_tva = (
float)
price2num($this->total_tva - $diff,
'', 1);
3685 $this->total_ttc = (
float)
price2num($this->total_ttc - $diff,
'', 1);
3686 $total_tva_by_vats[$obj->vatrate] = (
float)
price2num($total_tva_by_vats[$obj->vatrate] - $diff,
'', 1);
3687 $total_ttc_by_vats[$obj->vatrate] = (
float)
price2num($total_ttc_by_vats[$obj->vatrate] - $diff,
'', 1);
3695 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
3696 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
3699 if (!empty($this->situation_cycle_ref) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits') && $this->
type != $this::TYPE_CREDIT_NOTE) {
3700 $prev_sits = $this->get_prev_sits();
3702 foreach ($prev_sits as $sit) {
3703 $this->total_ht -= $sit->total_ht;
3704 $this->total_tva -= $sit->total_tva;
3705 $this->total_localtax1 -= $sit->total_localtax1;
3706 $this->total_localtax2 -= $sit->total_localtax2;
3707 $this->total_ttc -= $sit->total_ttc;
3708 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
3709 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
3710 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
3717 $this->total_localtax1 = (
float)
price2num($this->total_localtax1);
3718 $this->total_localtax2 = (
float)
price2num($this->total_localtax2);
3721 $this->db->free($resql);
3724 $fieldht =
'total_ht';
3726 $fieldlocaltax1 =
'localtax1';
3727 $fieldlocaltax2 =
'localtax2';
3728 $fieldttc =
'total_ttc';
3730 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
3731 $fieldtva =
'total_tva';
3734 if (!$error && empty($nodatabaseupdate)) {
3735 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
3738 $sql .=
" ".$fieldlocaltax1.
" = ".((
float)
price2num($this->total_localtax1,
'MT', 1)).
",";
3739 $sql .=
" ".$fieldlocaltax2.
" = ".((
float)
price2num($this->total_localtax2,
'MT', 1)).
",";
3741 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
3742 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
3743 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
3744 $sql .=
" WHERE rowid = ".((int) $this->
id);
3746 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3747 $resql = $this->db->query(
$sql);
3751 $this->error = $this->db->lasterror();
3752 $this->errors[] = $this->db->lasterror();
3757 $this->db->commit();
3760 $this->db->rollback();
3780 public function add_object_linked($origin =
null, $origin_id =
null, $f_user =
null, $notrigger = 0)
3783 global $user, $hookmanager, $action;
3784 $origin = (!empty($origin) ? $origin : $this->origin);
3785 $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
3786 $f_user = isset($f_user) ? $f_user : $user;
3789 if ($origin ==
'order') {
3790 $origin =
'commande';
3792 if ($origin ==
'invoice') {
3793 $origin =
'facture';
3795 if ($origin ==
'invoice_template') {
3796 $origin =
'facturerec';
3798 if ($origin ==
'supplierorder') {
3799 $origin =
'order_supplier';
3804 $coremodule = array(
'knowledgemanagement',
'partnership',
'workstation',
'ticket',
'recruitment',
'eventorganization',
'asset');
3806 $targettype = ((!empty($this->module) && ! in_array($this->module, $coremodule)) ? $this->module.
'_' :
'').$this->element;
3808 $parameters = array(
'targettype'=>$targettype);
3810 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3812 if (!empty($hookmanager->resArray[
'targettype'])) $targettype = $hookmanager->resArray[
'targettype'];
3818 $sql =
"INSERT INTO " . $this->db->prefix() .
"element_element (";
3819 $sql .=
"fk_source";
3820 $sql .=
", sourcetype";
3821 $sql .=
", fk_target";
3822 $sql .=
", targettype";
3823 $sql .=
") VALUES (";
3824 $sql .= ((int) $origin_id);
3825 $sql .=
", '" . $this->db->escape($origin) .
"'";
3826 $sql .=
", " . ((int) $this->
id);
3827 $sql .=
", '" . $this->db->escape($targettype) .
"'";
3830 dol_syslog(get_class($this) .
"::add_object_linked", LOG_DEBUG);
3831 if ($this->db->query(
$sql)) {
3834 $this->context[
'link_origin'] = $origin;
3835 $this->context[
'link_origin_id'] = $origin_id;
3836 $result = $this->call_trigger(
'OBJECT_LINK_INSERT', $f_user);
3843 $this->error = $this->db->lasterror();
3848 $this->db->commit();
3851 $this->db->rollback();
3878 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
3880 global $conf, $hookmanager, $action;
3884 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
3888 $this->linkedObjectsIds = array();
3889 $this->linkedObjects = array();
3891 $justsource =
false;
3892 $justtarget =
false;
3893 $withtargettype =
false;
3894 $withsourcetype =
false;
3896 $parameters = array(
'sourcetype'=>$sourcetype,
'sourceid'=>$sourceid,
'targettype'=>$targettype,
'targetid'=>$targetid);
3898 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3900 if (!empty($hookmanager->resArray[
'sourcetype'])) $sourcetype = $hookmanager->resArray[
'sourcetype'];
3901 if (!empty($hookmanager->resArray[
'sourceid'])) $sourceid = $hookmanager->resArray[
'sourceid'];
3902 if (!empty($hookmanager->resArray[
'targettype'])) $targettype = $hookmanager->resArray[
'targettype'];
3903 if (!empty($hookmanager->resArray[
'targetid'])) $targetid = $hookmanager->resArray[
'targetid'];
3906 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
3908 if (!empty($targettype)) {
3909 $withtargettype =
true;
3912 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
3914 if (!empty($sourcetype)) {
3915 $withsourcetype =
true;
3919 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
3920 $targetid = (!empty($targetid) ? $targetid : $this->id);
3921 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
3922 $targettype = (!empty($targettype) ? $targettype : $this->element);
3931 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
3932 $sql .=
" FROM ".$this->db->prefix().
"element_element";
3934 if ($justsource || $justtarget) {
3936 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3937 if ($withtargettype) {
3938 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
3940 } elseif ($justtarget) {
3941 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
3942 if ($withsourcetype) {
3943 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3947 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
3948 $sql .=
" ".$clause.
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
3949 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
3950 $this->linkedObjectsFullLoaded[$this->id] =
true;
3953 $sql .=
" ORDER BY ".$orderby;
3955 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
3956 $resql = $this->db->query(
$sql);
3958 $num = $this->db->num_rows($resql);
3961 $obj = $this->db->fetch_object($resql);
3962 if ($justsource || $justtarget) {
3964 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
3965 } elseif ($justtarget) {
3966 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
3969 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
3970 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
3972 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
3973 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
3979 if (!empty($this->linkedObjectsIds)) {
3980 $tmparray = $this->linkedObjectsIds;
3981 foreach ($tmparray as $objecttype => $objectids) {
3983 $module = $element = $subelement = $objecttype;
3985 if ($objecttype !=
'supplier_proposal' && $objecttype !=
'order_supplier' && $objecttype !=
'invoice_supplier'
3986 && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
3987 $module = $element = $regs[1];
3988 $subelement = $regs[2];
3991 $classpath = $element.
'/class';
3993 if ($objecttype ==
'facture') {
3994 $classpath =
'compta/facture/class';
3995 } elseif ($objecttype ==
'facturerec') {
3996 $classpath =
'compta/facture/class';
3997 $module =
'facture';
3998 } elseif ($objecttype ==
'propal') {
3999 $classpath =
'comm/propal/class';
4000 } elseif ($objecttype ==
'supplier_proposal') {
4001 $classpath =
'supplier_proposal/class';
4002 } elseif ($objecttype ==
'shipping') {
4003 $classpath =
'expedition/class';
4004 $subelement =
'expedition';
4005 $module =
'expedition';
4006 } elseif ($objecttype ==
'delivery') {
4007 $classpath =
'delivery/class';
4008 $subelement =
'delivery';
4009 $module =
'delivery_note';
4010 } elseif ($objecttype ==
'invoice_supplier' || $objecttype ==
'order_supplier') {
4011 $classpath =
'fourn/class';
4012 $module =
'fournisseur';
4013 } elseif ($objecttype ==
'fichinter') {
4014 $classpath =
'fichinter/class';
4015 $subelement =
'fichinter';
4016 $module =
'ficheinter';
4017 } elseif ($objecttype ==
'subscription') {
4018 $classpath =
'adherents/class';
4019 $module =
'adherent';
4020 } elseif ($objecttype ==
'contact') {
4021 $module =
'societe';
4024 $classfile = strtolower($subelement);
4025 $classname = ucfirst($subelement);
4027 if ($objecttype ==
'order') {
4028 $classfile =
'commande';
4029 $classname =
'Commande';
4030 } elseif ($objecttype ==
'invoice_supplier') {
4031 $classfile =
'fournisseur.facture';
4032 $classname =
'FactureFournisseur';
4033 } elseif ($objecttype ==
'order_supplier') {
4034 $classfile =
'fournisseur.commande';
4035 $classname =
'CommandeFournisseur';
4036 } elseif ($objecttype ==
'supplier_proposal') {
4037 $classfile =
'supplier_proposal';
4038 $classname =
'SupplierProposal';
4039 } elseif ($objecttype ==
'facturerec') {
4040 $classfile =
'facture-rec';
4041 $classname =
'FactureRec';
4042 } elseif ($objecttype ==
'subscription') {
4043 $classfile =
'subscription';
4044 $classname =
'Subscription';
4045 } elseif ($objecttype ==
'project' || $objecttype ==
'projet') {
4046 $classpath =
'projet/class';
4047 $classfile =
'project';
4048 $classname =
'Project';
4049 } elseif ($objecttype ==
'conferenceorboothattendee') {
4050 $classpath =
'eventorganization/class';
4051 $classfile =
'conferenceorboothattendee';
4052 $classname =
'ConferenceOrBoothAttendee';
4053 $module =
'eventorganization';
4054 } elseif ($objecttype ==
'conferenceorbooth') {
4055 $classpath =
'eventorganization/class';
4056 $classfile =
'conferenceorbooth';
4057 $classname =
'ConferenceOrBooth';
4058 $module =
'eventorganization';
4059 } elseif ($objecttype ==
'mo') {
4060 $classpath =
'mrp/class';
4067 if (
isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4068 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4071 if (class_exists($classname)) {
4072 foreach ($objectids as $i => $objectid) {
4073 $object =
new $classname($this->db);
4074 $ret = $object->fetch($objectid);
4076 $this->linkedObjects[$objecttype][$i] = $object;
4082 unset($this->linkedObjectsIds[$objecttype]);
4101 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4102 unset($this->linkedObjectsFullLoaded[$this->
id]);
4120 public function updateObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $f_user =
null, $notrigger = 0)
4123 $updatesource =
false;
4124 $updatetarget =
false;
4125 $f_user = isset($f_user) ? $f_user : $user;
4127 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4128 $updatesource =
true;
4129 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4130 $updatetarget =
true;
4136 $sql =
"UPDATE " . $this->db->prefix() .
"element_element SET ";
4137 if ($updatesource) {
4138 $sql .=
"fk_source = " . ((int) $sourceid);
4139 $sql .=
", sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4140 $sql .=
" WHERE fk_target = " . ((int) $this->
id);
4141 $sql .=
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4142 } elseif ($updatetarget) {
4143 $sql .=
"fk_target = " . ((int) $targetid);
4144 $sql .=
", targettype = '" . $this->db->escape($targettype) .
"'";
4145 $sql .=
" WHERE fk_source = " . ((int) $this->
id);
4146 $sql .=
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4149 dol_syslog(get_class($this) .
"::updateObjectLinked", LOG_DEBUG);
4150 if ($this->db->query(
$sql)) {
4153 $this->context[
'link_source_id'] = $sourceid;
4154 $this->context[
'link_source_type'] = $sourcetype;
4155 $this->context[
'link_target_id'] = $targetid;
4156 $this->context[
'link_target_type'] = $targettype;
4157 $result = $this->call_trigger(
'OBJECT_LINK_MODIFY', $f_user);
4164 $this->error = $this->db->lasterror();
4169 $this->db->commit();
4172 $this->db->rollback();
4190 public function deleteObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $rowid =
'', $f_user =
null, $notrigger = 0)
4193 $deletesource =
false;
4194 $deletetarget =
false;
4195 $f_user = isset($f_user) ? $f_user : $user;
4197 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4198 $deletesource =
true;
4199 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4200 $deletetarget =
true;
4203 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4204 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
4205 $targetid = (!empty($targetid) ? $targetid : $this->id);
4206 $targettype = (!empty($targettype) ? $targettype : $this->element);
4212 $this->context[
'link_id'] = $rowid;
4213 $this->context[
'link_source_id'] = $sourceid;
4214 $this->context[
'link_source_type'] = $sourcetype;
4215 $this->context[
'link_target_id'] = $targetid;
4216 $this->context[
'link_target_type'] = $targettype;
4217 $result = $this->call_trigger(
'OBJECT_LINK_DELETE', $f_user);
4225 $sql =
"DELETE FROM " . $this->db->prefix() .
"element_element";
4228 $sql .=
" rowid = " . ((int) $rowid);
4230 if ($deletesource) {
4231 $sql .=
" fk_source = " . ((int) $sourceid) .
" AND sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4232 $sql .=
" AND fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4233 } elseif ($deletetarget) {
4234 $sql .=
" fk_target = " . ((int) $targetid) .
" AND targettype = '" . $this->db->escape($targettype) .
"'";
4235 $sql .=
" AND fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4237 $sql .=
" (fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"')";
4239 $sql .=
" (fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"')";
4243 dol_syslog(get_class($this) .
"::deleteObjectLinked", LOG_DEBUG);
4244 if (!$this->db->query(
$sql)) {
4245 $this->error = $this->db->lasterror();
4246 $this->errors[] = $this->error;
4252 $this->db->commit();
4255 $this->db->rollback();
4271 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4277 $sql =
"SELECT ".$field_select.
" FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4278 $resql = $db->query(
$sql);
4281 if (!empty($resql)) {
4282 while ($res = $db->fetch_object($resql)) {
4283 $TRes[] = $res->{$field_select};
4300 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4306 $sql =
"DELETE FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4307 $resql = $db->query(
$sql);
4309 if (empty($resql)) {
4326 public function setStatut($status, $elementId =
null, $elementType =
'', $trigkey =
'', $fieldstatus =
'fk_statut')
4328 global $user, $langs, $conf;
4330 $savElementId = $elementId;
4332 $elementId = (!empty($elementId) ? $elementId : $this->id);
4333 $elementTable = (!empty($elementType) ? $elementType : $this->table_element);
4337 if ($elementTable ==
'facture_rec') {
4338 $fieldstatus =
"suspended";
4340 if ($elementTable ==
'mailing') {
4341 $fieldstatus =
"statut";
4343 if ($elementTable ==
'cronjob') {
4344 $fieldstatus =
"status";
4346 if ($elementTable ==
'user') {
4347 $fieldstatus =
"statut";
4349 if ($elementTable ==
'expensereport') {
4350 $fieldstatus =
"fk_statut";
4352 if ($elementTable ==
'commande_fournisseur_dispatch') {
4353 $fieldstatus =
"status";
4355 if (isset($this->fields) && is_array($this->fields) && array_key_exists(
'status', $this->fields)) {
4356 $fieldstatus =
'status';
4359 $sql =
"UPDATE ".$this->db->prefix().$elementTable;
4360 $sql .=
" SET ".$fieldstatus.
" = ".((int) $status);
4363 if ($status == 1 && in_array($elementTable, array(
'expensereport',
'inventory'))) {
4364 $sql .=
", fk_user_valid = ".((int) $user->id);
4366 if ($status == 1 && in_array($elementTable, array(
'expensereport'))) {
4367 $sql .=
", date_valid = '".$this->db->idate(
dol_now()).
"'";
4369 if ($status == 1 && in_array($elementTable, array(
'inventory'))) {
4370 $sql .=
", date_validation = '".$this->db->idate(
dol_now()).
"'";
4372 $sql .=
" WHERE rowid = ".((int) $elementId);
4373 $sql .=
" AND ".$fieldstatus.
" <> ".((int) $status);
4375 dol_syslog(get_class($this).
"::setStatut", LOG_DEBUG);
4376 $resql = $this->db->query(
$sql);
4380 $nb_rows_affected = $this->db->affected_rows($resql);
4382 if ($nb_rows_affected > 0) {
4383 if (empty($trigkey)) {
4385 if ($this->element ==
'supplier_proposal' && $status == 2) {
4386 $trigkey =
'SUPPLIER_PROPOSAL_SIGN';
4388 if ($this->element ==
'supplier_proposal' && $status == 3) {
4389 $trigkey =
'SUPPLIER_PROPOSAL_REFUSE';
4391 if ($this->element ==
'supplier_proposal' && $status == 4) {
4392 $trigkey =
'SUPPLIER_PROPOSAL_CLOSE';
4394 if ($this->element ==
'fichinter' && $status == 3) {
4395 $trigkey =
'FICHINTER_CLASSIFY_DONE';
4397 if ($this->element ==
'fichinter' && $status == 2) {
4398 $trigkey =
'FICHINTER_CLASSIFY_BILLED';
4400 if ($this->element ==
'fichinter' && $status == 1) {
4401 $trigkey =
'FICHINTER_CLASSIFY_UNBILLED';
4407 $result = $this->call_trigger($trigkey, $user);
4418 $this->db->commit();
4420 if (empty($savElementId)) {
4422 if ($fieldstatus ==
'tosell') {
4423 $this->status = $status;
4424 } elseif ($fieldstatus ==
'tobuy') {
4425 $this->status_buy = $status;
4427 $this->statut = $status;
4428 $this->status = $status;
4434 $this->db->rollback();
4435 dol_syslog(get_class($this).
"::setStatut ".$this->error, LOG_ERR);
4439 $this->error = $this->db->lasterror();
4440 $this->db->rollback();
4457 if (empty($id) && empty($ref)) {
4460 if (!empty($conf->global->MAIN_DISABLE_CANVAS)) {
4467 $sql =
"SELECT rowid, canvas";
4468 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
4469 $sql .=
" WHERE entity IN (".getEntity($this->element).
")";
4471 $sql .=
" AND rowid = ".((int) $id);
4474 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
4477 $resql = $this->db->query(
$sql);
4479 $obj = $this->db->fetch_object($resql);
4481 $this->canvas = $obj->canvas;
4501 $sql =
"SELECT special_code FROM ".$this->db->prefix().$this->table_element_line;
4502 $sql .=
" WHERE rowid = ".((int) $lineid);
4503 $resql = $this->db->query(
$sql);
4505 $row = $this->db->fetch_row($resql);
4529 if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
4530 dol_print_error(
'Called isObjectUsed on a class with property this->childtables not defined');
4534 $arraytoscan = $this->childtables;
4536 $tmparray = array_keys($this->childtables);
4537 if (is_numeric($tmparray[0])) {
4538 $arraytoscan = array_flip($this->childtables);
4543 foreach ($arraytoscan as $table => $element) {
4546 $sql =
"SELECT COUNT(*) as nb";
4547 $sql.=
" FROM ".$this->db->prefix().$table.
" as c";
4548 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4549 $sql.=
", ".$this->db->prefix().$element[
'parent'].
" as p";
4551 if (!empty($element[
'fk_element'])) {
4552 $sql.=
" WHERE c.".$element[
'fk_element'].
" = ".((int) $id);
4554 $sql.=
" WHERE c.".$this->fk_element.
" = ".((int) $id);
4556 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4557 $sql.=
" AND c.".$element[
'parentkey'].
" = p.rowid";
4559 if (!empty($element[
'parent']) && !empty($element[
'parenttypefield']) && !empty($element[
'parenttypevalue'])) {
4560 $sql.=
" AND c.".$element[
'parenttypefield'].
" = '".$this->db->escape($element[
'parenttypevalue']).
"'";
4562 if (!empty($entity)) {
4563 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4564 $sql.=
" AND p.entity = ".((int) $entity);
4566 $sql.=
" AND c.entity = ".((int) $entity);
4570 $resql = $this->db->query(
$sql);
4572 $obj = $this->db->fetch_object($resql);
4574 $langs->load(
"errors");
4576 $haschild += $obj->nb;
4577 if (is_numeric($element)) {
4578 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
4579 } elseif (is_string($element)) {
4580 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->
ref, $langs->transnoentitiesnoconv($element));
4582 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->
ref, $langs->transnoentitiesnoconv($element[
'name']));
4587 $this->errors[] = $this->db->lasterror();
4591 if ($haschild > 0) {
4592 $this->errors[] =
"ErrorRecordHasChildren";
4609 foreach ($this->lines as $key => $val) {
4611 if ($predefined == -1) {
4614 if ($predefined == 1 && $val->fk_product > 0) {
4617 if ($predefined == 0 && $val->fk_product <= 0) {
4620 if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
4623 if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
4630 dol_syslog(get_class($this).
'::hasProductsOrServices we found '.$nb.
' qualified lines of products/servcies');
4641 if (!empty($this->table_element_line) ) {
4642 $total_discount = 0.00;
4644 $sql =
"SELECT subprice as pu_ht, qty, remise_percent, total_ht";
4645 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
4646 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
4648 dol_syslog(get_class($this).
'::getTotalDiscount', LOG_DEBUG);
4649 $resql = $this->db->query(
$sql);
4651 $num = $this->db->num_rows($resql);
4654 $obj = $this->db->fetch_object($resql);
4656 $pu_ht = $obj->pu_ht;
4658 $total_ht = $obj->total_ht;
4660 $total_discount_line = floatval(
price2num(($pu_ht * $qty) - $total_ht,
'MT'));
4661 $total_discount += $total_discount_line;
4690 foreach ($this->lines as $line) {
4691 if (isset($line->qty_asked)) {
4692 if (empty($totalOrdered)) {
4695 $totalOrdered += $line->qty_asked;
4697 if (isset($line->qty_shipped)) {
4698 if (empty($totalToShip)) {
4701 $totalToShip += $line->qty_shipped;
4702 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
4703 if (empty($totalToShip)) {
4706 $totalToShip += $line->qty;
4710 if ($this->element ==
'shipping') {
4712 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
4714 $qty = $line->qty ? $line->qty : 0;
4717 $weight = !empty($line->weight) ? $line->weight : 0;
4718 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
4719 $volume = !empty($line->volume) ? $line->volume : 0;
4720 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
4722 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
4723 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
4724 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
4725 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
4729 if (!empty($weight_units)) {
4730 $weightUnit = $weight_units;
4732 if (!empty($volume_units)) {
4733 $volumeUnit = $volume_units;
4736 if (empty($totalWeight)) {
4739 if (empty($totalVolume)) {
4744 if ($weight_units < 50) {
4745 $trueWeightUnit = pow(10, $weightUnit);
4746 $totalWeight += $weight * $qty * $trueWeightUnit;
4748 if ($weight_units == 99) {
4750 $trueWeightUnit = 0.45359237;
4751 $totalWeight += $weight * $qty * $trueWeightUnit;
4752 } elseif ($weight_units == 98) {
4754 $trueWeightUnit = 0.0283495;
4755 $totalWeight += $weight * $qty * $trueWeightUnit;
4757 $totalWeight += $weight * $qty;
4760 if ($volume_units < 50) {
4762 $trueVolumeUnit = pow(10, $volumeUnit);
4764 $totalVolume += $volume * $qty * $trueVolumeUnit;
4766 $totalVolume += $volume * $qty;
4770 return array(
'weight'=>$totalWeight,
'volume'=>$totalVolume,
'ordered'=>$totalOrdered,
'toship'=>$totalToShip);
4783 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
4785 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
4786 $sql .=
" SET extraparams = ".(!empty($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null");
4787 $sql .=
" WHERE rowid = ".((int) $this->
id);
4789 dol_syslog(get_class($this).
"::setExtraParameters", LOG_DEBUG);
4790 $resql = $this->db->query(
$sql);
4792 $this->error = $this->db->lasterror();
4793 $this->db->rollback();
4796 $this->db->commit();
4819 global $conf, $user, $langs, $object, $hookmanager, $extrafields;
4823 if (!is_object($extrafields)) {
4824 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
4827 $extrafields->fetch_name_optionals_label($this->table_element_line);
4832 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4833 foreach ($dirtpls as $module => $reldir) {
4834 if (!empty($module)) {
4837 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_create.tpl.php';
4840 if (empty($conf->file->strict_mode)) {
4841 $res = @include $tpl;
4843 $res = include $tpl;
4870 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
4872 global $conf, $hookmanager, $langs, $user,
$form, $extrafields, $object;
4874 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
4878 if (
isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
4882 $num = count($this->lines);
4885 if (!is_object($extrafields)) {
4886 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
4889 $extrafields->fetch_name_optionals_label($this->table_element_line);
4891 $parameters = array(
'num'=>$num,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$this->table_element_line);
4892 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
4893 if (empty($reshook)) {
4897 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4898 foreach ($dirtpls as $module => $reldir) {
4900 if (!empty($module)) {
4903 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
4905 if (file_exists($tpl)) {
4906 if (empty($conf->file->strict_mode)) {
4907 $res = @include $tpl;
4909 $res = include $tpl;
4920 print
"<!-- begin printObjectLines() --><tbody>\n";
4921 foreach ($this->lines as $line) {
4923 $line->fetch_optionals();
4926 if (is_object($hookmanager)) {
4927 if (empty($line->fk_parent_line)) {
4928 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element);
4929 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
4931 $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);
4932 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
4935 if (empty($reshook)) {
4936 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
4941 print
"</tbody><!-- end printObjectLines() -->\n";
4961 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
4963 global $conf, $langs, $user, $object, $hookmanager;
4965 global $object_rights, $disableedit, $disablemove, $disableremove;
4967 $object_rights = $this->getRights();
4973 if ($action !=
'editline' || $selected != $line->id) {
4975 if (!empty($line->fk_product) && $line->fk_product > 0) {
4976 $product_static =
new Product($this->db);
4977 $product_static->fetch($line->fk_product);
4979 $product_static->ref = $line->ref;
4980 $product_static->label = !empty($line->label) ? $line->label :
"";
4982 $text = $product_static->getNomUrl(1);
4986 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
4987 dol_print_error(
'',
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
4991 $prod =
new Product($this->db);
4992 $prod->fetch($line->fk_product);
4994 $outputlangs = $langs;
4996 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
4997 $newlang =
GETPOST(
'lang_id',
'aZ09');
4999 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
5000 $newlang = $this->thirdparty->default_lang;
5002 if (!empty($newlang)) {
5003 $outputlangs =
new Translate(
"", $conf);
5004 $outputlangs->setDefaultLang($newlang);
5007 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5009 $label = $line->product_label;
5012 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5013 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5016 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5021 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5022 foreach ($dirtpls as $module => $reldir) {
5024 if (!empty($module)) {
5027 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5029 if (file_exists($tpl)) {
5030 if (empty($conf->file->strict_mode)) {
5031 $res = @include $tpl;
5033 $res = include $tpl;
5043 if ($this->statut == 0 && $action ==
'editline' && $selected == $line->id) {
5044 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5046 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5051 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5052 foreach ($dirtpls as $module => $reldir) {
5053 if (!empty($module)) {
5056 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5059 if (empty($conf->file->strict_mode)) {
5060 $res = @include $tpl;
5062 $res = include $tpl;
5087 global $langs, $hookmanager, $conf,
$form, $action;
5089 print
'<tr class="liste_titre">';
5090 print
'<td class="linecolref">'.$langs->trans(
'Ref').
'</td>';
5091 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
5092 print
'<td class="linecolvat right">'.$langs->trans(
'VATRate').
'</td>';
5093 print
'<td class="linecoluht right">'.$langs->trans(
'PriceUHT').
'</td>';
5095 print
'<td class="linecoluht_currency right">'.$langs->trans(
'PriceUHTCurrency').
'</td>';
5097 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
5099 print
'<td class="linecoluseunit left">'.$langs->trans(
'Unit').
'</td>';
5101 print
'<td class="linecoldiscount right">'.$langs->trans(
'ReductionShort').
'</td>';
5102 print
'<td class="linecolht right">'.$langs->trans(
'TotalHT').
'</td>';
5103 print
'<td class="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
5107 if (!empty($this->lines)) {
5108 foreach ($this->lines as $line) {
5111 if (is_object($hookmanager)) {
5112 $parameters = array(
'line'=>$line,
'i'=>$i,
'restrictlist'=>$restrictlist,
'selectedLines'=> $selectedLines);
5113 if (!empty($line->fk_parent_line)) { $parameters[
'fk_parent_line'] = $line->fk_parent_line; }
5114 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
5116 if (empty($reshook)) {
5117 $this->printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
5138 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5140 global $langs, $conf;
5143 if (!empty($line->date_start)) {
5144 $date_start = $line->date_start;
5146 $date_start = $line->date_debut_prevue;
5147 if ($line->date_debut_reel) {
5148 $date_start = $line->date_debut_reel;
5151 if (!empty($line->date_end)) {
5152 $date_end = $line->date_end;
5154 $date_end = $line->date_fin_prevue;
5155 if ($line->date_fin_reel) {
5156 $date_end = $line->date_fin_reel;
5160 $this->tpl[
'id'] = $line->id;
5162 $this->tpl[
'label'] =
'';
5163 if (!empty($line->fk_parent_line)) {
5164 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5167 if (($line->info_bits & 2) == 2) {
5169 $discount->fk_soc = $this->socid;
5170 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5171 } elseif (!empty($line->fk_product)) {
5172 $productstatic =
new Product($this->db);
5173 $productstatic->id = $line->fk_product;
5174 $productstatic->ref = $line->ref;
5175 $productstatic->type = $line->fk_product_type;
5176 if (empty($productstatic->ref)) {
5177 $line->fetch_product();
5178 $productstatic = $line->product;
5181 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
5182 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5184 if ($line->product_type == 1 && ($date_start || $date_end)) {
5188 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
''),
'service') :
img_object($langs->trans(
''),
'product')));
5189 if (!empty($line->desc)) {
5190 $this->tpl[
'label'] .= $line->desc;
5192 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5196 if ($line->product_type == 1 && ($date_start || $date_end)) {
5201 if (!empty($line->desc)) {
5202 if ($line->desc ==
'(CREDIT_NOTE)') {
5204 $discount->fetch($line->fk_remise_except);
5205 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5206 } elseif ($line->desc ==
'(DEPOSIT)') {
5208 $discount->fetch($line->fk_remise_except);
5209 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5210 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5212 $discount->fetch($line->fk_remise_except);
5213 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5214 } elseif ($line->desc ==
'(EXCESS PAID)') {
5216 $discount->fetch($line->fk_remise_except);
5217 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5219 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5222 $this->tpl[
'description'] =
' ';
5226 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5227 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5228 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5229 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5232 $this->tpl[
'price'] =
price($line->subprice);
5233 $this->tpl[
'total_ht'] =
price($line->total_ht);
5234 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5235 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5237 $this->tpl[
'unit'] = $langs->transnoentities($line->getLabelOfUnit(
'long'));
5239 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate($line->remise_percent,
true) :
' ';
5242 $this->tpl[
'strike'] = 0;
5244 $this->tpl[
'strike'] = 1;
5249 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5250 foreach ($dirtpls as $module => $reldir) {
5251 if (!empty($module)) {
5254 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5257 if (empty($conf->file->strict_mode)) {
5258 $res = @include $tpl;
5260 $res = include $tpl;
5285 $sql =
"INSERT INTO ".$this->db->prefix().
"element_resources (";
5286 $sql .=
"resource_id";
5287 $sql .=
", resource_type";
5288 $sql .=
", element_id";
5289 $sql .=
", element_type";
5291 $sql .=
", mandatory";
5292 $sql .=
") VALUES (";
5293 $sql .= ((int) $resource_id);
5294 $sql .=
", '".$this->db->escape($resource_type).
"'";
5295 $sql .=
", '".$this->db->escape($this->
id).
"'";
5296 $sql .=
", '".$this->db->escape($this->element).
"'";
5297 $sql .=
", '".$this->db->escape($busy).
"'";
5298 $sql .=
", '".$this->db->escape($mandatory).
"'";
5301 dol_syslog(get_class($this).
"::add_element_resource", LOG_DEBUG);
5302 if ($this->db->query(
$sql)) {
5303 $this->db->commit();
5306 $this->error = $this->db->lasterror();
5307 $this->db->rollback();
5328 $sql =
"DELETE FROM ".$this->db->prefix().
"element_resources";
5329 $sql .=
" WHERE rowid = ".((int) $rowid);
5331 dol_syslog(get_class($this).
"::delete_resource", LOG_DEBUG);
5333 $resql = $this->db->query(
$sql);
5335 $this->error = $this->db->lasterror();
5336 $this->db->rollback();
5340 $result = $this->call_trigger(strtoupper($element).
'_DELETE_RESOURCE', $user);
5342 $this->db->rollback();
5346 $this->db->commit();
5360 if (isset($this->lines) && is_array($this->lines)) {
5361 $nboflines = count($this->lines);
5362 for ($i = 0; $i < $nboflines; $i++) {
5363 $this->lines[$i] = clone $this->lines[$i];
5381 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5383 global $conf, $langs, $user, $hookmanager, $action;
5385 $srctemplatepath =
'';
5387 $parameters = array(
'modelspath'=>$modelspath,
'modele'=>$modele,
'outputlangs'=>$outputlangs,
'hidedetails'=>$hidedetails,
'hidedesc'=>$hidedesc,
'hideref'=>$hideref,
'moreparams'=>$moreparams);
5388 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5390 if (!empty($reshook)) {
5394 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5396 if (empty($modele)) {
5397 $this->error =
'BadValueForParameterModele';
5402 $err = error_reporting();
5404 @set_time_limit(120);
5405 error_reporting($err);
5408 $tmp = explode(
':', $modele, 2);
5409 if (!empty($tmp[1])) {
5411 $srctemplatepath = $tmp[1];
5418 $dirmodels = array(
'/');
5419 if (is_array($conf->modules_parts[
'models'])) {
5420 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
5422 foreach ($dirmodels as $reldir) {
5423 foreach (array(
'doc',
'pdf') as $prefix) {
5424 if (in_array(get_class($this), array(
'Adherent'))) {
5426 $file = $prefix.
"_".$modele.
".class.php";
5429 $file = $prefix.
"_".$modele.
".modules.php";
5434 if (file_exists($file)) {
5436 $classname = $prefix.
'_'.$modele;
5446 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5447 $this->errors[] = $this->error;
5457 $obj =
new $classname($this->db);
5460 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5461 $varfortemplatedir = $obj->scandir;
5462 if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) {
5463 $dirtoscan = $conf->global->$varfortemplatedir;
5465 $listoffiles = array();
5468 $listofdir = explode(
',', $dirtoscan);
5469 foreach ($listofdir as $key => $tmpdir) {
5470 $tmpdir = trim($tmpdir);
5471 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5473 unset($listofdir[$key]);
5476 if (is_dir($tmpdir)) {
5477 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
5478 if (count($tmpfiles)) {
5479 $listoffiles = array_merge($listoffiles, $tmpfiles);
5484 if (count($listoffiles)) {
5485 foreach ($listoffiles as $record) {
5486 $srctemplatepath = $record[
'fullname'];
5492 if (empty($srctemplatepath)) {
5493 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
5498 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
5500 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
5501 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
5508 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
5510 if (in_array(get_class($this), array(
'Adherent'))) {
5511 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards', $moreparams);
5513 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
5517 if ($resultwritefile > 0) {
5518 $outputlangs->charset_output = $sav_charset_output;
5521 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5525 if (!empty($obj->result[
'fullpath'])) {
5526 $destfull = $obj->result[
'fullpath'];
5529 $update_main_doc_field = 0;
5530 if (!empty($obj->update_main_doc_field)) {
5531 $update_main_doc_field = 1;
5537 $this->indexFile($destfull, $update_main_doc_field);
5540 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);
5548 $outputlangs->charset_output = $sav_charset_output;
5549 $this->error = $obj->error;
5550 $this->errors = $obj->errors;
5551 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
5565 public function indexFile($destfull, $update_main_doc_field)
5567 global $conf, $user;
5569 $upload_dir = dirname($destfull);
5570 $destfile = basename($destfull);
5571 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
5573 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5574 $filename = basename($destfile);
5575 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
5576 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
5578 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
5579 $ecmfile =
new EcmFiles($this->db);
5580 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
5583 $setsharekey =
false;
5584 if ($this->element ==
'propal' || $this->element ==
'proposal') {
5585 if (!isset($conf->global->PROPOSAL_ALLOW_ONLINESIGN) || !empty($conf->global->PROPOSAL_ALLOW_ONLINESIGN)) {
5586 $setsharekey =
true;
5588 if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5589 $setsharekey =
true;
5592 if ($this->element ==
'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
5593 $setsharekey =
true;
5595 if ($this->element ==
'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
5596 $setsharekey =
true;
5598 if ($this->element ==
'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
5599 $setsharekey =
true;
5601 if ($this->element ==
'product' && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) {
5602 $setsharekey =
true;
5604 if ($this->element ==
'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) {
5605 $setsharekey =
true;
5607 if ($this->element ==
'fichinter' && !empty($conf->global->FICHINTER_ALLOW_EXTERNAL_DOWNLOAD)) {
5608 $setsharekey =
true;
5610 if ($this->element ==
'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5611 $setsharekey =
true;
5615 if (empty($ecmfile->share)) {
5616 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5623 $ecmfile->fullpath_orig =
'';
5624 $ecmfile->gen_or_uploaded =
'generated';
5625 $ecmfile->description =
'';
5626 $ecmfile->keywords =
'';
5627 $result = $ecmfile->update($user);
5633 $ecmfile->entity = $conf->entity;
5634 $ecmfile->filepath = $rel_dir;
5635 $ecmfile->filename = $filename;
5637 $ecmfile->fullpath_orig =
'';
5638 $ecmfile->gen_or_uploaded =
'generated';
5639 $ecmfile->description =
'';
5640 $ecmfile->keywords =
'';
5641 $ecmfile->src_object_type = $this->table_element;
5642 $ecmfile->src_object_id = $this->id;
5644 $result = $ecmfile->create($user);
5656 if ($update_main_doc_field && !empty($this->table_element)) {
5657 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
5658 $sql .=
" WHERE rowid = ".((int) $this->
id);
5660 $resql = $this->db->query(
$sql);
5665 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
5684 if (file_exists($file_osencoded)) {
5685 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5688 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
5689 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
5690 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
5691 $maxheightmini = $tmparraysize[
'maxheightmini'];
5697 vignette($file_osencoded, $maxwidthsmall, $maxheightsmall,
'_small', $quality);
5701 vignette($file_osencoded, $maxwidthmini, $maxheightmini,
'_mini', $quality);
5740 global $conf, $_POST;
5744 return GETPOST($fieldname, $type, 3);
5747 if (isset($alternatevalue)) {
5748 return $alternatevalue;
5751 $newelement = $this->element;
5752 if ($newelement ==
'facture') {
5753 $newelement =
'invoice';
5755 if ($newelement ==
'commande') {
5756 $newelement =
'order';
5758 if (empty($newelement)) {
5759 dol_syslog(
"Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
5763 $keyforfieldname = strtoupper($newelement.
'_DEFAULT_'.$fieldname);
5765 if (isset($conf->global->$keyforfieldname)) {
5766 return $conf->global->$keyforfieldname;
5793 global $langs, $conf;
5794 if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX .
'_') !== 0) {
5795 dol_print_error(
'',
'The trigger "' . $triggerName .
'" does not start with "' . self::TRIGGER_PREFIX .
'_" as required.');
5798 if (!is_object($langs)) {
5799 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5803 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
5805 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
5808 if (!empty($this->errors)) {
5809 $this->errors = array_unique(array_merge($this->errors, $interface->errors));
5811 $this->errors = $interface->errors;
5831 if (!$this->element) {
5834 if (!($this->
id > 0)) {
5837 if (is_array($this->array_languages)) {
5841 $this->array_languages = array();
5843 $element = $this->element;
5844 if ($element ==
'categorie') {
5845 $element =
'categories';
5849 $sql =
"SELECT rowid, property, lang , value";
5850 $sql .=
" FROM ".$this->db->prefix().
"object_lang";
5851 $sql .=
" WHERE type_object = '".$this->db->escape($element).
"'";
5852 $sql .=
" AND fk_object = ".((int) $this->
id);
5855 $resql = $this->db->query(
$sql);
5857 $numrows = $this->db->num_rows($resql);
5860 while ($i < $numrows) {
5861 $obj = $this->db->fetch_object($resql);
5862 $key = $obj->property;
5863 $value = $obj->value;
5864 $codelang = $obj->lang;
5865 $type = $this->fields[$key][
'type'];
5868 if (preg_match(
'/date/', $type)) {
5869 $this->array_languages[$key][$codelang] = $this->db->jdate($value);
5871 $this->array_languages[$key][$codelang] = $value;
5878 $this->db->free($resql);
5899 global $_POST, $langs;
5902 foreach ($_POST as $postfieldkey => $postfieldvalue) {
5903 $tmparray = explode(
'-', $postfieldkey);
5904 if ($tmparray[0] !=
'field') {
5908 $element = $tmparray[1];
5909 $key = $tmparray[2];
5910 $codelang = $tmparray[3];
5913 if (!empty($onlykey) && $key != $onlykey) {
5916 if ($element != $this->element) {
5920 $key_type = $this->fields[$key][
'type'];
5923 if (isset($this->fields[$key][
'enabled'])) {
5924 $enabled =
dol_eval($this->fields[$key][
'enabled'], 1, 1,
'1');
5931 if (empty($enabled)) {
5936 if (in_array($key_type, array(
'date'))) {
5940 } elseif (in_array($key_type, array(
'datetime'))) {
5943 $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'));
5944 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
5945 $value_arr =
GETPOST($postfieldkey,
'array');
5946 if (!empty($value_arr)) {
5947 $value_key = implode(
',', $value_arr);
5951 } elseif (in_array($key_type, array(
'price',
'double'))) {
5952 $value_arr =
GETPOST($postfieldkey,
'alpha');
5955 $value_key =
GETPOST($postfieldkey);
5956 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
5961 $this->array_languages[$key][$codelang] = $value_key;
5986 $savDisableCompute = $conf->disable_compute;
5987 $conf->disable_compute = 1;
5989 $ret = $this->fetch($id);
5991 $conf->disable_compute = $savDisableCompute;
6009 global $conf, $extrafields;
6011 if (empty($rowid)) {
6014 if (empty($rowid) && isset($this->
rowid)) {
6015 $rowid = $this->rowid;
6019 if (!$this->table_element) {
6023 $this->array_options = array();
6025 if (!is_array($optionsArray)) {
6027 if (!isset($extrafields) || !is_object($extrafields)) {
6028 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6033 if (empty($extrafields->attributes[$this->table_element][
'loaded'])) {
6034 $extrafields->fetch_name_optionals_label($this->table_element);
6036 $optionsArray = (!empty($extrafields->attributes[$this->table_element][
'label']) ? $extrafields->attributes[$this->table_element][
'label'] :
null);
6038 global $extrafields;
6039 dol_syslog(
"Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
6042 $table_element = $this->table_element;
6043 if ($table_element ==
'categorie') {
6044 $table_element =
'categories';
6048 if (is_array($optionsArray) && count($optionsArray) > 0) {
6049 $sql =
"SELECT rowid";
6050 foreach ($optionsArray as $name => $label) {
6051 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] !=
'separate') {
6055 $sql .=
" FROM ".$this->db->prefix().$table_element.
"_extrafields";
6056 $sql .=
" WHERE fk_object = ".((int) $rowid);
6059 $resql = $this->db->query(
$sql);
6061 $numrows = $this->db->num_rows($resql);
6063 $tab = $this->db->fetch_array($resql);
6065 foreach ($tab as $key => $value) {
6067 if ($key !=
'rowid' && $key !=
'tms' && $key !=
'fk_member' && !is_int($key)) {
6069 if (!empty($extrafields->attributes[$this->table_element]) && in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date',
'datetime'))) {
6071 $this->array_options[
"options_".$key] = $this->db->jdate($value);
6073 $this->array_options[
"options_".$key] = $value;
6083 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6084 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6085 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'computed'][$key])) {
6087 if (empty($conf->disable_compute)) {
6088 global $objectoffield;
6089 $objectoffield = $this;
6090 $this->array_options[
'options_' . $key] =
dol_eval($extrafields->attributes[$this->table_element][
'computed'][$key], 1, 0,
'');
6096 $this->db->free($resql);
6104 $this->errors[]=$this->db->lasterror;
6121 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6127 $table_element = $this->table_element;
6128 if ($table_element ==
'categorie') {
6129 $table_element =
'categories';
6132 dol_syslog(get_class($this).
"::deleteExtraFields delete", LOG_DEBUG);
6134 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6136 $resql = $this->db->query($sql_del);
6138 $this->error = $this->db->lasterror();
6139 $this->db->rollback();
6142 $this->db->commit();
6159 global $conf, $langs, $user;
6161 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6165 if (empty($userused)) {
6171 if (!empty($this->array_options)) {
6173 $langs->load(
'admin');
6174 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6176 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6179 $new_array_options = array();
6180 foreach ($this->array_options as $key => $value) {
6181 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6182 $new_array_options[$key] = $value;
6183 } elseif (in_array($key, array_keys($target_extrafields))) {
6184 $new_array_options[
'options_'.$key] = $value;
6188 foreach ($new_array_options as $key => $value) {
6189 $attributeKey = substr($key, 8);
6190 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6191 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$attributeKey];
6192 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6193 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6194 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6195 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6199 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6200 $new_array_options[$key] =
null;
6204 if ($attributeRequired) {
6205 $mandatorypb =
false;
6206 if ($attributeType ==
'link' && $this->array_options[$key] ==
'-1') {
6207 $mandatorypb =
true;
6209 if ($this->array_options[$key] ===
'') {
6210 $mandatorypb =
true;
6212 if ($attributeType ==
'sellist' && $this->array_options[$key] ==
'0') {
6213 $mandatorypb =
true;
6216 $langs->load(
"errors");
6217 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6218 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6226 if (!empty($attrfieldcomputed)) {
6227 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6228 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6229 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6230 $new_array_options[$key] = $value;
6232 $new_array_options[$key] =
null;
6236 switch ($attributeType) {
6238 if (!is_numeric($value) && $value !=
'') {
6239 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6241 } elseif ($value ==
'') {
6242 $new_array_options[$key] =
null;
6248 if (!is_numeric($value) && $value !=
'') {
6249 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6250 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6252 } elseif ($value ==
'') {
6256 $new_array_options[$key] = $value;
6266 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6268 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6269 $algo = reset($tmparrays);
6274 if (is_object($this->oldcopy)) {
6276 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6277 $new_array_options[$key] = $this->array_options[$key];
6280 $newvalue =
dol_hash($this->array_options[$key], $algo);
6281 $new_array_options[$key] = $newvalue;
6284 $new_array_options[$key] = $this->array_options[$key];
6289 $new_array_options[$key] = $this->array_options[$key];
6295 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6296 $this->array_options[$key] = strtotime($this->array_options[$key]);
6298 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6302 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6303 $this->array_options[$key] = strtotime($this->array_options[$key]);
6305 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6308 $param_list = array_keys($attributeParam[
'options']);
6311 $InfoFieldList = explode(
":", $param_list[0]);
6313 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6314 if ($value ==
'-1') {
6315 $new_array_options[$key] =
'';
6317 $object =
new $InfoFieldList[0]($this->db);
6318 if (is_numeric($value)) {
6319 $res = $object->fetch($value);
6321 $res = $object->fetch(
'', $value);
6325 $new_array_options[$key] = $object->id;
6327 $this->error =
"Id/Ref '".$value.
"' for object '".$object->element.
"' not found";
6332 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6337 if (is_array($this->array_options[$key])) {
6338 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6340 $new_array_options[$key] = $this->array_options[$key];
6348 $table_element = $this->table_element;
6349 if ($table_element ==
'categorie') {
6350 $table_element =
'categories';
6353 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
6355 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6356 $this->db->query($sql_del);
6358 $sql =
"INSERT INTO ".$this->db->prefix().$table_element.
"_extrafields (fk_object";
6359 foreach ($new_array_options as $key => $value) {
6360 $attributeKey = substr($key, 8);
6362 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6363 $sql .=
",".$attributeKey;
6367 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6368 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6369 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6370 $sql .=
",".$tmpkey;
6374 $sql .=
") VALUES (".$this->id;
6376 foreach ($new_array_options as $key => $value) {
6377 $attributeKey = substr($key, 8);
6379 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6380 if ($new_array_options[$key] !=
'' || $new_array_options[$key] ==
'0') {
6381 $sql .=
",'".$this->db->escape($new_array_options[$key]).
"'";
6388 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6389 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6390 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6391 if (in_array($tmpval, array(
'int',
'double',
'price'))) {
6402 $resql = $this->db->query(
$sql);
6404 $this->error = $this->db->lasterror();
6408 if (!$error && $trigger) {
6410 $this->context = array(
'extrafieldaddupdate'=>1);
6411 $result = $this->call_trigger($trigger, $userused);
6419 $this->db->rollback();
6422 $this->db->commit();
6442 global $conf, $langs, $user;
6444 if (empty($userused)) {
6450 if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6454 if (is_array($this->array_languages)) {
6455 $new_array_languages = $this->array_languages;
6457 foreach ($new_array_languages as $key => $value) {
6458 $attributeKey = $key;
6459 $attributeType = $this->fields[$attributeKey][
'type'];
6460 $attributeLabel = $this->fields[$attributeKey][
'label'];
6465 switch ($attributeType) {
6467 if (!is_numeric($value) && $value !=
'') {
6468 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6470 } elseif ($value ==
'') {
6471 $new_array_languages[$key] =
null;
6476 if (!is_numeric($value) && $value !=
'') {
6477 dol_syslog($langs->trans(
"ExtraLanguageHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6478 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6480 } elseif ($value ==
'') {
6481 $new_array_languages[$key] =
null;
6483 $new_array_languages[$key] = $value;
6497 $table_element = $this->table_element;
6498 if ($table_element ==
'categorie') {
6499 $table_element =
'categories';
6502 dol_syslog(get_class($this).
"::insertExtraLanguages delete then insert", LOG_DEBUG);
6504 foreach ($new_array_languages as $key => $langcodearray) {
6505 foreach ($langcodearray as $langcode => $value) {
6506 $sql_del =
"DELETE FROM ".$this->db->prefix().
"object_lang";
6507 $sql_del .=
" WHERE fk_object = ".((int) $this->
id).
" AND property = '".$this->db->escape($key).
"' AND type_object = '".$this->db->escape($table_element).
"'";
6508 $sql_del .=
" AND lang = '".$this->db->escape($langcode).
"'";
6509 $this->db->query($sql_del);
6511 if ($value !==
'') {
6512 $sql =
"INSERT INTO ".$this->db->prefix().
"object_lang (fk_object, property, type_object, lang, value";
6513 $sql .=
") VALUES (".$this->id.
", '".$this->db->escape($key).
"', '".$this->db->escape($table_element).
"', '".$this->db->escape($langcode).
"', '".$this->db->escape($value).
"'";
6516 $resql = $this->db->query(
$sql);
6518 $this->error = $this->db->lasterror();
6526 if (!$error && $trigger) {
6528 $this->context = array(
'extralanguagesaddupdate'=>1);
6529 $result = $this->call_trigger($trigger, $userused);
6537 $this->db->rollback();
6540 $this->db->commit();
6560 global $conf, $langs, $user;
6562 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6566 if (empty($userused)) {
6572 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
6574 $langs->load(
'admin');
6575 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6577 $extrafields->fetch_name_optionals_label($this->table_element);
6579 $value = $this->array_options[
"options_".$key];
6581 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
6582 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
6583 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
6584 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
6585 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
6588 if ($attributeRequired) {
6589 $mandatorypb =
false;
6590 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
6591 $mandatorypb =
true;
6593 if ($this->array_options[
"options_".$key] ===
'') {
6594 $mandatorypb =
true;
6597 $langs->load(
"errors");
6598 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
6599 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6607 if (!empty($attrfieldcomputed)) {
6608 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6609 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6610 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6611 $this->array_options[
"options_".$key] = $value;
6613 $this->array_options[
"options_".$key] =
null;
6617 switch ($attributeType) {
6619 if (!is_numeric($value) && $value !=
'') {
6620 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6622 } elseif ($value ===
'') {
6623 $this->array_options[
"options_".$key] =
null;
6628 if (!is_numeric($value) && $value !=
'') {
6629 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6630 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6632 } elseif ($value ===
'') {
6636 $this->array_options[
"options_".$key] = $value;
6645 $this->array_options[
"options_".$key] =
price2num($this->array_options[
"options_".$key]);
6649 if (empty($this->array_options[
"options_".$key])) {
6650 $this->array_options[
"options_".$key] =
null;
6652 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
6656 if (empty($this->array_options[
"options_".$key])) {
6657 $this->array_options[
"options_".$key] =
null;
6659 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
6663 if (empty($this->array_options[
"options_".$key])) {
6664 $this->array_options[
"options_".$key] =
null;
6668 if ($this->array_options[
"options_".$key] ===
'') {
6669 $this->array_options[
"options_".$key] =
null;
6703 if (is_array($this->array_options[$key])) {
6704 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6706 $new_array_options[$key] = $this->array_options[$key];
6713 $linealreadyfound = 0;
6716 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6717 $resql = $this->db->query(
$sql);
6719 $tmpobj = $this->db->fetch_object($resql);
6721 $linealreadyfound = $tmpobj->nb;
6725 if ($linealreadyfound) {
6726 if ($this->array_options[
"options_".$key] ===
null) {
6727 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = null";
6729 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($this->array_options[
"options_".$key]).
"'";
6731 $sql .=
" WHERE fk_object = ".((int) $this->
id);
6733 $result = $this->insertExtraFields(
'', $user);
6739 $resql = $this->db->query(
$sql);
6742 $this->error = $this->db->lasterror();
6744 if (!$error && $trigger) {
6746 $this->context = array(
'extrafieldupdate'=>1);
6747 $result = $this->call_trigger($trigger, $userused);
6755 dol_syslog(__METHOD__.$this->error, LOG_ERR);
6756 $this->db->rollback();
6759 $this->db->commit();
6779 global $conf, $langs, $user;
6781 if (empty($userused)) {
6787 if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6809 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
6811 global $conf, $langs,
$form;
6813 if (!is_object(
$form)) {
6814 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
6818 if (!empty($this->fields)) {
6819 $val = $this->fields[$key];
6823 $fieldValidationErrorMsg =
'';
6824 $validationClass =
'';
6825 $fieldValidationErrorMsg = $this->getFieldError($key);
6826 if (!empty($fieldValidationErrorMsg)) {
6827 $validationClass =
' --error';
6829 $validationClass =
' --success';
6836 $param[
'options'] = array();
6838 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
6840 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6841 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6843 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6844 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6846 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
6847 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6849 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6850 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6852 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6853 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6855 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
6856 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6858 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
6859 $param[
'options'] = array($reg[1] =>
'N');
6861 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
6862 $param[
'options'] = array();
6865 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
6866 $param[
'options'] = array();
6869 $param[
'options'] = array();
6870 $type = $this->fields[$key][
'type'];
6874 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
6875 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
6879 $label = $this->fields[$key][
'label'];
6881 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
6882 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
6883 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
6884 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
6885 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
6887 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
6888 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
6889 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
6891 $objectid = $this->id;
6894 if (!preg_match(
'/^search_/', $keyprefix)) {
6895 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
6902 if (empty($morecss) && !empty($val[
'css'])) {
6903 $morecss = $val[
'css'];
6904 } elseif (empty($morecss)) {
6905 if ($type ==
'date') {
6906 $morecss =
'minwidth100imp';
6907 } elseif ($type ==
'datetime' || $type ==
'link') {
6908 $morecss =
'minwidth200imp';
6909 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
6910 $morecss =
'maxwidth75';
6911 } elseif ($type ==
'url') {
6912 $morecss =
'minwidth400';
6913 } elseif ($type ==
'boolean') {
6916 if (round($size) < 12) {
6917 $morecss =
'minwidth100';
6918 } elseif (round($size) <= 48) {
6919 $morecss =
'minwidth200';
6921 $morecss =
'minwidth400';
6927 if (!empty($validationClass)) {
6928 $morecss.= $validationClass;
6931 if (in_array($type, array(
'date'))) {
6932 $tmp = explode(
',', $size);
6937 if (!$required && $value ==
'') {
6942 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
6943 } elseif (in_array($type, array(
'datetime'))) {
6944 $tmp = explode(
',', $size);
6949 if (!$required && $value ==
'') $value =
'-1';
6952 $out =
$form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
6953 } elseif (in_array($type, array(
'duration'))) {
6954 $out =
$form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
6955 } elseif (in_array($type, array(
'int',
'integer'))) {
6956 $tmp = explode(
',', $size);
6958 $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' :
'').
'>';
6959 } elseif (in_array($type, array(
'real'))) {
6960 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6961 } elseif (preg_match(
'/varchar/', $type)) {
6962 $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' :
'').
'>';
6963 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
6964 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
6965 } elseif (preg_match(
'/^text/', $type)) {
6966 if (!preg_match(
'/search_/', $keyprefix)) {
6967 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
6968 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
6969 $out = $doleditor->Create(1);
6971 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
6973 } elseif (preg_match(
'/^html/', $type)) {
6974 if (!preg_match(
'/search_/', $keyprefix)) {
6975 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
6976 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
6977 $out = $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
6979 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
6981 } elseif ($type ==
'boolean') {
6983 if (!empty($value)) {
6984 $checked =
' checked value="1" ';
6986 $checked =
' value="1" ';
6988 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
6989 } elseif ($type ==
'price') {
6990 if (!empty($value)) {
6991 $value =
price($value);
6993 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
6994 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
6995 if (!empty($value)) {
6996 $value =
price($value);
6998 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
6999 } elseif ($type ==
'select') {
7001 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
7002 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7003 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7006 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7007 if ((!isset($this->fields[$key][
'default'])) || ($this->fields[$key][
'notnull'] != 1)) {
7008 $out .=
'<option value="0"> </option>';
7010 foreach ($param[
'options'] as $keyb => $valb) {
7011 if ((
string) $keyb ==
'') {
7014 if (strpos($valb,
"|") !==
false) {
7015 list($valb, $parent) = explode(
'|', $valb);
7017 $out .=
'<option value="'.$keyb.
'"';
7018 $out .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
7019 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7020 $out .=
'>'.$valb.
'</option>';
7022 $out .=
'</select>';
7023 } elseif ($type ==
'sellist') {
7025 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
7026 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7027 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7030 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7031 if (is_array($param[
'options'])) {
7032 $param_list = array_keys($param[
'options']);
7033 $InfoFieldList = explode(
":", $param_list[0]);
7043 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7045 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7046 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7047 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7049 $keyList = $InfoFieldList[2].
' as rowid';
7052 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7053 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7054 $keyList .=
', '.$parentField;
7057 $filter_categorie =
false;
7058 if (count($InfoFieldList) > 5) {
7059 if ($InfoFieldList[0] ==
'categorie') {
7060 $filter_categorie =
true;
7064 if ($filter_categorie ===
false) {
7065 $fields_label = explode(
'|', $InfoFieldList[1]);
7066 if (is_array($fields_label)) {
7068 $keyList .= implode(
', ', $fields_label);
7072 $sql =
"SELECT " . $keyList;
7073 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7074 if (!empty($InfoFieldList[4])) {
7076 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7077 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7081 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7082 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7084 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7088 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7089 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
7090 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7092 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7095 $sqlwhere .=
' WHERE 1=1';
7098 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7099 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7104 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
7106 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
7107 $resql = $this->db->query(
$sql);
7109 $out .=
'<option value="0"> </option>';
7110 $num = $this->db->num_rows($resql);
7114 $obj = $this->db->fetch_object($resql);
7118 $fields_label = explode(
'|', $InfoFieldList[1]);
7119 if (count($fields_label) > 1) {
7121 foreach ($fields_label as $field_toshow) {
7122 $labeltoshow .= $obj->$field_toshow .
' ';
7125 $labeltoshow = $obj->{$InfoFieldList[1]};
7127 $labeltoshow =
dol_trunc($labeltoshow, 45);
7129 if ($value == $obj->rowid) {
7130 foreach ($fields_label as $field_toshow) {
7131 $translabel = $langs->trans($obj->$field_toshow);
7132 if ($translabel != $obj->$field_toshow) {
7133 $labeltoshow =
dol_trunc($translabel) .
' ';
7135 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
7138 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7141 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7142 if ($translabel != $obj->{$InfoFieldList[1]}) {
7143 $labeltoshow =
dol_trunc($translabel, 18);
7145 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
7148 if (empty($labeltoshow)) {
7149 $labeltoshow =
'(not defined)';
7151 if ($value == $obj->rowid) {
7152 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7155 if (!empty($InfoFieldList[3]) && $parentField) {
7156 $parent = $parentName .
':' . $obj->{$parentField};
7160 $out .=
'<option value="' . $obj->rowid .
'"';
7161 $out .= ($value == $obj->rowid ?
' selected' :
'');
7162 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
7163 $out .=
'>' . $labeltoshow .
'</option>';
7168 $this->db->free($resql);
7170 print
'Error in request ' .
$sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7173 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7174 $data =
$form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7175 $out .=
'<option value="0"> </option>';
7176 foreach ($data as $data_key => $data_value) {
7177 $out .=
'<option value="' . $data_key .
'"';
7178 $out .= ($value == $data_key ?
' selected' :
'');
7179 $out .=
'>' . $data_value .
'</option>';
7183 $out .=
'</select>';
7184 } elseif ($type ==
'checkbox') {
7185 $value_arr = explode(
',', $value);
7186 $out =
$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0, $morecss, 0,
'100%');
7187 } elseif ($type ==
'radio') {
7189 foreach ($param[
'options'] as $keyopt => $valopt) {
7190 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
7191 $out .=
' value="'.$keyopt.
'"';
7192 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
7193 $out .= ($value == $keyopt ?
'checked' :
'');
7194 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
7196 } elseif ($type ==
'chkbxlst') {
7197 if (is_array($value)) {
7198 $value_arr = $value;
7200 $value_arr = explode(
',', $value);
7203 if (is_array($param[
'options'])) {
7204 $param_list = array_keys($param[
'options']);
7205 $InfoFieldList = explode(
":", $param_list[0]);
7215 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7217 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7218 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7219 $keyList .=
', '.$parentField;
7221 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7222 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7223 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7225 $keyList = $InfoFieldList[2].
' as rowid';
7229 $filter_categorie =
false;
7230 if (count($InfoFieldList) > 5) {
7231 if ($InfoFieldList[0] ==
'categorie') {
7232 $filter_categorie =
true;
7236 if ($filter_categorie ===
false) {
7237 $fields_label = explode(
'|', $InfoFieldList[1]);
7238 if (is_array($fields_label)) {
7240 $keyList .= implode(
', ', $fields_label);
7244 $sql =
"SELECT " . $keyList;
7245 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
7246 if (!empty($InfoFieldList[4])) {
7248 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7249 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7253 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7254 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7256 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7260 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7261 $sql .=
' as main, ' . $this->db->prefix() . $InfoFieldList[0] .
'_extrafields as extra';
7262 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7264 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7267 $sqlwhere .=
' WHERE 1=1';
7270 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7271 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7277 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
7278 $resql = $this->db->query(
$sql);
7280 $num = $this->db->num_rows($resql);
7287 $obj = $this->db->fetch_object($resql);
7291 $fields_label = explode(
'|', $InfoFieldList[1]);
7292 if (count($fields_label) > 1) {
7294 foreach ($fields_label as $field_toshow) {
7295 $labeltoshow .= $obj->$field_toshow .
' ';
7298 $labeltoshow = $obj->{$InfoFieldList[1]};
7300 $labeltoshow =
dol_trunc($labeltoshow, 45);
7302 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7303 foreach ($fields_label as $field_toshow) {
7304 $translabel = $langs->trans($obj->$field_toshow);
7305 if ($translabel != $obj->$field_toshow) {
7306 $labeltoshow =
dol_trunc($translabel, 18) .
' ';
7308 $labeltoshow =
dol_trunc($obj->$field_toshow, 18) .
' ';
7312 $data[$obj->rowid] = $labeltoshow;
7315 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7316 if ($translabel != $obj->{$InfoFieldList[1]}) {
7317 $labeltoshow =
dol_trunc($translabel, 18);
7319 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
7322 if (empty($labeltoshow)) {
7323 $labeltoshow =
'(not defined)';
7326 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7327 $data[$obj->rowid] = $labeltoshow;
7330 if (!empty($InfoFieldList[3]) && $parentField) {
7331 $parent = $parentName .
':' . $obj->{$parentField};
7335 $data[$obj->rowid] = $labeltoshow;
7340 $this->db->free($resql);
7342 $out =
$form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr,
'', 0, $morecss, 0,
'100%');