From cdb63bada39a44c7e555c77bd617fb1a1e7e22f6 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 26 Jan 2018 18:13:55 +0100 Subject: [PATCH 01/18] FIX: #7974 Contract - Invalid reference on the document --- htdocs/contrat/card.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index a1a38d04626..ae1178adf9a 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2015 Juanjo Menent + * Copyright (C) 2010-2017 Juanjo Menent * Copyright (C) 2013 Christophe Battarel * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014-2016 Ferran Marcet @@ -753,6 +753,30 @@ if (empty($reshook)) else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->validate($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } } else if ($action == 'reopen' && $user->rights->contrat->creer) From b48bcc9ab88fe704751da5469e5b2bbf276f9fb7 Mon Sep 17 00:00:00 2001 From: kadogo Date: Sat, 27 Jan 2018 18:59:07 +0100 Subject: [PATCH 02/18] NEW: Add an API for fichinter We missed an API for fichinter It add list, create and create line functions --- htdocs/api/admin/explorer.php | 7 + htdocs/api/index.php | 6 + .../fichinter/class/api_fichinters.class.php | 333 ++++++++++++++++++ 3 files changed, 346 insertions(+) create mode 100644 htdocs/fichinter/class/api_fichinters.class.php diff --git a/htdocs/api/admin/explorer.php b/htdocs/api/admin/explorer.php index b09acb6772a..35b082c6d65 100644 --- a/htdocs/api/admin/explorer.php +++ b/htdocs/api/admin/explorer.php @@ -89,6 +89,13 @@ foreach ($modulesdir as $dir) } if (empty($conf->$module->enabled)) $enabled=false; + if ($module == 'ficheinter') { + $obj = 'fichinter'; + $part = 'fichinter'; + $enabled=true; + $module='fichinter'; + } + if ($enabled) { /* diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 7bb062c03df..aefe8ff495a 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -148,6 +148,11 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/resources.json' | $enabled=true; if (empty($conf->$modulenameforenabled->enabled)) $enabled=false; + if ($module == 'ficheinter'){ + $enabled=true; + $moduledirforclass='fichinter'; + } + if ($enabled) { // If exists, load the API class for enable module @@ -249,6 +254,7 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/resources.json' $classfile = str_replace('_', '', $module); if ($module == 'supplierinvoices') $classfile = 'supplier_invoices'; if ($module == 'supplierorders') $classfile = 'supplier_orders'; + if ($module == 'fichinters') $moduledirforclass = 'fichinter'; $dir_part_file = dol_buildpath('/'.$moduledirforclass.'/class/api_'.$classfile.'.class.php'); $classname=ucwords($module); diff --git a/htdocs/fichinter/class/api_fichinters.class.php b/htdocs/fichinter/class/api_fichinters.class.php new file mode 100644 index 00000000000..2f5be83393b --- /dev/null +++ b/htdocs/fichinter/class/api_fichinters.class.php @@ -0,0 +1,333 @@ + + * Copyright (C) 2016 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + use Luracast\Restler\RestException; + + require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; + +/** + * API class for fichinters + * + * @access protected + * @class DolibarrApiAccess {@requires user,external} + */ +class Fichinters extends DolibarrApi +{ + + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'socid', + 'fk_project', + 'description' + ); + + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDSLINE = array( + 'fk_fichinter', + 'description', + 'date', + 'duree' + ); + + /** + * @var fichinter $fichinter {@type fichinter} + */ + public $fichinter; + + /** + * Constructor + */ + function __construct() + { + global $db, $conf; + $this->db = $db; + $this->fichinter = new Fichinter($this->db); + } + + /** + * List fichinters + * + * Get a list of fichinters + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $thirdparty_ids Thirdparty ids to filter orders of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i} + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @return array Array of order objects + * + * @throws RestException + */ + function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') { + global $db, $conf; + + $obj_ret = array(); + + // case of external user, $thirdparty_ids param is ignored and replaced by user's socid + $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids; + + // If the internal user must only see his customers, force searching by him + $search_sale = 0; + if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; + + $sql = "SELECT t.rowid"; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as t"; + + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + + $sql.= ' WHERE t.entity IN ('.getEntity('fichinter').')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; + if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")"; + if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + // Insert sale filter + if ($search_sale > 0) + { + $sql .= " AND sc.fk_user = ".$search_sale; + } + // Add sql filters + if ($sqlfilters) + { + if (! DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql.= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql.= $db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $fichinter_static = new Fichinter($db); + if($fichinter_static->fetch($obj->rowid)) { + $obj_ret[] = $fichinter_static; + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve fichinter list : '.$db->lasterror()); + } + if( ! count($obj_ret)) { + throw new RestException(404, 'No finchinter found'); + } + return $obj_ret; + } + + /** + * Create fichinter object + * + * @param array $request_data Request data + * @return int ID of fichinter + */ + function post($request_data = NULL) + { + if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); + foreach($request_data as $field => $value) { + $this->fichinter->$field = $value; + } + + if ($this->fichinter->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, "Error creating fichinter", array_merge(array($this->fichinter->error), $this->fichinter->errors)); + } + + return $this->fichinter->id; + } + + /** + * Create fichinter line object + * + * @param array $request_data Request data + * + * @url POST /line + * + * @return boolean Create line fichinter work + */ + function postLine($request_data = NULL) + { + if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validateLine($request_data); + + foreach($request_data as $field => $value) { + $this->fichinter->$field = $value; + } + + if( ! $result ) { + throw new RestException(404, 'Fichinter not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if ($this->fichinter->addLine( + DolibarrApiAccess::$user, + $this->fichinter->fk_fichinter, + $this->fichinter->description, + $this->fichinter->date, + $this->fichinter->duree) < 0) { + throw new RestException(500, "Error creating fichinter line", array_merge(array($this->fichinter->error), $this->fichinter->errors)); + } + + return $this->fichinter; + } + + /** + * Validate a fichinter + * + * @param int $id fichinter ID + * + * @url POST validate + * + * @return array + * + */ + function validFichinter($id) + { + if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { + throw new RestException(401, "Insuffisant rights"); + } + $result = $this->fichinter->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Fichinter not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if( ! $this->fichinter->setValid(DolibarrApiAccess::$user)) { + throw new RestException(500, 'Error when validate fichinter'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Fichinter validated' + ) + ); + } + + /** + * Close a fichinter + * + * @param int $id fichinter ID + * + * @url POST close + * + * @return array + * + */ + + function closeFichinter($id) + { + if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { + throw new RestException(401, "Insuffisant rights"); + } + $result = $this->fichinter->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Fichinter not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if(! $this->fichinter->setStatut(3) ) { + throw new RestException(500, 'Error when closed fichinter'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Fichinter closed' + ) + ); + } + + /** + * Validate fields before create or update object + * + * @param array $data Data to validate + * @return array + * + * @throws RestException + */ + function _validate($data) + { + $fichinter = array(); + foreach (Fichinters::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $fichinter[$field] = $data[$field]; + } + return $fichinter; + } + + /** + * Validate fields before create or update object + * + * @param array $data Data to validate + * @return array + * + * @throws RestException + */ + function _validateLine($data) + { + $fichinter = array(); + foreach (Fichinters::$FIELDSLINE as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $fichinter[$field] = $data[$field]; + } + return $fichinter; + } + + +} From ba58578d602796643c7612c34d3c38a6992f57fb Mon Sep 17 00:00:00 2001 From: kadogo Date: Sat, 27 Jan 2018 19:31:48 +0100 Subject: [PATCH 03/18] FIX: Global on $user parameter reset the variable When we use the fichinter API with global, the $user object is reset If global is not applied on $user we can retrieve the informations from it --- htdocs/fichinter/class/fichinter.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 70192c460d2..fb2359092a0 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -140,7 +140,7 @@ class Fichinter extends CommonObject */ function create($user, $notrigger=0) { - global $conf, $user, $langs; + global $conf, $langs; dol_syslog(get_class($this)."::create ref=".$this->ref); From 3c281ccefab54ddb9d2caad5bcaf7d8178fa7349 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Mon, 29 Jan 2018 17:50:00 +0100 Subject: [PATCH 04/18] FIX: Bad localtaxes assignment in cashdesk --- htdocs/cashdesk/class/Facturation.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index b55524a874a..6397e3d30da 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -1,7 +1,7 @@ +/* Copyright (C) 2007-2008 Jeremie Ollivier * Copyright (C) 2008-2010 Laurent Destailleur - * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2010-2018 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -117,7 +117,12 @@ class Facturation } // Define part of HT, VAT, TTC - $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); + + // Local Taxes + $localtax1_tx = get_localtax($txtva, 1, $societe); + $localtax2_tx = get_localtax($txtva, 2, $societe); + + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, $localtax1_tx, $localtax2_tx, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; From 8102883356c5c56e1a877a7f7f8f694f651924b6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jan 2018 20:36:40 +0100 Subject: [PATCH 05/18] Fix error when email list contains ', ,' Fix output dir of notification --- htdocs/core/class/notify.class.php | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 6f2f9e56d61..6190f2d3acf 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -58,7 +58,7 @@ class Notify 'SHIPPING_VALIDATE' ); - + /** * Constructor * @@ -85,14 +85,14 @@ class Notify $langs->load("mails"); $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); - + $nb=-1; if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); - + if (is_array($listofnotiftodo)) { $i=0; @@ -106,7 +106,7 @@ class Notify } if ($i) $texte.=')'; } - + return $texte; } @@ -149,9 +149,9 @@ class Notify } $sql.= " AND s.entity IN (".getEntity('societe').")"; if ($socid > 0) $sql.= " AND s.rowid = ".$socid; - + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); - + $resql = $this->db->query($sql); if ($resql) { @@ -176,7 +176,7 @@ class Notify } } } - + if (! $error) { if ($userid >= 0 && in_array('user', $scope)) @@ -194,9 +194,9 @@ class Notify } $sql.= " AND c.entity IN (".getEntity('user').")"; if ($userid > 0) $sql.= " AND c.rowid = ".$userid; - + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); - + $resql = $this->db->query($sql); if ($resql) { @@ -237,10 +237,10 @@ class Notify { if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; } - + $threshold = (float) $reg[1]; if ($valueforthreshold < $threshold) continue; - + $tmpemail=explode(',',$val); foreach($tmpemail as $key2 => $val2) { @@ -295,7 +295,7 @@ class Notify $hookmanager=new HookManager($this->db); } $hookmanager->initHooks(array('notification')); - + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); $langs->load("other"); @@ -342,7 +342,7 @@ class Notify $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage else $sql.= " AND a.code = '".$notifcode."'"; // New usage - + $result = $this->db->query($sql); if ($result) { @@ -369,7 +369,7 @@ class Notify } $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification"); - + switch ($notifcode) { case 'BILL_VALIDATE': $link='/compta/facture/card.php?facid='.$object->id; @@ -397,13 +397,13 @@ class Notify break; case 'FICHINTER_ADD_CONTACT': $link='/fichinter/card.php?id='.$object->id; - $dir_output = $conf->facture->dir_output; + $dir_output = $conf->ficheinter->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$object->ref); break; case 'FICHINTER_VALIDATE': $link='/fichinter/card.php?id='.$object->id; - $dir_output = $conf->facture->dir_output; + $dir_output = $conf->ficheinter->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); break; @@ -462,7 +462,7 @@ class Notify if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - + $mailfile = new CMailFile( $subject, $sendto, @@ -478,16 +478,16 @@ class Notify ); if ($mailfile->sendfile()) - { + { if ($obj->type_target == 'touserid') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; - + } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; - + } if (! $this->db->query($sql)) { @@ -651,8 +651,9 @@ class Notify } dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); - $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string - $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string + $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid + $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string + $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string } if ($sendto) @@ -664,7 +665,7 @@ class Notify if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - + $mailfile = new CMailFile( $subject, $sendto, From c80fa48225e489fe46a7b2225c13eef48afe683f Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Thu, 1 Feb 2018 09:31:04 +0100 Subject: [PATCH 06/18] FIX update_extras on fourn card --- htdocs/fourn/card.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 328157af7bf..d99df78c27c 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -101,6 +101,21 @@ if (empty($reshook)) $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); if ($result < 0) dol_print_error($db,$object->error); } + if ($action == 'update_extras') { + $object->fetch($id); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + + if ($ret < 0) $error++; + if (! $error) + { + $result = $object->insertExtraFields(); + if ($result < 0) $error++; + } + if ($error) $action = 'edit_extras'; + } } From 13106d34a6a0623c2f45fbf15a13cae843825883 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 2 Feb 2018 12:36:47 +0100 Subject: [PATCH 07/18] Fix: compatibility with multicompany sharing --- htdocs/core/class/commonobject.class.php | 47 +++++++++++++----------- htdocs/societe/class/societe.class.php | 20 +++++----- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 83c38477f28..fa59659ab31 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1183,33 +1183,38 @@ abstract class CommonObject } /** - * Load object from specific field + * Load object from specific field * - * @param string $table Table element or element line - * @param string $field Field selected - * @param string $key Import key - * @return int <0 if KO, >0 if OK + * @param string $table Table element or element line + * @param string $field Field selected + * @param string $key Import key + * @param string $element Element name + * @return int <0 if KO, >0 if OK */ - function fetchObjectFrom($table,$field,$key) - { - global $conf; + function fetchObjectFrom($table, $field, $key, $element = null) + { + global $conf; - $result=false; + $result=false; - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE ".$field." = '".$key."'"; - $sql.= " AND entity = ".$conf->entity; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE ".$field." = '".$key."'"; + if (! empty($element)) { + $sql.= " AND entity IN (".getEntity($element).")"; + } else { + $sql.= " AND entity = ".$conf->entity; + } - dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - $result = $this->fetch($row[0]); - } + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_row($resql); + $result = $this->fetch($row[0]); + } - return $result; - } + return $result; + } /** * Getter generic. Load value from a specific field diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b950b2f2c46..afc33f110cf 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1051,16 +1051,16 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid'; if ($rowid) $sql .= ' WHERE s.rowid = '.$rowid; - else if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element, 1).")"; + else if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element).")"; $resql=$this->db->query($sql); if ($resql) From 464ee6f9d6e9b5d9357d808a911010a1207eb21c Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 2 Feb 2018 17:46:25 +0100 Subject: [PATCH 08/18] Revert --- htdocs/cashdesk/class/Facturation.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index 6397e3d30da..b55524a874a 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -1,7 +1,7 @@ +/* Copyright (C) 2007-2008 Jeremie Ollivier * Copyright (C) 2008-2010 Laurent Destailleur - * Copyright (C) 2010-2018 Juanjo Menent + * Copyright (C) 2010 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -117,12 +117,7 @@ class Facturation } // Define part of HT, VAT, TTC - - // Local Taxes - $localtax1_tx = get_localtax($txtva, 1, $societe); - $localtax2_tx = get_localtax($txtva, 2, $societe); - - $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, $localtax1_tx, $localtax2_tx, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; From 6de2a08d708a2a408bbd321c5eec50b875e564b4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 19:10:52 +0100 Subject: [PATCH 09/18] Fix scrutinizer bugs --- htdocs/compta/bank/bankentries_list.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 0493ffef3b0..380392c6805 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -387,7 +387,7 @@ if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - +$options = array(); if ($id > 0 || ! empty($ref)) { @@ -398,7 +398,6 @@ if ($id > 0 || ! empty($ref)) // Load bank groups require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php'; $bankcateg = new BankCateg($db); - $options = array(); foreach ($bankcateg->fetchAll() as $bankcategory) { $options[$bankcategory->id] = $bankcategory->label; @@ -531,7 +530,6 @@ dol_syslog('compta/bank/bankentries_list.php', LOG_DEBUG); $resql = $db->query($sql); if ($resql) { - $var=True; $num = $db->num_rows($resql); $arrayofselected=is_array($toselect)?$toselect:array(); @@ -569,14 +567,12 @@ if ($resql) // Form to reconcile if ($user->rights->banque->consolidate && $action == 'reconcile') { -// print ''; -// print ''; -// print '
'; print '
'; print ''.$langs->trans("InputReceiptNumber").': '; print ''; // The only default value is value we just entered print '
'; - if ($options) { + if (is_array($options) && count($options)) + { print $langs->trans("EventualyAddCategory").': '; print Form::selectarray('cat', $options, GETPOST('cat'), 1); } @@ -629,7 +625,6 @@ if ($resql) '; } print '

'; -// print '
'; } // Form to add a transaction with no invoice @@ -663,7 +658,8 @@ if ($resql) print ''; print ''; print ''; - if (is_array($options) && count($options)) { + if (is_array($options) && count($options)) + { print '
'.$langs->trans("Rubrique").': '; print Form::selectarray('cat1', $options, GETPOST('cat1'), 1); } From 5ab5c12a7b2ce5ad2fb59f6e4e950007a9875644 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 19:42:00 +0100 Subject: [PATCH 10/18] Code comments --- .../install/mysql/tables/llx_commandedet.sql | 20 +++++++++---------- .../install/mysql/tables/llx_facturedet.sql | 2 +- htdocs/install/mysql/tables/llx_propaldet.sql | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_commandedet.sql b/htdocs/install/mysql/tables/llx_commandedet.sql index 81ba14cca2c..93999b6f60e 100644 --- a/htdocs/install/mysql/tables/llx_commandedet.sql +++ b/htdocs/install/mysql/tables/llx_commandedet.sql @@ -39,26 +39,26 @@ create table llx_commandedet remise real DEFAULT 0, -- montant de la remise fk_remise_except integer NULL, -- Lien vers table des remises fixes price real, -- prix final - subprice double(24,8) DEFAULT 0, -- P.U. HT (exemple 100) - total_ht double(24,8) DEFAULT 0, -- Total HT de la ligne toute quantite et incluant remise ligne et globale - total_tva double(24,8) DEFAULT 0, -- Total TVA de la ligne toute quantite et incluant remise ligne et globale - total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 - total_localtax2 double(24,8) DEFAULT 0, -- Total LocalTax2 - total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale + subprice double(24,8) DEFAULT 0, -- P.U. HT (exemple 100) + total_ht double(24,8) DEFAULT 0, -- Total HT de la ligne toute quantite et incluant remise ligne et globale + total_tva double(24,8) DEFAULT 0, -- Total TVA de la ligne toute quantite et incluant remise ligne et globale + total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 + total_localtax2 double(24,8) DEFAULT 0, -- Total LocalTax2 + total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale product_type integer DEFAULT 0, date_start datetime DEFAULT NULL, -- date debut si service date_end datetime DEFAULT NULL, -- date fin si service info_bits integer DEFAULT 0, -- TVA NPR ou non - buy_price_ht double(24,8) DEFAULT 0, -- buying price + buy_price_ht double(24,8) DEFAULT 0, -- buying price fk_product_fournisseur_price integer DEFAULT NULL, -- reference of supplier price when line was added (may be used to update buy_price_ht current price when future invoice will be created) - special_code integer DEFAULT 0, -- code pour les lignes speciales + special_code integer DEFAULT 0, -- code for special lines (may be 1=transport, 2=ecotax, 3=option, moduleid=...) rang integer DEFAULT 0, - fk_unit integer DEFAULT NULL, -- lien vers table des unités + fk_unit integer DEFAULT NULL, -- lien vers table des unités import_key varchar(14), - fk_commandefourndet integer DEFAULT NULL, -- link to detail line of commande fourn (resplenish) + fk_commandefourndet integer DEFAULT NULL, -- link to detail line of commande fourn (resplenish) fk_multicurrency integer, multicurrency_code varchar(255), diff --git a/htdocs/install/mysql/tables/llx_facturedet.sql b/htdocs/install/mysql/tables/llx_facturedet.sql index 28c07e6d508..77d87c68c23 100644 --- a/htdocs/install/mysql/tables/llx_facturedet.sql +++ b/htdocs/install/mysql/tables/llx_facturedet.sql @@ -57,7 +57,7 @@ create table llx_facturedet fk_code_ventilation integer DEFAULT 0 NOT NULL, -- Id in table llx_accounting_bookeeping to know accounting account for product line - special_code integer DEFAULT 0, -- code pour les lignes speciales + special_code integer DEFAULT 0, -- code for special lines (may be 1=transport, 2=ecotax, 3=option, moduleid=...) rang integer DEFAULT 0, -- position of line fk_contract_line integer NULL, -- id of contract line when invoice comes from contract lines import_key varchar(14), diff --git a/htdocs/install/mysql/tables/llx_propaldet.sql b/htdocs/install/mysql/tables/llx_propaldet.sql index 70029acdb08..808e7b54ad3 100644 --- a/htdocs/install/mysql/tables/llx_propaldet.sql +++ b/htdocs/install/mysql/tables/llx_propaldet.sql @@ -52,8 +52,8 @@ create table llx_propaldet buy_price_ht double(24,8) DEFAULT 0, -- buying price fk_product_fournisseur_price integer DEFAULT NULL, -- reference of supplier price when line was added (may be used to update buy_price_ht current price when future invoice will be created) - special_code integer DEFAULT 0, -- code pour les lignes speciales - rang integer DEFAULT 0, -- ordre affichage sur la propal + special_code integer DEFAULT 0, -- code for special lines (may be 1=transport, 2=ecotax, 3=option, moduleid=...) + rang integer DEFAULT 0, -- ordre affichage sur la propal fk_unit integer DEFAULT NULL, -- lien vers table des unités fk_multicurrency integer, From 30c68aecf2b65d0b50ad1f04c121c508184f4526 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 19:52:09 +0100 Subject: [PATCH 11/18] Code comment --- htdocs/install/mysql/tables/llx_commandedet.sql | 2 +- htdocs/install/mysql/tables/llx_facturedet.sql | 2 +- htdocs/install/mysql/tables/llx_propaldet.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_commandedet.sql b/htdocs/install/mysql/tables/llx_commandedet.sql index 93999b6f60e..0d6468309f5 100644 --- a/htdocs/install/mysql/tables/llx_commandedet.sql +++ b/htdocs/install/mysql/tables/llx_commandedet.sql @@ -45,7 +45,7 @@ create table llx_commandedet total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 total_localtax2 double(24,8) DEFAULT 0, -- Total LocalTax2 total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale - product_type integer DEFAULT 0, + product_type integer DEFAULT 0, -- 0 or 1. Value 9 may be used by some modules (amount of line may not be included into generated discount if value is 9). date_start datetime DEFAULT NULL, -- date debut si service date_end datetime DEFAULT NULL, -- date fin si service info_bits integer DEFAULT 0, -- TVA NPR ou non diff --git a/htdocs/install/mysql/tables/llx_facturedet.sql b/htdocs/install/mysql/tables/llx_facturedet.sql index 77d87c68c23..05c68e92751 100644 --- a/htdocs/install/mysql/tables/llx_facturedet.sql +++ b/htdocs/install/mysql/tables/llx_facturedet.sql @@ -47,7 +47,7 @@ create table llx_facturedet total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 for total quantity of line total_localtax2 double(24,8) DEFAULT 0, -- Total LocalTax2 for total quantity of line total_ttc double(24,8), -- Total TTC de la ligne toute quantite et incluant remise ligne et globale - product_type integer DEFAULT 0, + product_type integer DEFAULT 0, -- 0 or 1. Value 9 may be used by some modules (amount of line may not be included into generated discount if value is 9). date_start datetime DEFAULT NULL, -- date start if service date_end datetime DEFAULT NULL, -- date end if service info_bits integer DEFAULT 0, -- VAT NPR or not (for france only) diff --git a/htdocs/install/mysql/tables/llx_propaldet.sql b/htdocs/install/mysql/tables/llx_propaldet.sql index 808e7b54ad3..283708fd7ce 100644 --- a/htdocs/install/mysql/tables/llx_propaldet.sql +++ b/htdocs/install/mysql/tables/llx_propaldet.sql @@ -44,7 +44,7 @@ create table llx_propaldet total_localtax1 double(24,8) DEFAULT 0, -- Total localtax1 total_localtax2 double(24,8) DEFAULT 0, -- Total localtax2 total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale - product_type integer DEFAULT 0, + product_type integer DEFAULT 0, -- 0 or 1. Value 9 may be used by some modules (amount of line may not be included into generated discount if value is 9). date_start datetime DEFAULT NULL, -- date debut si service date_end datetime DEFAULT NULL, -- date fin si service info_bits integer DEFAULT 0, -- TVA NPR ou non From 48a31b2398de34c4b885b817cc9ee25d0ee9eada Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 19:58:30 +0100 Subject: [PATCH 12/18] Update explorer.php --- htdocs/api/admin/explorer.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/api/admin/explorer.php b/htdocs/api/admin/explorer.php index 7b3dd2544cc..0aecfcd5d7e 100644 --- a/htdocs/api/admin/explorer.php +++ b/htdocs/api/admin/explorer.php @@ -87,15 +87,14 @@ foreach ($modulesdir as $dir) $part = 'compta/facture'; $obj = 'facture'; } - if (empty($conf->$module->enabled)) $enabled=false; - if ($module == 'ficheinter') { $obj = 'fichinter'; $part = 'fichinter'; - $enabled=true; $module='fichinter'; } + if (empty($conf->$module->enabled)) $enabled=false; + if ($enabled) { /* From 408fc69fac5945bbe7d3de5c867fb49ee1de4485 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 19:59:21 +0100 Subject: [PATCH 13/18] Update index.php --- htdocs/api/index.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index ad1e2fdf7d2..99334880d3a 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -152,11 +152,6 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $enabled=true; if (empty($conf->$modulenameforenabled->enabled)) $enabled=false; - if ($module == 'ficheinter'){ - $enabled=true; - $moduledirforclass='fichinter'; - } - if ($enabled) { // If exists, load the API class for enable module From c6fba7273d76c0c9aa0c7ff92df760ee21c6902d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 20:58:26 +0100 Subject: [PATCH 14/18] Api interventions --- htdocs/api/index.php | 8 +- htdocs/commande/class/api_orders.class.php | 2 +- htdocs/core/lib/functions2.lib.php | 3 + ....class.php => api_interventions.class.php} | 211 +++++++++++++----- 4 files changed, 162 insertions(+), 62 deletions(-) rename htdocs/fichinter/class/{api_fichinters.class.php => api_interventions.class.php} (63%) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 99334880d3a..353b945cfda 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -145,6 +145,7 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $modulenameforenabled = $module; if ($module == 'propale') { $modulenameforenabled='propal'; } if ($module == 'supplierproposal') { $modulenameforenabled='supplier_proposal'; } + if ($module == 'ficheinter') { $modulenameforenabled='ficheinter'; } dol_syslog("Found module file ".$file." - module=".$module." - modulenameforenabled=".$modulenameforenabled." - moduledirforclass=".$moduledirforclass); @@ -217,7 +218,7 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $moduledirforclass = getModuleDirForApiClass($module); // Load a dedicated API file - dol_syslog("Load a dedicated API file moduledirforclass=".$moduledirforclass); + dol_syslog("Load a dedicated API file module=".$module." moduledirforclass=".$moduledirforclass); $tmpmodule = $module; if ($tmpmodule != 'api') @@ -229,6 +230,11 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $classfile = 'supplier_orders'; if ($module == 'supplierinvoices') $classfile = 'supplier_invoices'; + if ($module == 'ficheinter') + $classfile = 'interventions'; + if ($module == 'interventions') + $classfile = 'interventions'; + $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2); $classname = ucwords($module); diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index c261f9e7c90..cbd505a41b8 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -472,7 +472,7 @@ class Orders extends DolibarrApi /** * Validate an order * - * If you get a bad value for param notrigger check that ou provide this in body + * If you get a bad value for param notrigger check, provide this in body * { * "idwarehouse": 0, * "notrigger": 0 diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 5f5288e7c53..c0dc04ccb38 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2258,6 +2258,9 @@ function getModuleDirForApiClass($module) elseif ($module == 'users') { $moduledirforclass = 'user'; } + elseif ($module == 'ficheinter' || $module == 'interventions') { + $moduledirforclass = 'fichinter'; + } return $moduledirforclass; } diff --git a/htdocs/fichinter/class/api_fichinters.class.php b/htdocs/fichinter/class/api_interventions.class.php similarity index 63% rename from htdocs/fichinter/class/api_fichinters.class.php rename to htdocs/fichinter/class/api_interventions.class.php index 2f5be83393b..23073737d7e 100644 --- a/htdocs/fichinter/class/api_fichinters.class.php +++ b/htdocs/fichinter/class/api_interventions.class.php @@ -26,7 +26,7 @@ * @access protected * @class DolibarrApiAccess {@requires user,external} */ -class Fichinters extends DolibarrApi +class Interventions extends DolibarrApi { /** @@ -42,7 +42,6 @@ class Fichinters extends DolibarrApi * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDSLINE = array( - 'fk_fichinter', 'description', 'date', 'duree' @@ -64,9 +63,38 @@ class Fichinters extends DolibarrApi } /** - * List fichinters + * Get properties of a Expense Report object * - * Get a list of fichinters + * Return an array with Expense Report informations + * + * @param int $id ID of Expense Report + * @return array|mixed Data without useless information + * + * @throws RestException + */ + function get($id) + { + if(! DolibarrApiAccess::$user->rights->ficheinter->lire) { + throw new RestException(401); + } + + $result = $this->fichinter->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Intervention report not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->fichinter->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->fichinter); + } + + /** + * List of interventions + * + * Return a list of interventions * * @param string $sortfield Sort field * @param string $sortorder Sort order @@ -139,7 +167,7 @@ class Fichinters extends DolibarrApi $obj = $db->fetch_object($result); $fichinter_static = new Fichinter($db); if($fichinter_static->fetch($obj->rowid)) { - $obj_ret[] = $fichinter_static; + $obj_ret[] = $this->_cleanObjectDatas($fichinter_static); } $i++; } @@ -154,10 +182,10 @@ class Fichinters extends DolibarrApi } /** - * Create fichinter object + * Create intervention object * * @param array $request_data Request data - * @return int ID of fichinter + * @return int ID of intervention */ function post($request_data = NULL) { @@ -177,16 +205,50 @@ class Fichinters extends DolibarrApi return $this->fichinter->id; } + /** - * Create fichinter line object + * Get lines of an intervention * + * @param int $id Id of intervention + * + * @url GET {id}/lines + * + * @return int + */ + /* TODO + function getLines($id) { + if(! DolibarrApiAccess::$user->rights->ficheinter->lire) { + throw new RestException(401); + } + + $result = $this->fichinter->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Intervention not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->fichinter->getLinesArray(); + $result = array(); + foreach ($this->fichinter->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + */ + + /** + * Add a line to given intervention + * + * @param int $id Id of intervention to update * @param array $request_data Request data * - * @url POST /line + * @url POST {id}/lines * - * @return boolean Create line fichinter work + * @return int */ - function postLine($request_data = NULL) + function postLine($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { throw new RestException(401, "Insuffisant rights"); @@ -199,96 +261,107 @@ class Fichinters extends DolibarrApi } if( ! $result ) { - throw new RestException(404, 'Fichinter not found'); + throw new RestException(404, 'Intervention not found'); } if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if ($this->fichinter->addLine( + $updateRes = $this->fichinter->addLine( DolibarrApiAccess::$user, - $this->fichinter->fk_fichinter, + $id, $this->fichinter->description, $this->fichinter->date, - $this->fichinter->duree) < 0) { - throw new RestException(500, "Error creating fichinter line", array_merge(array($this->fichinter->error), $this->fichinter->errors)); - } + $this->fichinter->duree + ); - return $this->fichinter; + if ($updateRes > 0) { + return $updateRes; + } + else { + throw new RestException(400, $this->fichinter->error); + } } /** - * Validate a fichinter + * Validate an intervention * - * @param int $id fichinter ID + * If you get a bad value for param notrigger check, provide this in body + * { + * "notrigger": 0 + * } * - * @url POST validate + * @param int $id Intervention ID + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * + * @url POST {id}/validate * * @return array - * */ - function validFichinter($id) + function validate($id, $notrigger=0) { if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { throw new RestException(401, "Insuffisant rights"); } $result = $this->fichinter->fetch($id); if( ! $result ) { - throw new RestException(404, 'Fichinter not found'); + throw new RestException(404, 'Intervention not found'); } - if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if( ! $this->fichinter->setValid(DolibarrApiAccess::$user)) { - throw new RestException(500, 'Error when validate fichinter'); + if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Fichinter validated' - ) - ); + $result = $this->fichinter->setValid(DolibarrApiAccess::$user, $notrigger); + if ($result == 0) { + throw new RestException(304, 'Error nothing done. May be object is already validated'); + } + if ($result < 0) { + throw new RestException(500, 'Error when validating Intervention: '.$this->commande->error); + } + + $this->fichinter->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->fichinter); } /** - * Close a fichinter + * Close an intervention * - * @param int $id fichinter ID + * @param int $id Intervention ID * - * @url POST close + * @url POST {id}/close * * @return array - * */ - function closeFichinter($id) { - if(! DolibarrApiAccess::$user->rights->ficheinter->creer) { - throw new RestException(401, "Insuffisant rights"); - } + if(! DolibarrApiAccess::$user->rights->ficheinter->creer) + { + throw new RestException(401, "Insuffisant rights"); + } $result = $this->fichinter->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Fichinter not found'); + if (! $result) { + throw new RestException(404, 'Intervention not found'); } - if( ! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if(! $this->fichinter->setStatut(3) ) { - throw new RestException(500, 'Error when closed fichinter'); + if (! DolibarrApi::_checkAccessToResource('fichinter',$this->fichinter->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Fichinter closed' - ) - ); + $result = $this->fichinter->setStatut(3); + + if ($result == 0) { + throw new RestException(304, 'Error nothing done. May be object is already closed'); + } + if ($result < 0) { + throw new RestException(500, 'Error when closing Intervention: '.$this->fichinter->error); + } + + $this->fichinter->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->fichinter); } /** @@ -302,7 +375,7 @@ class Fichinters extends DolibarrApi function _validate($data) { $fichinter = array(); - foreach (Fichinters::$FIELDS as $field) { + foreach (Interventions::$FIELDS as $field) { if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $fichinter[$field] = $data[$field]; @@ -310,6 +383,24 @@ class Fichinters extends DolibarrApi return $fichinter; } + + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + function _cleanObjectDatas($object) { + + $object = parent::_cleanObjectDatas($object); + + unset($object->statuts_short); + unset($object->statuts_logo); + unset($object->statuts); + + return $object; + } + /** * Validate fields before create or update object * @@ -321,7 +412,7 @@ class Fichinters extends DolibarrApi function _validateLine($data) { $fichinter = array(); - foreach (Fichinters::$FIELDSLINE as $field) { + foreach (Interventions::$FIELDSLINE as $field) { if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $fichinter[$field] = $data[$field]; From 0e3d5ea9e57e15504dbb6134b791fddf5e62e80d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 4 Feb 2018 11:44:39 +0100 Subject: [PATCH 15/18] Fix missing translation --- htdocs/comm/action/class/actioncomm.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 985a50df9ec..c7aa1d80800 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1633,6 +1633,7 @@ class ActionComm extends CommonObject if (empty($conf->global->AGENDA_REMINDER_EMAIL)) { + $langs->load("agenda"); $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Agenda")); return 0; } From 956df63c87012895e405f56c2a2e883b831bf53c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 4 Feb 2018 12:55:29 +0100 Subject: [PATCH 16/18] Fix extrafields updated twice --- htdocs/contrat/class/contrat.class.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index a6d557a0776..4ca490c43af 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1278,16 +1278,7 @@ class Contrat extends CommonObject } } - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used + if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used { $result=$this->insertExtraFields(); if ($result < 0) From 3cfb6aaa67f2daf97fe3c17f42ad5a228a94d7be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 4 Feb 2018 12:59:16 +0100 Subject: [PATCH 17/18] Fix missing trigger CONTRACT_MODIFY --- htdocs/contrat/class/contrat.class.php | 11 ++++------- ...nterface_99_modMyModule_MyModuleTriggers.class.php | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 4ca490c43af..e3900d2d89e 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1268,13 +1268,10 @@ class Contrat extends CommonObject { if (! $notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers + // Call triggers + $result=$this->call_trigger('CONTRACT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } } diff --git a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php index 62b35bfdf39..e413c969119 100644 --- a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php +++ b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php @@ -211,6 +211,7 @@ class InterfaceMyModuleTriggers extends DolibarrTriggers // Contracts case 'CONTRACT_CREATE': case 'CONTRACT_ACTIVATE': + case 'CONTRACT_MODIFY': case 'CONTRACT_CANCEL': case 'CONTRACT_CLOSE': case 'CONTRACT_DELETE': From 5a609215d5436aafe7369fde1b7544ce0b5d1e9c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 4 Feb 2018 13:20:47 +0100 Subject: [PATCH 18/18] Fix default value was not save at creation Conflicts: htdocs/core/class/extrafields.class.php --- htdocs/core/class/extrafields.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 5334b490e12..f7cfbc1f24a 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -168,7 +168,7 @@ class ExtraFields if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') { // Add declaration of field into table - $result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed, $entity, $langfile, $enabled); + $result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default_value, $computed, $entity, $langfile, $enabled); $err2=$this->errno; if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) {