From 998eea09bd2f43ba3508d7cb7ba1c43128d8a39a Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Mon, 18 Sep 2017 16:48:13 +0100 Subject: [PATCH 001/126] Added new option MAIN_SHOW_STATE_CODE (on/off; 1/0) to show state code in select fields options and values. Changed option MAIN_SHOW_REGION_IN_STATE to on/off - 1/0 and to mix with the new MAIN_SHOW_STATE_CODE (can show region name and state code) --- htdocs/core/class/html.formcompany.class.php | 21 +++++++++---- htdocs/core/lib/company.lib.php | 32 ++++++++++++++------ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 6389733f72c..6dde7cccd98 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -265,16 +265,25 @@ class FormCompany { $out.= ''; } $i++; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 159e7a6435a..27f2f152ea3 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -390,14 +390,17 @@ function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv= * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @return string String with state code or state name (Return value is always utf8 encoded and without entities) */ -function getState($id,$withcode='',$dbtouse=0) +function getState($id,$dbtouse=0) { - global $db,$langs; + global $db,$langs,$conf; if (! is_object($dbtouse)) $dbtouse=$db; - $sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements"; - $sql.= " WHERE rowid=".$id; + $sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM"; + $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c"; + $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".$id; + $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1"; + $sql .= " ORDER BY c.code, d.code_departement"; dol_syslog("Company.lib::getState", LOG_DEBUG); $resql=$dbtouse->query($sql); @@ -406,11 +409,22 @@ function getState($id,$withcode='',$dbtouse=0) $obj = $dbtouse->fetch_object($resql); if ($obj) { - $label=$obj->label; - if ($withcode == '1') return $label=$obj->code?"$obj->code":"$obj->code - $label"; - else if ($withcode == '2') return $label=$obj->code; - else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label); - else return $label; + if(!empty($conf->global->MAIN_SHOW_STATE_CODE) && $conf->global->MAIN_SHOW_STATE_CODE == 1) { + if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) { + return $label = $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); + } + else { + return $label = $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); + } + } + else { + if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) { + return $label = $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); + } + else { + return $label = ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); + } + } } else { From 76a2513c76a11651bb8546b032af53ba4549736a Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Mon, 18 Sep 2017 17:49:31 +0100 Subject: [PATCH 002/126] Added self to contributors list --- htdocs/core/lib/company.lib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 27f2f152ea3..2f830a24549 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -9,6 +9,7 @@ * Copyright (C) 2013 Alexandre Spangaro * Copyright (C) 2015 Frederic France * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2017 Rui Strecht * * 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 From f1126b65bf69883c849ce79d5363c567c823ccb2 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 20 Sep 2017 12:06:35 +0100 Subject: [PATCH 003/126] Updated method to fetch state name, code and id to match method used with country Reverted some previous changes to allow backwards compatibility Extended MAIN_SHOW_REGION_IN_STATE to include showing region in thirdparty card --- htdocs/admin/company.php | 20 +++++++-- htdocs/core/class/commonobject.class.php | 54 +++++++++++++++++++++--- htdocs/core/lib/company.lib.php | 33 ++++++++++++--- htdocs/societe/class/societe.class.php | 31 ++++++++++---- 4 files changed, 112 insertions(+), 26 deletions(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index bd84c1d6339..3b52fb5b875 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -67,7 +67,19 @@ if ( ($action == 'update' && ! GETPOST("cancel",'alpha')) dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS", GETPOST("address",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN", GETPOST("town",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP", GETPOST("zipcode",'alpha'),'chaine',0,'',$conf->entity); - dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", GETPOST("state_id",'alpha'),'chaine',0,'',$conf->entity); + + //dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", GETPOST("state_id",'alpha'),'chaine',0,'',$conf->entity); + $tmparray=getState(GETPOST('state_id','int'),'all','',$db,$langs,0); + if (! empty($tmparray['id'])) + { + $mysoc->state_id =$tmparray['id']; + $mysoc->state_code =$tmparray['code']; + $mysoc->state_label=$tmparray['label']; + + $s=$mysoc->state_id.':'.$mysoc->state_code.':'.$mysoc->state_label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s,'chaine',0,'',$conf->entity); + } + dolibarr_set_const($db, "MAIN_MONNAIE", GETPOST("currency",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TEL", GETPOST("tel",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX", GETPOST("fax",'alpha'),'chaine',0,'',$conf->entity); @@ -336,7 +348,7 @@ if ($action == 'edit' || $action == 'updateedit') print ''; - $formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_STATE,$mysoc->country_code,'state_id'); + $formcompany->select_departement($mysoc->state_id,$mysoc->country_code,'state_id'); print ''."\n"; @@ -721,7 +733,9 @@ else print ''.$langs->trans("State").''; - if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE); + if ($mysoc->state_id) { + print getState($mysoc->state_id,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE); + } else print ' '; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 54a907a3c0f..6a5d841684e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -186,7 +186,7 @@ abstract class CommonObject * @var string * @see getFullAddress() */ - public $country; + public $country; /** * @var int * @see getFullAddress(), country @@ -196,7 +196,32 @@ abstract class CommonObject * @var string * @see getFullAddress(), isInEEC(), country */ - public $country_code; + public $country_code; + /** + * @var string + * @see getFullAddress() + */ + public $state; + /** + * @var int + * @see getFullAddress(), state + */ + public $state_id; + /** + * @var string + * @see getFullAddress(), state + */ + public $state_code; + /** + * @var string + * @see getFullAddress(), region + */ + public $region; + /** + * @var string + * @see getFullAddress(), region + */ + public $region_code; /** * @var int @@ -418,15 +443,25 @@ abstract class CommonObject * @param string $sep Separator to use to build string * @return string Full address string */ - function getFullAddress($withcountry=0,$sep="\n") + function getFullAddress($withcountry=0,$sep="\n",$withregion=0) { if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) { require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; $tmparray=getCountry($this->country_id,'all'); $this->country_code=$tmparray['code']; - $this->country =$tmparray['label']; - } + $this->country =$tmparray['label']; + } + + if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) + { + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; + $tmparray=getState($this->state_id,'all',0,1); + $this->state_code =$tmparray['code']; + $this->state =$tmparray['label']; + $this->region_code =$tmparray['region_code']; + $this->region =$tmparray['region']; + } return dol_format_address($this, $withcountry, $sep); } @@ -465,7 +500,7 @@ abstract class CommonObject $out=''; $outdone=0; - $coords = $this->getFullAddress(1,', '); + $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE); if ($coords) { if (! empty($conf->use_javascript_ajax)) @@ -483,7 +518,12 @@ abstract class CommonObject if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) { - $out.=($outdone?' - ':'').$this->state; + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1 && $this->region) { + $out.=($outdone?' - ':'').$this->region.' - '.$this->state; + } + else { + $out.=($outdone?' - ':'').$this->state; + } $outdone++; } diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2f830a24549..5a6a1bf6944 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -391,13 +391,13 @@ function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv= * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @return string String with state code or state name (Return value is always utf8 encoded and without entities) */ -function getState($id,$dbtouse=0) +function getState($id,$withcode='',$dbtouse=0,$withregion='',$outputlangs='',$entconv=1,$searchlabel='') { - global $db,$langs,$conf; + global $db,$langs; if (! is_object($dbtouse)) $dbtouse=$db; - $sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM"; + $sql = "SELECT d.rowid as id, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.code_region as region_code, r.nom as region_name FROM"; $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c"; $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".$id; $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1"; @@ -410,22 +410,41 @@ function getState($id,$dbtouse=0) $obj = $dbtouse->fetch_object($resql); if ($obj) { - if(!empty($conf->global->MAIN_SHOW_STATE_CODE) && $conf->global->MAIN_SHOW_STATE_CODE == 1) { - if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) { + $label=((! empty($obj->name) && $obj->name!='-')?$obj->name:''); + if (is_object($outputlangs)) + { + $outputlangs->load("dict"); + if ($entconv) $label=($obj->code && ($outputlangs->trans("State".$obj->code)!="State".$obj->code))?$outputlangs->trans("State".$obj->code):$label; + else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code)!="State".$obj->code))?$outputlangs->transnoentitiesnoconv("State".$obj->code):$label; + } + + if ($withcode == 1) { + if ($withregion == 1) { return $label = $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); } else { return $label = $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); } } - else { - if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) { + else if ($withcode == 2) { + if ($withregion == 1) { return $label = $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); } else { return $label = ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); } } + else if ($withcode === 'all') { + if ($withregion == 1) { + return array('id'=>$obj->id,'code'=>$obj->code,'label'=>$label,'region_code'=>$obj->region_code,'region'=>$obj->region_name); + } + else { + return array('id'=>$obj->id,'code'=>$obj->code,'label'=>$label); + } + } + else { + return $label; + } } else { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 55a328e2538..91b5ef3205c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3050,16 +3050,29 @@ class Societe extends CommonObject $this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS; $this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP; $this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN; - $this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE; - /* Disabled: we don't want any SQL request into method setMySoc. This method set object from env only. - If we need label, label must be loaded by output that need it from id (label depends on output language) - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; - if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) { - $this->state_id= $conf->global->MAIN_INFO_SOCIETE_STATE; - $this->state = getState($this->state_id); - } - */ + // We define state_id, state_code and state + $state_id=$state_code=$state_label=''; + if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) + { + $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE); + $state_id=$tmp[0]; + if (! empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" or "id:code:label:region_code:region" + { + $state_code=$tmp[1]; + $state_label=$tmp[2]; + } + else // For backward compatibility + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + $state_code=getState($state_id,2,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore + $state_label=getState($state_id,0,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore + } + } + $this->state_id=$state_id; + $this->state_code=$state_code; + $this->state=$state_label; + if (is_object($langs)) $this->state=($langs->trans('State'.$state_code)!='State'.$state_code)?$langs->trans('State'.$state_code):$state_label; $this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE; From 24f8ea003a2b42401bd9d213505d237acce65fae Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 20 Sep 2017 12:30:59 +0100 Subject: [PATCH 004/126] Added self to contributors list --- htdocs/admin/company.php | 1 + htdocs/core/class/commonobject.class.php | 1 + htdocs/societe/class/societe.class.php | 1 + 3 files changed, 3 insertions(+) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 3b52fb5b875..e41cf19715a 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -5,6 +5,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2011-2017 Philippe Grand * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2017 Rui Strecht * * 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 diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6a5d841684e..994c7654614 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -12,6 +12,7 @@ * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016 Bahfir abbes * Copyright (C) 2017 ATM Consulting + * Copyright (C) 2017 Rui Strecht * * 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 diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 91b5ef3205c..53ea9870eed 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -12,6 +12,7 @@ * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2017 Rui Strecht * * 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 From 395100ca70f91bb953908ba1625d8d88564aae44 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 20 Sep 2017 12:45:18 +0100 Subject: [PATCH 005/126] Added missing comments for new function parameters, removed unused parameter $searchlabel --- htdocs/core/class/commonobject.class.php | 1 + htdocs/core/lib/company.lib.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 994c7654614..c194a5abb40 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -442,6 +442,7 @@ abstract class CommonObject * * @param int $withcountry 1=Add country into address string * @param string $sep Separator to use to build string + * @param int $withregion 1=Add region into address string * @return string Full address string */ function getFullAddress($withcountry=0,$sep="\n",$withregion=0) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 5a6a1bf6944..e041e489499 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -383,15 +383,19 @@ function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv= /** * Return state translated from an id. Return value is always utf8 encoded and without entities. * - * @param int $id id of state (province/departement) + * @param int $id id of state (province/departement) * @param int $withcode '0'=Return label, * '1'=Return string code + label, * '2'=Return code, * 'all'=return array('id'=>,'code'=>,'label'=>) + * @param int $withregion '0'=Ignores region, + * '1'=Add region name/code/id as needed to output, * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) - * @return string String with state code or state name (Return value is always utf8 encoded and without entities) + * @param Translate $outputlangs Langs object for output translation, not fully implemented yet + * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output + * @return mixed String with state code or state name or Array('id','code','label')/Array('id','code','label','region_code','region') */ -function getState($id,$withcode='',$dbtouse=0,$withregion='',$outputlangs='',$entconv=1,$searchlabel='') +function getState($id,$withcode='',$dbtouse=0,$withregion='',$outputlangs='',$entconv=1) { global $db,$langs; From 9fc8012663bd2b8d1fcbfa62dc23ac1f9309fd10 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 20 Sep 2017 14:30:53 +0100 Subject: [PATCH 006/126] Tiny fix to php doc variables --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index e041e489499..5f8fc1f8ae2 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -388,9 +388,9 @@ function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv= * '1'=Return string code + label, * '2'=Return code, * 'all'=return array('id'=>,'code'=>,'label'=>) + * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @param int $withregion '0'=Ignores region, * '1'=Add region name/code/id as needed to output, - * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @param Translate $outputlangs Langs object for output translation, not fully implemented yet * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output * @return mixed String with state code or state name or Array('id','code','label')/Array('id','code','label','region_code','region') From 6c0cb31c088bdccea116aad41732562edf837d37 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Mon, 9 Oct 2017 11:44:10 +0100 Subject: [PATCH 007/126] Fixed issue with merge error --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 60d0f17f6c5..4e47d24c1dd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -452,7 +452,7 @@ abstract class CommonObject * @param int $withregion 1=Add region into address string * @return string Full address string */ - function getFullAddress($withcountry=0,$sep="\n",$withregion=0)function getFullAddress($withcountry=0,$sep="\n",$withregion=0) + function getFullAddress($withcountry=0,$sep="\n",$withregion=0) { if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) { From b387c3fdf84b00e220906cdb2dba65f40746dac5 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 31 Jan 2018 11:45:30 +0000 Subject: [PATCH 008/126] Forgot to update other files to same PR changes --- htdocs/admin/company.php | 2 +- htdocs/core/class/commonobject.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 825f4a89be9..4456cd918be 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -742,7 +742,7 @@ else print ''.$langs->trans("State").''; if ($mysoc->state_id) { - print getState($mysoc->state_id,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE); + print getState($mysoc->state_id,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); } else print ' '; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0ee5a371c73..43c216de26c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -507,7 +507,7 @@ abstract class CommonObject $out=''; $outdone=0; - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE); + $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); if ($coords) { if (! empty($conf->use_javascript_ajax)) @@ -525,7 +525,7 @@ abstract class CommonObject if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) { - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1 && $this->region) { + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { $out.=($outdone?' - ':'').$this->region.' - '.$this->state; } else { From 8c732a14431c9a78c010051a25bac7a548516954 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Tue, 6 Feb 2018 12:01:54 +0000 Subject: [PATCH 009/126] Trying to not include sql request into method setMysoc --- htdocs/admin/company.php | 21 +- htdocs/core/class/commonobject.class.php | 8 +- htdocs/core/class/commonobject.class.php.orig | 6652 ----------------- htdocs/societe/class/societe.class.php | 32 +- 4 files changed, 17 insertions(+), 6696 deletions(-) delete mode 100644 htdocs/core/class/commonobject.class.php.orig diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 4456cd918be..2b63bc7a4e8 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -78,19 +78,8 @@ if ( ($action == 'update' && ! GETPOST("cancel",'alpha')) dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS", GETPOST("address",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN", GETPOST("town",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP", GETPOST("zipcode",'alpha'),'chaine',0,'',$conf->entity); - - //dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", GETPOST("state_id",'alpha'),'chaine',0,'',$conf->entity); - $tmparray=getState(GETPOST('state_id','int'),'all','',$db,$langs,0); - if (! empty($tmparray['id'])) - { - $mysoc->state_id =$tmparray['id']; - $mysoc->state_code =$tmparray['code']; - $mysoc->state_label=$tmparray['label']; - - $s=$mysoc->state_id.':'.$mysoc->state_code.':'.$mysoc->state_label; - dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s,'chaine',0,'',$conf->entity); - } - + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", GETPOST("state_id",'alpha'),'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_REGION", GETPOST("region_code",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_MONNAIE", GETPOST("currency",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TEL", GETPOST("tel",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX", GETPOST("fax",'alpha'),'chaine',0,'',$conf->entity); @@ -359,7 +348,7 @@ if ($action == 'edit' || $action == 'updateedit') print ''; - $formcompany->select_departement($mysoc->state_id,$mysoc->country_code,'state_id'); + $formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_STATE,$mysoc->country_code,'state_id'); print ''."\n"; @@ -741,9 +730,7 @@ else print ''.$langs->trans("State").''; - if ($mysoc->state_id) { - print getState($mysoc->state_id,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); - } + if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); else print ' '; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a62c0d671ac..c935b02e555 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -465,10 +465,10 @@ abstract class CommonObject { require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; $tmparray=getState($this->state_id,'all',0,1); - $this->state_code =$tmparray['code']; - $this->state =$tmparray['label']; - $this->region_code =$tmparray['region_code']; - $this->region =$tmparray['region']; + $this->state_code =$tmparray['code']; + $this->state =$tmparray['label']; + $this->region_code =$tmparray['region_code']; + $this->region =$tmparray['region']; } return dol_format_address($this, $withcountry, $sep); diff --git a/htdocs/core/class/commonobject.class.php.orig b/htdocs/core/class/commonobject.class.php.orig deleted file mode 100644 index c5e2115c6cd..00000000000 --- a/htdocs/core/class/commonobject.class.php.orig +++ /dev/null @@ -1,6652 +0,0 @@ - - * Copyright (C) 2005-2013 Regis Houssin - * Copyright (C) 2010-2013 Juanjo Menent - * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2010-2015 Juanjo Menent - * Copyright (C) 2012-2013 Christophe Battarel - * Copyright (C) 2011-2014 Philippe Grand - * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012-2015 Raphaël Doursenaud - * Copyright (C) 2012 Cedric Salvador - * Copyright (C) 2015 Alexandre Spangaro - * Copyright (C) 2016 Bahfir abbes - * Copyright (C) 2017 ATM Consulting - * Copyright (C) 2017 Nicolas ZABOURI -<<<<<<< HEAD - * Copyright (C) 2017 Rui Strecht -======= - * Copyright (C) 2018 Frederic France ->>>>>>> develop - * - * 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 . - */ - -/** - * \file htdocs/core/class/commonobject.class.php - * \ingroup core - * \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...) - */ - - -/** - * Parent class of all other business classes (invoices, contracts, proposals, orders, ...) - */ -abstract class CommonObject -{ - /** - * @var DoliDb Database handler (result of a new DoliDB) - */ - public $db; - /** - * @var int The object identifier - */ - public $id; - /** - * @var string Error string - * @see errors - */ - public $error; - /** - * @var string[] Array of error strings - */ - public $errors=array(); - /** - * @var string - */ - public $element; - /** - * @var string - */ - public $table_element; - /** - * @var - */ - public $table_element_line; - /** - * @var string Key value used to track if data is coming from import wizard - */ - public $import_key; - /** - * @var mixed Contains data to manage extrafields - */ - public $array_options=array(); - /** - * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked - */ - public $linkedObjectsIds; - /** - * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked - */ - public $linkedObjects; - /** - * @var Object To store a cloned copy of object before to edit it and keep track of old properties - */ - public $oldcopy; - - /** - * @var string Column name of the ref field. - */ - protected $table_ref_field = ''; - - - - // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. - - /** - * @var array Can be used to pass information when only object is provided to method - */ - public $context=array(); - - /** - * @var string Contains canvas name if record is an alternative canvas record - */ - public $canvas; - - /** - * @var Project The related project - * @see fetch_projet() - */ - public $project; - /** - * @var int The related project ID - * @see setProject(), project - */ - public $fk_project; - /** - * @deprecated - * @see project - */ - public $projet; - - /** - * @var Contact a related contact - * @see fetch_contact() - */ - public $contact; - /** - * @var int The related contact ID - * @see fetch_contact() - */ - public $contact_id; - - /** - * @var Societe A related thirdparty - * @see fetch_thirdparty() - */ - public $thirdparty; - - /** - * @var User A related user - * @see fetch_user() - */ - public $user; - - /** - * @var string The type of originating object ('commande', 'facture', ...) - * @see fetch_origin() - */ - public $origin; - /** - * @var int The id of originating object - * @see fetch_origin() - */ - public $origin_id; - - /** - * @var string The object's reference - */ - public $ref; - /** - * @var string The object's previous reference - */ - public $ref_previous; - /** - * @var string The object's next reference - */ - public $ref_next; - /** - * @var string An external reference for the object - */ - public $ref_ext; - - /** - * @var int The object's status - * @see setStatut() - */ - public $statut; - - /** - * @var string - * @see getFullAddress() - */ - public $country; - /** - * @var int - * @see getFullAddress(), country - */ - public $country_id; - /** - * @var string - * @see getFullAddress(), isInEEC(), country - */ - public $country_code; - /** - * @var string - * @see getFullAddress() - */ - public $state; - /** - * @var int - * @see getFullAddress(), state - */ - public $state_id; - /** - * @var string - * @see getFullAddress(), state - */ - public $state_code; - /** - * @var string - * @see getFullAddress(), region - */ - public $region; - /** - * @var string - * @see getFullAddress(), region - */ - public $region_code; - - /** - * @var int - * @see fetch_barcode() - */ - public $barcode_type; - /** - * @var string - * @see fetch_barcode(), barcode_type - */ - public $barcode_type_code; - /** - * @var string - * @see fetch_barcode(), barcode_type - */ - public $barcode_type_label; - /** - * @var string - * @see fetch_barcode(), barcode_type - */ - public $barcode_type_coder; - - /** - * @var int Payment method ID (cheque, cash, ...) - * @see setPaymentMethods() - */ - public $mode_reglement_id; - - /** - * @var int Payment terms ID - * @see setPaymentTerms() - */ - public $cond_reglement_id; - /** - * @var int Payment terms ID - * @deprecated Kept for compatibility - * @see cond_reglement_id; - */ - public $cond_reglement; - - /** - * @var int Delivery address ID - * @deprecated - * @see setDeliveryAddress() - */ - public $fk_delivery_address; - - /** - * @var int Shipping method ID - * @see setShippingMethod() - */ - public $shipping_method_id; - - /** - * @var string - * @see SetDocModel() - */ - public $modelpdf; - - /** - * @var int Bank account ID - * @see SetBankAccount() - */ - public $fk_account; - - /** - * @var string Public note - * @see update_note() - */ - public $note_public; - /** - * @var string Private note - * @see update_note() - */ - public $note_private; - /** - * @deprecated - * @see note_public - */ - public $note; - - /** - * @var float Total amount before taxes - * @see update_price() - */ - public $total_ht; - /** - * @var float Total VAT amount - * @see update_price() - */ - public $total_tva; - /** - * @var float Total local tax 1 amount - * @see update_price() - */ - public $total_localtax1; - /** - * @var float Total local tax 2 amount - * @see update_price() - */ - public $total_localtax2; - /** - * @var float Total amount with taxes - * @see update_price() - */ - public $total_ttc; - - /** - * @var CommonObjectLine[] - */ - public $lines; - - /** - * @var mixed Contains comments - * @see fetchComments() - */ - public $comments=array(); - - /** - * @var int - * @see setIncoterms() - */ - public $fk_incoterms; - /** - * @var string - * @see SetIncoterms() - */ - public $libelle_incoterms; - /** - * @var string - * @see display_incoterms() - */ - public $location_incoterms; - - public $name; - public $lastname; - public $firstname; - public $civility_id; - - - // No constructor as it is an abstract class - - /** - * Check an object id/ref exists - * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch - * - * @param string $element String of element ('product', 'facture', ...) - * @param int $id Id of object - * @param string $ref Ref of object to check - * @param string $ref_ext Ref ext of object to check - * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists - */ - static function isExistingObject($element, $id, $ref='', $ref_ext='') - { - global $db,$conf; - - $sql = "SELECT rowid, ref, ref_ext"; - $sql.= " FROM ".MAIN_DB_PREFIX.$element; - $sql.= " WHERE entity IN (".getEntity($element).")" ; - - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; - else { - $error='ErrorWrongParameters'; - dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); - return -1; - } - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; - - dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) - { - $num=$db->num_rows($resql); - if ($num > 0) return 1; - else return 0; - } - return -1; - } - - /** - * Method to output saved errors - * - * @return string String with errors - */ - function errorsToString() - { - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); - } - - /** - * Return full name (civility+' '+name+' '+lastname) - * - * @param Translate $langs Language object for translation of civility (used only if option is 1) - * @param int $option 0=No option, 1=Add civility - * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname - * @param int $maxlen Maximum length - * @return string String with full name - */ - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) - { - //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."
\n"; - $lastname=$this->lastname; - $firstname=$this->firstname; - if (empty($lastname)) $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:''))))); - - $ret=''; - if ($option && $this->civility_id) - { - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; - else $ret.=$this->civility_id.' '; - } - - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); - - return dol_trunc($ret,$maxlen); - } - - /** - * Return full address of contact - * - * @param int $withcountry 1=Add country into address string - * @param string $sep Separator to use to build string - * @param int $withregion 1=Add region into address string - * @return string Full address string - */ - function getFullAddress($withcountry=0,$sep="\n",$withregion=0) - { - if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) - { - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; - $tmparray=getCountry($this->country_id,'all'); - $this->country_code=$tmparray['code']; - $this->country =$tmparray['label']; - } - - if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) - { - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; - $tmparray=getState($this->state_id,'all',0,1); - $this->state_code =$tmparray['code']; - $this->state =$tmparray['label']; - $this->region_code =$tmparray['region_code']; - $this->region =$tmparray['region']; - } - - return dol_format_address($this, $withcountry, $sep); - } - - - /** - * Return full address for banner - * - * @param string $htmlkey HTML id to make banner content unique - * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) - * @return string Full address string - */ - function getBannerAddress($htmlkey, $object) - { - global $conf, $langs; - - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS - - $contactid=0; - $thirdpartyid=0; - if ($this->element == 'societe') - { - $thirdpartyid=$this->id; - } - if ($this->element == 'contact') - { - $contactid=$this->id; - $thirdpartyid=$object->fk_soc; - } - if ($this->element == 'user') - { - $contactid=$this->contact_id; - $thirdpartyid=$object->fk_soc; - } - - $out=''; - - $outdone=0; - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); - if ($coords) - { - if (! empty($conf->use_javascript_ajax)) - { - $namecoords = $this->getFullName($langs,1).'
'.$coords; - // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile - $out.=''; - $out.=img_picto($langs->trans("Address"), 'object_address.png'); - $out.=' '; - } - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; - $outdone++; - } - - if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress - && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) - { - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; - } - else { - $out.=($outdone?' - ':'').$this->state; - } - $outdone++; - } - - if (! empty($this->phone) || ! empty($this->phone_pro) || ! empty($this->phone_mobile) || ! empty($this->phone_perso) || ! empty($this->fax) || ! empty($this->office_phone) || ! empty($this->user_mobile) || ! empty($this->office_fax)) $out.=($outdone?'
':''); - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; - } - if (! empty($this->phone_pro)) { - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; - } - if (! empty($this->phone_mobile)) { - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; - } - if (! empty($this->phone_perso)) { - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; - } - if (! empty($this->office_phone)) { - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; - } - if (! empty($this->user_mobile)) { - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; - } - if (! empty($this->fax)) { - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; - } - if (! empty($this->office_fax)) { - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; - } - - $out.='
'; - $outdone=0; - if (! empty($this->email)) - { - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); - $outdone++; - } - if (! empty($this->url)) - { - $out.=dol_print_url($this->url,'_goout',0,1); - $outdone++; - } - if (! empty($conf->skype->enabled)) - { - $out.='
'; - if ($this->skype) $out.=dol_print_skype($this->skype,$this->id,$object->id,'AC_SKYPE'); - $outdone++; - } - - $out.=''; - - return $out; - } - - /** - * Return the link of last main doc file for direct public download. - * - * @param string $modulepart Module related to document - * @param int $initsharekey Init the share key if it was not yet defined - * @return string Link or empty string if there is no download link - */ - function getLastMainDocLink($modulepart, $initsharekey=0) - { - global $user, $dolibarr_main_url_root; - - if (empty($this->last_main_doc)) - { - return ''; // No known last doc - } - - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; - $ecmfile=new EcmFiles($this->db); - $result = $ecmfile->fetch(0, '', $this->last_main_doc); - if ($result < 0) - { - $this->error = $ecmfile->error; - $this->errors = $ecmfile->errors; - return -1; - } - - if (empty($ecmfile->id)) - { - // Add entry into index - if ($initsharekey) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first - /* - $ecmfile->filepath = $rel_dir; - $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content - $ecmfile->fullpath_orig = ''; - $ecmfile->gen_or_uploaded = 'generated'; - $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content - $ecmfile->share = getRandomPassword(true); - $result = $ecmfile->create($user); - if ($result < 0) - { - $this->error = $ecmfile->error; - $this->errors = $ecmfile->errors; - } - */ - } - else return ''; - } - elseif (empty($ecmfile->share)) - { - // Add entry into index - if ($initsharekey) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $ecmfile->share = getRandomPassword(true); - $ecmfile->update($user); - } - else return ''; - } - - // Define $urlwithroot - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current - - $forcedownload=0; - - $paramlink=''; - //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. - //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. - //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; - - $fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); - - // Here $ecmfile->share is defined - return $fulllink; - } - - - /** - * Add a link between element $this->element and a contact - * - * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link - * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL - * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) - * @param int $notrigger Disable all triggers - * @return int <0 if KO, >0 if OK - */ - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) - { - global $user,$langs; - - - dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); - - // Check parameters - if ($fk_socpeople <= 0) - { - $langs->load("errors"); - $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); - return -1; - } - if (! $type_contact) - { - $langs->load("errors"); - $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); - return -2; - } - - $id_type_contact=0; - if (is_numeric($type_contact)) - { - $id_type_contact=$type_contact; - } - else - { - // On recherche id type_contact - $sql = "SELECT tc.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; - $sql.= " AND tc.source='".$this->db->escape($source)."'"; - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; - //print $sql; - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - if ($obj) $id_type_contact=$obj->rowid; - } - } - - if ($id_type_contact == 0) - { - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; - dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT"); - return -3; - } - - $datecreate = dol_now(); - - // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error - $TListeContacts=$this->liste_contact(-1, $source); - $already_added=false; - if(!empty($TListeContacts)) { - foreach($TListeContacts as $array_contact) { - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { - $already_added=true; - break; - } - } - } - - if(!$already_added) { - - $this->db->begin(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= "'".$this->db->idate($datecreate)."'"; - $sql.= ", 4, ". $id_type_contact; - $sql.= ")"; - - $resql=$this->db->query($sql); - if ($resql) - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - } - - $this->db->commit(); - return 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $this->error=$this->db->errno(); - $this->db->rollback(); - echo 'err rollback'; - return -2; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } - } else return 0; - } - - /** - * Copy contact from one element to current - * - * @param CommonObject $objFrom Source element - * @param string $source Nature of contact ('internal' or 'external') - * @return int >0 if OK, <0 if KO - */ - function copy_linked_contact($objFrom, $source='internal') - { - $contacts = $objFrom->liste_contact(-1, $source); - foreach($contacts as $contact) - { - if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) - { - $this->error=$this->db->lasterror(); - return -1; - } - } - return 1; - } - - /** - * Update a link to contact line - * - * @param int $rowid Id of line contact-element - * @param int $statut New status of link - * @param int $type_contact_id Id of contact type (not modified if 0) - * @param int $fk_socpeople Id of soc_people to update (not modified if 0) - * @return int <0 if KO, >= 0 if OK - */ - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) - { - // Insertion dans la base - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; - $sql.= " statut = ".$statut; - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; - $sql.= " where rowid = ".$rowid; - $resql=$this->db->query($sql); - if ($resql) - { - return 0; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } - - /** - * Delete a link to contact line - * - * @param int $rowid Id of contact link line to delete - * @param int $notrigger Disable all triggers - * @return int >0 if OK, <0 if KO - */ - function delete_contact($rowid, $notrigger=0) - { - global $user; - - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE rowid =".$rowid; - - dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); - if ($this->db->query($sql)) - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); - if ($result < 0) { $this->db->rollback(); return -1; } - } - - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - /** - * Delete all links between an object $this and all its contacts - * - * @param string $source '' or 'internal' or 'external' - * @param string $code Type of contact (code or id) - * @return int >0 if OK, <0 if KO - */ - function delete_linked_contact($source='',$code='') - { - $temp = array(); - $typeContact = $this->liste_type_contact($source,'',0,0,$code); - - foreach($typeContact as $key => $value) - { - array_push($temp,$key); - } - $listId = implode(",", $temp); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql.= " WHERE element_id = ".$this->id; - if ($listId) - $sql.= " AND fk_c_type_contact IN (".$listId.")"; - - dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); - if ($this->db->query($sql)) - { - return 1; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } - - /** - * Get array of all contacts for an object - * - * @param int $statut Status of links to get (-1=all) - * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) - * @param int $list 0:Return array contains all properties, 1:Return array contains just id - * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) - * @return array Array of contacts - */ - function liste_contact($statut=-1,$source='external',$list=0,$code='') - { - global $langs; - - $tab=array(); - - $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; - $sql.= " WHERE ec.element_id =".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; - $sql.= " AND tc.active=1"; - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; - $sql.=" ORDER BY t.lastname ASC"; - - dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - if (! $list) - { - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, - 'nom'=>$obj->lastname, // For backward compatibility - 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, - 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); - } - else - { - $tab[$i]=$obj->id; - } - - $i++; - } - - return $tab; - } - else - { - $this->error=$this->db->lasterror(); - dol_print_error($this->db); - return -1; - } - } - - - /** - * Update status of a contact linked to object - * - * @param int $rowid Id of link between object and contact - * @return int <0 if KO, >=0 if OK - */ - function swapContactStatus($rowid) - { - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; - $sql.= " tc.code, tc.libelle"; - //$sql.= ", s.fk_soc"; - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; - //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lie a une societe - $sql.= " WHERE ec.rowid =".$rowid; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; - - dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - $newstatut = ($obj->statut == 4) ? 5 : 4; - $result = $this->update_contact($rowid, $newstatut); - $this->db->free($resql); - return $result; - } - else - { - $this->error=$this->db->error(); - dol_print_error($this->db); - return -1; - } - - } - - /** - * Return array with list of possible values for type of contacts - * - * @param string $source 'internal', 'external' or 'all' - * @param string $order Sort order by : 'position', 'code', 'rowid'... - * @param int $option 0=Return array id->label, 1=Return array code->label - * @param int $activeonly 0=all status of contact, 1=only the active - * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') - * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) - */ - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') - { - global $langs; - - if (empty($order)) $order='position'; - if ($order == 'position') $order.=',code'; - - $tab = array(); - $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; - $sql.= $this->db->order($order,'ASC'); - - //print "sql=".$sql; - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - if (empty($option)) $tab[$obj->rowid]=$libelle_type; - else $tab[$obj->code]=$libelle_type; - $i++; - } - return $tab; - } - else - { - $this->error=$this->db->lasterror(); - //dol_print_error($this->db); - return null; - } - } - - /** - * Return id of contacts for a source and a contact code. - * Example: contact client de facturation ('external', 'BILLING') - * Example: contact client de livraison ('external', 'SHIPPING') - * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL') - * - * @param string $source 'external' or 'internal' - * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... - * @param int $status limited to a certain status - * @return array List of id for such contacts - */ - function getIdContact($source,$code,$status=0) - { - global $conf; - - $result=array(); - $i=0; - //cas particulier pour les expeditions - if($this->element=='shipping' && $this->origin_id != 0) { - $id=$this->origin_id; - $element='commande'; - } else { - $id=$this->id; - $element=$this->element; - } - - $sql = "SELECT ec.fk_socpeople"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.element_id = ".$id; - $sql.= " AND ec.fk_socpeople = c.rowid"; - if ($source == 'internal') $sql.= " AND c.entity IN (0,".$conf->entity.")"; - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; - $sql.= " AND tc.element = '".$element."'"; - $sql.= " AND tc.source = '".$source."'"; - $sql.= " AND tc.code = '".$code."'"; - $sql.= " AND tc.active = 1"; - if ($status) $sql.= " AND ec.statut = ".$status; - - dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - $result[$i]=$obj->fk_socpeople; - $i++; - } - } - else - { - $this->error=$this->db->error(); - return null; - } - - return $result; - } - - /** - * Load object contact with id=$this->contactid into $this->contact - * - * @param int $contactid Id du contact. Use this->contactid if empty. - * @return int <0 if KO, >0 if OK - */ - function fetch_contact($contactid=null) - { - if (empty($contactid)) $contactid=$this->contactid; - - if (empty($contactid)) return 0; - - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - $contact = new Contact($this->db); - $result=$contact->fetch($contactid); - $this->contact = $contact; - return $result; - } - - /** - * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty - * - * @param int $force_thirdparty_id Force thirdparty id - * @return int <0 if KO, >0 if OK - */ - function fetch_thirdparty($force_thirdparty_id=0) - { - global $conf; - - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) - return 0; - - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; - - $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); - if ($force_thirdparty_id) - $idtofetch = $force_thirdparty_id; - - if ($idtofetch) { - $thirdparty = new Societe($this->db); - $result = $thirdparty->fetch($idtofetch); - $this->thirdparty = $thirdparty; - - // Use first price level if level not defined for third party - if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) { - $this->thirdparty->price_level = 1; - } - - return $result; - } else - return -1; - } - - - /** - * Looks for an object with ref matching the wildcard provided - * It does only work when $this->table_ref_field is set - * - * @param string $ref Wildcard - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO - */ - public function fetchOneLike($ref) - { - if (!$this->table_ref_field) { - return 0; - } - - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; - - $query = $this->db->query($sql); - - if (!$this->db->num_rows($query)) { - return 0; - } - - $result = $this->db->fetch_object($query); - - return $this->fetch($result->rowid); - } - - /** - * Load data for barcode into properties ->barcode_type* - * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but - * if it is not defined, ->element must be defined to know default barcode type. - * - * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) - */ - function fetch_barcode() - { - global $conf; - - dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); - - $idtype=$this->barcode_type; - if (empty($idtype) && $idtype != '0') // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined - { - if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; - else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); - } - - if ($idtype > 0) - { - if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) // If data not already loaded - { - $sql = "SELECT rowid, code, libelle as label, coder"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql.= " WHERE rowid = ".$idtype; - dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - $this->barcode_type = $obj->rowid; - $this->barcode_type_code = $obj->code; - $this->barcode_type_label = $obj->label; - $this->barcode_type_coder = $obj->coder; - return 1; - } - else - { - dol_print_error($this->db); - return -1; - } - } - } - return 0; - } - - /** - * Charge le projet d'id $this->fk_project dans this->projet - * - * @return int <0 if KO, >=0 if OK - */ - function fetch_projet() - { - include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility - if (empty($this->fk_project)) return 0; - - $project = new Project($this->db); - $result = $project->fetch($this->fk_project); - - $this->projet = $project; // deprecated - $this->project = $project; - return $result; - } - - /** - * Charge le user d'id userid dans this->user - * - * @param int $userid Id du contact - * @return int <0 if KO, >0 if OK - */ - function fetch_user($userid) - { - $user = new User($this->db); - $result=$user->fetch($userid); - $this->user = $user; - return $result; - } - - /** - * Read linked origin object - * - * @return void - */ - function fetch_origin() - { - if ($this->origin == 'shipping') $this->origin = 'expedition'; - if ($this->origin == 'delivery') $this->origin = 'livraison'; - - $origin = $this->origin; - - $classname = ucfirst($origin); - $this->$origin = new $classname($this->db); - $this->$origin->fetch($this->origin_id); - } - - /** - * Load object from specific field - * - * @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, $element = null) - { - global $conf; - - $result=false; - - $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]); - } - - return $result; - } - - /** - * Getter generic. Load value from a specific field - * - * @param string $table Table of element or element line - * @param int $id Element id - * @param string $field Field selected - * @return int <0 if KO, >0 if OK - */ - function getValueFrom($table, $id, $field) - { - $result=false; - if (!empty($id) && !empty($field) && !empty($table)) { - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE rowid = ".$id; - - dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - $result = $row[0]; - } - } - return $result; - } - - /** - * Setter generic. Update a specific field into database. - * Warning: Trigger is run only if param trigkey is provided. - * - * @param string $field Field to update - * @param mixed $value New value - * @param string $table To force other table element or element line (should not be used) - * @param int $id To force other object id (should not be used) - * @param string $format Data format ('text', 'date'). 'text' is used if not defined - * @param string $id_field To force rowid field name. 'rowid' is used if not defined - * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' - * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') - * @return int <0 if KO, >0 if OK - * @see updateExtraField - */ - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='') - { - global $user,$langs,$conf; - - if (empty($table)) $table=$this->table_element; - if (empty($id)) $id=$this->id; - if (empty($format)) $format='text'; - if (empty($id_field)) $id_field='rowid'; - - $error=0; - - $this->db->begin(); - - // Special case - if ($table == 'product' && $field == 'note_private') $field='note'; - - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); - if (! empty($fuser) && is_object($fuser)) $sql.=", fk_user_modif = ".$fuser->id; - elseif (empty($fuser) || $fuser != 'none') $sql.=", fk_user_modif = ".$user->id; - $sql.= " WHERE ".$id_field." = ".$id; - - dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - if ($trigkey) - { - $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors - if ($result < 0) $error++; - } - - if (! $error) - { - if (property_exists($this, $field)) $this->$field = $value; - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -2; - } - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - /** - * Load properties id_previous and id_next by comparing $fieldid with $this->ref - * - * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" - * @param string $fieldid Name of field to use for the select MAX and MIN - * @param int $nodbprefix Do not include DB prefix to forge table name - * @return int <0 if KO, >0 if OK - */ - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) - { - global $user; - - if (! $this->table_element) - { - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); - return -1; - } - if ($fieldid == 'none') return 1; - - // Security on socid - $socid = 0; - if ($user->societe_id > 0) $socid = $user->societe_id; - - // this->ismultientitymanaged contains - // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - $alias = 's'; - if ($this->element == 'societe') $alias = 'te'; - - $sql = "SELECT MAX(te.".$fieldid.")"; - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; - if (! empty($filter)) - { - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility - $sql.=$filter; - } - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."
"; - - $result = $this->db->query($sql); - if (! $result) - { - $this->error=$this->db->lasterror(); - return -1; - } - $row = $this->db->fetch_row($result); - $this->ref_previous = $row[0]; - - - $sql = "SELECT MIN(te.".$fieldid.")"; - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; - if (! empty($filter)) - { - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility - $sql.=$filter; - } - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."
"; - // Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null - - $result = $this->db->query($sql); - if (! $result) - { - $this->error=$this->db->lasterror(); - return -2; - } - $row = $this->db->fetch_row($result); - $this->ref_next = $row[0]; - - return 1; - } - - - /** - * Return list of id of contacts of project - * - * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) - * @return array Array of id of contacts (if source=external or internal) - * Array of id of third parties with at least one contact on project (if source=thirdparty) - */ - function getListContactId($source='external') - { - $contactAlreadySelected = array(); - $tab = $this->liste_contact(-1,$source); - $num=count($tab); - $i = 0; - while ($i < $num) - { - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; - else $contactAlreadySelected[$i] = $tab[$i]['id']; - $i++; - } - return $contactAlreadySelected; - } - - - /** - * Link element with a project - * - * @param int $projectid Project id to link element to - * @return int <0 if KO, >0 if OK - */ - function setProject($projectid) - { - if (! $this->table_element) - { - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); - return -1; - } - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - if ($this->table_element == 'actioncomm') - { - if ($projectid) $sql.= ' SET fk_project = '.$projectid; - else $sql.= ' SET fk_project = NULL'; - $sql.= ' WHERE id = '.$this->id; - } - else - { - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; - else $sql.= ' SET fk_projet = NULL'; - $sql.= ' WHERE rowid = '.$this->id; - } - - dol_syslog(get_class($this)."::setProject", LOG_DEBUG); - if ($this->db->query($sql)) - { - $this->fk_project = $projectid; - return 1; - } - else - { - dol_print_error($this->db); - return -1; - } - } - - /** - * Change the payments methods - * - * @param int $id Id of new payment method - * @return int >0 if OK, <0 if KO - */ - function setPaymentMethods($id) - { - dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); - if ($this->statut >= 0 || $this->element == 'societe') - { - // TODO uniformize field name - $fieldname = 'fk_mode_reglement'; - if ($this->element == 'societe') $fieldname = 'mode_reglement'; - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname.' = '.$id; - $sql .= ' WHERE rowid='.$this->id; - - if ($this->db->query($sql)) - { - $this->mode_reglement_id = $id; - // for supplier - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; - return 1; - } - else - { - dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; - } - } - else - { - dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); - $this->error='Status of the object is incompatible '.$this->statut; - return -2; - } - } - - /** - * Change the multicurrency code - * - * @param string $code multicurrency code - * @return int >0 if OK, <0 if KO - */ - function setMulticurrencyCode($code) - { - dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')'); - if ($this->statut >= 0 || $this->element == 'societe') - { - $fieldname = 'multicurrency_code'; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; - $sql .= ' WHERE rowid='.$this->id; - - if ($this->db->query($sql)) - { - $this->multicurrency_code = $code; - - list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); - if ($rate) $this->setMulticurrencyRate($rate); - - return 1; - } - else - { - dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; - } - } - else - { - dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); - $this->error='Status of the object is incompatible '.$this->statut; - return -2; - } - } - - /** - * Change the multicurrency rate - * - * @param double $rate multicurrency rate - * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency - * @return int >0 if OK, <0 if KO - */ - function setMulticurrencyRate($rate, $mode=1) - { - dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); - if ($this->statut >= 0 || $this->element == 'societe') - { - $fieldname = 'multicurrency_tx'; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname.' = '.$rate; - $sql .= ' WHERE rowid='.$this->id; - - if ($this->db->query($sql)) - { - $this->multicurrency_tx = $rate; - - // Update line price - if (!empty($this->lines)) - { - foreach ($this->lines as &$line) - { - if($mode == 1) { - $line->subprice = 0; - } - - switch ($this->element) { - case 'propal': - $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); - break; - case 'commande': - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); - break; - case 'facture': - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice); - break; - case 'supplier_proposal': - $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->ref_fourn, $line->multicurrency_subprice); - break; - case 'order_supplier': - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); - break; - case 'invoice_supplier': - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); - break; - default: - dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); - break; - } - - } - } - - return 1; - } - else - { - dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; - } - } - else - { - dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); - $this->error='Status of the object is incompatible '.$this->statut; - return -2; - } - } - - /** - * Change the payments terms - * - * @param int $id Id of new payment terms - * @return int >0 if OK, <0 if KO - */ - function setPaymentTerms($id) - { - dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); - if ($this->statut >= 0 || $this->element == 'societe') - { - // TODO uniformize field name - $fieldname = 'fk_cond_reglement'; - if ($this->element == 'societe') $fieldname = 'cond_reglement'; - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname.' = '.$id; - $sql .= ' WHERE rowid='.$this->id; - - if ($this->db->query($sql)) - { - $this->cond_reglement_id = $id; - // for supplier - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; - $this->cond_reglement = $id; // for compatibility - return 1; - } - else - { - dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; - } - } - else - { - dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); - $this->error='Status of the object is incompatible '.$this->statut; - return -2; - } - } - - /** - * Define delivery address - * @deprecated - * - * @param int $id Address id - * @return int <0 si ko, >0 si ok - */ - function setDeliveryAddress($id) - { - $fieldname = 'fk_delivery_address'; - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - if ($this->db->query($sql)) - { - $this->fk_delivery_address = $id; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); - return -1; - } - } - - - /** - * Change the shipping method - * - * @param int $shipping_method_id Id of shipping method - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @param User $userused Object user - * - * @return int 1 if OK, 0 if KO - */ - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) - { - global $user; - - if (empty($userused)) $userused=$user; - - $error = 0; - - if (! $this->table_element) { - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); - return -1; - } - - $this->db->begin(); - - if ($shipping_method_id<0) $shipping_method_id='NULL'; - dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_shipping_method = ".$shipping_method_id; - $sql.= " WHERE rowid=".$this->id; - $resql = $this->db->query($sql); - if (! $resql) { - dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); - $this->error = $this->db->lasterror(); - $error++; - } else { - if (!$notrigger) - { - // Call trigger - $this->context=array('shippingmethodupdate'=>1); - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); - if ($result < 0) $error++; - // End call trigger - } - } - if ($error) - { - $this->db->rollback(); - return -1; - } else { - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; - $this->db->commit(); - return 1; - } - - } - - - /** - * Change the warehouse - * - * @param int $warehouse_id Id of warehouse - * @return int 1 if OK, 0 if KO - */ - function setWarehouse($warehouse_id) - { - if (! $this->table_element) { - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); - return -1; - } - if ($warehouse_id<0) $warehouse_id='NULL'; - dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_warehouse = ".$warehouse_id; - $sql.= " WHERE rowid=".$this->id; - - if ($this->db->query($sql)) { - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; - return 1; - } else { - dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); - $this->error=$this->db->error(); - return 0; - } - } - - - /** - * Set last model used by doc generator - * - * @param User $user User object that make change - * @param string $modelpdf Modele name - * @return int <0 if KO, >0 if OK - */ - function setDocModel($user, $modelpdf) - { - if (! $this->table_element) - { - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); - return -1; - } - - $newmodelpdf=dol_trunc($modelpdf,255); - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; - $sql.= " WHERE rowid = ".$this->id; - // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; - // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; - - dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dol_print_error($this->db); - return 0; - } - } - - - /** - * Change the bank account - * - * @param int $fk_account Id of bank account - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @param User $userused Object user - * @return int 1 if OK, 0 if KO - */ - function setBankAccount($fk_account, $notrigger=false, $userused=null) - { - global $user; - - if (empty($userused)) $userused=$user; - - $error = 0; - - if (! $this->table_element) { - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); - return -1; - } - $this->db->begin(); - - if ($fk_account<0) $fk_account='NULL'; - dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_account = ".$fk_account; - $sql.= " WHERE rowid=".$this->id; - - $resql = $this->db->query($sql); - if (! $resql) - { - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); - $this->error = $this->db->lasterror(); - $error++; - } - else - { - if (!$notrigger) - { - // Call trigger - $this->context=array('bankaccountupdate'=>1); - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); - if ($result < 0) $error++; - // End call trigger - } - } - if ($error) - { - $this->db->rollback(); - return -1; - } - else - { - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; - $this->db->commit(); - return 1; - } - } - - - // TODO: Move line related operations to CommonObjectLine? - - /** - * Save a new position (field rang) for details lines. - * You can choose to set position for lines with already a position or lines without any position defined. - * - * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. - * @param string $rowidorder ASC or DESC - * @param boolean $fk_parent_line Table with fk_parent_line field or not - * @return int <0 if KO, >0 if OK - */ - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) - { - if (! $this->table_element_line) - { - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); - return -1; - } - if (! $this->fk_element) - { - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); - return -1; - } - - // Count number of lines to reorder (according to choice $renum) - $nl=0; - $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; - if (! $renum) $sql.= ' AND rang = 0'; - if ($renum) $sql.= ' AND rang <> 0'; - - dol_syslog(get_class($this)."::line_order", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - $nl = $row[0]; - } - else dol_print_error($this->db); - if ($nl > 0) - { - // The goal of this part is to reorder all lines, with all children lines sharing the same - // counter that parents. - $rows=array(); - - // We first search all lines that are parent lines (for multilevel details lines) - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; - - dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $i=0; - $num = $this->db->num_rows($resql); - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $rows[] = $row[0]; // Add parent line into array rows - $childrens = $this->getChildrenOfLine($row[0]); - if (! empty($childrens)) - { - foreach($childrens as $child) - { - array_push($rows, $child); - } - } - $i++; - } - - // Now we set a new number for each lines (parent and children with children included into parent tree) - if (! empty($rows)) - { - foreach($rows as $key => $row) - { - $this->updateRangOfLine($row, ($key+1)); - } - } - } - else - { - dol_print_error($this->db); - } - } - return 1; - } - - /** - * Get children of line - * - * @param int $id Id of parent line - * @return array Array with list of children lines id - */ - function getChildrenOfLine($id) - { - $rows=array(); - - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - $sql.= ' AND fk_parent_line = '.$id; - $sql.= ' ORDER BY rang ASC'; - - dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $i=0; - $num = $this->db->num_rows($resql); - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $rows[$i] = $row[0]; - $i++; - } - } - - return $rows; - } - - /** - * Update a line to have a lower rank - * - * @param int $rowid Id of line - * @param boolean $fk_parent_line Table with fk_parent_line field or not - * @return void - */ - function line_up($rowid, $fk_parent_line=true) - { - $this->line_order(false, 'ASC', $fk_parent_line); - - // Get rang of line - $rang = $this->getRangOfLine($rowid); - - // Update position of line - $this->updateLineUp($rowid, $rang); - } - - /** - * Update a line to have a higher rank - * - * @param int $rowid Id of line - * @param boolean $fk_parent_line Table with fk_parent_line field or not - * @return void - */ - function line_down($rowid, $fk_parent_line=true) - { - $this->line_order(false, 'ASC', $fk_parent_line); - - // Get rang of line - $rang = $this->getRangOfLine($rowid); - - // Get max value for rang - $max = $this->line_max(); - - // Update position of line - $this->updateLineDown($rowid, $rang, $max); - } - - /** - * Update position of line (rang) - * - * @param int $rowid Id of line - * @param int $rang Position - * @return void - */ - function updateRangOfLine($rowid,$rang) - { - $fieldposition = 'rang'; - if ($this->table_element_line == 'ecm_files') $fieldposition = 'position'; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; - $sql.= ' WHERE rowid = '.$rowid; - - dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); - if (! $this->db->query($sql)) - { - dol_print_error($this->db); - } - } - - /** - * Update position of line with ajax (rang) - * - * @param array $rows Array of rows - * @return void - */ - function line_ajaxorder($rows) - { - $num = count($rows); - for ($i = 0 ; $i < $num ; $i++) - { - $this->updateRangOfLine($rows[$i], ($i+1)); - } - } - - /** - * Update position of line up (rang) - * - * @param int $rowid Id of line - * @param int $rang Position - * @return void - */ - function updateLineUp($rowid,$rang) - { - if ($rang > 1 ) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.$rang ; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - $sql.= ' AND rang = '.($rang - 1); - if ($this->db->query($sql) ) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.($rang - 1); - $sql.= ' WHERE rowid = '.$rowid; - if (! $this->db->query($sql) ) - { - dol_print_error($this->db); - } - } - else - { - dol_print_error($this->db); - } - } - } - - /** - * Update position of line down (rang) - * - * @param int $rowid Id of line - * @param int $rang Position - * @param int $max Max - * @return void - */ - function updateLineDown($rowid,$rang,$max) - { - if ($rang < $max) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.$rang; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - $sql.= ' AND rang = '.($rang+1); - if ($this->db->query($sql) ) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.($rang+1); - $sql.= ' WHERE rowid = '.$rowid; - if (! $this->db->query($sql) ) - { - dol_print_error($this->db); - } - } - else - { - dol_print_error($this->db); - } - } - } - - /** - * Get position of line (rang) - * - * @param int $rowid Id of line - * @return int Value of rang in table of lines - */ - function getRangOfLine($rowid) - { - $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE rowid ='.$rowid; - - dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - return $row[0]; - } - } - - /** - * Get rowid of the line relative to its position - * - * @param int $rang Rang value - * @return int Rowid of the line - */ - function getIdOfLine($rang) - { - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - $sql.= ' AND rang = '.$rang; - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - return $row[0]; - } - } - - /** - * Get max value used for position of line (rang) - * - * @param int $fk_parent_line Parent line id - * @return int Max value of rang in table of lines - */ - function line_max($fk_parent_line=0) - { - // Search the last rang with fk_parent_line - if ($fk_parent_line) - { - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - $sql.= ' AND fk_parent_line = '.$fk_parent_line; - - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - if (! empty($row[0])) - { - return $row[0]; - } - else - { - return $this->getRangOfLine($fk_parent_line); - } - } - } - // If not, search the last rang of element - else - { - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - return $row[0]; - } - } - } - - /** - * Update external ref of element - * - * @param string $ref_ext Update field ref_ext - * @return int <0 if KO, >0 if OK - */ - function update_ref_ext($ref_ext) - { - if (! $this->table_element) - { - dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); - return -1; - } - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; - - dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); - if ($this->db->query($sql)) - { - $this->ref_ext = $ref_ext; - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - - /** - * Update note of element - * - * @param string $note New value for note - * @param string $suffix '', '_public' or '_private' - * @return int <0 if KO, >0 if OK - */ - function update_note($note,$suffix='') - { - global $user; - - if (! $this->table_element) - { - dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); - return -1; - } - if (! in_array($suffix,array('','_public','_private'))) - { - dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); - return -2; - } - // Special cas - //var_dump($this->table_element);exit; - if ($this->table_element == 'product') $suffix=''; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; - $sql.= " WHERE rowid =". $this->id; - - dol_syslog(get_class($this)."::update_note", LOG_DEBUG); - if ($this->db->query($sql)) - { - if ($suffix == '_public') $this->note_public = $note; - else if ($suffix == '_private') $this->note_private = $note; - else - { - $this->note = $note; // deprecated - $this->note_private = $note; - } - return 1; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } - - /** - * Update public note (kept for backward compatibility) - * - * @param string $note New value for note - * @return int <0 if KO, >0 if OK - * @deprecated - * @see update_note() - */ - function update_note_public($note) - { - return $this->update_note($note,'_public'); - } - - /** - * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). - * Must be called at end of methods addline or updateline. - * - * @param int $exclspec >0 = Exclude special product (product_type=9) - * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode total of rounding, '1'=Force mode rounding of total - * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. - * @param Societe $seller If roundingadjust is '0' or '1' or maybe 'auto', it means we recalculate total for lines before calculating total for object and for this, we need seller object. - * @return int <0 if KO, >0 if OK - */ - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) - { - global $conf; - - // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) - $MODULE = ""; - if ($this->element == 'propal') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; - elseif ($this->element == 'order') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; - elseif ($this->element == 'facture') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; - elseif ($this->element == 'facture_fourn') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; - elseif ($this->element == 'order_supplier') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; - elseif ($this->element == 'supplier_proposal') - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; - - if (! empty($MODULE)) { - if (! empty($conf->global->$MODULE)) { - $modsactivated = explode(',', $conf->global->$MODULE); - foreach ($modsactivated as $mod) { - if ($conf->$mod->enabled) - return 1; // update was disabled by specific setup - } - } - } - - include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; - - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility - - $forcedroundingmode=$roundingadjust; - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; - - $error=0; - - $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; - - // Define constants to find lines to sum - $fieldtva='total_tva'; - $fieldlocaltax1='total_localtax1'; - $fieldlocaltax2='total_localtax2'; - $fieldup='subprice'; - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') - { - $fieldtva='tva'; - $fieldup='pu_ht'; - } - if ($this->element == 'expensereport') - { - $fieldup='value_unit'; - } - - $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,'; - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - if ($exclspec) - { - $product_field='product_type'; - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; - } - $sql.= ' ORDER by rowid'; // We want to be sure to always use same order of line to not change lines differently when option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND is used - - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $this->total_ht = 0; - $this->total_tva = 0; - $this->total_localtax1 = 0; - $this->total_localtax2 = 0; - $this->total_ttc = 0; - $total_ht_by_vats = array(); - $total_tva_by_vats = array(); - $total_ttc_by_vats = array(); - $this->multicurrency_total_ht = 0; - $this->multicurrency_total_tva = 0; - $this->multicurrency_total_ttc = 0; - - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' - if ($forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' - { - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); - $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); - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); - if ($diff) - { - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; - dol_syslog('We found unconsistent data into detailed line (difference of '.$diff.') 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); - $resqlfix=$this->db->query($sqlfix); - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); - $obj->total_tva = $tmpcal[1]; - $obj->total_ttc = $tmpcal[2]; - // - } - } - - $this->total_ht += $obj->total_ht; // The field visible at end of line detail - $this->total_tva += $obj->total_tva; - $this->total_localtax1 += $obj->total_localtax1; - $this->total_localtax2 += $obj->total_localtax2; - $this->total_ttc += $obj->total_ttc; - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail - $this->multicurrency_total_tva += $obj->multicurrency_total_tva; - $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; - - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; - $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; - $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; - $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; - - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency - { - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); - //print 'Line '.$i.' rowid='.$obj->rowid.' vat_rate='.$obj->vatrate.' total_ht='.$obj->total_ht.' total_tva='.$obj->total_tva.' total_ttc='.$obj->total_ttc.' total_ht_by_vats='.$total_ht_by_vats[$obj->vatrate].' total_tva_by_vats='.$total_tva_by_vats[$obj->vatrate].' (new calculation = '.$tmpvat.') total_ttc_by_vats='.$total_ttc_by_vats[$obj->vatrate].($diff?" => DIFF":"")."
\n"; - if ($diff) - { - if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".($obj->total_tva - $diff).", total_ttc = ".($obj->total_ttc - $diff)." WHERE rowid = ".$obj->rowid; - 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); - $resqlfix=$this->db->query($sqlfix); - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); - $this->total_tva -= $diff; - $this->total_ttc -= $diff; - $total_tva_by_vats[$obj->vatrate] -= $diff; - $total_ttc_by_vats[$obj->vatrate] -= $diff; - - } - } - - $i++; - } - - // Add revenue stamp to total - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; - - // Situations totals - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits')) - { - $prev_sits = $this->get_prev_sits(); - - foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch. - $this->total_ht -= $sit->total_ht; - $this->total_tva -= $sit->total_tva; - $this->total_localtax1 -= $sit->total_localtax1; - $this->total_localtax2 -= $sit->total_localtax2; - $this->total_ttc -= $sit->total_ttc; - $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; - $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; - $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; - } - } - - $this->db->free($resql); - - // Now update global field total_ht, total_ttc and tva - $fieldht='total_ht'; - $fieldtva='tva'; - $fieldlocaltax1='localtax1'; - $fieldlocaltax2='localtax2'; - $fieldttc='total_ttc'; - // Specific code for backward compatibility with old field names - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; - if ($this->element == 'propal') $fieldttc='total'; - if ($this->element == 'expensereport') $fieldtva='total_tva'; - if ($this->element == 'supplier_proposal') $fieldttc='total'; - - if (empty($nodatabaseupdate)) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; - $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; - $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; - $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; - $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; - $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; - $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; - $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; - $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; - $sql .= ' WHERE rowid = '.$this->id; - - //print "xx".$sql; - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $error++; - $this->error=$this->db->lasterror(); - $this->errors[]=$this->db->lasterror(); - } - } - - if (! $error) - { - return 1; - } - else - { - return -1; - } - } - else - { - dol_print_error($this->db,'Bad request in update_price'); - return -1; - } - } - - /** - * Add objects linked in llx_element_element. - * - * @param string $origin Linked element type - * @param int $origin_id Linked element id - * @return int <=0 if KO, >0 if OK - * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked - */ - function add_object_linked($origin=null, $origin_id=null) - { - $origin = (! empty($origin) ? $origin : $this->origin); - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); - - // Special case - if ($origin == 'order') $origin='commande'; - if ($origin == 'invoice') $origin='facture'; - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; - $sql.= "fk_source"; - $sql.= ", sourcetype"; - $sql.= ", fk_target"; - $sql.= ", targettype"; - $sql.= ") VALUES ("; - $sql.= $origin_id; - $sql.= ", '".$this->db->escape($origin)."'"; - $sql.= ", ".$this->id; - $sql.= ", '".$this->db->escape($this->element)."'"; - $sql.= ")"; - - dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); - if ($this->db->query($sql)) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return 0; - } - } - - /** - * Fetch array of objects linked to current object. Links are loaded into this->linkedObjects array and this->linkedObjectsIds - * Possible usage for parameters: - * - all parameters empty -> we look all link to current object (current object can be source or target) - * - source id+type -> will get target list linked to source - * - target id+type -> will get source list linked to target - * - source id+type + target type -> will get target list of the type - * - target id+type + target source -> will get source list of the type - * - * @param int $sourceid Object source id (if not defined, id of object) - * @param string $sourcetype Object source type (if not defined, element name of object) - * @param int $targetid Object target id (if not defined, id of object) - * @param string $targettype Object target type (if not defined, elemennt name of object) - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided - * @param int $alsosametype 0=Return only links to object that differs from source. 1=Include also link to objects of same type. - * @return void - * @see add_object_linked, updateObjectLinked, deleteObjectLinked - */ - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1) - { - global $conf; - - $this->linkedObjectsIds=array(); - $this->linkedObjects=array(); - - $justsource=false; - $justtarget=false; - $withtargettype=false; - $withsourcetype=false; - - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) - { - $justsource=true; // the source (id and type) is a search criteria - if (! empty($targettype)) $withtargettype=true; - } - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) - { - $justtarget=true; // the target (id and type) is a search criteria - if (! empty($sourcetype)) $withsourcetype=true; - } - - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); - $targetid = (! empty($targetid) ? $targetid : $this->id); - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); - $targettype = (! empty($targettype) ? $targettype : $this->element); - - /*if (empty($sourceid) && empty($targetid)) - { - dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR); - return -1; - }*/ - - // Links between objects are stored in table element_element - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; - $sql.= " WHERE "; - if ($justsource || $justtarget) - { - if ($justsource) - { - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; - } - else if ($justtarget) - { - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; - } - } - else - { - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; - } - $sql .= ' ORDER BY sourcetype'; - //print $sql; - - dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - if ($justsource || $justtarget) - { - if ($justsource) - { - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; - } - else if ($justtarget) - { - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; - } - } - else - { - if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) - { - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; - } - if ($obj->fk_target == $targetid && $obj->targettype == $targettype) - { - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; - } - } - $i++; - } - - if (! empty($this->linkedObjectsIds)) - { - foreach($this->linkedObjectsIds as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) - { - // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) - $module = $element = $subelement = $objecttype; - if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) - { - $module = $element = $regs[1]; - $subelement = $regs[2]; - } - - $classpath = $element.'/class'; - // To work with non standard classpath or module name - if ($objecttype == 'facture') { - $classpath = 'compta/facture/class'; - } - else if ($objecttype == 'facturerec') { - $classpath = 'compta/facture/class'; $module = 'facture'; - } - else if ($objecttype == 'propal') { - $classpath = 'comm/propal/class'; - } - else if ($objecttype == 'supplier_proposal') { - $classpath = 'supplier_proposal/class'; - } - else if ($objecttype == 'shipping') { - $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; - } - else if ($objecttype == 'delivery') { - $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; - } - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { - $classpath = 'fourn/class'; $module = 'fournisseur'; - } - else if ($objecttype == 'fichinter') { - $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; - } - else if ($objecttype == 'subscription') { - $classpath = 'adherents/class'; $module = 'adherent'; - } - - // Set classfile - $classfile = strtolower($subelement); $classname = ucfirst($subelement); - - if ($objecttype == 'order') { - $classfile = 'commande'; $classname = 'Commande'; - } - else if ($objecttype == 'invoice_supplier') { - $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; - } - else if ($objecttype == 'order_supplier') { - $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; - } - else if ($objecttype == 'supplier_proposal') { - $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; - } - else if ($objecttype == 'facturerec') { - $classfile = 'facture-rec'; $classname = 'FactureRec'; - } - else if ($objecttype == 'subscription') { - $classfile = 'subscription'; $classname = 'Subscription'; - } - - // Here $module, $classfile and $classname are set - if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) - { - dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); - //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); - if (class_exists($classname)) - { - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element - { - $object = new $classname($this->db); - $ret = $object->fetch($objectid); - if ($ret >= 0) - { - $this->linkedObjects[$objecttype][$i] = $object; - } - } - } - } - } - } - } - else - { - dol_print_error($this->db); - } - } - - /** - * Update object linked of a current object - * - * @param int $sourceid Object source id - * @param string $sourcetype Object source type - * @param int $targetid Object target id - * @param string $targettype Object target type - * @return int >0 if OK, <0 if KO - * @see add_object_linked, fetObjectLinked, deleteObjectLinked - */ - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') - { - $updatesource=false; - $updatetarget=false; - - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; - - $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; - if ($updatesource) - { - $sql.= "fk_source = ".$sourceid; - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; - } - else if ($updatetarget) - { - $sql.= "fk_target = ".$targetid; - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; - $sql.= " WHERE fk_source = ".$this->id; - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; - } - - dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); - if ($this->db->query($sql)) - { - return 1; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } - - /** - * Delete all links between an object $this - * - * @param int $sourceid Object source id - * @param string $sourcetype Object source type - * @param int $targetid Object target id - * @param string $targettype Object target type - * @param int $rowid Row id of line to delete. If defined, other parameters are not used. - * @return int >0 if OK, <0 if KO - * @see add_object_linked, updateObjectLinked, fetchObjectLinked - */ - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') - { - $deletesource=false; - $deletetarget=false; - - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; - - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); - $targetid = (! empty($targetid) ? $targetid : $this->id); - $targettype = (! empty($targettype) ? $targettype : $this->element); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE"; - if ($rowid > 0) - { - $sql.=" rowid = ".$rowid; - } - else - { - if ($deletesource) - { - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; - } - else if ($deletetarget) - { - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; - } - else - { - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; - $sql.= " OR"; - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; - } - } - - dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); - if ($this->db->query($sql)) - { - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->errors[]=$this->error; - return -1; - } - } - - /** - * Set status of an object - * - * @param int $status Status to set - * @param int $elementId Id of element to force (use this->id by default) - * @param string $elementType Type of element to force (use this->table_element by default) - * @return int <0 if KO, >0 if OK - */ - function setStatut($status,$elementId=null,$elementType='') - { - global $user,$langs,$conf; - - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. - - $elementId = (!empty($elementId)?$elementId:$this->id); - $elementTable = (!empty($elementType)?$elementType:$this->table_element); - - $this->db->begin(); - - $fieldstatus="fk_statut"; - if ($elementTable == 'mailing') $fieldstatus="statut"; - if ($elementTable == 'user') $fieldstatus="statut"; - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; - - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; - $sql.= " SET ".$fieldstatus." = ".$status; - // If status = 1 = validated, update also fk_user_valid - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid=".$elementId; - - dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); - if ($this->db->query($sql)) - { - $error = 0; - - $trigkey=''; - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; - - if ($trigkey) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - } - - if (! $error) - { - $this->db->commit(); - - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) - { - $this->statut = $status; - $this->status = $status; - } - - return 1; - } - else - { - $this->db->rollback(); - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); - return -1; - } - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - - /** - * Load type of canvas of an object if it exists - * - * @param int $id Record id - * @param string $ref Record ref - * @return int <0 if KO, 0 if nothing done, >0 if OK - */ - function getCanvas($id=0,$ref='') - { - global $conf; - - if (empty($id) && empty($ref)) return 0; - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. - - // Clean parameters - $ref = trim($ref); - - $sql = "SELECT rowid, canvas"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE entity IN (".getEntity($this->element).")"; - if (! empty($id)) $sql.= " AND rowid = ".$id; - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; - - $resql = $this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - if ($obj) - { - $this->canvas = $obj->canvas; - return 1; - } - else return 0; - } - else - { - dol_print_error($this->db); - return -1; - } - } - - - /** - * Get special code of a line - * - * @param int $lineid Id of line - * @return int Special code - */ - function getSpecialCode($lineid) - { - $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE rowid = '.$lineid; - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - return $row[0]; - } - } - - /** - * Function to check if an object is used by others. - * Check is done into this->childtables. There is no check into llx_element_element. - * - * @param int $id Force id of object - * @return int <0 if KO, 0 if not used, >0 if already used - */ - function isObjectUsed($id=0) - { - global $langs; - - if (empty($id)) $id=$this->id; - - // Check parameters - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) - { - dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); - return -1; - } - - $arraytoscan = $this->childtables; - // For backward compatibility, we check if array is old format array('table1', 'table2', ...) - $tmparray=array_keys($this->childtables); - if (is_numeric($tmparray[0])) - { - $arraytoscan = array_flip($this->childtables); - } - - // Test if child exists - $haschild=0; - foreach($arraytoscan as $table => $elementname) - { - //print $id.'-'.$table.'-'.$elementname.'
'; - // Check if third party can be deleted - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE ".$this->fk_element." = ".$id; - $resql=$this->db->query($sql); - if ($resql) - { - $obj=$this->db->fetch_object($resql); - if ($obj->nb > 0) - { - $langs->load("errors"); - //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; - $haschild += $obj->nb; - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); - break; // We found at least one, we stop here - } - } - else - { - $this->errors[]=$this->db->lasterror(); - return -1; - } - } - if ($haschild > 0) - { - $this->errors[]="ErrorRecordHasChildren"; - return $haschild; - } - else return 0; - } - - /** - * Function to say how many lines object contains - * - * @param int $predefined -1=All, 0=Count free product/service only, 1=Count predefined product/service only, 2=Count predefined product, 3=Count predefined service - * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found - */ - function hasProductsOrServices($predefined=-1) - { - $nb=0; - - foreach($this->lines as $key => $val) - { - $qualified=0; - if ($predefined == -1) $qualified=1; - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; - if ($qualified) $nb++; - } - dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); - return $nb; - } - - /** - * Function that returns the total amount HT of discounts applied for all lines. - * - * @return float - */ - function getTotalDiscount() - { - $total_discount=0.00; - - $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; - $sql.= " WHERE ".$this->fk_element." = ".$this->id; - - dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $pu_ht = $obj->pu_ht; - $qty= $obj->qty; - $total_ht = $obj->total_ht; - - $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); - $total_discount += $total_discount_line; - - $i++; - } - } - - //print $total_discount; exit; - return price2num($total_discount); - } - - - /** - * Return into unit=0, the calculated total of weight and volume of all lines * qty - * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. - * - * @return array array('weight'=>...,'volume'=>...) - */ - function getTotalWeightVolume() - { - $totalWeight = 0; - $totalVolume = 0; - // defined for shipment only - $totalOrdered = ''; - // defined for shipment only - $totalToShip = ''; - - foreach ($this->lines as $line) - { - if (isset($line->qty_asked)) - { - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' - $totalOrdered+=$line->qty_asked; // defined for shipment only - } - if (isset($line->qty_shipped)) - { - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' - $totalToShip+=$line->qty_shipped; // defined for shipment only - } - - // Define qty, weight, volume, weight_units, volume_units - if ($this->element == 'shipping') { - // for shipments - $qty = $line->qty_shipped ? $line->qty_shipped : 0; - } - else { - $qty = $line->qty ? $line->qty : 0; - } - - $weight = $line->weight ? $line->weight : 0; - $volume = $line->volume ? $line->volume : 0; - - $weight_units=$line->weight_units; - $volume_units=$line->volume_units; - - $weightUnit=0; - $volumeUnit=0; - if (! empty($weight_units)) $weightUnit = $weight_units; - if (! empty($volume_units)) $volumeUnit = $volume_units; - - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' - - //var_dump($line->volume_units); - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) - { - $trueWeightUnit=pow(10, $weightUnit); - $totalWeight += $weight * $qty * $trueWeightUnit; - } - else { - if ($weight_units == 99) { - // conversion 1 Pound = 0.45359237 KG - $trueWeightUnit = 0.45359237; - $totalWeight += $weight * $qty * $trueWeightUnit; - } elseif ($weight_units == 98) { - // conversion 1 Ounce = 0.0283495 KG - $trueWeightUnit = 0.0283495; - $totalWeight += $weight * $qty * $trueWeightUnit; - } - else - $totalWeight += $weight * $qty; // This may be wrong if we mix different units - } - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) - { - //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; - $trueVolumeUnit=pow(10, $volumeUnit); - //print $line->volume; - $totalVolume += $volume * $qty * $trueVolumeUnit; - } - else - { - $totalVolume += $volume * $qty; // This may be wrong if we mix different units - } - } - - return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); - } - - - /** - * Set extra parameters - * - * @return int <0 if KO, >0 if OK - */ - function setExtraParameters() - { - $this->db->begin(); - - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - - - /** - * Return incoterms informations - * TODO Use a cache for label get - * - * @return string incoterms info - */ - function display_incoterms() - { - $out = ''; - $this->libelle_incoterms = ''; - if (!empty($this->fk_incoterms)) - { - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; - $result = $this->db->query($sql); - if ($result) - { - $res = $this->db->fetch_object($result); - $out .= $res->code; - } - } - - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; - - return $out; - } - - /** - * Return incoterms informations for pdf display - * - * @return string incoterms info - */ - function getIncotermsForPDF() - { - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - if ($num > 0) - { - $res = $this->db->fetch_object($resql); - return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; - } - else - { - return ''; - } - } - else - { - $this->errors[] = $this->db->lasterror(); - return false; - } - } - - /** - * Define incoterms values of current object - * - * @param int $id_incoterm Id of incoterm to set or '' to remove - * @param string $location location of incoterm - * @return int <0 if KO, >0 if OK - */ - function setIncoterms($id_incoterm, $location) - { - if ($this->id && $this->table_element) - { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); - $sql.= " WHERE rowid = " . $this->id; - dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->fk_incoterms = $id_incoterm; - $this->location_incoterms = $location; - - $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; - $res = $this->db->query($sql); - if ($res) - { - $obj = $this->db->fetch_object($res); - $this->libelle_incoterms = $obj->libelle; - } - return 1; - } - else - { - $this->errors[] = $this->db->lasterror(); - return -1; - } - } - else return -1; - } - - - /** - * Return if a country is inside the EEC (European Economic Community) - * @deprecated - * - * @return boolean true = country inside EEC, false = country outside EEC - */ - function isInEEC() - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - return isInEEC($this); - } - - - // -------------------- - // TODO: All functions here must be redesigned and moved as they are not business functions but output functions - // -------------------- - - /* This is to show add lines */ - - /** - * Show add free and predefined products/services form - * - * @param int $dateSelector 1=Show also date range input fields - * @param Societe $seller Object thirdparty who sell - * @param Societe $buyer Object thirdparty who buy - * @return void - */ - function formAddObjectLine($dateSelector,$seller,$buyer) - { - global $conf,$user,$langs,$object,$hookmanager; - global $form,$bcnd,$var; - - //Line extrafield - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline = new ExtraFields($this->db); - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); - - // Output template part (modules that overwrite templates must declare this into descriptor) - // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); - foreach($dirtpls as $reldir) - { - $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); - if (empty($conf->file->strict_mode)) { - $res=@include $tpl; - } else { - $res=include $tpl; // for debug - } - if ($res) break; - } - } - - - - /* This is to show array of line of details */ - - - /** - * Return HTML table for object lines - * TODO Move this into an output class file (htmlline.class.php) - * If lines are into a template, title must also be into a template - * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. - * - * @param string $action Action code - * @param string $seller Object of seller third party - * @param string $buyer Object of buyer third party - * @param int $selected Object line selected - * @param int $dateSelector 1=Show also date range input fields - * @return void - */ - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) - { - global $conf, $hookmanager, $langs, $user; - // TODO We should not use global var for this ! - global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; - - // Define usemargins - $usemargins=0; - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; - - $num = count($this->lines); - - //Line extrafield - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline = new ExtraFields($this->db); - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); - - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); - $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - print ''; - - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print ' '; - - // Description - print ''.$langs->trans('Description').''; - - if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') - { - print ''.$langs->trans("SupplierRef").''; - } - - // VAT - print ''.$langs->trans('VAT').''; - - // Price HT - print ''.$langs->trans('PriceUHT').''; - - // Multicurrency - if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).''; - - if ($inputalsopricewithtax) print ''.$langs->trans('PriceUTTC').''; - - // Qty - print ''.$langs->trans('Qty').''; - - if($conf->global->PRODUCT_USE_UNITS) - { - print ''.$langs->trans('Unit').''; - } - - // Reduction short - print ''.$langs->trans('ReductionShort').''; - - if ($this->situation_cycle_ref) { - print '' . $langs->trans('Progress') . ''; - } - - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) - { - if (!empty($user->rights->margins->creer)) - { - if ($conf->global->MARGIN_TYPE == "1") - print ''.$langs->trans('BuyingPrice').''; - else - print ''.$langs->trans('CostPrice').''; - } - - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) - print ''.$langs->trans('MarginRate').''; - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) - print ''.$langs->trans('MarkRate').''; - } - - // Total HT - print ''.$langs->trans('TotalHTShort').''; - - // Multicurrency - if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).''; - - if ($outputalsopricetotalwithtax) print ''.$langs->trans('TotalTTCShort').''; - - print ''; // No width to allow autodim - - print ''; - - print ''; - - print "\n"; - } - - $var = true; - $i = 0; - - foreach ($this->lines as $line) - { - //Line extrafield - $line->fetch_optionals($line->id,$extralabelslines); - - - - //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) - if (is_object($hookmanager)) // Old code is commented on preceding line. - { - if (empty($line->fk_parent_line)) - { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - } - else - { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line); - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - } - } - if (empty($reshook)) - { - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); - } - - $i++; - } - } - - /** - * Return HTML content of a detail line - * TODO Move this into an output class file (htmlline.class.php) - * - * @param string $action GET/POST action - * @param CommonObjectLine $line Selected object line to output - * @param string $var Is it a an odd line (true) - * @param int $num Number of line (0) - * @param int $i I - * @param int $dateSelector 1=Show also date range input fields - * @param string $seller Object of seller third party - * @param string $buyer Object of buyer third party - * @param int $selected Object line selected - * @param int $extrafieldsline Object of extrafield line attribute - * @return void - */ - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) - { - global $conf,$langs,$user,$object,$hookmanager; - global $form,$bc,$bcdd; - global $object_rights, $disableedit, $disablemove; // TODO We should not use global var for this ! - - $object_rights = $this->getRights(); - - $element=$this->element; - - $text=''; $description=''; $type=0; - - // Show product and description - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); - // Try to enhance type detection using date_start and date_end for free lines where type was not saved. - if (! empty($line->date_start)) $type=1; // deprecated - if (! empty($line->date_end)) $type=1; // deprecated - - // Ligne en mode visu - if ($action != 'editline' || $selected != $line->id) - { - // Product - if ($line->fk_product > 0) - { - $product_static = new Product($this->db); - $product_static->fetch($line->fk_product); - - $product_static->ref = $line->ref; //can change ref in hook - $product_static->label = $line->label; //can change label in hook - $text=$product_static->getNomUrl(1); - - // Define output language and label - if (! empty($conf->global->MAIN_MULTILANGS)) - { - if (! is_object($this->thirdparty)) - { - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); - return; - } - - $prod = new Product($this->db); - $prod->fetch($line->fk_product); - - $outputlangs = $langs; - $newlang=''; - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; - } - else - { - $label = $line->product_label; - } - - $text.= ' - '.(! empty($line->label)?$line->label:$label); - $description.=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. - } - - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); - - // Output template part (modules that overwrite templates must declare this into descriptor) - // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); - foreach($dirtpls as $reldir) - { - $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); - if (empty($conf->file->strict_mode)) { - $res=@include $tpl; - } else { - $res=include $tpl; // for debug - } - if ($res) break; - } - } - - // Ligne en mode update - if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) - { - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); - $placeholder=' placeholder="'.$langs->trans("Label").'"'; - - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); - - // Output template part (modules that overwrite templates must declare this into descriptor) - // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); - foreach($dirtpls as $reldir) - { - $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); - if (empty($conf->file->strict_mode)) { - $res=@include $tpl; - } else { - $res=include $tpl; // for debug - } - if ($res) break; - } - } - } - - - /* This is to show array of line of details of source object */ - - - /** - * Return HTML table table of source object lines - * TODO Move this and previous function into output html class file (htmlline.class.php). - * If lines are into a template, title must also be into a template - * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. - * - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only - * @return void - */ - function printOriginLinesList($restrictlist='') - { - global $langs, $hookmanager, $conf; - - print ''; - print ''.$langs->trans('Ref').''; - print ''.$langs->trans('Description').''; - print ''.$langs->trans('VATRate').''; - print ''.$langs->trans('PriceUHT').''; - if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('PriceUHTCurrency').''; - print ''.$langs->trans('Qty').''; - if($conf->global->PRODUCT_USE_UNITS) - { - print ''.$langs->trans('Unit').''; - } - print ''.$langs->trans('ReductionShort').''; - - $var = true; - $i = 0; - - foreach ($this->lines as $line) - { - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) - { - if (empty($line->fk_parent_line)) - { - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); - $action=''; - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - } - } - else - { - $this->printOriginLine($line, $var, $restrictlist); - } - - $i++; - } - } - - /** - * Return HTML with a line of table array of source object lines - * TODO Move this and previous function into output html class file (htmlline.class.php). - * If lines are into a template, title must also be into a template - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. - * - * @param CommonObjectLine $line Line - * @param string $var Var - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) - * @return void - */ - function printOriginLine($line, $var, $restrictlist='') - { - global $langs, $conf; - - //var_dump($line); - if (!empty($line->date_start)) - { - $date_start=$line->date_start; - } - else - { - $date_start=$line->date_debut_prevue; - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; - } - if (!empty($line->date_end)) - { - $date_end=$line->date_end; - } - else - { - $date_end=$line->date_fin_prevue; - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; - } - - $this->tpl['label'] = ''; - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); - - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object - { - $discount=new DiscountAbsolute($this->db); - $discount->fk_soc = $this->socid; - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); - } - else if (! empty($line->fk_product)) - { - $productstatic = new Product($this->db); - $productstatic->id = $line->fk_product; - $productstatic->ref = $line->ref; - $productstatic->type = $line->fk_product_type; - $this->tpl['label'].= $productstatic->getNomUrl(1); - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); - // Dates - if ($line->product_type == 1 && ($date_start || $date_end)) - { - $this->tpl['label'].= get_date_range($date_start,$date_end); - } - } - else - { - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); - if (!empty($line->desc)) { - $this->tpl['label'].=$line->desc; - }else { - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); - } - // Dates - if ($line->product_type == 1 && ($date_start || $date_end)) - { - $this->tpl['label'].= get_date_range($date_start,$date_end); - } - } - - if (! empty($line->desc)) - { - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); - } - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); - } - elseif ($line->desc == '(EXCESS RECEIVED)') - { - $discount=new DiscountAbsolute($this->db); - $discount->fetch($line->fk_remise_except); - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); - } - else - { - $this->tpl['description'] = dol_trunc($line->desc,60); - } - } - else - { - $this->tpl['description'] = ' '; - } - - // VAT Rate - $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); - $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; - - $this->tpl['price'] = price($line->subprice); - $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); - $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; - if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); - $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; - - // Is the line strike or not - $this->tpl['strike']=0; - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; - - // Output template part (modules that overwrite templates must declare this into descriptor) - // Use global variables + $dateSelector + $seller and $buyer - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); - foreach($dirtpls as $reldir) - { - $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); - if (empty($conf->file->strict_mode)) { - $res=@include $tpl; - } else { - $res=include $tpl; // for debug - } - if ($res) break; - } - } - - - /** - * Add resources to the current object : add entry into llx_element_resources - * Need $this->element & $this->id - * - * @param int $resource_id Resource id - * @param string $resource_type 'resource' - * @param int $busy Busy or not - * @param int $mandatory Mandatory or not - * @return int <=0 if KO, >0 if OK - */ - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) - { - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; - $sql.= "resource_id"; - $sql.= ", resource_type"; - $sql.= ", element_id"; - $sql.= ", element_type"; - $sql.= ", busy"; - $sql.= ", mandatory"; - $sql.= ") VALUES ("; - $sql.= $resource_id; - $sql.= ", '".$this->db->escape($resource_type)."'"; - $sql.= ", '".$this->db->escape($this->id)."'"; - $sql.= ", '".$this->db->escape($this->element)."'"; - $sql.= ", '".$this->db->escape($busy)."'"; - $sql.= ", '".$this->db->escape($mandatory)."'"; - $sql.= ")"; - - dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); - if ($this->db->query($sql)) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return 0; - } - } - - /** - * Delete a link to resource line - * - * @param int $rowid Id of resource line to delete - * @param int $element element name (for trigger) TODO: use $this->element into commonobject class - * @param int $notrigger Disable all triggers - * @return int >0 if OK, <0 if KO - */ - function delete_resource($rowid, $element, $notrigger=0) - { - global $user; - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; - $sql.= " WHERE rowid=".$rowid; - - dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); - - $resql=$this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); - if ($result < 0) { $this->db->rollback(); return -1; } - } - $this->db->commit(); - return 1; - } - } - - - /** - * Overwrite magic function to solve problem of cloning object that are kept as references - * - * @return void - */ - function __clone() - { - // Force a copy of this->lines, otherwise it will point to same object. - if (isset($this->lines) && is_array($this->lines)) - { - $nboflines=count($this->lines); - for($i=0; $i < $nboflines; $i++) - { - $this->lines[$i] = clone $this->lines[$i]; - } - } - } - - /** - * Common function for all objects extending CommonObject for generating documents - * - * @param string $modelspath Relative folder where generators are placed - * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. - * @param Translate $outputlangs Output language to use - * @param int $hidedetails 1 to hide details. 0 by default - * @param int $hidedesc 1 to hide product description. 0 by default - * @param int $hideref 1 to hide product reference. 0 by default - * @param null|array $moreparams Array to provide more information - * @return int >0 if OK, <0 if KO - */ - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) - { - global $conf, $langs, $user; - - $srctemplatepath=''; - - // Increase limit for PDF build - $err=error_reporting(); - error_reporting(0); - @set_time_limit(120); - error_reporting($err); - - // If selected model is a filename template (then $modele="modelname" or "modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php - else $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir.$modelspath.$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // If generator was found - if ($filefound) - { - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db - - require_once $file; - - $obj = new $classname($this->db); - - // If generator is ODT, we must have srctemplatepath defined, if not we set it. - if ($obj->type == 'odt' && empty($srctemplatepath)) - { - $varfortemplatedir=$obj->scandir; - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) - { - $dirtoscan=$conf->global->$varfortemplatedir; - - $listoffiles=array(); - - // Now we add first model found in directories scanned - $listofdir=explode(',',$dirtoscan); - foreach($listofdir as $key => $tmpdir) - { - $tmpdir=trim($tmpdir); - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); - if (! $tmpdir) { unset($listofdir[$key]); continue; } - if (is_dir($tmpdir)) - { - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); - } - } - - if (count($listoffiles)) - { - foreach($listoffiles as $record) - { - $srctemplatepath=$record['fullname']; - break; - } - } - } - - if (empty($srctemplatepath)) - { - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; - return -1; - } - } - - if ($obj->type == 'odt' && ! empty($srctemplatepath)) - { - if (! dol_is_file($srctemplatepath)) - { - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; - return -1; - } - } - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - - if (in_array(get_class($this), array('Adherent'))) - { - $arrayofrecords = array(); // The write_file of templates of adherent class need this var - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); - } - else - { - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); - } - // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. - - if ($resultwritefile > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Index file in database - if (! empty($obj->result['fullpath'])) - { - $destfull = $obj->result['fullpath']; - $upload_dir = dirname($destfull); - $destfile = basename($destfull); - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); - - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir - { - $filename = basename($destfile); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; - $ecmfile=new EcmFiles($this->db); - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); - - // Set the public "share" key - $setsharekey = false; - if ($this->element == 'propal') - { - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok - if ($useonlinesignature) $setsharekey=true; - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; - } - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; - if ($setsharekey) - { - if (empty($ecmfile->share)) // Because object not found or share not set yet - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $ecmfile->share = getRandomPassword(true); - } - } - - if ($result > 0) - { - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content - $ecmfile->fullpath_orig = ''; - $ecmfile->gen_or_uploaded = 'generated'; - $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content - $result = $ecmfile->update($user); - if ($result < 0) - { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - } - else - { - $ecmfile->entity = $conf->entity; - $ecmfile->filepath = $rel_dir; - $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content - $ecmfile->fullpath_orig = ''; - $ecmfile->gen_or_uploaded = 'generated'; - $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content - $result = $ecmfile->create($user); - if ($result < 0) - { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - } - - /*$this->result['fullname']=$destfull; - $this->result['filepath']=$ecmfile->filepath; - $this->result['filename']=$ecmfile->filename;*/ - //var_dump($obj->update_main_doc_field);exit; - - // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) - $update_main_doc_field=0; - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; - if ($update_main_doc_field && ! empty($this->table_element)) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; - $sql.= ' WHERE rowid = '.$this->id; - $resql = $this->db->query($sql); - if (! $resql) dol_print_error($this->db); - } - } - } - else - { - 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); - } - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); - return -1; - } - - } - else - { - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - dol_print_error('',$this->error); - return -1; - } - } - - /** - * Build thumb - * - * @param string $file Path file in UTF8 to original file to create thumbs from. - * @return void - */ - function addThumbs($file) - { - global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; - - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... - - $file_osencoded=dol_osencode($file); - if (file_exists($file_osencoded)) - { - // Create small thumbs for company (Ratio is near 16/9) - // Used on logon for example - vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); - - // Create mini thumbs for company (Ratio is near 16/9) - // Used on menu or for setup page for example - vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); - } - } - - - /* Functions common to commonobject and commonobjectline */ - - /* For default values */ - - /** - * Return the default value to use for a field when showing the create form of object. - * Return values in this order: - * 1) If parameter is available into POST, we return it first. - * 2) If not but an alternate value was provided as parameter of function, we return it. - * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). - * 4) Return value found into database (TODO No yet implemented) - * - * @param string $fieldname Name of field - * @param string $alternatevalue Alternate value to use - * @return string|string[] Default value (can be an array if the GETPOST return an array) - **/ - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) - { - global $conf, $_POST; - - // If param here has been posted, we use this value first. - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); - - if (isset($alternatevalue)) return $alternatevalue; - - $newelement=$this->element; - if ($newelement == 'facture') $newelement='invoice'; - if ($newelement == 'commande') $newelement='order'; - if (empty($newelement)) - { - dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); - return ''; - } - - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); - //var_dump($keyforfieldname); - if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; - - // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname - - } - - - /* For triggers */ - - - /** - * Call trigger based on this instance. - * Some context information may also be provided into array property this->context. - * NB: Error from trigger are stacked in interface->errors - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. - * - * @param string $trigger_name trigger's name to execute - * @param User $user Object user - * @return int Result of run_triggers - */ - function call_trigger($trigger_name, $user) - { - global $langs,$conf; - - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); - - if ($result < 0) - { - if (!empty($this->errors)) - { - $this->errors=array_unique(array_merge($this->errors,$interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice. - } - else - { - $this->errors=$interface->errors; - } - } - return $result; - } - - - /* Functions for extrafields */ - - - /** - * Function to get extra fields of an object into $this->array_options - * This method is in most cases called by method fetch of objects but you can call it separately. - * - * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. - * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded - */ - function fetch_optionals($rowid=null, $optionsArray=null) - { - if (empty($rowid)) $rowid=$this->id; - - // To avoid SQL errors. Probably not the better solution though - if (!$this->table_element) { - return 0; - } - - if (! is_array($optionsArray)) - { - // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. - // TODO Use of existing extrafield is not yet ready (must mutualize code that use extrafields in form first) - // global $extrafields; - //if (! is_object($extrafields)) - //{ - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - //} - - // Load array of extrafields for elementype = $this->table_element - if (empty($extrafields->attributes[$this->table_element]['loaded'])) - { - $extrafields->fetch_name_optionals_label($this->table_element); - } - $optionsArray = $extrafields->attributes[$this->table_element]['label']; - } - - $table_element = $this->table_element; - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility - - // Request to get complementary values - if (is_array($optionsArray) && count($optionsArray) > 0) - { - $sql = "SELECT rowid"; - foreach ($optionsArray as $name => $label) - { - if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') - { - $sql.= ", ".$name; - } - } - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; - $sql.= " WHERE fk_object = ".$rowid; - - dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $numrows=$this->db->num_rows($resql); - if ($numrows) - { - $tab = $this->db->fetch_array($resql); - - foreach ($tab as $key => $value) - { - // Test fetch_array ! is_int($key) because fetch_array result is a mix table with Key as alpha and Key as int (depend db engine) - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) - { - // we can add this attribute to object - $this->array_options["options_".$key]=$value; - } - } - } - - $this->db->free($resql); - - if ($numrows) return $numrows; - else return 0; - } - else - { - dol_print_error($this->db); - return -1; - } - } - return 0; - } - - /** - * Delete all extra fields values for the current object. - * - * @return int <0 if KO, >0 if OK - */ - function deleteExtraFields() - { - $this->db->begin(); - - $table_element = $this->table_element; - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility - - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); - $resql=$this->db->query($sql_del); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - - /** - * Add/Update all extra fields values for the current object. - * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) - * This function delete record with all extrafields and insert them again from the array $this->array_options. - * - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) - * @param User $userused Object user - * @return int -1=error, O=did nothing, 1=OK - * @see updateExtraField, setValueFrom - */ - function insertExtraFields($trigger='', $userused=null) - { - global $conf,$langs,$user; - - if (empty($userused)) $userused=$user; - - $error=0; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used - - if (! empty($this->array_options)) - { - // Check parameters - $langs->load('admin'); - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); - - //Eliminate copied source object extra_fields that do not exist in target object - $new_array_options=array(); - foreach ($this->array_options as $key => $value) { - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test - $new_array_options[$key] = $value; - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix - $new_array_options['options_'.$key] = $value; - } - - foreach($new_array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - $attributeType = $extrafields->attribute_type[$attributeKey]; - $attributeLabel = $extrafields->attribute_label[$attributeKey]; - $attributeParam = $extrafields->attribute_param[$attributeKey]; - $attributeRequired = $extrafields->attribute_required[$attributeKey]; - - if ($attributeRequired) - { - $mandatorypb=false; - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; - if ($this->array_options[$key] === '') $mandatorypb=true; - if ($mandatorypb) - { - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); - return -1; - } - } - - switch ($attributeType) - { - case 'int': - if (!is_numeric($value) && $value!='') - { - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); - return -1; - } - elseif ($value=='') - { - $new_array_options[$key] = null; - } - break; - /*case 'select': // Not required, we chosed value='0' for undefined values - if ($value=='-1') - { - $this->array_options[$key] = null; - } - break;*/ - case 'price': - $new_array_options[$key] = price2num($this->array_options[$key]); - break; - case 'date': - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); - break; - case 'datetime': - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); - break; - case 'link': - $param_list=array_keys($attributeParam['options']); - // 0 : ObjectName - // 1 : classPath - $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) - { - if ($value == '-1') // -1 is key for no defined in combo list of objects - { - $new_array_options[$key]=''; - } - elseif ($value) - { - $object = new $InfoFieldList[0]($this->db); - if (is_numeric($value)) $res=$object->fetch($value); - else $res=$object->fetch('',$value); - - if ($res > 0) $new_array_options[$key]=$object->id; - else - { - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; - $this->db->rollback(); - return -1; - } - } - } - else - { - dol_syslog('Error bad setup of extrafield', LOG_WARNING); - } - break; - } - } - - $this->db->begin(); - - $table_element = $this->table_element; - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility - - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); - $this->db->query($sql_del); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; - foreach($new_array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - // Add field of attribut - if ($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate - $sql.=",".$attributeKey; - } - $sql .= ") VALUES (".$this->id; - - foreach($new_array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - // Add field o fattribut - if($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate) - { - if ($new_array_options[$key] != '') - { - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; - } - else - { - $sql.=",null"; - } - } - } - $sql.=")"; - - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $error++; - } - - if (! $error && $trigger) - { - // Call trigger - $this->context=array('extrafieldaddupdate'=>1); - $result=$this->call_trigger($trigger, $userused); - if ($result < 0) $error++; - // End call trigger - } - - if ($error) - { - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - else return 0; - } - - /** - * Update an exta field value for the current object. - * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) - * - * @param string $key Key of the extrafield - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) - * @param User $userused Object user - * @return int -1=error, O=did nothing, 1=OK - * @see setValueFrom - */ - function updateExtraField($key, $trigger, $userused) - { - global $conf,$langs,$user; - - if (empty($userused)) $userused=$user; - - $error=0; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used - - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) - { - // Check parameters - $langs->load('admin'); - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); - - $value=$this->array_options["options_".$key]; - $attributeType = $extrafields->attribute_type[$key]; - $attributeLabel = $extrafields->attribute_label[$key]; - $attributeParam = $extrafields->attribute_param[$key]; - switch ($attributeType) - { - case 'int': - if (!is_numeric($value) && $value!='') - { - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); - return -1; - } - elseif ($value=='') - { - $this->array_options["options_".$key] = null; - } - break; - /*case 'select': // Not required, we chosed value='0' for undefined values - if ($value=='-1') - { - $this->array_options[$key] = null; - } - break;*/ - case 'price': - $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); - break; - case 'date': - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); - break; - case 'datetime': - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); - break; - case 'link': - $param_list=array_keys($attributeParam ['options']); - // 0 : ObjectName - // 1 : classPath - $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - if ($value) - { - $object = new $InfoFieldList[0]($this->db); - $object->fetch(0,$value); - $this->array_options["options_".$key]=$object->id; - } - break; - } - - $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; - $sql .= " WHERE fk_object = ".$this->id; - $resql = $this->db->query($sql); - if (! $resql) - { - $error++; - $this->error=$this->db->lasterror(); - } - - if (! $error && $trigger) - { - // Call trigger - $this->context=array('extrafieldupdate'=>1); - $result=$this->call_trigger($trigger, $userused); - if ($result < 0) $error++; - // End call trigger - } - - if ($error) - { - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - else return 0; - } - - - /** - * Return HTML string to put an input field into a page - * Code very similar with showInputField of extra fields - * - * @param array $val Array of properties for field to show - * @param string $key Key of attribute - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) - * @param string $moreparam To add more parametes on html input tag - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) - * @param string|int $showsize Value for css to define size. May also be a numeric. - * @return string - */ - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) - { - global $conf,$langs,$form; - - if (! is_object($form)) - { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form=new Form($this->db); - } - - $objectid = $this->id; - - $label= $val['label']; - $type = $val['type']; - $size = $val['css']; - - // Convert var to be able to share same code than showInputField of extrafields - if (preg_match('/varchar\((\d+)\)/', $type, $reg)) - { - $type = 'varchar'; // convert varchar(xx) int varchar - $size = $reg[1]; - } - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar - if (is_array($val['arrayofkeyval'])) $type='select'; - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; - - //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used - $default=$val['default']; - $computed=$val['computed']; - $unique=$val['unique']; - $required=$val['required']; - $param=$val['param']; - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) - { - $type='link'; - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); - } - $langfile=$val['langfile']; - $list=$val['list']; - $hidden=(abs($val['visible'])!=1 ? 1 : 0); - $help=$val['help']; - - if ($computed) - { - if (! preg_match('/^search_/', $keyprefix)) return ''.$langs->trans("AutomaticallyCalculated").''; - else return ''; - } - - // Use in priorit showsize from parameters, then $val['css'] then autodefine - if (empty($showsize) && ! empty($val['css'])) - { - $showsize = $val['css']; - } - if (empty($showsize)) - { - if ($type == 'date') - { - //$showsize=10; - $showsize = 'minwidth100imp'; - } - elseif ($type == 'datetime') - { - //$showsize=19; - $showsize = 'minwidth200imp'; - } - elseif (in_array($type,array('int','double','price'))) - { - //$showsize=10; - $showsize = 'maxwidth75'; - } - elseif ($type == 'url') - { - $showsize='minwidth400'; - } - elseif ($type == 'boolean') - { - $showsize=''; - } - else - { - if (round($size) < 12) - { - $showsize = 'minwidth100'; - } - else if (round($size) <= 48) - { - $showsize = 'minwidth200'; - } - else - { - //$showsize=48; - $showsize = 'minwidth400'; - } - } - } - //var_dump($showsize.' '.$size); - - if (in_array($type,array('date','datetime'))) - { - $tmp=explode(',',$size); - $newsize=$tmp[0]; - - $showtime = in_array($type,array('datetime')) ? 1 : 0; - - // Do not show current date when field not required (see select_date() method) - if (!$required && $value == '') $value = '-1'; - - // TODO Must also support $moreparam - $out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1); - } - elseif (in_array($type,array('int','integer'))) - { - $tmp=explode(',',$size); - $newsize=$tmp[0]; - $out=''; - } - elseif (preg_match('/varchar/', $type)) - { - $out=''; - } - elseif (in_array($type, array('mail', 'phone', 'url'))) - { - $out=''; - } - elseif ($type == 'text') - { - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,0,ROWS_5,'90%'); - $out=$doleditor->Create(1); - } - elseif ($type == 'html') - { - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); - $out=$doleditor->Create(1); - } - elseif ($type == 'boolean') - { - $checked=''; - if (!empty($value)) { - $checked=' checked value="1" '; - } else { - $checked=' value="1" '; - } - $out=''; - } - elseif ($type == 'price') - { - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. - $value=price($value); - } - $out=' '.$langs->getCurrencySymbol($conf->currency); - } - elseif ($type == 'double') - { - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. - $value=price($value); - } - $out=' '; - } - elseif ($type == 'select') - { - $out = ''; - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) - { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); - } - - $out.=''; - } - elseif ($type == 'sellist') - { - $out = ''; - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) - { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); - } - - $out.=''; - } - elseif ($type == 'checkbox') - { - $value_arr=explode(',',$value); - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); - } - elseif ($type == 'radio') - { - $out=''; - foreach ($param['options'] as $keyopt => $val) - { - $out.=''.$val.'
'; - } - } - elseif ($type == 'chkbxlst') - { - if (is_array($value)) { - $value_arr = $value; - } - else { - $value_arr = explode(',', $value); - } - - if (is_array($param['options'])) { - $param_list = array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - // 0 : tableName - // 1 : label field name - // 2 : key fields name (if differ of rowid) - // 3 : key field parent (for dependent lists) - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); - - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); - $keyList .= ', ' . $parentField; - } - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { - if (strpos($InfoFieldList[4], 'extra.') !== false) { - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; - } else { - $keyList = $InfoFieldList[2] . ' as rowid'; - } - } - - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $keyList .= ', '; - $keyList .= implode(', ', $fields_label); - } - - $sqlwhere = ''; - $sql = 'SELECT ' . $keyList; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; - if (! empty($InfoFieldList[4])) { - - // can use SELECT request - if (strpos($InfoFieldList[4], '$SEL$')!==false) { - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); - } - - // current object id can be use into filter - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); - } else { - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); - } - - // We have to join on extrafield table - if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; - } else { - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; - } - } else { - $sqlwhere .= ' WHERE 1=1'; - } - // Some tables may have field, some other not. For the moment we disable it. - if (in_array($InfoFieldList[0], array ('tablewithentity'))) - { - $sqlwhere .= ' AND entity = ' . $conf->entity; - } - // $sql.=preg_replace('/^ AND /','',$sqlwhere); - // print $sql; - - $sql .= $sqlwhere; - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - - $data=array(); - - while ( $i < $num ) { - $labeltoshow = ''; - $obj = $this->db->fetch_object($resql); - - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $notrans = true; - foreach ( $fields_label as $field_toshow ) { - $labeltoshow .= $obj->$field_toshow . ' '; - } - } else { - $labeltoshow = $obj->{$InfoFieldList[1]}; - } - $labeltoshow = dol_trunc($labeltoshow, 45); - - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - foreach ( $fields_label as $field_toshow ) { - $translabel = $langs->trans($obj->$field_toshow); - if ($translabel != $obj->$field_toshow) { - $labeltoshow = dol_trunc($translabel, 18) . ' '; - } else { - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; - } - } - - $data[$obj->rowid]=$labeltoshow; - - } else { - if (! $notrans) { - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - if ($translabel != $obj->{$InfoFieldList[1]}) { - $labeltoshow = dol_trunc($translabel, 18); - } else { - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); - } - } - if (empty($labeltoshow)) - $labeltoshow = '(not defined)'; - - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - $data[$obj->rowid]=$labeltoshow; - } - - if (! empty($InfoFieldList[3])) { - $parent = $parentName . ':' . $obj->{$parentField}; - } - - $data[$obj->rowid]=$labeltoshow; - } - - $i ++; - } - $this->db->free($resql); - - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); - - } else { - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.
'; - } - } - $out .= ''; - } - elseif ($type == 'link') - { - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' - $showempty=(($val['notnull'] == 1 && $val['default'] != '')?0:1); - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); - } - elseif ($type == 'password') - { - // If prefix is 'search_', field is used as a filter, we use a common text field. - $out=''; - } - if (!empty($hidden)) { - $out=''; - } - /* Add comments - if ($type == 'date') $out.=' (YYYY-MM-DD)'; - elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; - */ - return $out; - } - - - /** - * Return HTML string to show a field into a page - * Code very similar with showOutputField of extra fields - * - * @param array $val Array of properties of field to show - * @param string $key Key of attribute - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) - * @param string $moreparam To add more parametes on html input tag - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) - * @param mixed $showsize Value for css to define size. May also be a numeric. - * @return string - */ - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) - { - global $conf,$langs,$form; - - if (! is_object($form)) - { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form=new Form($this->db); - } - - $objectid = $this->id; - $label = $val['label']; - $type = $val['type']; - $size = $val['css']; - - // Convert var to be able to share same code than showOutputField of extrafields - if (preg_match('/varchar\((\d+)\)/', $type, $reg)) - { - $type = 'varchar'; // convert varchar(xx) int varchar - $size = $reg[1]; - } - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar - if (is_array($val['arrayofkeyval'])) $type='select'; - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; - - //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used - $default=$val['default']; - $computed=$val['computed']; - $unique=$val['unique']; - $required=$val['required']; - $param=$val['param']; - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) - { - $type='link'; - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); - } - $langfile=$val['langfile']; - $list=$val['list']; - $help=$val['help']; - $hidden=(($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) - - if ($hidden) return ''; - - // If field is a computed field, value must become result of compute - if ($computed) - { - // Make the eval of compute string - //var_dump($computed); - $value = dol_eval($computed, 1, 0); - } - - if (empty($showsize)) - { - if ($type == 'date') - { - //$showsize=10; - $showsize = 'minwidth100imp'; - } - elseif ($type == 'datetime') - { - //$showsize=19; - $showsize = 'minwidth200imp'; - } - elseif (in_array($type,array('int','double','price'))) - { - //$showsize=10; - $showsize = 'maxwidth75'; - } - elseif ($type == 'url') - { - $showsize='minwidth400'; - } - elseif ($type == 'boolean') - { - $showsize=''; - } - else - { - if (round($size) < 12) - { - $showsize = 'minwidth100'; - } - else if (round($size) <= 48) - { - $showsize = 'minwidth200'; - } - else - { - //$showsize=48; - $showsize = 'minwidth400'; - } - } - } - - // Format output value differently according to properties of field - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); - elseif ($type == 'date') - { - $value=dol_print_date($value,'day'); - } - elseif ($type == 'datetime') - { - $value=dol_print_date($value,'dayhour'); - } - elseif ($type == 'double') - { - if (!empty($value)) { - $value=price($value); - } - } - elseif ($type == 'boolean') - { - $checked=''; - if (!empty($value)) { - $checked=' checked '; - } - $value=''; - } - elseif ($type == 'mail') - { - $value=dol_print_email($value,0,0,0,64,1,1); - } - elseif ($type == 'url') - { - $value=dol_print_url($value,'_blank',32,1); - } - elseif ($type == 'phone') - { - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); - } - elseif ($type == 'price') - { - $value=price($value,0,$langs,0,0,-1,$conf->currency); - } - elseif ($type == 'select') - { - $value=$param['options'][$value]; - } - elseif ($type == 'sellist') - { - $param_list=array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - - $selectkey="rowid"; - $keyList='rowid'; - - if (count($InfoFieldList)>=3) - { - $selectkey = $InfoFieldList[2]; - $keyList=$InfoFieldList[2].' as rowid'; - } - - $fields_label = explode('|',$InfoFieldList[1]); - if(is_array($fields_label)) { - $keyList .=', '; - $keyList .= implode(', ', $fields_label); - } - - $sql = 'SELECT '.$keyList; - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; - if (strpos($InfoFieldList[4], 'extra')!==false) - { - $sql.= ' as main'; - } - if ($selectkey=='rowid' && empty($value)) { - $sql.= " WHERE ".$selectkey."=0"; - } elseif ($selectkey=='rowid') { - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); - }else { - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; - } - - //$sql.= ' AND entity = '.$conf->entity; - - dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $value=''; // value was used, so now we reste it to use it to build final output - - $obj = $this->db->fetch_object($resql); - - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|',$InfoFieldList[1]); - - if(is_array($fields_label) && count($fields_label)>1) - { - foreach ($fields_label as $field_toshow) - { - $translabel=''; - if (!empty($obj->$field_toshow)) { - $translabel=$langs->trans($obj->$field_toshow); - } - if ($translabel!=$field_toshow) { - $value.=dol_trunc($translabel,18).' '; - }else { - $value.=$obj->$field_toshow.' '; - } - } - } - else - { - $translabel=''; - if (!empty($obj->{$InfoFieldList[1]})) { - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); - } - if ($translabel!=$obj->{$InfoFieldList[1]}) { - $value=dol_trunc($translabel,18); - }else { - $value=$obj->{$InfoFieldList[1]}; - } - } - } - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); - } - elseif ($type == 'radio') - { - $value=$param['options'][$value]; - } - elseif ($type == 'checkbox') - { - $value_arr=explode(',',$value); - $value=''; - if (is_array($value_arr)) - { - foreach ($value_arr as $keyval=>$valueval) { - $toprint[]='
  • '.$param['options'][$valueval].'
  • '; - } - } - $value='
      '.implode(' ', $toprint).'
    '; - } - elseif ($type == 'chkbxlst') - { - $value_arr = explode(',', $value); - - $param_list = array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - - $selectkey = "rowid"; - $keyList = 'rowid'; - - if (count($InfoFieldList) >= 3) { - $selectkey = $InfoFieldList[2]; - $keyList = $InfoFieldList[2] . ' as rowid'; - } - - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $keyList .= ', '; - $keyList .= implode(', ', $fields_label); - } - - $sql = 'SELECT ' . $keyList; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; - if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main'; - } - // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; - // $sql.= ' AND entity = '.$conf->entity; - - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $value = ''; // value was used, so now we reste it to use it to build final output - $toprint=array(); - while ( $obj = $this->db->fetch_object($resql) ) { - - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - if (is_array($fields_label) && count($fields_label) > 1) { - foreach ( $fields_label as $field_toshow ) { - $translabel = ''; - if (! empty($obj->$field_toshow)) { - $translabel = $langs->trans($obj->$field_toshow); - } - if ($translabel != $field_toshow) { - $toprint[]='
  • '.dol_trunc($translabel, 18).'
  • '; - } else { - $toprint[]='
  • '.$obj->$field_toshow.'
  • '; - } - } - } else { - $translabel = ''; - if (! empty($obj->{$InfoFieldList[1]})) { - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - } - if ($translabel != $obj->{$InfoFieldList[1]}) { - $toprint[]='
  • '.dol_trunc($translabel, 18).'
  • '; - } else { - $toprint[]='
  • '.$obj->{$InfoFieldList[1]}.'
  • '; - } - } - } - } - $value='
      '.implode(' ', $toprint).'
    '; - - } else { - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); - } - } - elseif ($type == 'link') - { - $out=''; - - // only if something to display (perf) - if ($value) - { - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' - - $InfoFieldList = explode(":", $param_list[0]); - $classname=$InfoFieldList[0]; - $classpath=$InfoFieldList[1]; - if (! empty($classpath)) - { - dol_include_once($InfoFieldList[1]); - if ($classname && class_exists($classname)) - { - $object = new $classname($this->db); - $object->fetch($value); - $value=$object->getNomUrl(3); - } - } - else - { - dol_syslog('Error bad setup of extrafield', LOG_WARNING); - return 'Error bad setup of extrafield'; - } - } - } - elseif ($type == 'text' || $type == 'html') - { - $value=dol_htmlentitiesbr($value); - } - elseif ($type == 'password') - { - $value=preg_replace('/./i','*',$value); - } - - //print $type.'-'.$size; - $out=$value; - - return $out; - } - - - /** - * Function to show lines of extrafields with output datas - * - * @param Extrafields $extrafields Extrafield Object - * @param string $mode Show output (view) or input (edit) for extrafield - * @param array $params Optional parameters - * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) - * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) - * - * @return string - */ - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='') - { - global $_POST, $conf, $langs, $action; - - $out = ''; - - if (count($extrafields->attribute_label) > 0) - { - $out .= "\n"; - $out .= ' '; - $out .= "\n"; - - $e = 0; - foreach($extrafields->attribute_label as $key=>$label) - { - if (empty($extrafields->attribute_list[$key])) continue; // 0 = Never visible field - if (($mode == 'create' || $mode == 'edit') && abs($extrafields->attribute_list[$key]) != 1 && abs($extrafields->attribute_list[$key]) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list - - // Load language if required - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); - - if (is_array($params) && count($params)>0) { - if (array_key_exists('colspan',$params)) { - $colspan=$params['colspan']; - } - }else { - $colspan='3'; - } - - switch($mode) { - case "view": - $value=$this->array_options["options_".$key.$keysuffix]; - break; - case "edit": - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. - // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') - if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) - { - if (is_array($getposttemp)) { - // $getposttemp is an array but following code expects a comma separated string - $value = implode(",", $getposttemp); - } else { - $value = $getposttemp; - } - } else { - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. - } - break; - } - //var_dump($value); - - if ($extrafields->attribute_type[$key] == 'separate') - { - $out .= $extrafields->showSeparator($key); - } - else - { - $csstyle=''; - $class=(!empty($extrafields->attribute_hidden[$key]) ? 'class="hideobject" ' : ''); - if (is_array($params) && count($params)>0) { - if (array_key_exists('style',$params)) { - $csstyle=$params['style']; - } - } - if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) - { - $out .= ''; - $colspan='0'; - } - else - { - $out .= ''; - } - // Convert date into timestamp format (value in memory must be a timestamp) - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min",'int',3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year",'int',3)):$this->db->jdate($this->array_options['options_'.$key]); - } - // Convert float submited string into real php numeric (value in memory must be a php numeric) - if (in_array($extrafields->attribute_type[$key],array('price','double'))) - { - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix,'int',3)):$this->array_options['options_'.$key]; - } - - $labeltoshow = $langs->trans($label); - - if($extrafields->attribute_required[$key]) - { - $labeltoshow = ''.$labeltoshow.''; - } - $out .= ''.$labeltoshow.''; - - $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; - $out .=''; - - switch($mode) { - case "view": - $out .= $extrafields->showOutputField($key, $value); - break; - case "edit": - $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); - break; - } - - $out .= ''; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= ''; - else $out .= ''; - $e++; - } - } - $out .= "\n"; - // Add code to manage list depending on others - if (! empty($conf->use_javascript_ajax)) { - $out .= ' - '."\n"; - $out .= ' '."\n"; - } - } - return $out; - } - - - /** - * Returns the rights used for this class - * @return stdClass - */ - public function getRights() - { - global $user; - - $element = $this->element; - if ($element == 'facturerec') $element='facture'; - - return $user->rights->{$element}; - } - - /** - * Function used to replace a thirdparty id with another one. - * This function is meant to be called from replaceThirdparty with the appropiate tables - * Column name fk_soc MUST be used to identify thirdparties - * - * @param DoliDB $db Database handler - * @param int $origin_id Old thirdparty id (the thirdparty to delete) - * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) - * @param string[] $tables Tables that need to be changed - * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) - * @return bool True if success, False if error - */ - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) - { - foreach ($tables as $table) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; - - if (! $db->query($sql)) - { - if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. - //$this->errors = $db->lasterror(); - return false; - } - } - - return true; - } - - /** - * Get buy price to use for margin calculation. This function is called when buy price is unknown. - * Set buy price = sell price if ForceBuyingPriceIfNull configured, - * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice - * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice - * else set min buy price as buy price - * - * @param float $unitPrice Product unit price - * @param float $discountPercent Line discount percent - * @param int $fk_product Product id - * @return float <0 if KO, buyprice if OK - */ - public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) - { - global $conf; - - $buyPrice = 0; - - if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false - { - $buyPrice = $unitPrice * (1 - $discountPercent / 100); - } - else - { - // Get cost price for margin calculation - if (! empty($fk_product)) - { - if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') - { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $product = new Product($this->db); - $result = $product->fetch($fk_product); - if ($result <= 0) - { - $this->errors[] = 'ErrorProductIdDoesNotExists'; - return -1; - } - if ($product->cost_price > 0) - { - $buyPrice = $product->cost_price; - } - else if ($product->pmp > 0) - { - $buyPrice = $product->pmp; - } - } - else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') - { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $product = new Product($this->db); - $result = $product->fetch($fk_product); - if ($result <= 0) - { - $this->errors[] = 'ErrorProductIdDoesNotExists'; - return -1; - } - if ($product->pmp > 0) - { - $buyPrice = $product->pmp; - } - } - - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) - { - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; - $productFournisseur = new ProductFournisseur($this->db); - if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) - { - $buyPrice = $productFournisseur->fourn_unitprice; - } - else if ($result < 0) - { - $this->errors[] = $productFournisseur->error; - return -2; - } - } - } - } - return $buyPrice; - } - - - - /** - * Function test if type is array - * - * @param array $info content informations of field - * @return bool - */ - protected function isArray($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='array') return true; - else return false; - } - else return false; - } - - /** - * Function test if type is null - * - * @param array $info content informations of field - * @return bool - */ - protected function isNull($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='null') return true; - else return false; - } - else return false; - } - - - /** - * Function test if type is date - * - * @param array $info content informations of field - * @return bool - */ - public function isDate($info) - { - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; - else return false; - } - - /** - * Function test if type is integer - * - * @param array $info content informations of field - * @return bool - */ - public function isInt($info) - { - if(is_array($info)) - { - if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true; - else return false; - } - else return false; - } - - /** - * Function test if type is float - * - * @param array $info content informations of field - * @return bool - */ - public function isFloat($info) - { - if(is_array($info)) - { - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; - else return false; - } - else return false; - } - - /** - * Function test if type is text - * - * @param array $info content informations of field - * @return bool - */ - public function isText($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='text') return true; - else return false; - } - else return false; - } - - /** - * Function test if is indexed - * - * @param array $info content informations of field - * @return bool - */ - protected function isIndex($info) - { - if(is_array($info)) - { - if(isset($info['index']) && $info['index']==true) return true; - else return false; - } - else return false; - } - - /** - * Function to prepare the values to insert. - * Note $this->${field} are set by the page that make the createCommon or the updateCommon. - * - * @return array - */ - private function set_save_query() - { - global $conf; - - $queryarray=array(); - foreach ($this->fields as $field=>$info) // Loop on definition of fields - { - // Depending on field type ('datetime', ...) - if($this->isDate($info)) - { - if(empty($this->{$field})) - { - $queryarray[$field] = NULL; - } - else - { - $queryarray[$field] = $this->db->idate($this->{$field}); - } - } - else if($this->isArray($info)) - { - $queryarray[$field] = serialize($this->{$field}); - } - else if($this->isInt($info)) - { - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; - else - { - $queryarray[$field] = (int) price2num($this->{$field}); - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. - } - } - else if($this->isFloat($info)) - { - $queryarray[$field] = (double) price2num($this->{$field}); - if (empty($queryarray[$field])) $queryarray[$field]=0; - } - else - { - $queryarray[$field] = $this->{$field}; - } - - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; - } - - return $queryarray; - } - - /** - * Function to load data from a SQL pointer into properties of current object $this - * - * @param stdClass $obj Contain data of object from database - */ - private function setVarsFromFetchObj(&$obj) - { - foreach ($this->fields as $field => $info) - { - if($this->isDate($info)) - { - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; - else $this->{$field} = strtotime($obj->{$field}); - } - elseif($this->isArray($info)) - { - $this->{$field} = @unserialize($obj->{$field}); - // Hack for data not in UTF8 - if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); - } - elseif($this->isInt($info)) - { - if ($field == 'rowid') $this->id = (int) $obj->{$field}; - else $this->{$field} = (int) $obj->{$field}; - } - elseif($this->isFloat($info)) - { - $this->{$field} = (double) $obj->{$field}; - } - elseif($this->isNull($info)) - { - $val = $obj->{$field}; - // zero is not null - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); - } - else - { - $this->{$field} = $obj->{$field}; - } - } - - // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; - } - - /** - * Function to concat keys of fields - * - * @return string - */ - private function get_field_list() - { - $keys = array_keys($this->fields); - return implode(',', $keys); - } - - /** - * Add quote to field value if necessary - * - * @param string|int $value Value to protect - * @param array $fieldsentry Properties of field - * @return string - */ - protected function quote($value, $fieldsentry) { - if (is_null($value)) return 'NULL'; - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); - else return "'".$this->db->escape($value)."'"; - } - - - /** - * Create object into database - * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int <0 if KO, Id of created object if OK - */ - public function createCommon(User $user, $notrigger = false) - { - global $langs; - - $error = 0; - - $now=dol_now(); - - $fieldvalues = $this->set_save_query(); - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. - - $keys=array(); - $values = array(); - foreach ($fieldvalues as $k => $v) { - $keys[$k] = $k; - $value = $this->fields[$k]; - $values[$k] = $this->quote($v, $value); - } - - // Clean and check mandatory - foreach($keys as $key) - { - // If field is an implicit foreign key field - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; - - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); - if ($this->fields[$key]['notnull'] == 1 && ! isset($values[$key])) - { - $error++; - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); - } - - // If field is an implicit foreign key field - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; - } - - if ($error) return -1; - - $this->db->begin(); - - if (! $error) - { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; - $sql.= ' ('.implode( ", ", $keys ).')'; - $sql.= ' VALUES ('.implode( ", ", $values ).')'; - - $res = $this->db->query($sql); - if ($res===false) { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } - - if (! $error) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - } - - // Create extrafields - if (! $error) - { - $result=$this->insertExtraFields(); - if ($result < 0) $error++; - } - - // Triggers - if (! $error && ! $notrigger) - { - // Call triggers - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return $this->id; - } - } - - - /** - * Load object in memory from the database - * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK - */ - public function fetchCommon($id, $ref = null) - { - if (empty($id) && empty($ref)) return false; - - $sql = 'SELECT '.$this->get_field_list(); - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - - if(!empty($id)) $sql.= ' WHERE rowid = '.$id; - else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); - - $res = $this->db->query($sql); - if ($res) - { - $obj = $this->db->fetch_object($res); - if ($obj) - { - $this->setVarsFromFetchObj($obj); - return $this->id; - } - else - { - return 0; - } - } - else - { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - return -1; - } - } - - /** - * Update object into database - * - * @param User $user User that modifies - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int <0 if KO, >0 if OK - */ - public function updateCommon(User $user, $notrigger = false) - { - global $conf, $langs; - - $error = 0; - - $now=dol_now(); - - $fieldvalues = $this->set_save_query(); - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. - - $keys=array(); - $values = array(); - foreach ($fieldvalues as $k => $v) { - $keys[$k] = $k; - $value = $this->fields[$k]; - $values[$k] = $this->quote($v, $value); - $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); - } - - // Clean and check mandatory - foreach($keys as $key) - { - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field - - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); - /* - if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) - { - $error++; - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); - }*/ - } - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; - - $this->db->begin(); - if (! $error) - { - $res = $this->db->query($sql); - if ($res===false) - { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } - - // Update extrafield - if (! $error) - { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - } - - // Triggers - if (! $error && ! $notrigger) - { - // Call triggers - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); - if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail - // End call triggers - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return $this->id; - } - } - - /** - * Delete object in database - * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int <0 if KO, >0 if OK - */ - public function deleteCommon(User $user, $notrigger = false) - { - $error=0; - - $this->db->begin(); - - if (! $error) { - if (! $notrigger) { - // Call triggers - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); - if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail - // End call triggers - } - } - - if (! $error) - { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; - $sql.= " WHERE fk_object=" . $this->id; - - $resql = $this->db->query($sql); - if (! $resql) - { - $this->errors[] = $this->db->lasterror(); - $error++; - } - } - - if (! $error) - { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; - - $res = $this->db->query($sql); - if($res===false) { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } - } - - /** - * Initialise object with example values - * Id must be 0 if object instance is a specimen - * - * @return void - */ - public function initAsSpecimenCommon() - { - $this->id = 0; - - // TODO... - } - - /** - * Load comments linked with current task - * @return boolean 1 if ok - */ - public function fetchComments() - { - require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; - - $comment = new Comment($this->db); - $this->comments = Comment::fetchAllFor($this->element, $this->id); - return 1; - } - - /** - * Return nb comments already posted - * - * @return int - */ - public function getNbComments() - { - return count($this->comments); - } - -} diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b1255e10b9c..e17891dab06 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -117,6 +117,13 @@ class Societe extends CommonObject var $state_code; var $state; + /** + * Id of region + * @var int + */ + var $region_code; + var $region; + /** * State code * @var string @@ -3126,29 +3133,8 @@ class Societe extends CommonObject $this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS; $this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP; $this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN; - - // We define state_id, state_code and state - $state_id=$state_code=$state_label=''; - if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) - { - $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE); - $state_id=$tmp[0]; - if (! empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" or "id:code:label:region_code:region" - { - $state_code=$tmp[1]; - $state_label=$tmp[2]; - } - else // For backward compatibility - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - $state_code=getState($state_id,2,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore - $state_label=getState($state_id,0,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore - } - } - $this->state_id=$state_id; - $this->state_code=$state_code; - $this->state=$state_label; - if (is_object($langs)) $this->state=($langs->trans('State'.$state_code)!='State'.$state_code)?$langs->trans('State'.$state_code):$state_label; + $this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE; + $this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION; $this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE; From 3a7cb43ad5c6235b9436e34f9ddba9fd6b3e9a78 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 7 Feb 2018 16:06:58 +0000 Subject: [PATCH 010/126] Forgot withregion condition if we want no state code --- htdocs/core/lib/company.lib.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 710798331ac..d8b9d090473 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -518,7 +518,12 @@ function getState($id,$withcode='',$dbtouse=0,$withregion='',$outputlangs='',$en } } else { - return $label; + if ($withregion == 1) { + return $label = $obj->region_name . ' - ' . $label; + } + else { + return $label; + } } } else From ecea8d698c3c83e98588e9e8272642f8f574f86b Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 7 Feb 2018 16:07:33 +0000 Subject: [PATCH 011/126] Forgot that MAIN_SHOW_STATE_CODE is not just 0 or 1 --- htdocs/core/class/html.formcompany.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 6d4547eb68c..7e69d7c7ca0 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -267,7 +267,8 @@ class FormCompany } // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - if(!empty($conf->global->MAIN_SHOW_STATE_CODE) && $conf->global->MAIN_SHOW_STATE_CODE == 1) { + if(!empty($conf->global->MAIN_SHOW_STATE_CODE) && + ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) { if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) { $out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); } From f52beef3eb31d7161049391557d9eee438c3f451 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 7 Feb 2018 16:54:21 +0000 Subject: [PATCH 012/126] Added translation to company.php if MAIN_SHOW_REGION_IN_STATE_SELECT is activated --- htdocs/admin/company.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 2b63bc7a4e8..dff69c08abe 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -729,7 +729,8 @@ else print ''; - print ''.$langs->trans("State").''; + if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print ''.$langs->trans("Region-State").''; + else print ''.$langs->trans("State").''; if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); else print ' '; print ''; From fd594f7e749f0573e81aa9c59890084e79371a59 Mon Sep 17 00:00:00 2001 From: Rui Strecht Date: Wed, 7 Feb 2018 16:57:43 +0000 Subject: [PATCH 013/126] Fixed wrong global --- htdocs/admin/company.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index dff69c08abe..06fa93bfd2a 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -729,7 +729,7 @@ else print ''; - if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print ''.$langs->trans("Region-State").''; + if (! empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT)) print ''.$langs->trans("Region-State").''; else print ''.$langs->trans("State").''; if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE,$conf->global->MAIN_SHOW_STATE_CODE,0,$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); else print ' '; From 9eeb80151eefc59acc76f0eb0ce84d38df01104c Mon Sep 17 00:00:00 2001 From: TuxGasy Date: Fri, 9 Mar 2018 21:13:54 +0100 Subject: [PATCH 014/126] Fix bug when updating multi currency rate on invoice supplier --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ab7afea77a4..4d44a4b6fec 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1560,7 +1560,7 @@ abstract class CommonObject $this->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); break; case 'invoice_supplier': - $this->updateline($line->id, $line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); + $this->updateline($line->id, $line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); break; default: dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); From fd36ade61a1a6e9a68079638a260e00b2cfff204 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 10 Mar 2018 11:20:32 +0100 Subject: [PATCH 015/126] Fix unit in replenish #7225 --- htdocs/product/stock/replenish.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 26c6ab1dfd1..23cb58ed7e3 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -154,6 +154,8 @@ if ($action == 'order' && isset($_POST['valid'])) $line->total_ttc = $line->total_ht + $line->total_tva; $line->remise_percent = $obj->remise_percent; $line->ref_fourn = $obj->ref_fourn; + $line->type = $product->type; + $line->fk_unit = $product->fk_unit; $suppliers[$obj->fk_soc]['lines'][] = $line; } } @@ -198,7 +200,13 @@ if ($action == 'order' && isset($_POST['valid'])) $line->remise_percent, 'HT', 0, - $line->info_bits + $line->type, + 0, + false, + null, + null, + 0, + $line->fk_unit ); } if ($result < 0) { From c00885384232356c0c51475a861c204242255334 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 10 Mar 2018 23:03:41 +0100 Subject: [PATCH 016/126] Fix #8057 --- htdocs/contact/class/contact.class.php | 21 +++++++++++-------- .../mailings/advthirdparties.modules.php | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 3b7ce848731..21c7527dae2 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -991,9 +991,10 @@ class Contact extends CommonObject * @param string $option Where the link point to * @param int $maxlen Max length of * @param string $moreparam Add more param into URL + * @param int $notooltip 1=Disable tooltip * @return string String with URL */ - function getNomUrl($withpicto=0,$option='',$maxlen=0,$moreparam='') + function getNomUrl($withpicto=0,$option='',$maxlen=0,$moreparam='',$notooltip=0) { global $conf, $langs, $hookmanager; @@ -1012,13 +1013,15 @@ class Contact extends CommonObject $link = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label=$langs->trans("ShowContact"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.= ' class="classfortooltip">'; + if (empty($notooltip)) { + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowContact"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.= ' class="classfortooltip"'; + } if (! is_object($hookmanager)) { @@ -1030,7 +1033,7 @@ class Contact extends CommonObject $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) $linkclose = $hookmanager->resPrint; - $link.=$linkclose; + $link.=$linkclose.'>'; $linkend=''; diff --git a/htdocs/core/modules/mailings/advthirdparties.modules.php b/htdocs/core/modules/mailings/advthirdparties.modules.php index 9252ae5ec3a..a747bc3625c 100644 --- a/htdocs/core/modules/mailings/advthirdparties.modules.php +++ b/htdocs/core/modules/mailings/advthirdparties.modules.php @@ -100,7 +100,7 @@ class mailing_advthirdparties extends MailingTargets 'source_url' => $this->url($obj->id,'thirdparty'), 'source_id' => $obj->id, 'source_type' => 'thirdparty' - ); + ); } } @@ -289,11 +289,11 @@ class mailing_advthirdparties extends MailingTargets if ($type=='thirdparty') { $companystatic=new Societe($this->db); $companystatic->fetch($id); - return $companystatic->getNomUrl(0); + return $companystatic->getNomUrl(0,'',0,1); } elseif ($type=='contact') { $contactstatic=new Contact($this->db); $contactstatic->fetch($id); - return $contactstatic->getNomUrl(0); + return $contactstatic->getNomUrl(0,'',0,'',1); } } From c2397fad60d61f5939bf57775c9a3e7e8a95815b Mon Sep 17 00:00:00 2001 From: Inovea Conseil Date: Sat, 10 Mar 2018 23:49:43 +0100 Subject: [PATCH 017/126] Fix #8092 --- htdocs/societe/card.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index d3f629952b1..b5d643abc98 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -10,6 +10,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2018 Nicolas ZABOURI * * 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 @@ -295,7 +296,8 @@ if (empty($reshook)) if (! $error) { $result = $object->insertExtraFields(); - if ($result < 0) $error++; + if ($result < 0) $errors = $object->errors; + } if ($error) $action = 'edit_extras'; } From 03f7df88c622708db3d8f95b18317d29f3e4823c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 00:05:32 +0100 Subject: [PATCH 018/126] Update card.php --- htdocs/societe/card.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index b5d643abc98..42abde0e09b 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -292,12 +292,15 @@ if (empty($reshook)) // 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 ($ret < 0) { $error++; } if (! $error) { $result = $object->insertExtraFields(); - if ($result < 0) $errors = $object->errors; - + if ($result < 0) + { + $error++; + $errors = $object->errors; + } } if ($error) $action = 'edit_extras'; } From 897b3f7b7948a3eab94006a6c670ea491da7e30f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 00:31:26 +0100 Subject: [PATCH 019/126] Fix setup --- htdocs/compta/bank/list.php | 4 +- htdocs/core/modules/modAccounting.class.php | 41 ++++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/htdocs/compta/bank/list.php b/htdocs/compta/bank/list.php index 817d6dc84e9..537585a63d9 100644 --- a/htdocs/compta/bank/list.php +++ b/htdocs/compta/bank/list.php @@ -89,8 +89,8 @@ $arrayfields=array( 'accountype'=>array('label'=>$langs->trans("Type"), 'checked'=>1), 'b.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1), 'b.number'=>array('label'=>$langs->trans("AccountIdShort"), 'checked'=>1), - 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>$conf->accountancy->enabled), - 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>$conf->accountancy->enabled), + 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>$conf->accounting->enabled), + 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>$conf->accounting->enabled), 'toreconcile'=>array('label'=>$langs->trans("TransactionsToConciliate"), 'checked'=>1), 'b.currency_code'=>array('label'=>$langs->trans("Currency"), 'checked'=>0), 'b.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 3f8a7c092b8..325c504af42 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -71,73 +71,88 @@ class modAccounting extends DolibarrModules $this->langfiles = array("accountancy","compta"); // Constants + // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) + // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), + // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) + // ); $this->const = array(); $this->const[1] = array( "MAIN_COMPANY_CODE_ALWAYS_REQUIRED", "chaine", "1", - "With this constants on, third party code is always required whatever is numbering module behaviour" + "With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 0 ); $this->const[2] = array( "MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED", "chaine", "1", - "With this constants on, bank account number is always required" + "With this constants on, bank account number is always required", 0, 'current', 1 ); $this->const[3] = array( "ACCOUNTING_ACCOUNT_SUSPENSE", "chaine", - "471" + "471", + "", 0, 'current', 0 ); $this->const[4] = array( "ACCOUNTING_ACCOUNT_TRANSFER_CASH", "chaine", - "58" + "58", + "", 0, 'current', 0 ); $this->const[5] = array( "CHARTOFACCOUNTS", "chaine", - "2" + "2", + "", 0, 'current', 0 ); $this->const[6] = array( "ACCOUNTING_EXPORT_MODELCSV", "chaine", - "1" + "1", + "", 0, 'current', 0 ); $this->const[7] = array( "ACCOUNTING_LENGTH_GACCOUNT", "chaine", - "" + "", + "", 0, 'current', 0 ); $this->const[8] = array( "ACCOUNTING_LENGTH_AACCOUNT", "chaine", - "" + "", + "", 0, 'current', 0 ); $this->const[9] = array( "ACCOUNTING_LIST_SORT_VENTILATION_TODO", "yesno", - "1" + "1", + "", 0, 'current', 0 ); $this->const[10] = array( "ACCOUNTING_LIST_SORT_VENTILATION_DONE", "yesno", - "1" + "1", + "", 0, 'current', 0 ); $this->const[11] = array ( "ACCOUNTING_EXPORT_DATE", "chaine", - "%d%m%Y" + "%d%m%Y", + "", 0, 'current', 0 ); $this->const[12] = array( "ACCOUNTING_EXPORT_SEPARATORCSV", "string", - "," + ",", + "", 0, 'current', 0 ); $this->const[13] = array( "ACCOUNTING_EXPORT_FORMAT", "chaine", - "csv" + "csv", + "", 0, 'current', 0 ); // Tabs From 5c4b5cc74f38e3346b8a7ad5e34a5a7977da8db7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 00:40:35 +0100 Subject: [PATCH 020/126] fix --- htdocs/compta/bank/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/list.php b/htdocs/compta/bank/list.php index 537585a63d9..6a39416342e 100644 --- a/htdocs/compta/bank/list.php +++ b/htdocs/compta/bank/list.php @@ -89,8 +89,8 @@ $arrayfields=array( 'accountype'=>array('label'=>$langs->trans("Type"), 'checked'=>1), 'b.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1), 'b.number'=>array('label'=>$langs->trans("AccountIdShort"), 'checked'=>1), - 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>$conf->accounting->enabled), - 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>$conf->accounting->enabled), + 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>(! empty($conf->accounting->enabled) || ! empty($conf->accounting->enabled))), + 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>(! empty($conf->accounting->enabled) || ! empty($conf->accounting->enabled))), 'toreconcile'=>array('label'=>$langs->trans("TransactionsToConciliate"), 'checked'=>1), 'b.currency_code'=>array('label'=>$langs->trans("Currency"), 'checked'=>0), 'b.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), From a3d25b24d31b43c21dc6276af1f45d08ac1e8e55 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 19:27:03 +0100 Subject: [PATCH 021/126] FIX #8285 Extrafields now reported by /api/index.php/agendaevents/{id} --- htdocs/comm/action/class/api_agendaevents.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 58deec46f5e..7fd76b5d1a9 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -80,6 +80,8 @@ class AgendaEvents extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + $result = $this->actioncomm->fetch_optionals(); + $this->actioncomm->fetchObjectLinked(); return $this->_cleanObjectDatas($this->actioncomm); } @@ -319,7 +321,6 @@ class AgendaEvents extends DolibarrApi unset($object->usermod); unset($object->libelle); - unset($object->array_options); unset($object->context); unset($object->canvas); unset($object->contact); From b04d38e7602d1aea839bd2655531c8030936228e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 11 Mar 2018 20:16:06 +0100 Subject: [PATCH 022/126] Update ticketsup.lang --- htdocs/langs/en_US/ticketsup.lang | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index ebf1f89309a..b50116c4997 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -18,14 +18,14 @@ # Generic # -Module110120Name = Tickets -Module110120Desc = Ticket system for incident management +Module56000Name=Tickets +Module56000Desc=Ticket system for incident management -Permission110121=See tickets -Permission110122=Modify tickets -Permission110123=Delete tickets -Permission110124=Manage tickets -Permission110125=See tickets of all thirdparties (not effective for external users, always be limited to the thirdparty they depend on) +Permission56001=See tickets +Permission56002=Modify tickets +Permission56003=Delete tickets +Permission56004=Manage tickets +Permission56005=See tickets of all thirdparties (not effective for external users, always be limited to the thirdparty they depend on) TicketsupDictType=Tickets type TicketsupDictCategory=Tickets categories @@ -70,22 +70,22 @@ Category=Category Severity=Severity # Email templates -MailToSendTicketsupMessage = To send email from ticket message +MailToSendTicketsupMessage=To send email from ticket message # # Admin page # -TicketsupSetup = Ticket module setup -TicketSupSettings = Settings -TicketsupSetupPage = -TicketsupPublicAccess = A public interface requiring no identification is available at the following url -TicketsupSetupDictionaries = The type of application categories and severity level are configurable from dictionaries +TicketsupSetup=Ticket module setup +TicketSupSettings=Settings +TicketsupSetupPage= +TicketsupPublicAccess=A public interface requiring no identification is available at the following url +TicketsupSetupDictionaries=The type of application categories and severity level are configurable from dictionaries TicketParamModule=Module variable setup TicketParamMail=Email setup -TicketEmailNotificationFrom = Notification email from -TicketEmailNotificationFromHelp = Used into ticket message answer by example -TicketEmailNotificationTo = Notifications email to -TicketEmailNotificationToHelp = Send email notifications to this address. +TicketEmailNotificationFrom=Notification email from +TicketEmailNotificationFromHelp=Used into ticket message answer by example +TicketEmailNotificationTo=Notifications email to +TicketEmailNotificationToHelp=Send email notifications to this address. TicketNewEmailBodyLabel=Text message sent after creating a ticket (public interface) TicketNewEmailBodyHelp=The text specified here will be inserted into the email confirming the creation of a new ticket from the public interface. Information on the consultation of the ticket are automatically added. TicketParamPublicInterface=Public interface setup @@ -128,9 +128,9 @@ TicketNotNotifyTiersAtCreate=Do not notify the company to the creation # # About page # -About = About -TicketSupAbout = About ticket module -TicketSupAboutModule = The development of this module has been initiated by the company Libr&thic. +About=About +TicketSupAbout=About ticket module +TicketSupAboutModule=The development of this module has been initiated by the company Libr&thic. TicketSupAboutModuleHelp=You can get help by using the contact form on the website librethic.io TicketSupAboutModuleImprove=Feel free to suggest improvements! Please visit the project page on Doliforge website to report bugs and add tasks. TicketSupAboutModuleThanks=Thanks to nwa who creates icons for this module./ From 111bbd98cebc740da39ac07e1036377ad840295d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 11 Mar 2018 20:36:52 +0100 Subject: [PATCH 023/126] Update ticketsup.php --- htdocs/admin/ticketsup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/ticketsup.php b/htdocs/admin/ticketsup.php index be1a3d2f8bf..f0dfb8c690a 100644 --- a/htdocs/admin/ticketsup.php +++ b/htdocs/admin/ticketsup.php @@ -235,9 +235,9 @@ $head = ticketsupAdminPrepareHead(); dol_fiche_head( $head, 'settings', - $langs->trans("Module110120Name"), + $langs->trans("Module56000Name"), 0, - "ticketsup@ticketsup" + "ticketsup" ); print '

    ' . $langs->trans("TicketsupSetupDictionaries") . ' : ' . dol_buildpath('/admin/dict.php', 2) . '

    '; @@ -546,7 +546,7 @@ if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) { // Email d'envoi des notifications print '' . $langs->trans("TicketEmailNotificationFrom") . ''; print ''; -print ''; +print ''; print ''; print $form->textwithpicto('', $langs->trans("TicketEmailNotificationFromHelp"), 1, 'help'); print ''; From ad05ddfe5c1fd0987c40df2ccd5cabc501d76bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 11 Mar 2018 20:42:39 +0100 Subject: [PATCH 024/126] Update ticketsup_extrafields.php --- htdocs/admin/ticketsup_extrafields.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/ticketsup_extrafields.php b/htdocs/admin/ticketsup_extrafields.php index 6a6a36a3bf8..09fe827ca7c 100644 --- a/htdocs/admin/ticketsup_extrafields.php +++ b/htdocs/admin/ticketsup_extrafields.php @@ -26,7 +26,7 @@ require_once DOL_DOCUMENT_ROOT."/core/lib/ticketsup.lib.php"; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); $langs->load("admin"); $extrafields = new ExtraFields($db); @@ -50,11 +50,7 @@ if (!$user->admin) { /* * Actions */ -if (versioncompare(versiondolibarrarray(), array(3, 5, 0)) > 0) { - include DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php'; -} elseif (versioncompare(versiondolibarrarray(), array(3, 4, 0)) > 0) { - include DOL_DOCUMENT_ROOT . '/core/admin_extrafields.inc.php'; -} +include DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php'; /* * View @@ -74,9 +70,9 @@ $head = ticketsupAdminPrepareHead(); dol_fiche_head( $head, 'attributes', - $langs->trans("Module110120Name"), + $langs->trans("Module56000Name"), 0, - "ticketsup@ticketsup" + "ticketsup" ); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; From 683486eaf1a6d2b811fbbab8544d2cd1bad8ecfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 11 Mar 2018 21:00:39 +0100 Subject: [PATCH 025/126] Update html.formticketsup.class.php --- htdocs/core/class/html.formticketsup.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 52b470c0929..08dbc4e0fe6 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -499,7 +499,7 @@ class FormTicketsup } print ''; if ($user->admin && !$noadmininfo) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1); + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } @@ -597,7 +597,7 @@ class FormTicketsup } print ''; if ($user->admin && !$noadmininfo) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1); + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } @@ -694,7 +694,7 @@ class FormTicketsup } print ''; if ($user->admin && !$noadmininfo) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1); + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } From e1654f4215b3613940887a51499759e11651aa6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 21:18:18 +0100 Subject: [PATCH 026/126] Fix division by zero --- htdocs/compta/tva/quadri_detail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index c622881d273..d4ccbf98804 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -447,7 +447,7 @@ else $ratiopaymentinvoice=1; if ($modetax == 0) { - if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); print ''; //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; if ($fields['payment_amount'] && $fields['ftotal_ttc']) From 51c94fadfa8f1405f7164af90c1a81cbbaadc66b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 21:31:34 +0100 Subject: [PATCH 027/126] Look and feel v7 --- htdocs/admin/taxes.php | 18 +++++++++++++----- htdocs/langs/en_US/compta.lang | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/htdocs/admin/taxes.php b/htdocs/admin/taxes.php index a4aa1afbd8c..391f3c38cc7 100644 --- a/htdocs/admin/taxes.php +++ b/htdocs/admin/taxes.php @@ -113,13 +113,14 @@ if ($action == 'update') { */ llxHeader(); + $form=new Form($db); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans('TaxSetup'),$linkback,'title_setup'); -dol_fiche_head(); +dol_fiche_head(null, '0', '', -1); if (empty($mysoc->tva_assuj)) { @@ -127,6 +128,8 @@ if (empty($mysoc->tva_assuj)) } else { + print '
    '; + print ''; // Cas des parametres TAX_MODE_SELL/BUY_SERVICE/PRODUCT @@ -146,7 +149,7 @@ else print "
    \n"; print '
    '; - print load_fiche_titre($langs->trans("SummaryOfVatExigibilityUsedByDefault"),'',''); + print ' -> '.$langs->trans("SummaryOfVatExigibilityUsedByDefault"); //print ' ('.$langs->trans("CanBeChangedWhenMakingInvoice").')'; print ''; @@ -195,22 +198,27 @@ else print "
    \n"; + + /* * Others params */ + +print load_fiche_titre($langs->trans("OtherOptions"),'',''); + print '
    '; print ''; -print ''; +print ''; print "\n"; foreach ($list as $key) { - + print ''; // Param - $label = $langs->trans($key); + $label = $langs->trans($key); print ''; // Value diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index d1413fb0454..e476c951123 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -31,7 +31,7 @@ Credit=Credit Piece=Accounting Doc. AmountHTVATRealReceived=Net collected AmountHTVATRealPaid=Net paid -VATToPay=VAT sells +VATToPay=Tax sales VATReceived=Tax received VATToCollect=Tax purchases VATSummary=Tax Balance From c0d4ca3682c282d0c1cbb42cb28776ab8884861b Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 11 Mar 2018 22:28:27 +0100 Subject: [PATCH 028/126] Fix : Remove two langs->load("sendings") and use loadLangs instead --- htdocs/commande/card.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index a35f89f9038..44375df6dc8 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -56,15 +56,7 @@ if (!empty($conf->variants->enabled)) { require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; } -$langs->load('orders'); -$langs->load('sendings'); -$langs->load('companies'); -$langs->load('bills'); -$langs->load('propal'); -$langs->load('deliveries'); -$langs->load('sendings'); -$langs->load('products'); -$langs->load('other'); +$langs->loadLangs(array('orders','sendings','companies','bills','propal','deliveries','products','other')); if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); if (! empty($conf->margin->enabled)) $langs->load('margins'); if (! empty($conf->productbatch->enabled)) $langs->load("productbatch"); From d1fbf2a80eda51f06e63d37210c0c65580d66a84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:07:57 +0100 Subject: [PATCH 029/126] Dolibarrize --- htdocs/public/ticketsup/create_ticket.php | 30 ++++---------------- htdocs/public/ticketsup/index.php | 29 ++++--------------- htdocs/public/ticketsup/view.php | 34 ++++++----------------- 3 files changed, 19 insertions(+), 74 deletions(-) diff --git a/htdocs/public/ticketsup/create_ticket.php b/htdocs/public/ticketsup/create_ticket.php index 867658b48ac..bc5fc584219 100644 --- a/htdocs/public/ticketsup/create_ticket.php +++ b/htdocs/public/ticketsup/create_ticket.php @@ -45,30 +45,12 @@ if (!defined('NOREQUIREHTML')) { define("NOLOGIN", 1); // This means this output page does not require to be logged. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. -// Change this following line to use the correct relative path (../, ../../, etc) -$res = 0; -if (!$res && file_exists("../main.inc.php")) { - $res = @include "../main.inc.php"; -} - -if (!$res && file_exists("../../main.inc.php")) { - $res = @include "../../main.inc.php"; -} - -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include "../../../main.inc.php"; -} - -if (!$res) { - die("Include of main fails"); -} - -dol_include_once('/ticketsup/class/ticketsup.class.php'); -dol_include_once('/ticketsup/class/html.formticketsup.class.php'); -dol_include_once('/ticketsup/lib/ticketsup.lib.php'); - -require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Load traductions files requiredby by page $langs->load("companies"); diff --git a/htdocs/public/ticketsup/index.php b/htdocs/public/ticketsup/index.php index ed141b32922..f913ce9c70d 100644 --- a/htdocs/public/ticketsup/index.php +++ b/htdocs/public/ticketsup/index.php @@ -42,30 +42,11 @@ if (!defined("NOLOGIN")) { } // If this page is public (can be called outside logged session) -// Change this following line to use the correct relative path (../, ../../, etc) -$res = 0; -if (!$res && file_exists("../main.inc.php")) { - $res = @include '../main.inc.php'; -} - -if (!$res && file_exists("../../main.inc.php")) { - $res = @include '../../main.inc.php'; -} - -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include '../../../main.inc.php'; -} - -if (!$res) { - die("Include of main fails"); -} - -require_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php'; - -// Change this following line to use the correct relative path from htdocs -dol_include_once('/ticketsup/class/ticketsup.class.php'); -dol_include_once('/ticketsup/class/html.formticketsup.class.php'); -dol_include_once('/ticketsup/lib/ticketsup.lib.php'); +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); diff --git a/htdocs/public/ticketsup/view.php b/htdocs/public/ticketsup/view.php index 036d1d17b86..68e18e67d14 100644 --- a/htdocs/public/ticketsup/view.php +++ b/htdocs/public/ticketsup/view.php @@ -17,8 +17,8 @@ /** * \file ticketsup/public/index.php - * \ingroup ticketsup - * \brief Public file to add and manage ticket + * \ingroup ticketsup + * \brief Public file to add and manage ticket */ if (!defined('NOCSRFCHECK')) { @@ -34,28 +34,10 @@ if (!defined("NOLOGIN")) { } // If this page is public (can be called outside logged session) -// Change this following line to use the correct relative path (../, ../../, etc) -$res = 0; -if (!$res && file_exists("../main.inc.php")) { - $res = @include '../main.inc.php'; -} - -if (!$res && file_exists("../../main.inc.php")) { - $res = @include '../../main.inc.php'; -} - -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include '../../../main.inc.php'; -} - -if (!$res) { - die("Include of main fails"); -} - -// Change this following line to use the correct relative path from htdocs -dol_include_once('/ticketsup/class/actions_ticketsup.class.php'); -dol_include_once('/ticketsup/class/html.formticketsup.class.php'); -dol_include_once('/ticketsup/lib/ticketsup.lib.php'); +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); @@ -300,13 +282,13 @@ if ($action == "view_ticket" || $action == "add_message" || $action == "close" | print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticketsup'); $object->viewTicketMessages(false); - print '
    '; + print '
    '; // Logs list print load_fiche_titre($langs->trans('TicketHistory'), '', 'history@ticketsup'); $object->viewTicketLogs(false); } else { - print ''; + print ''; } } else { print '

    ' . $langs->trans("TicketPublicMsgViewLogIn") . '

    '; From b5ca4ca3915614150edf78a78253d967e38fdf71 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:19:43 +0100 Subject: [PATCH 030/126] PHPunit --- test/phpunit/TicketsupTest.php | 82 +++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/test/phpunit/TicketsupTest.php b/test/phpunit/TicketsupTest.php index d45c72b14d5..9e807b855db 100644 --- a/test/phpunit/TicketsupTest.php +++ b/test/phpunit/TicketsupTest.php @@ -25,20 +25,20 @@ namespace test\unit; global $conf,$user,$langs,$db; -//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver +//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //require_once 'PHPUnit/Autoload.php'; -$res = false; -if (file_exists(dirname(__FILE__).'/../../../../htdocs/master.inc.php')) { - $res = require_once dirname(__FILE__).'/../../../../htdocs/master.inc.php'; -} elseif (file_exists(dirname(__FILE__).'/../../../../../htdocs/master.inc.php')) { - $res = require_once dirname(__FILE__).'/../../../../../htdocs/master.inc.php'; -} else { - die('Include of mains fails'); +require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/user/class/usergroup.class.php'; +require_once dirname(__FILE__).'/../../htdocs/ticketsup/class/ticketsup.class.php'; + +if (empty($user->id)) { + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } +$conf->global->MAIN_DISABLE_ALL_MAILS=1; -require_once dirname(__FILE__).'/../../class/ticketsup.class.php'; - if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; @@ -144,10 +144,10 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $localobject->initAsSpecimen(); $localobject->fk_statut = '\'1=1'; $result=$localobject->create($user); - + print __METHOD__." result=".$result."\n"; $this->assertEquals($result, -1); - + // Try to create one with correct values $localobject=new \Ticketsup($this->savdb); $localobject->initAsSpecimen(); @@ -155,7 +155,7 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertLessThan($result, 0); - + return $result; } @@ -209,7 +209,7 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupsetProject * @@ -226,16 +226,16 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $project_id = 1; - + $result=$localobject->setProject($project_id); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupsetContract * @@ -252,16 +252,16 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $contract_id = 1; - + $result=$localobject->setContract($contract_id); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupsetProgression * @@ -278,16 +278,16 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $percent = 80; $result=$localobject->setProgression($percent); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupassignUser * @@ -304,17 +304,17 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $user_id_to_assign = 1; - + $result=$localobject->assignUser($user, $user_id_to_assign); ; print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupassignUserOther * @@ -331,17 +331,17 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $user_id_to_assign = 2; - + $result=$localobject->assignUser($user, $user_id_to_assign); ; print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } - + /** * testTicketsupcreateTicketLog * @@ -358,13 +358,13 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - - + + $message = 'Test ticket log'; $noemail = 1; $result=$localobject->createTicketLog($user, $message, $noemail); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject; } @@ -385,15 +385,15 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $result=$localobject->close(); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - + $this->assertLessThan($result, 0); return $localobject->id; } - - + + /** * testTicketsupDelete * @@ -405,7 +405,7 @@ class TicketsupTest extends \PHPUnit_Framework_TestCase */ public function testTicketsupDelete($id) { - + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; From 6da3fbe3c9898d28b0c4f3107463c5bc11f28a18 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:21:14 +0100 Subject: [PATCH 031/126] Translation --- htdocs/langs/en_US/ticketsup.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index b50116c4997..986a1882936 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -19,7 +19,7 @@ # Module56000Name=Tickets -Module56000Desc=Ticket system for incident management +Module56000Desc=Ticket system for issue or request management Permission56001=See tickets Permission56002=Modify tickets From 6ac070823f3476b3a62a2727887328f08cbb900c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:22:55 +0100 Subject: [PATCH 032/126] Fix phpcs --- htdocs/ticketsup/class/actions_ticketsup.class.php | 12 ++++++------ htdocs/ticketsup/tpl/linkedobjectblock.tpl.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/ticketsup/class/actions_ticketsup.class.php b/htdocs/ticketsup/class/actions_ticketsup.class.php index c87264098ef..5ab3fabaffd 100644 --- a/htdocs/ticketsup/class/actions_ticketsup.class.php +++ b/htdocs/ticketsup/class/actions_ticketsup.class.php @@ -774,7 +774,7 @@ class ActionsTicketsup $message = $message_intro . $message; // Add signature - $message .= '
    ' . $message_signature; + $message .= '
    ' . $message_signature; if (!empty($this->dao->origin_email)) { $sendto[] = $this->dao->origin_email; @@ -1118,7 +1118,7 @@ class ActionsTicketsup $userstat = new User($this->db); $res = $userstat->fetch($arraylogs['fk_user_create']); if ($res) { - print '
    '.$userstat->getNomUrl(1).''; + print '
    '.$userstat->getNomUrl(1).''; } } } @@ -1296,11 +1296,11 @@ class ActionsTicketsup $userstat = new User($this->db); $res = $userstat->fetch($arraymsgs['fk_user_action']); if ($res) { - print '
    '; + print '
    '; print $userstat->getNomUrl(1); } } else { - print '
    '; + print '
    '; print $langs->trans('Customer'); } } @@ -1496,7 +1496,7 @@ class ActionsTicketsup // Sort results to be similar to status object list sort($exclude_status); - //print '
    '; + //print '
    '; foreach ($this->dao->statuts_short as $status => $statut_label) { if (!in_array($status, $exclude_status)) { print '
    '; @@ -1506,7 +1506,7 @@ class ActionsTicketsup print '
    '; } } - print '

    '; + print '
    '; } diff --git a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php index 4c1a00c3d82..dc03dd32c3c 100644 --- a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php +++ b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php @@ -31,7 +31,7 @@ if (empty($conf) || ! is_object($conf)) $langs = $GLOBALS['langs']; $langs->load('ticketsup@ticketsup'); $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; -echo '
    '; +echo '
    '; print_titre($langs->trans('RelatedTickets')); ?>
    ' . $langs->trans('OtherOptions') . '' . $langs->trans('Parameters') . '
    From 1ede43971d813a8849323a9222f9172bd4ec030b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:40:25 +0100 Subject: [PATCH 033/126] Dolibarrize module ticket --- .../boxes/box_last_modified_ticketsup.php | 2 +- htdocs/core/boxes/box_last_ticketsup.php | 2 +- .../core/class/html.formticketsup.class.php | 2 +- htdocs/core/class/translate.class.php | 4 +-- htdocs/core/lib/ticketsup.lib.php | 2 +- htdocs/core/modules/modTicketsup.class.php | 22 +++++++------- htdocs/core/modules/modules_ticketsup.php | 4 +-- .../ticketsup/mod_ticketsup_universal.php | 2 +- ...face_50_modTicketsup_TicketEmail.class.php | 4 +-- htdocs/langs/en_US/ticketsup.lang | 2 +- htdocs/public/ticketsup/create_ticket.php | 2 +- htdocs/public/ticketsup/index.php | 2 +- htdocs/public/ticketsup/list.php | 2 +- htdocs/public/ticketsup/view.php | 2 +- htdocs/ticketsup/card.php | 4 +-- htdocs/ticketsup/class/ticketsup.class.php | 8 ++--- htdocs/ticketsup/contacts.php | 4 +-- htdocs/ticketsup/document.php | 3 +- htdocs/ticketsup/history.php | 4 +-- htdocs/ticketsup/index.php | 30 +++++++++---------- .../ticketsup/tpl/linkedobjectblock.tpl.php | 4 +-- 21 files changed, 56 insertions(+), 55 deletions(-) diff --git a/htdocs/core/boxes/box_last_modified_ticketsup.php b/htdocs/core/boxes/box_last_modified_ticketsup.php index 08bf47ad46c..fd49653eced 100644 --- a/htdocs/core/boxes/box_last_modified_ticketsup.php +++ b/htdocs/core/boxes/box_last_modified_ticketsup.php @@ -31,7 +31,7 @@ class box_last_modified_ticketsup extends ModeleBoxes { public $boxcode = "box_last_modified_ticketsup"; - public $boximg = "ticketsup@ticketsup"; + public $boximg = "ticketsup"; public $boxlabel; public $depends = array("ticketsup"); public $db; diff --git a/htdocs/core/boxes/box_last_ticketsup.php b/htdocs/core/boxes/box_last_ticketsup.php index 3eecceb74ae..6044bb179f5 100644 --- a/htdocs/core/boxes/box_last_ticketsup.php +++ b/htdocs/core/boxes/box_last_ticketsup.php @@ -31,7 +31,7 @@ class box_last_ticketsup extends ModeleBoxes { public $boxcode = "box_last_ticketsup"; - public $boximg = "ticketsup@ticketsup"; + public $boximg = "ticketsup"; public $boxlabel; public $depends = array("ticketsup"); public $db; diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 08dbc4e0fe6..d504a846507 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -122,7 +122,7 @@ class FormTicketsup $langs->load("other"); $langs->load("mails"); - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $form = new Form($this->db); $formcompany = new FormCompany($this->db); diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 69fe031459d..62abbbbcc18 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -205,7 +205,7 @@ class Translate // Check cache if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain { - //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); + dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); return 0; } @@ -231,7 +231,7 @@ class Translate $filelangexists=is_file($file_lang_osencoded); - //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); + dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); if ($filelangexists) { diff --git a/htdocs/core/lib/ticketsup.lib.php b/htdocs/core/lib/ticketsup.lib.php index b25f3d1a4cd..ca27e9e8024 100644 --- a/htdocs/core/lib/ticketsup.lib.php +++ b/htdocs/core/lib/ticketsup.lib.php @@ -31,7 +31,7 @@ function ticketsupAdminPrepareHead() { global $langs, $conf; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $h = 0; $head = array(); diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index 38299617788..7e824cdf47b 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -74,7 +74,7 @@ class modTicketsup extends DolibarrModules // use this->picto='pictovalue' // If file is in module/img directory under name object_pictovalue.png // use this->picto='pictovalue@module' - $this->picto = 'ticketsup@ticketsup'; // mypicto@ticketsup + $this->picto = 'ticketsup'; // mypicto@ticketsup // Defined all module parts (triggers, login, substitutions, menus, css, etc...) // for default path (eg: /ticketsup/core/xxxxx) (0=disable, 1=enable) // for specific path of parts (eg: /ticketsup/core/modules/barcode) @@ -135,7 +135,7 @@ class modTicketsup extends DolibarrModules $conf->ticketsup->enabled=0; } $this->dictionaries = array( - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'tabname' => array(MAIN_DB_PREFIX . "c_ticketsup_type", MAIN_DB_PREFIX . "c_ticketsup_category", MAIN_DB_PREFIX . "c_ticketsup_severity"), 'tablib' => array("TicketsupDictType", "TicketsupDictCategory", "TicketsupDictSeverity"), 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_type as f', 'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_category as f', 'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_severity as f'), @@ -153,10 +153,10 @@ class modTicketsup extends DolibarrModules $r = 0; // Example: - $this->boxes[$r][1] = "box_last_ticketsup@ticketsup"; + $this->boxes[$r][1] = "box_last_ticketsup"; $r++; - $this->boxes[$r][1] = "box_last_modified_ticketsup@ticketsup"; + $this->boxes[$r][1] = "box_last_modified_ticketsup"; $r++; // Permissions @@ -209,7 +209,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor. 'url' => '/ticketsup/index.php', - 'langs' => 'ticketsup@ticketsup', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'langs' => 'ticketsup', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position' => 100, 'enabled' => '1', // Define condition to show or hide menu entry. Use '$conf->ticketsup->enabled' if entry must be visible if module is enabled. 'perms' => '$user->rights->ticketsup->read', // Use 'perms'=>'$user->rights->ticketsup->level1->level2' if you want your menu with a permission rules @@ -223,7 +223,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsup', 'url' => '/ticketsup/index.php', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 101, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -236,7 +236,7 @@ class modTicketsup extends DolibarrModules 'titre' => 'NewTicket', 'mainmenu' => 'ticketsup', 'url' => '/ticketsup/new.php?action=create_ticket', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 102, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->write', @@ -250,7 +250,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsuplist', 'url' => '/ticketsup/list.php', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 103, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -264,7 +264,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsuplist', 'url' => '/ticketsup/list.php?search_fk_status=non_closed', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 104, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -278,7 +278,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsupmy', 'url' => '/ticketsup/list.php?mode=my_assign', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 105, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -291,7 +291,7 @@ class modTicketsup extends DolibarrModules 'titre' => 'MenuTicketsupMyAssignNonClosed', 'mainmenu' => 'ticketsup', 'url' => '/ticketsup/list.php?mode=my_assign&search_fk_status=non_closed', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 106, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', diff --git a/htdocs/core/modules/modules_ticketsup.php b/htdocs/core/modules/modules_ticketsup.php index 9eb652c31f4..e6e47adaa9f 100644 --- a/htdocs/core/modules/modules_ticketsup.php +++ b/htdocs/core/modules/modules_ticketsup.php @@ -49,7 +49,7 @@ abstract class ModeleNumRefTicketsup public function info() { global $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); return $langs->trans("NoDescription"); } @@ -61,7 +61,7 @@ abstract class ModeleNumRefTicketsup public function getExample() { global $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); return $langs->trans("NoExample"); } diff --git a/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php b/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php index 8c0c8c8fe0c..881ba5a7f15 100644 --- a/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php +++ b/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php @@ -43,7 +43,7 @@ class mod_ticketsup_universal extends ModeleNumRefTicketsup { global $conf, $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $langs->load("admin"); $form = new Form($this->db); diff --git a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php index 1990f184f84..16b317cc108 100644 --- a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php @@ -50,7 +50,7 @@ class InterfaceTicketEmail extends DolibarrTriggers $this->family = "ticketsup"; $this->description = "Triggers of the module ticketsup"; $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'ticketsup@ticketsup'; + $this->picto = 'ticketsup'; } /** @@ -176,7 +176,7 @@ class InterfaceTicketEmail extends DolibarrTriggers $filename = array(); $mimetype = array(); - $langs->load('ticketsup@ticketsup'); + $langs->load('ticketsup'); $object->fetch('', $object->track_id); diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index 986a1882936..8187e8220d9 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -180,7 +180,7 @@ TicketMessageSuccessfullyAdded=Message successfully added TicketMessagesList=Message list NoMsgForThisTicket=No message for this ticket Properties=Classification -LastNewTickets=Last %s tickets newest (not read) +LatestNewTickets=Last %s tickets newest (not read) TicketSeverity=Severity ShowTicket=See ticket RelatedTickets=Related tickets diff --git a/htdocs/public/ticketsup/create_ticket.php b/htdocs/public/ticketsup/create_ticket.php index bc5fc584219..a0cb6f787ac 100644 --- a/htdocs/public/ticketsup/create_ticket.php +++ b/htdocs/public/ticketsup/create_ticket.php @@ -56,7 +56,7 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $langs->load("companies"); $langs->load("other"); $langs->load("mails"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); diff --git a/htdocs/public/ticketsup/index.php b/htdocs/public/ticketsup/index.php index f913ce9c70d..8352282c4af 100644 --- a/htdocs/public/ticketsup/index.php +++ b/htdocs/public/ticketsup/index.php @@ -51,7 +51,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); $langs->load("errors"); // Get parameters diff --git a/htdocs/public/ticketsup/list.php b/htdocs/public/ticketsup/list.php index adea8def5ea..34413168bc0 100644 --- a/htdocs/public/ticketsup/list.php +++ b/htdocs/public/ticketsup/list.php @@ -42,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $track_id = GETPOST('track_id', 'alpha'); diff --git a/htdocs/public/ticketsup/view.php b/htdocs/public/ticketsup/view.php index 68e18e67d14..c0069d9f6ee 100644 --- a/htdocs/public/ticketsup/view.php +++ b/htdocs/public/ticketsup/view.php @@ -42,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $track_id = GETPOST('track_id', 'alpha'); diff --git a/htdocs/ticketsup/card.php b/htdocs/ticketsup/card.php index b5ffa4b63d8..5bf64d34cc8 100644 --- a/htdocs/ticketsup/card.php +++ b/htdocs/ticketsup/card.php @@ -48,7 +48,7 @@ if (!class_exists('Contact')) { // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); @@ -208,7 +208,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } $head = ticketsup_prepare_head($object->dao); - dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), 0, 'ticketsup'); $object->dao->label = $object->dao->ref; // Author if ($object->dao->fk_user_create > 0) { diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index e507e2e89a7..902bb6943ef 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -53,7 +53,7 @@ class Ticketsup extends CommonObject /** * @var string String with name of icon for ticketsupcore. Must be the part after the 'object_' into object_ticketsupcore.png */ - public $picto = 'ticketsup@ticketsup'; + public $picto = 'ticketsup'; /** @@ -1309,9 +1309,9 @@ class Ticketsup extends CommonObject $lien = ''; $lienfin = ''; - $picto = 'ticketsup@ticketsup'; + $picto = 'ticketsup'; if (!$this->public) { - $picto = 'ticketsup@ticketsup'; + $picto = 'ticketsup'; } $label = $langs->trans("ShowTicket") . ': ' . $this->ref . ' - ' . $this->subject; @@ -1501,7 +1501,7 @@ class Ticketsup extends CommonObject $nb_sent = 0; - $langs->load('ticketsup@ticketsup'); + $langs->load('ticketsup'); // Retrieve email of all contacts (internal and external) $contacts = $this->listeContact(-1, 'internal'); diff --git a/htdocs/ticketsup/contacts.php b/htdocs/ticketsup/contacts.php index 72b72ac0e57..9ef592b22a7 100644 --- a/htdocs/ticketsup/contacts.php +++ b/htdocs/ticketsup/contacts.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; // Load traductions files requiredby by page $langs->load("companies"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $socid = GETPOST("socid", 'int'); @@ -144,7 +144,7 @@ if ($id > 0 || !empty($track_id) || !empty($ref)) { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object); - dol_fiche_head($head, 'tabTicketContacts', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketContacts', $langs->trans("Ticket"), 0, 'ticketsup'); $object->label = $object->ref; // Author if ($object->fk_user_create > 0) { diff --git a/htdocs/ticketsup/document.php b/htdocs/ticketsup/document.php index f9d96beaf1f..f221dce73c2 100644 --- a/htdocs/ticketsup/document.php +++ b/htdocs/ticketsup/document.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; $langs->load("companies"); $langs->load('other'); +$langs->load("ticketsup"); $action = GETPOST('action'); $confirm = GETPOST('confirm'); @@ -122,7 +123,7 @@ if ($object->id) { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object); - dol_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticketsup'); $object->label = $object->ref; // Author if ($object->fk_user_create > 0) { diff --git a/htdocs/ticketsup/history.php b/htdocs/ticketsup/history.php index 48ba39a2b02..9bd69ade897 100644 --- a/htdocs/ticketsup/history.php +++ b/htdocs/ticketsup/history.php @@ -36,7 +36,7 @@ if (!class_exists('Contact')) { // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); @@ -102,7 +102,7 @@ if ($action == 'view') { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object->dao); - dol_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticketsup'); $object->dao->label = $object->dao->ref; // Author if ($object->dao->fk_user_create > 0) { diff --git a/htdocs/ticketsup/index.php b/htdocs/ticketsup/index.php index 505812f84c6..e596d9149c1 100644 --- a/htdocs/ticketsup/index.php +++ b/htdocs/ticketsup/index.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); $WIDTH = DolGraph::getDefaultGraphSizeForStats('width'); $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); @@ -55,17 +55,17 @@ $endyear = $year; $object = new ActionsTicketsup($db); -/******************************************************************* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ -/*************************************************** - * PAGE - * - * Put here all code to build page - ****************************************************/ +/* + * Actions + */ + +// None + + +/* + * View + */ llxHeader('', $langs->trans('TicketsIndex'), ''); @@ -241,10 +241,10 @@ if (count($dataseries) >1) { $px1->SetCssPrefix("cssboxes"); $px1->mode = 'depth'; //$px1->SetTitle($langs->trans("TicketStatByStatus")); - + $px1->draw($filenamenb, $fileurlnb); print $px1->show(); - + print $stringtoshow; } } @@ -295,7 +295,7 @@ if ($result) { $i = 0; - $transRecordedType = $langs->trans("LastNewTickets", $max); + $transRecordedType = $langs->trans("LatestNewTickets", $max); print '
    '; print ''; print ''; @@ -347,7 +347,7 @@ if ($result) { $db->free(); } else { - print ''; + print ''; } print "
    ' . $transRecordedType . '' . $langs->trans('Ref') . '
    ' . $langs->trans('NoTicketsFound') . '
    ' . $langs->trans('NoTicketsFound') . '
    "; diff --git a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php index dc03dd32c3c..824f392d638 100644 --- a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php +++ b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php @@ -29,7 +29,7 @@ if (empty($conf) || ! is_object($conf)) load('ticketsup@ticketsup'); +$langs->load('ticketsup'); $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; echo '
    '; print_titre($langs->trans('RelatedTickets')); @@ -47,7 +47,7 @@ foreach ($linkedObjectBlock as $object) { subject) ? ' '.$object->subject : ''); ?> + trans("ShowTicket"), "ticketsup") . ' ' . (! empty($object->subject) ? ' '.$object->subject : ''); ?> datec, 'day'); ?> From ae82d045f8f23ad77b17551c1e4123b17c6bb5a3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Mar 2018 23:40:25 +0100 Subject: [PATCH 034/126] Dolibarrize module ticket --- htdocs/admin/ticketsup.php | 28 ++++++++--------- htdocs/admin/ticketsup_extrafields.php | 14 ++++----- .../boxes/box_last_modified_ticketsup.php | 2 +- htdocs/core/boxes/box_last_ticketsup.php | 2 +- .../core/class/html.formticketsup.class.php | 6 ++-- htdocs/core/class/translate.class.php | 4 +-- htdocs/core/lib/ticketsup.lib.php | 2 +- htdocs/core/modules/modTicketsup.class.php | 22 +++++++------- htdocs/core/modules/modules_ticketsup.php | 4 +-- .../ticketsup/mod_ticketsup_universal.php | 2 +- ...face_50_modTicketsup_TicketEmail.class.php | 4 +-- .../install/mysql/migration/7.0.0-8.0.0.sql | 1 + htdocs/install/mysql/tables/llx_ticketsup.sql | 3 +- htdocs/langs/en_US/ticketsup.lang | 2 +- htdocs/public/ticketsup/create_ticket.php | 2 +- htdocs/public/ticketsup/index.php | 2 +- htdocs/public/ticketsup/list.php | 2 +- htdocs/public/ticketsup/view.php | 2 +- htdocs/ticketsup/card.php | 4 +-- htdocs/ticketsup/class/ticketsup.class.php | 8 ++--- htdocs/ticketsup/contacts.php | 4 +-- htdocs/ticketsup/document.php | 3 +- htdocs/ticketsup/history.php | 4 +-- htdocs/ticketsup/index.php | 30 +++++++++---------- htdocs/ticketsup/list.php | 19 +++++------- htdocs/ticketsup/new.php | 25 ++++++++-------- .../ticketsup/tpl/linkedobjectblock.tpl.php | 4 +-- 27 files changed, 101 insertions(+), 104 deletions(-) diff --git a/htdocs/admin/ticketsup.php b/htdocs/admin/ticketsup.php index f0dfb8c690a..4f6839d1e59 100644 --- a/htdocs/admin/ticketsup.php +++ b/htdocs/admin/ticketsup.php @@ -18,14 +18,15 @@ /** * \file admin/ticketsup.php - * \ingroup ticketsup - * \brief This file is a module setup page + * \ingroup ticketsup + * \brief This file is a module setup page */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT."/ticketsup/class/ticketsup.class.php"; require_once DOL_DOCUMENT_ROOT."/core/lib/ticketsup.lib.php"; + // Translations $langs->load("ticketsup"); @@ -214,9 +215,12 @@ if ($action == 'setvarother') { } } + + /* * View */ + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $form = new Form($db); @@ -226,28 +230,22 @@ $page_name = "TicketsupSetup"; llxHeader('', $langs->trans($page_name), $help_url); // Subheader -$linkback = '' -. $langs->trans("BackToModuleList") . ''; -print load_fiche_titre($langs->trans($page_name), $linkback); +$linkback = '' . $langs->trans("BackToModuleList") . ''; + +print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); // Configuration header $head = ticketsupAdminPrepareHead(); -dol_fiche_head( - $head, - 'settings', - $langs->trans("Module56000Name"), - 0, - "ticketsup" -); -print '

    ' . $langs->trans("TicketsupSetupDictionaries") . ' : ' . dol_buildpath('/admin/dict.php', 2) . '

    '; +dol_fiche_head($head, 'settings', $langs->trans("Module56000Name"), -1, "ticketsup"); -print '

    ' . $langs->trans("TicketsupPublicAccess") . ' : ' . dol_buildpath('/ticketsup/public/index.php', 2) . '

    '; +print $langs->trans("TicketsupSetupDictionaries") . ' : ' . dol_buildpath('/admin/dict.php', 2) . '
    '; -//print '

    '. $langs->trans("TicketsupSetupPage").'

    '; +print $langs->trans("TicketsupPublicAccess") . ' : ' . dol_buildpath('/ticketsup/public/index.php', 2) . ''; dol_fiche_end(); + /* * Projects Numbering model */ diff --git a/htdocs/admin/ticketsup_extrafields.php b/htdocs/admin/ticketsup_extrafields.php index 09fe827ca7c..5709472e858 100644 --- a/htdocs/admin/ticketsup_extrafields.php +++ b/htdocs/admin/ticketsup_extrafields.php @@ -47,11 +47,15 @@ if (!$user->admin) { accessforbidden(); } + /* * Actions */ + include DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php'; + + /* * View */ @@ -63,17 +67,11 @@ $page_name = "TicketsupSetup"; llxHeader('', $langs->trans($page_name), $help_url); $linkback = '' . $langs->trans("BackToModuleList") . ''; -print load_fiche_titre($langs->trans("TicketsupSetup"), $linkback, 'setup'); +print load_fiche_titre($langs->trans("TicketsupSetup"), $linkback, 'title_setup'); $head = ticketsupAdminPrepareHead(); -dol_fiche_head( - $head, - 'attributes', - $langs->trans("Module56000Name"), - 0, - "ticketsup" -); +dol_fiche_head($head, 'attributes', $langs->trans("Module56000Name"), -1, "ticketsup"); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/core/boxes/box_last_modified_ticketsup.php b/htdocs/core/boxes/box_last_modified_ticketsup.php index 08bf47ad46c..fd49653eced 100644 --- a/htdocs/core/boxes/box_last_modified_ticketsup.php +++ b/htdocs/core/boxes/box_last_modified_ticketsup.php @@ -31,7 +31,7 @@ class box_last_modified_ticketsup extends ModeleBoxes { public $boxcode = "box_last_modified_ticketsup"; - public $boximg = "ticketsup@ticketsup"; + public $boximg = "ticketsup"; public $boxlabel; public $depends = array("ticketsup"); public $db; diff --git a/htdocs/core/boxes/box_last_ticketsup.php b/htdocs/core/boxes/box_last_ticketsup.php index 3eecceb74ae..6044bb179f5 100644 --- a/htdocs/core/boxes/box_last_ticketsup.php +++ b/htdocs/core/boxes/box_last_ticketsup.php @@ -31,7 +31,7 @@ class box_last_ticketsup extends ModeleBoxes { public $boxcode = "box_last_ticketsup"; - public $boximg = "ticketsup@ticketsup"; + public $boximg = "ticketsup"; public $boxlabel; public $depends = array("ticketsup"); public $db; diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 08dbc4e0fe6..2bf41921793 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -122,7 +122,7 @@ class FormTicketsup $langs->load("other"); $langs->load("mails"); - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $form = new Form($this->db); $formcompany = new FormCompany($this->db); @@ -148,6 +148,7 @@ class FormTicketsup } print ''; + print '
    '; print ''; @@ -194,7 +195,7 @@ class FormTicketsup } }); }); - + function runJsCodeForEvent'.$htmlname.'(obj) { console.log("Run runJsCodeForEvent'.$htmlname.'"); var id = $("#'.$htmlname.'").val(); @@ -392,6 +393,7 @@ class FormTicketsup } print '
    '; + print '
    '; print '
    '; print ''; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 69fe031459d..62abbbbcc18 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -205,7 +205,7 @@ class Translate // Check cache if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain { - //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); + dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); return 0; } @@ -231,7 +231,7 @@ class Translate $filelangexists=is_file($file_lang_osencoded); - //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); + dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); if ($filelangexists) { diff --git a/htdocs/core/lib/ticketsup.lib.php b/htdocs/core/lib/ticketsup.lib.php index b25f3d1a4cd..ca27e9e8024 100644 --- a/htdocs/core/lib/ticketsup.lib.php +++ b/htdocs/core/lib/ticketsup.lib.php @@ -31,7 +31,7 @@ function ticketsupAdminPrepareHead() { global $langs, $conf; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $h = 0; $head = array(); diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index 38299617788..7e824cdf47b 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -74,7 +74,7 @@ class modTicketsup extends DolibarrModules // use this->picto='pictovalue' // If file is in module/img directory under name object_pictovalue.png // use this->picto='pictovalue@module' - $this->picto = 'ticketsup@ticketsup'; // mypicto@ticketsup + $this->picto = 'ticketsup'; // mypicto@ticketsup // Defined all module parts (triggers, login, substitutions, menus, css, etc...) // for default path (eg: /ticketsup/core/xxxxx) (0=disable, 1=enable) // for specific path of parts (eg: /ticketsup/core/modules/barcode) @@ -135,7 +135,7 @@ class modTicketsup extends DolibarrModules $conf->ticketsup->enabled=0; } $this->dictionaries = array( - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'tabname' => array(MAIN_DB_PREFIX . "c_ticketsup_type", MAIN_DB_PREFIX . "c_ticketsup_category", MAIN_DB_PREFIX . "c_ticketsup_severity"), 'tablib' => array("TicketsupDictType", "TicketsupDictCategory", "TicketsupDictSeverity"), 'tabsql' => array('SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_type as f', 'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_category as f', 'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM ' . MAIN_DB_PREFIX . 'c_ticketsup_severity as f'), @@ -153,10 +153,10 @@ class modTicketsup extends DolibarrModules $r = 0; // Example: - $this->boxes[$r][1] = "box_last_ticketsup@ticketsup"; + $this->boxes[$r][1] = "box_last_ticketsup"; $r++; - $this->boxes[$r][1] = "box_last_modified_ticketsup@ticketsup"; + $this->boxes[$r][1] = "box_last_modified_ticketsup"; $r++; // Permissions @@ -209,7 +209,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor. 'url' => '/ticketsup/index.php', - 'langs' => 'ticketsup@ticketsup', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'langs' => 'ticketsup', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position' => 100, 'enabled' => '1', // Define condition to show or hide menu entry. Use '$conf->ticketsup->enabled' if entry must be visible if module is enabled. 'perms' => '$user->rights->ticketsup->read', // Use 'perms'=>'$user->rights->ticketsup->level1->level2' if you want your menu with a permission rules @@ -223,7 +223,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsup', 'url' => '/ticketsup/index.php', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 101, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -236,7 +236,7 @@ class modTicketsup extends DolibarrModules 'titre' => 'NewTicket', 'mainmenu' => 'ticketsup', 'url' => '/ticketsup/new.php?action=create_ticket', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 102, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->write', @@ -250,7 +250,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsuplist', 'url' => '/ticketsup/list.php', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 103, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -264,7 +264,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsuplist', 'url' => '/ticketsup/list.php?search_fk_status=non_closed', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 104, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -278,7 +278,7 @@ class modTicketsup extends DolibarrModules 'mainmenu' => 'ticketsup', 'leftmenu' => 'ticketsupmy', 'url' => '/ticketsup/list.php?mode=my_assign', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 105, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', @@ -291,7 +291,7 @@ class modTicketsup extends DolibarrModules 'titre' => 'MenuTicketsupMyAssignNonClosed', 'mainmenu' => 'ticketsup', 'url' => '/ticketsup/list.php?mode=my_assign&search_fk_status=non_closed', - 'langs' => 'ticketsup@ticketsup', + 'langs' => 'ticketsup', 'position' => 106, 'enabled' => 1, 'perms' => '$user->rights->ticketsup->read', diff --git a/htdocs/core/modules/modules_ticketsup.php b/htdocs/core/modules/modules_ticketsup.php index 9eb652c31f4..e6e47adaa9f 100644 --- a/htdocs/core/modules/modules_ticketsup.php +++ b/htdocs/core/modules/modules_ticketsup.php @@ -49,7 +49,7 @@ abstract class ModeleNumRefTicketsup public function info() { global $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); return $langs->trans("NoDescription"); } @@ -61,7 +61,7 @@ abstract class ModeleNumRefTicketsup public function getExample() { global $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); return $langs->trans("NoExample"); } diff --git a/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php b/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php index 8c0c8c8fe0c..881ba5a7f15 100644 --- a/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php +++ b/htdocs/core/modules/ticketsup/mod_ticketsup_universal.php @@ -43,7 +43,7 @@ class mod_ticketsup_universal extends ModeleNumRefTicketsup { global $conf, $langs; - $langs->load("ticketsup@ticketsup"); + $langs->load("ticketsup"); $langs->load("admin"); $form = new Form($this->db); diff --git a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php index 1990f184f84..16b317cc108 100644 --- a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php @@ -50,7 +50,7 @@ class InterfaceTicketEmail extends DolibarrTriggers $this->family = "ticketsup"; $this->description = "Triggers of the module ticketsup"; $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'ticketsup@ticketsup'; + $this->picto = 'ticketsup'; } /** @@ -176,7 +176,7 @@ class InterfaceTicketEmail extends DolibarrTriggers $filename = array(); $mimetype = array(); - $langs->load('ticketsup@ticketsup'); + $langs->load('ticketsup'); $object->fetch('', $object->track_id); diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index e9543583b03..37e22e182a7 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -146,6 +146,7 @@ CREATE TABLE llx_ticketsup tms timestamp )ENGINE=innodb; +ALTER TABLE llx_ticketsup ADD COLUMN notify_tiers_at_create integer; ALTER TABLE llx_ticketsup ADD UNIQUE uk_ticketsup_rowid_track_id (rowid, track_id); ALTER TABLE llx_ticketsup ADD INDEX id_ticketsup_track_id (track_id); diff --git a/htdocs/install/mysql/tables/llx_ticketsup.sql b/htdocs/install/mysql/tables/llx_ticketsup.sql index 5449cf4825d..f79cda97712 100644 --- a/htdocs/install/mysql/tables/llx_ticketsup.sql +++ b/htdocs/install/mysql/tables/llx_ticketsup.sql @@ -18,7 +18,7 @@ CREATE TABLE llx_ticketsup ( rowid integer AUTO_INCREMENT PRIMARY KEY, entity integer DEFAULT 1, - ref varchar(128) NOT NULL, + ref varchar(128) NOT NULL, track_id varchar(128) NOT NULL, fk_soc integer DEFAULT 0, fk_project integer DEFAULT 0, @@ -37,5 +37,6 @@ CREATE TABLE llx_ticketsup datec datetime, date_read datetime, date_close datetime, + notify_tiers_at_create, tms timestamp )ENGINE=innodb; diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index 986a1882936..8187e8220d9 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -180,7 +180,7 @@ TicketMessageSuccessfullyAdded=Message successfully added TicketMessagesList=Message list NoMsgForThisTicket=No message for this ticket Properties=Classification -LastNewTickets=Last %s tickets newest (not read) +LatestNewTickets=Last %s tickets newest (not read) TicketSeverity=Severity ShowTicket=See ticket RelatedTickets=Related tickets diff --git a/htdocs/public/ticketsup/create_ticket.php b/htdocs/public/ticketsup/create_ticket.php index bc5fc584219..a0cb6f787ac 100644 --- a/htdocs/public/ticketsup/create_ticket.php +++ b/htdocs/public/ticketsup/create_ticket.php @@ -56,7 +56,7 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $langs->load("companies"); $langs->load("other"); $langs->load("mails"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); diff --git a/htdocs/public/ticketsup/index.php b/htdocs/public/ticketsup/index.php index f913ce9c70d..8352282c4af 100644 --- a/htdocs/public/ticketsup/index.php +++ b/htdocs/public/ticketsup/index.php @@ -51,7 +51,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); $langs->load("errors"); // Get parameters diff --git a/htdocs/public/ticketsup/list.php b/htdocs/public/ticketsup/list.php index adea8def5ea..34413168bc0 100644 --- a/htdocs/public/ticketsup/list.php +++ b/htdocs/public/ticketsup/list.php @@ -42,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $track_id = GETPOST('track_id', 'alpha'); diff --git a/htdocs/public/ticketsup/view.php b/htdocs/public/ticketsup/view.php index 68e18e67d14..c0069d9f6ee 100644 --- a/htdocs/public/ticketsup/view.php +++ b/htdocs/public/ticketsup/view.php @@ -42,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $track_id = GETPOST('track_id', 'alpha'); diff --git a/htdocs/ticketsup/card.php b/htdocs/ticketsup/card.php index b5ffa4b63d8..5bf64d34cc8 100644 --- a/htdocs/ticketsup/card.php +++ b/htdocs/ticketsup/card.php @@ -48,7 +48,7 @@ if (!class_exists('Contact')) { // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); @@ -208,7 +208,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } $head = ticketsup_prepare_head($object->dao); - dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), 0, 'ticketsup'); $object->dao->label = $object->dao->ref; // Author if ($object->dao->fk_user_create > 0) { diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index e507e2e89a7..902bb6943ef 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -53,7 +53,7 @@ class Ticketsup extends CommonObject /** * @var string String with name of icon for ticketsupcore. Must be the part after the 'object_' into object_ticketsupcore.png */ - public $picto = 'ticketsup@ticketsup'; + public $picto = 'ticketsup'; /** @@ -1309,9 +1309,9 @@ class Ticketsup extends CommonObject $lien = ''; $lienfin = ''; - $picto = 'ticketsup@ticketsup'; + $picto = 'ticketsup'; if (!$this->public) { - $picto = 'ticketsup@ticketsup'; + $picto = 'ticketsup'; } $label = $langs->trans("ShowTicket") . ': ' . $this->ref . ' - ' . $this->subject; @@ -1501,7 +1501,7 @@ class Ticketsup extends CommonObject $nb_sent = 0; - $langs->load('ticketsup@ticketsup'); + $langs->load('ticketsup'); // Retrieve email of all contacts (internal and external) $contacts = $this->listeContact(-1, 'internal'); diff --git a/htdocs/ticketsup/contacts.php b/htdocs/ticketsup/contacts.php index 72b72ac0e57..9ef592b22a7 100644 --- a/htdocs/ticketsup/contacts.php +++ b/htdocs/ticketsup/contacts.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; // Load traductions files requiredby by page $langs->load("companies"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $socid = GETPOST("socid", 'int'); @@ -144,7 +144,7 @@ if ($id > 0 || !empty($track_id) || !empty($ref)) { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object); - dol_fiche_head($head, 'tabTicketContacts', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketContacts', $langs->trans("Ticket"), 0, 'ticketsup'); $object->label = $object->ref; // Author if ($object->fk_user_create > 0) { diff --git a/htdocs/ticketsup/document.php b/htdocs/ticketsup/document.php index f9d96beaf1f..f221dce73c2 100644 --- a/htdocs/ticketsup/document.php +++ b/htdocs/ticketsup/document.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; $langs->load("companies"); $langs->load('other'); +$langs->load("ticketsup"); $action = GETPOST('action'); $confirm = GETPOST('confirm'); @@ -122,7 +123,7 @@ if ($object->id) { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object); - dol_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticketsup'); $object->label = $object->ref; // Author if ($object->fk_user_create > 0) { diff --git a/htdocs/ticketsup/history.php b/htdocs/ticketsup/history.php index 48ba39a2b02..9bd69ade897 100644 --- a/htdocs/ticketsup/history.php +++ b/htdocs/ticketsup/history.php @@ -36,7 +36,7 @@ if (!class_exists('Contact')) { // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); // Get parameters $id = GETPOST('id', 'int'); @@ -102,7 +102,7 @@ if ($action == 'view') { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } $head = ticketsup_prepare_head($object->dao); - dol_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticketsup@ticketsup'); + dol_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticketsup'); $object->dao->label = $object->dao->ref; // Author if ($object->dao->fk_user_create > 0) { diff --git a/htdocs/ticketsup/index.php b/htdocs/ticketsup/index.php index 505812f84c6..e596d9149c1 100644 --- a/htdocs/ticketsup/index.php +++ b/htdocs/ticketsup/index.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; // Load traductions files requiredby by page $langs->load("companies"); $langs->load("other"); -$langs->load("ticketsup@ticketsup"); +$langs->load("ticketsup"); $WIDTH = DolGraph::getDefaultGraphSizeForStats('width'); $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); @@ -55,17 +55,17 @@ $endyear = $year; $object = new ActionsTicketsup($db); -/******************************************************************* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ -/*************************************************** - * PAGE - * - * Put here all code to build page - ****************************************************/ +/* + * Actions + */ + +// None + + +/* + * View + */ llxHeader('', $langs->trans('TicketsIndex'), ''); @@ -241,10 +241,10 @@ if (count($dataseries) >1) { $px1->SetCssPrefix("cssboxes"); $px1->mode = 'depth'; //$px1->SetTitle($langs->trans("TicketStatByStatus")); - + $px1->draw($filenamenb, $fileurlnb); print $px1->show(); - + print $stringtoshow; } } @@ -295,7 +295,7 @@ if ($result) { $i = 0; - $transRecordedType = $langs->trans("LastNewTickets", $max); + $transRecordedType = $langs->trans("LatestNewTickets", $max); print ''; print ''; print ''; @@ -347,7 +347,7 @@ if ($result) { $db->free(); } else { - print ''; + print ''; } print "
    ' . $transRecordedType . '' . $langs->trans('Ref') . '
    ' . $langs->trans('NoTicketsFound') . '
    ' . $langs->trans('NoTicketsFound') . '
    "; diff --git a/htdocs/ticketsup/list.php b/htdocs/ticketsup/list.php index 43c405c5578..ea56c133b6b 100644 --- a/htdocs/ticketsup/list.php +++ b/htdocs/ticketsup/list.php @@ -34,7 +34,6 @@ if (!empty($conf->projet->enabled)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php'; } -// Load traductions files requiredby by page // Load traductions files requiredby by page $langs->loadLangs( array( @@ -60,7 +59,7 @@ $id = GETPOST('id','int'); $msg_id = GETPOST('msg_id', 'int'); $socid = GETPOST('socid', 'int'); $projectid = GETPOST('projectid', 'int'); - +$search_fk_status = GETPOST('search_fk_status', 'alpha'); $mode = GETPOST('mode', 'alpha'); // Load variable for pagination @@ -186,16 +185,15 @@ if (empty($reshook)) } -/*************************************************** - * PAGE - * - * Put here all code to build page - ****************************************************/ + +/* + * View + */ + $help_url = 'FR:DocumentationModuleTicket'; llxHeader('', $langs->trans('TicketList'), $help_url); $form = new Form($db); - $formTicket = new FormTicketsup($db); $user_assign = new User($db); @@ -203,9 +201,6 @@ $user_create = new User($db); $socstatic = new Societe($db); -$search_fk_status = GETPOST('search_fk_status', 'alpha'); - - // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; @@ -447,7 +442,7 @@ print ''; print_barre_liste($langs->trans('TicketList'), $page, 'list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'img/ticketsup-32.png', 1); if ($mode == 'my_assign') { - print '
    ' . $langs->trans('TicketAssignedToMeInfos') . '
    '; + print '
    ' . $langs->trans('TicketAssignedToMeInfos') . '

    '; } // Add code for pre mass action (confirmation or email presend form) $topicmail="SendTicketsupRef"; diff --git a/htdocs/ticketsup/new.php b/htdocs/ticketsup/new.php index 18e8fbf5a17..3d1a3c7c9f2 100644 --- a/htdocs/ticketsup/new.php +++ b/htdocs/ticketsup/new.php @@ -1,6 +1,6 @@ - * 2016 Christophe Battarel +/* Copyright (C) 2013-2016 Jean-François FERRY + * Copyright (C) 2016 Christophe Battarel * * 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 @@ -50,13 +50,19 @@ if (!$user->rights->ticketsup->read || !$user->rights->ticketsup->write) { $object = new ActionsTicketsup($db); + +/* + * Actions + */ + $object->doActions($action); -/*************************************************** - * PAGE - * - * Put here all code to build page - ****************************************************/ + + +/* + * View + */ + $help_url = 'FR:DocumentationModuleTicket'; $page_title = $object->getTitle($action); llxHeader('', $page_title, $help_url); @@ -85,11 +91,6 @@ if ($action == 'create_ticket') { $formticket->showForm(); } -/*************************************************** - * LINKED OBJECT BLOCK - * - * Put here code to view linked object - ****************************************************/ //$somethingshown=$object->showLinkedObjectBlock(); // End of page diff --git a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php index dc03dd32c3c..824f392d638 100644 --- a/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php +++ b/htdocs/ticketsup/tpl/linkedobjectblock.tpl.php @@ -29,7 +29,7 @@ if (empty($conf) || ! is_object($conf)) load('ticketsup@ticketsup'); +$langs->load('ticketsup'); $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; echo '
    '; print_titre($langs->trans('RelatedTickets')); @@ -47,7 +47,7 @@ foreach ($linkedObjectBlock as $object) { subject) ? ' '.$object->subject : ''); ?> + trans("ShowTicket"), "ticketsup") . ' ' . (! empty($object->subject) ? ' '.$object->subject : ''); ?> datec, 'day'); ?> From 478b3dfa427ed306088d3cb81945d0725c672177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 12 Mar 2018 08:34:47 +0100 Subject: [PATCH 035/126] Update llx_ticketsup.sql --- htdocs/install/mysql/tables/llx_ticketsup.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_ticketsup.sql b/htdocs/install/mysql/tables/llx_ticketsup.sql index f79cda97712..aeb5d41814d 100644 --- a/htdocs/install/mysql/tables/llx_ticketsup.sql +++ b/htdocs/install/mysql/tables/llx_ticketsup.sql @@ -37,6 +37,6 @@ CREATE TABLE llx_ticketsup datec datetime, date_read datetime, date_close datetime, - notify_tiers_at_create, + notify_tiers_at_create tinyint, tms timestamp )ENGINE=innodb; From 98320ffad29dc4791f7dbb522f80b72cc7f51ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 12 Mar 2018 08:36:18 +0100 Subject: [PATCH 036/126] Update 7.0.0-8.0.0.sql --- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 37e22e182a7..67f18f374f0 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -143,6 +143,7 @@ CREATE TABLE llx_ticketsup datec datetime, date_read datetime, date_close datetime, + notify_tiers_at_create tinyint, tms timestamp )ENGINE=innodb; From 98b7d4c2e29174838ec0de29ce435fa6a22692e8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 12:27:40 +0100 Subject: [PATCH 037/126] NEW Can set the start/end date of service line in invoice templates --- htdocs/compta/facture/card.php | 35 +++++++------ .../facture/class/facture-rec.class.php | 33 +++++++++--- htdocs/compta/facture/class/facture.class.php | 41 +++++++++++---- htdocs/compta/facture/fiche-rec.php | 52 +++++-------------- htdocs/core/tpl/objectline_create.tpl.php | 30 +++++++++-- htdocs/core/tpl/objectline_edit.tpl.php | 27 ++++++++-- htdocs/core/tpl/objectline_view.tpl.php | 30 ++++++----- .../install/mysql/migration/7.0.0-8.0.0.sql | 3 ++ .../mysql/tables/llx_facturedet_rec.sql | 2 + htdocs/langs/en_US/bills.lang | 4 ++ htdocs/theme/eldy/style.css.php | 4 +- htdocs/theme/md/style.css.php | 3 ++ 12 files changed, 171 insertions(+), 93 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 90bc80a6a19..1dd7dab2de8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -553,7 +553,7 @@ if (empty($reshook)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) ) { - $idwarehouse = GETPOST('idwarehouse'); + $idwarehouse = GETPOST('idwarehouse','int'); $object->fetch($id); $object->fetch_thirdparty(); @@ -640,8 +640,8 @@ if (empty($reshook)) else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement) { $object->fetch($id); - $close_code = $_POST["close_code"]; - $close_note = $_POST["close_note"]; + $close_code = GETPOST("close_code",'none'); + $close_note = GETPOST("close_note",'none'); if ($close_code) { $result = $object->set_paid($user, $close_code, $close_note); if ($result<0) setEventMessages($object->error, $object->errors, 'errors'); @@ -651,8 +651,8 @@ if (empty($reshook)) } // Classify "abandoned" else if ($action == 'confirm_canceled' && $confirm == 'yes') { $object->fetch($id); - $close_code = $_POST["close_code"]; - $close_note = $_POST["close_note"]; + $close_code = GETPOST("close_code",'none'); + $close_note = GETPOST("close_note",'none'); if ($close_code) { $result = $object->set_canceled($user, $close_code, $close_note); if ($result<0) setEventMessages($object->error, $object->errors, 'errors'); @@ -1419,6 +1419,7 @@ if (empty($reshook)) } } + // Situation invoices if (GETPOST('type') == Facture::TYPE_SITUATION && (!empty($_POST['situations']))) { $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -1455,16 +1456,16 @@ if (empty($reshook)) $object->fetch_thirdparty(); $object->date = $datefacture; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim($_POST['note_public']); - $object->note = trim($_POST['note']); - $object->ref_client = $_POST['ref_client']; - $object->ref_int = $_POST['ref_int']; - $object->modelpdf = $_POST['model']; - $object->fk_project = $_POST['projectid']; - $object->cond_reglement_id = $_POST['cond_reglement_id']; - $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->remise_absolue = $_POST['remise_absolue']; - $object->remise_percent = $_POST['remise_percent']; + $object->note_public = trim(GETPOST('note_public','none')); + $object->note = trim(GETPOST('note','none')); + $object->ref_client = GETPOST('ref_client','alpha'); + $object->ref_int = GETPOST('ref_int','alpha'); + $object->modelpdf = GETPOST('model','alpha'); + $object->fk_project = GETPOST('projectid','int'); + $object->cond_reglement_id = GETPOST('cond_reglement_id','int'); + $object->mode_reglement_id = GETPOST('mode_reglement_id','int'); + $object->remise_absolue = GETPOST('remise_absolue','int'); + $object->remise_percent = GETPOST('remise_percent','int'); // Proprietes particulieres a facture de remplacement @@ -1533,14 +1534,14 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef=''; - $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); + $product_desc=(GETPOST('dp_desc','none')?GETPOST('dp_desc','none'):''); $price_ht = GETPOST('price_ht'); $price_ht_devise = GETPOST('multicurrency_price_ht'); $prod_entry_mode = GETPOST('prod_entry_mode','alpha'); if ($prod_entry_mode == 'free') { $idprod=0; - $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + $tva_tx = (GETPOST('tva_tx','alpha') ? GETPOST('tva_tx','alpha') : 0); } else { diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index c36e6cb09d1..630433324c4 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -439,7 +439,7 @@ class FactureRec extends CommonInvoice $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, '; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; - $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc,'; //$sql.= ' l.situation_percent, l.fk_prev_id,'; //$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' l.rang, l.special_code,'; @@ -487,6 +487,8 @@ class FactureRec extends CommonInvoice $line->remise_percent = $objp->remise_percent; $line->fk_remise_except = $objp->fk_remise_except; $line->fk_product = $objp->fk_product; + $line->date_start_fill = $objp->date_start_fill; + $line->date_end_fill = $objp->date_end_fill; $line->info_bits = $objp->info_bits; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -602,15 +604,17 @@ class FactureRec extends CommonInvoice * @param string $label Label of the line * @param string $fk_unit Unit * @param double $pu_ht_devise Unit price in currency + * @param int $date_start_fill 1=Flag to fill start date when generating invoice + * @param int $date_end_fill 1=Flag to fill end date when generating invoice * @return int <0 if KO, Id of line if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0) + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0) { global $mysoc; $facid=$this->id; - dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise", LOG_DEBUG); + dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise,date_start_fill=$date_start_fill,date_end_fill=$date_end_fill", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Check parameters @@ -700,6 +704,8 @@ class FactureRec extends CommonInvoice $sql.= ", total_localtax1"; $sql.= ", total_localtax2"; $sql.= ", total_ttc"; + $sql.= ", date_start_fill"; + $sql.= ", date_end_fill"; $sql.= ", info_bits"; $sql.= ", rang"; $sql.= ", special_code"; @@ -727,6 +733,8 @@ class FactureRec extends CommonInvoice $sql.= ", ".price2num($total_localtax1); $sql.= ", ".price2num($total_localtax2); $sql.= ", ".price2num($total_ttc); + $sql.= ", ".(int) $date_start_fill; + $sql.= ", ".(int) $date_end_fill; $sql.= ", ".$info_bits; $sql.= ", ".$rang; $sql.= ", ".$special_code; @@ -778,9 +786,11 @@ class FactureRec extends CommonInvoice * @param string $fk_unit Unit * @param double $pu_ht_devise Unit price in currency * @param int $notrigger disable line update trigger + * @param int $date_start_fill 1=Flag to fill start date when generating invoice + * @param int $date_end_fill 1=Flag to fill end date when generating invoice * @return int <0 if KO, Id of line if OK */ - function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise = 0, $notrigger=0) + function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise = 0, $notrigger=0, $date_start_fill=0, $date_end_fill=0) { global $mysoc; @@ -883,6 +893,8 @@ class FactureRec extends CommonInvoice $sql.= ", total_localtax1='".price2num($total_localtax1)."'"; $sql.= ", total_localtax2='".price2num($total_localtax2)."'"; $sql.= ", total_ttc='".price2num($total_ttc)."'"; + $sql.= ", date_start_fill=".((int) $date_start_fill); + $sql.= ", date_end_fill=".((int) $date_end_fill); $sql.= ", info_bits=".$info_bits; $sql.= ", rang=".$rang; $sql.= ", special_code=".$special_code; @@ -948,7 +960,7 @@ class FactureRec extends CommonInvoice * Create all recurrents invoices (for all entities if multicompany is used). * A result may also be provided into this->output. * - * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found. + * WARNING: This method change temporarly context $conf->entity to be in correct context for each recurring invoice found. * * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) */ @@ -1561,6 +1573,10 @@ class FactureLigneRec extends CommonInvoiceLine public $element='facturedetrec'; public $table_element='facturedet_rec'; + var $date_start_fill; + var $date_end_fill; + + /** * Delete line in database * @@ -1615,7 +1631,7 @@ class FactureLigneRec extends CommonInvoiceLine { $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,'; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; - $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' l.rang, l.special_code,'; $sql.= ' l.fk_unit, l.fk_contract_line,'; $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; @@ -1655,6 +1671,8 @@ class FactureLigneRec extends CommonInvoiceLine $this->remise_percent = $objp->remise_percent; $this->fk_remise_except = $objp->fk_remise_except; $this->fk_product = $objp->fk_product; + $this->date_start_fill = $objp->date_start_fill; + $this->date_end_fill = $objp->date_end_fill; $this->info_bits = $objp->info_bits; $this->total_ht = $objp->total_ht; $this->total_tva = $objp->total_tva; @@ -1711,6 +1729,9 @@ class FactureLigneRec extends CommonInvoiceLine $sql.= ", product_type=".$this->product_type; $sql.= ", remise_percent='".price2num($this->remise_percent)."'"; $sql.= ", subprice='".price2num($this->subprice)."'"; + $sql.= ", info_bits='".price2num($this->info_bits)."'"; + $sql.= ", date_start_fill=".(int) $this->date_start_fill; + $sql.= ", date_end_fill=".(int) $this->date_end_fill; $sql.= ", total_ht='".price2num($this->total_ht)."'"; $sql.= ", total_tva='".price2num($this->total_tva)."'"; $sql.= ", total_localtax1='".price2num($this->total_localtax1)."'"; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 1939aa0e62f..8aca7562654 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -287,6 +287,10 @@ class Facture extends CommonInvoice $this->db->begin(); + $originaldatewhen=null; + $nextdatewhen=null; + $previousdaynextdatewhen=null; + // Create invoice from a template invoice if ($this->fac_rec > 0) { @@ -297,7 +301,10 @@ class Facture extends CommonInvoice $result=$_facrec->fetch($this->fac_rec); $result=$_facrec->fetchObjectLinked(); // This load $_facrec->linkedObjectsIds + // Define some dates $originaldatewhen = $_facrec->date_when; + $nextdatewhen=dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency); + $previousdaynextdatewhen=dol_time_plus_duree($nextdatewhen, -1, 'd'); $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template @@ -374,7 +381,8 @@ class Facture extends CommonInvoice $substitutionarray['__INVOICE_NEXT_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'y'), '%Y'); // Only for tempalte invoice $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = dol_print_date($originaldatewhen, 'dayhour'); - $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date(dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency), 'dayhour'); + $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($nextdatewhen, 'dayhour'); + $substitutionarray['__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($previousdaynextdatewhen, 'dayhour'); //var_dump($substitutionarray);exit; @@ -494,6 +502,7 @@ class Facture extends CommonInvoice } } + // Propagate contacts if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object { $originforcontact = $this->origin; @@ -531,11 +540,10 @@ class Facture extends CommonInvoice else dol_print_error($resqlcontact); } - /* - * Insert lines of invoices into database + * Insert lines of invoices, if not from template invoice, into database */ - if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode) + if (! $error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode) { $fk_parent_line = 0; @@ -545,9 +553,18 @@ class Facture extends CommonInvoice $newinvoiceline=$this->lines[$i]; $newinvoiceline->fk_facture=$this->id; - // TODO This seems not used. Here we put origin 'facture' but after, we put an id of object ! - $newinvoiceline->origin = $this->element; - $newinvoiceline->origin_id = $this->lines[$i]->id; + $newinvoiceline->origin = $this->lines[$i]->element; + $newinvoiceline->origin_id = $this->lines[$i]->id; + + // Auto set date of service ? + if ($this->lines[$i]->date_start_fill == 1 && $originaldatewhen) // $originaldatewhen is defined when generating from recurring invoice only + { + $newinvoiceline->date_start = $originaldatewhen; + } + if ($this->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen) // $previousdaynextdatewhen is defined when generating from recurring invoice only + { + $newinvoiceline->date_end = $previousdaynextdatewhen; + } if ($result >= 0) { @@ -581,7 +598,7 @@ class Facture extends CommonInvoice } } } - else // If this->lines is an array of invoice line arrays + elseif (! $error && empty($this->fac_rec)) // If this->lines is an array of invoice line arrays { $fk_parent_line = 0; @@ -689,7 +706,9 @@ class Facture extends CommonInvoice $localtax2_tx, $_facrec->lines[$i]->fk_product, $_facrec->lines[$i]->remise_percent, - '','',0, + ($_facrec->lines[$i]->date_start_fill == 1 && $originaldatewhen)?$originaldatewhen:'', + ($_facrec->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen)?$previousdaynextdatewhen:'', + 0, $tva_npr, '', 'HT', @@ -2522,8 +2541,8 @@ class Facture extends CommonInvoice * @param double $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) * @param int $fk_product Id of predefined product/service * @param double $remise_percent Percent of discount on line - * @param int $date_start Date start of service - * @param int $date_end Date end of service + * @param int $date_start Date start of service + * @param int $date_end Date end of service * @param int $ventil Code of dispatching into accountancy * @param int $info_bits Bits de type de lignes * @param int $fk_remise_except Id discount used diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 8d955f1141d..6f96e74d345 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -66,22 +66,8 @@ if ($action == "create" || $action == "add") $objecttype = ''; $result = restrictedArea($user, 'facture', $id, $objecttype); $projectid = GETPOST('projectid','int'); -$search_ref=GETPOST('search_ref'); -$search_societe=GETPOST('search_societe'); -$search_montant_ht=GETPOST('search_montant_ht'); -$search_montant_vat=GETPOST('search_montant_vat'); -$search_montant_ttc=GETPOST('search_montant_ttc'); -$search_payment_mode=GETPOST('search_payment_mode'); -$search_payment_term=GETPOST('search_payment_term'); -$day=GETPOST('day'); -$year=GETPOST('year'); -$month=GETPOST('month'); -$day_date_when=GETPOST('day_date_when'); $year_date_when=GETPOST('year_date_when'); $month_date_when=GETPOST('month_date_when'); -$search_recurring=GETPOST('search_recurring','int'); -$search_frequency=GETPOST('search_frequency','alpha'); -$search_unit_frequency=GETPOST('search_unit_frequency','alpha'); $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); @@ -144,28 +130,6 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once - // Do we click on purge search criteria ? - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers - { - $search_ref=''; - $search_societe=''; - $search_montant_ht=''; - $search_montant_vat=''; - $search_montant_ttc=''; - $search_montant_mode=''; - $search_montant_term=''; - $day=''; - $year=''; - $month=''; - $day_date_when=''; - $year_date_when=''; - $month_date_when=''; - $search_recurring=''; - $search_frequency=''; - $search_unit_frequency=''; - $search_array_options=array(); - } - // Mass actions /*$objectclass='MyObject'; $objectlabel='MyObject'; @@ -686,6 +650,9 @@ if (empty($reshook)) $fk_unit= GETPOST('units', 'alpha'); } + $date_start_fill = GETPOST('date_start_fill','int'); + $date_end_fill = GETPOST('date_end_fill','int'); + // Margin $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value @@ -706,7 +673,7 @@ if (empty($reshook)) else { // Insert line - $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit); + $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill); if ($result > 0) { @@ -762,6 +729,9 @@ if (empty($reshook)) unset($_POST['date_endmonth']); unset($_POST['date_endyear']); + unset($_POST['date_start_fill']); + unset($_POST['date_end_fill']); + unset($_POST['situations']); unset($_POST['progress']); } @@ -883,6 +853,9 @@ if (empty($reshook)) $error ++; } + $date_start_fill = GETPOST('date_start_fill','int'); + $date_end_fill = GETPOST('date_end_fill','int'); + // Update line if (! $error) { @@ -905,7 +878,10 @@ if (empty($reshook)) $special_code, $label, GETPOST('units'), - $pu_ht_devise + $pu_ht_devise, + 0, + $date_start_fill, + $date_end_fill ); if ($result >= 0) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 501e3db3d6c..e2dfed0f68b 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -283,6 +283,18 @@ else { if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes'; $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,$toolbarname,'',false,true,$enabled,$nbrows,'98%'); $doleditor->Create(); + + // Show autofill date for recuring invoices + if (! empty($conf->service->enabled) && $object->element == 'facturerec') + { + echo '

    '; + echo $langs->trans('AutoFillDateFrom').' '; + echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1); + echo ' - '; + echo $langs->trans('AutoFillDateTo').' '; + echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1); + echo '
    '; + } ?> @@ -594,8 +606,17 @@ jQuery(document).ready(function() { if (editor) { editor.focus(); } } } - if (jQuery('#select_type').val() == '0') jQuery('#trlinefordates').hide(); - else jQuery('#trlinefordates').show(); + console.log("Hide/show date according to product type"); + if (jQuery('#select_type').val() == '0') + { + jQuery('#trlinefordates').hide(); + jQuery('.divlinefordates').hide(); + } + else + { + jQuery('#trlinefordates').show(); + jQuery('.divlinefordates').show(); + } }); $("#prod_entry_mode_predef").on( "click", function() { @@ -799,7 +820,7 @@ function setforfree() { jQuery("#units, #title_units").show(); } function setforpredef() { - console.log("Call setforpredef. We hide some fields"); + console.log("Call setforpredef. We hide some fields and show dates"); jQuery("#select_type").val(-1); jQuery("#prod_entry_mode_free").prop('checked',false).change(); @@ -820,6 +841,9 @@ function setforpredef() { jQuery(".np_marginRate").hide(); // May no exists jQuery(".np_markRate").hide(); // May no exists jQuery("#units, #title_units").hide(); + + jQuery('#trlinefordates').show(); + jQuery('.divlinefordates').show(); } diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 67adba3a2ae..30b4f01cfb8 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -62,7 +62,10 @@ if (!empty($conf->multicurrency->enabled)) $colspan+=2; $coldisplay=-1; // We remove first td ?> > - global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>global->MAIN_VIEW_LINE_NUMBER))?2:1; ?> + global->MAIN_VIEW_LINE_NUMBER)) { ?> + + +
    @@ -83,7 +86,7 @@ $coldisplay=-1; // We remove first td echo ' - '.nl2br($line->product_label); ?> -
    +

    @@ -110,6 +113,18 @@ $coldisplay=-1; // We remove first td } else { print ''; } + + // Show autofill date for recuring invoices + if (! empty($conf->service->enabled) && $line->product_type == 1 && $line->element == 'facturedetrec') + { + echo '
    '; + echo $langs->trans('AutoFillDateFrom').' '; + echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1); + echo ' - '; + echo $langs->trans('AutoFillDateTo').' '; + echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1); + } + ?> @@ -117,7 +132,7 @@ $coldisplay=-1; // We remove first td if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines { ?> - + service->enabled) && $line->product_type == 1 && $dateSelector) { ?> > + global->MAIN_VIEW_LINE_NUMBER)) { ?> + + trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:''); @@ -264,7 +282,8 @@ $coldisplay=-1; // We remove first td ?> - + '; diff --git a/htdocs/loan/createschedule.php b/htdocs/loan/createschedule.php index 70688461ae9..4ab2499c265 100644 --- a/htdocs/loan/createschedule.php +++ b/htdocs/loan/createschedule.php @@ -22,14 +22,11 @@ */ require '../main.inc.php'; - require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php'; -global $user; - $loanid = GETPOST('loanid', 'int'); $action = GETPOST('action','aZ09'); @@ -107,6 +104,7 @@ $(document).ready(function() { var idcap=echeance-1; idcap = '#hi_capital'+idcap; var capital=$(idcap).val(); + console.log("Change montly amount echeance="+echeance+" idcap="+idcap+" capital="+capital); $.ajax({ dataType: 'json', url: 'calcmens.php', @@ -135,50 +133,59 @@ $(document).ready(function() { print '
    '; print ''; print ''; -if(count($echeance->lines)>0){ +if(count($echeance->lines)>0) +{ print ''; }else{ print ''; } print ''; print ''; -print '"; +print ''; print ''; print ''; -Print ''; -Print ''; -Print ''; -Print ''; -Print ''; -print ''; +Print ''; +Print ''; +Print ''; +Print ''; +Print ''; +print ''."\n"; if ($object->nbterm > 0 && count($echeance->lines)==0) { $i=1; $capital = $object->capital; - while($i <$object->nbterm+1){ - $mens = round($echeance->calc_mens($capital, $object->rate/100, $object->nbterm-$i+1),2,PHP_ROUND_HALF_UP); + while($i <$object->nbterm+1) + { + $mens = price2num($echeance->calc_mens($capital, $object->rate/100, $object->nbterm-$i+1), 'MT'); $int = ($capital*($object->rate/12))/100; - $int = round($int,2,PHP_ROUND_HALF_UP); - $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + $int = price2num($int, 'MT'); + $cap_rest = price2num($capital - ($mens-$int), 'MT'); print ''; print ''; print ''; print ''; print ''; print ''; - print ''; + print ''."\n"; $i++; $capital = $cap_rest; } -}elseif(count($echeance->lines)>0){ +} +elseif(count($echeance->lines)>0) +{ $i=1; $capital = $object->capital; foreach ($echeance->lines as $line){ $mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest; $int = $line->amount_interest; - $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + $cap_rest = price2num($capital - ($mens-$int), 'MT'); print ''; print ''; print ''; @@ -189,7 +196,7 @@ if ($object->nbterm > 0 && count($echeance->lines)==0) } print ''; print ''; - print ''; + print ''."\n"; $i++; $capital = $cap_rest; } From d045dca00395744468395bbebc39b25417beb05a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 20:03:32 +0100 Subject: [PATCH 056/126] Fix financial commitment --- htdocs/loan/card.php | 4 +-- htdocs/loan/createschedule.php | 45 ++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index f44316ba45d..b6bb7ce81bf 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -422,11 +422,11 @@ if ($id > 0) print ''; diff --git a/htdocs/loan/createschedule.php b/htdocs/loan/createschedule.php index 70688461ae9..4ab2499c265 100644 --- a/htdocs/loan/createschedule.php +++ b/htdocs/loan/createschedule.php @@ -22,14 +22,11 @@ */ require '../main.inc.php'; - require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php'; -global $user; - $loanid = GETPOST('loanid', 'int'); $action = GETPOST('action','aZ09'); @@ -107,6 +104,7 @@ $(document).ready(function() { var idcap=echeance-1; idcap = '#hi_capital'+idcap; var capital=$(idcap).val(); + console.log("Change montly amount echeance="+echeance+" idcap="+idcap+" capital="+capital); $.ajax({ dataType: 'json', url: 'calcmens.php', @@ -135,50 +133,59 @@ $(document).ready(function() { print ''; print ''; print ''; -if(count($echeance->lines)>0){ +if(count($echeance->lines)>0) +{ print ''; }else{ print ''; } print '
    ' . "Création d'échéancier'; +print $langs->trans("FinancialCommitment"); +print '
    Echéance Date Montant Intérêts Capital restant du
    '.$langs->trans("DueDate").''.$langs->trans("Date").''.$langs->trans("Amount").''.$langs->trans("InterestAmount").''.$langs->trans("Remain"); +print ' ('.price2num($object->capital).')'; +print ''; +print '
    ' . $i .'' . dol_print_date(dol_time_plus_duree($object->datestart, $i-1, 'm'),'day') . ''.price($int,0,'',1).' €'.price($cap_rest).' €
    ' . $i .'' . dol_print_date($line->datep,'day') . ''.price($int,0,'',1).' €'.price($cap_rest).' €
    '; print ''; -print '"; +print ''; print ''; print ''; -Print ''; -Print ''; -Print ''; -Print ''; -Print ''; -print ''; +Print ''; +Print ''; +Print ''; +Print ''; +Print ''; +print ''."\n"; if ($object->nbterm > 0 && count($echeance->lines)==0) { $i=1; $capital = $object->capital; - while($i <$object->nbterm+1){ - $mens = round($echeance->calc_mens($capital, $object->rate/100, $object->nbterm-$i+1),2,PHP_ROUND_HALF_UP); + while($i <$object->nbterm+1) + { + $mens = price2num($echeance->calc_mens($capital, $object->rate/100, $object->nbterm-$i+1), 'MT'); $int = ($capital*($object->rate/12))/100; - $int = round($int,2,PHP_ROUND_HALF_UP); - $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + $int = price2num($int, 'MT'); + $cap_rest = price2num($capital - ($mens-$int), 'MT'); print ''; print ''; print ''; print ''; print ''; print ''; - print ''; + print ''."\n"; $i++; $capital = $cap_rest; } -}elseif(count($echeance->lines)>0){ +} +elseif(count($echeance->lines)>0) +{ $i=1; $capital = $object->capital; foreach ($echeance->lines as $line){ $mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest; $int = $line->amount_interest; - $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP); + $cap_rest = price2num($capital - ($mens-$int), 'MT'); print ''; print ''; print ''; @@ -189,7 +196,7 @@ if ($object->nbterm > 0 && count($echeance->lines)==0) } print ''; print ''; - print ''; + print ''."\n"; $i++; $capital = $cap_rest; } From f2bba8fb03f3c6e015cb02d8259f40f48c495f36 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 20:11:34 +0100 Subject: [PATCH 057/126] Fix translation --- htdocs/langs/en_US/loan.lang | 4 +++- htdocs/loan/card.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index d00b11738be..9aae3869cc3 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -50,4 +50,6 @@ ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accounting account capital by default LOAN_ACCOUNTING_ACCOUNT_INTEREST=Accounting account interest by default LOAN_ACCOUNTING_ACCOUNT_INSURANCE=Accounting account insurance by default -CreateCalcSchedule=Créer / Modifier échéancier de pret +FinancialCommitment=Financial commitment +CreateCalcSchedule=Edit financial commitment +InterestAmount=Interest amount diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index faa109181da..06e0066968d 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -692,7 +692,7 @@ if ($id > 0) $total_insurance = 0; $total_interest = 0; $total_capital = 0; - print '
    ' . "Création d'échéancier'; +print $langs->trans("FinancialCommitment"); +print '
    Echéance Date Montant Intérêts Capital restant du
    '.$langs->trans("DueDate").''.$langs->trans("Date").''.$langs->trans("Amount").''.$langs->trans("InterestAmount").''.$langs->trans("Remain"); +print ' ('.price2num($object->capital).')'; +print ''; +print '
    ' . $i .'' . dol_print_date(dol_time_plus_duree($object->datestart, $i-1, 'm'),'day') . ''.price($int,0,'',1).' €'.price($cap_rest).' €
    ' . $i .'' . dol_print_date($line->datep,'day') . ''.price($int,0,'',1).' €'.price($cap_rest).' €
    '; + print '
    '; print ''; print ''; print ''; @@ -729,7 +729,9 @@ if ($id > 0) $staytopay = $object->capital - $totalpaid; print ''; - print ''; + print ''; } print "
    '.$langs->trans("RefPayment").''.$langs->trans("Date").'
    '.$langs->trans("RemainderToPay").' :'.price($staytopay, 0, $langs, 0, 0, -1, $conf->currency).'
    '; + print price($staytopay, 0, $langs, 0, 0, -1, $conf->currency); + print '
    "; $db->free($resql); From 717a1daf28ad5a9bdcf6c98a6be5d879a34d24af Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 20:26:47 +0100 Subject: [PATCH 058/126] Fix sql injection --- htdocs/ticketsup/class/ticketsup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index b76cb9a0861..34fc63f8366 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -894,12 +894,12 @@ class Ticketsup extends CommonObject if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "ticketsup_logs"; - $sql .= " WHERE fk_track_id = '" . $this->track_id . "'"; + $sql .= " WHERE fk_track_id = '" . $this->db->escape($this->track_id) . "'"; $resql = $this->db->query($sql); } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "ticketsup_msg"; - $sql .= " WHERE fk_track_id = '" . $this->track_id . "'"; + $sql .= " WHERE fk_track_id = '" . $this->db->escape($this->track_id) . "'"; $resql = $this->db->query($sql); } From 56d023165ef43997461f5ea9b0ae988282c44552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 12 Mar 2018 20:43:38 +0100 Subject: [PATCH 059/126] Update ticketsup.class.php --- htdocs/ticketsup/class/ticketsup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index 34fc63f8366..0e8e7e71574 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -2262,7 +2262,7 @@ class Ticketsup extends CommonObject * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) * @return array Array of contacts */ - function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') + function listeContact($statut = -1, $source = 'external', $list = 0, $code = '') { global $langs; From 08bca60ae2c03ca79e4d89ee529b051f8253e60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 12 Mar 2018 20:52:39 +0100 Subject: [PATCH 060/126] Update ticketsup.class.php --- htdocs/ticketsup/class/ticketsup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index 0e8e7e71574..f1f23b09dcd 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -341,8 +341,8 @@ class Ticketsup extends CommonObject $sql .= " " . (!isset($this->fk_soc) ? '0' : "'" . $this->db->escape($this->fk_soc) . "'") . ","; $sql .= " " . (!isset($this->fk_project) ? '0' : "'" . $this->db->escape($this->fk_project) . "'") . ","; $sql .= " " . (!isset($this->origin_email) ? 'NULL' : "'" . $this->db->escape($this->origin_email) . "'") . ","; - $sql .= " " . ($this->fk_user_create > 0 ? ($user->id > 0 ? $user->id : 'NULL') : $this->fk_user_create) . ","; - $sql .= " " . ($this->fk_user_assign > 0 ? 'NULL' : $this->fk_user_assign) . ","; + $sql .= " " . ($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id : 'NULL')) . ","; + $sql .= " " . ($this->fk_user_assign > 0 ? $this->fk_user_assign : 'NULL') . ","; $sql .= " " . (!isset($this->subject) ? 'NULL' : "'" . $this->db->escape($this->subject) . "'") . ","; $sql .= " " . (!isset($this->message) ? 'NULL' : "'" . $this->db->escape($this->message) . "'") . ","; $sql .= " " . (!isset($this->fk_statut) ? '0' : "'" . $this->db->escape($this->fk_statut) . "'") . ","; From 7b864aeaec14b184dbc68330dd372b6e7a8774a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 21:29:03 +0100 Subject: [PATCH 061/126] Fix regression with live box --- htdocs/public/payment/newpayment.php | 2 +- htdocs/stripe/config.php | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index f7ceb201da5..3ad3f2d33fd 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -542,7 +542,7 @@ if (! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBO { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning'); } -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); } diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index 0e207474a51..31959b3516f 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -33,15 +33,6 @@ global $conf; //use \includes\stripe as stripe; $stripe = array(); -if ((empty($conf->global->STRIPECONNECT_LIVE) && ! (empty($conf->stripeconnect->enabled))) || GETPOST('forcesandbox','alpha')) -{ - $stripe = array( - "secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY, - "publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY - ); -} -else -{ if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')) { $stripe = array( @@ -56,7 +47,6 @@ else "publishable_key" => $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY ); } -} require_once DOL_DOCUMENT_ROOT."/includes/stripe/lib/Stripe.php"; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; From 01f25b00b04ecddf61093eb821f11ca99cc23a71 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Mar 2018 23:43:47 +0100 Subject: [PATCH 062/126] Test --- test/phpunit/TicketsupTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/phpunit/TicketsupTest.php b/test/phpunit/TicketsupTest.php index e709a8855ca..84490d7cae7 100644 --- a/test/phpunit/TicketsupTest.php +++ b/test/phpunit/TicketsupTest.php @@ -131,11 +131,11 @@ class TicketsupTest extends PHPUnit_Framework_TestCase // Try to create one with bad values $localobject=new Ticketsup($this->savdb); $localobject->initAsSpecimen(); - $localobject->fk_statut = '\'1=1'; + $localobject->ref = ''; $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; - $this->assertEquals(-1, $result, $localobject->error); + $this->assertEquals(-3, $result, $localobject->error.join(',', $localobject->errors)); // Try to create one with correct values $localobject=new Ticketsup($this->savdb); @@ -143,7 +143,7 @@ class TicketsupTest extends PHPUnit_Framework_TestCase $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result, $localobject->error); + $this->assertGreaterThan(0, $result, $localobject->error.join(',', $localobject->errors)); return $result; } From 9408a98c52af9befdfc1828e240c5a1145a4f9ef Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 00:26:09 +0100 Subject: [PATCH 063/126] Fix SQL and ADD support LIVE/TEST mode --- htdocs/stripe/class/stripe.class.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 801d0e17057..3a9c8646686 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -98,12 +98,20 @@ class Stripe extends CommonObject public function getStripeCustomerAccount($id) { global $conf; - + if (empty($conf->global->STRIPECONNECT_LIVE)) { + $mode = 0; + } else { + if (empty($conf->global->STRIPE_LIVE)) { + $mode = 0; + } else { + $mode = $conf->global->STRIPE_LIVE; + } + } $sql = "SELECT sa.key_account as key_account, sa.entity"; - $sql.= " FROM " . MAIN_DB_PREFIX . "llx_societe_accounts as sa"; + $sql.= " FROM " . MAIN_DB_PREFIX . "llx_societe_account as sa"; $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; - $sql.= " AND site = 'stripe'"; + $sql.= " AND sa.site = 'stripe' AND sa.status = ".$mode; dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $result = $this->db->query($sql); From d6be9651a0fd69f748f44cf46c45ec56beb7ce77 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 00:29:28 +0100 Subject: [PATCH 064/126] ADD key_account variable for stripe or other gateway --- htdocs/install/mysql/tables/llx_societe_account.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_societe_account.sql b/htdocs/install/mysql/tables/llx_societe_account.sql index 9938d47bfb5..e1a421affe4 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.sql @@ -27,6 +27,7 @@ CREATE TABLE llx_societe_account( site varchar(128), -- name of external web site fk_website integer, -- id of local web site note_private text, + key_account varchar(128), date_last_login datetime, date_previous_login datetime, date_creation datetime NOT NULL, @@ -36,4 +37,4 @@ CREATE TABLE llx_societe_account( import_key varchar(14), status integer -- END MODULEBUILDER FIELDS -) ENGINE=innodb; \ No newline at end of file +) ENGINE=innodb; From 6c7a5cebdfc37ce02c3acf0088a62793fd16c087 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Tue, 13 Mar 2018 09:34:50 +0100 Subject: [PATCH 065/126] FIX check verif exped on delete order --- htdocs/commande/class/commande.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index de3a47d36d4..b450a6ad16b 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3126,6 +3126,7 @@ class Commande extends CommonOrder if ($result < 0) $error++; // End call triggers } + if($this->nb_expedition()!=0)$error++; //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail if (! $error) From 490acd96dc060f71bfb41e53f46c135c0985b3f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 09:37:59 +0100 Subject: [PATCH 066/126] It is better to let the caller decide which mode (live or not) to take --- htdocs/stripe/class/stripe.class.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 3a9c8646686..cfeecd2bda8 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -93,25 +93,18 @@ class Stripe extends CommonObject * getStripeCustomerAccount * * @param int $id Id of third party - * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' + * @param int $status Status + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' */ - public function getStripeCustomerAccount($id) + public function getStripeCustomerAccount($id, $status=0) { global $conf; - if (empty($conf->global->STRIPECONNECT_LIVE)) { - $mode = 0; - } else { - if (empty($conf->global->STRIPE_LIVE)) { - $mode = 0; - } else { - $mode = $conf->global->STRIPE_LIVE; - } - } + $sql = "SELECT sa.key_account as key_account, sa.entity"; $sql.= " FROM " . MAIN_DB_PREFIX . "llx_societe_account as sa"; $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; - $sql.= " AND sa.site = 'stripe' AND sa.status = ".$mode; + $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $result = $this->db->query($sql); From 51229a602f136f5aa9c654af6edcf43edf8588e9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 09:51:45 +0100 Subject: [PATCH 067/126] Update commande.class.php --- htdocs/commande/class/commande.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index b450a6ad16b..6c156997995 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3126,7 +3126,8 @@ class Commande extends CommonOrder if ($result < 0) $error++; // End call triggers } - if($this->nb_expedition()!=0)$error++; + + if ($this->nb_expedition() != 0) $error++; //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail if (! $error) From dcd3387a30cd57c59ab2f94d38dd2574452c647d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 09:53:21 +0100 Subject: [PATCH 068/126] Update commande.class.php --- htdocs/commande/class/commande.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6c156997995..429566e054d 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3127,8 +3127,12 @@ class Commande extends CommonOrder // End call triggers } - if ($this->nb_expedition() != 0) $error++; - + if ($this->nb_expedition() != 0) + { + $this->errors[] = $langs->trans('SomeShipmentExists'); + $error++; + } + //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail if (! $error) { From 5d512af4b4c53921fc581e8dc7ea4c2e201560bc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 09:53:33 +0100 Subject: [PATCH 069/126] Fix migration --- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 5 +++-- .../install/mysql/tables/llx_societe_account.sql | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 1d1261edf5f..6ff739b5f40 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -235,6 +235,7 @@ CREATE TABLE llx_societe_account( -- BEGIN MODULEBUILDER FIELDS rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, entity integer DEFAULT 1, + key_account varchar(128), login varchar(128) NOT NULL, pass_encoding varchar(24) NOT NULL, pass_crypted varchar(128), @@ -255,13 +256,13 @@ CREATE TABLE llx_societe_account( ) ENGINE=innodb; --- BEGIN MODULEBUILDER INDEXES +ALTER TABLE llx_societe_account ADD COLUMN key_account varchar(128); + ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_rowid (rowid); ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_login (login); ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_status (status); ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_website (fk_website); ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_soc (fk_soc); --- END MODULEBUILDER INDEXES ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_login_website_soc(entity, fk_soc, login, site, fk_website); diff --git a/htdocs/install/mysql/tables/llx_societe_account.sql b/htdocs/install/mysql/tables/llx_societe_account.sql index e1a421affe4..4dd17f441ed 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.sql @@ -19,17 +19,17 @@ CREATE TABLE llx_societe_account( -- BEGIN MODULEBUILDER FIELDS rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, entity integer DEFAULT 1, + key_account varchar(128), login varchar(128) NOT NULL, - pass_encoding varchar(24) NOT NULL, - pass_crypted varchar(128), - pass_temp varchar(128), -- temporary password when asked for forget password - fk_soc integer, + pass_encoding varchar(24) NOT NULL, + pass_crypted varchar(128), + pass_temp varchar(128), -- temporary password when asked for forget password + fk_soc integer, site varchar(128), -- name of external web site fk_website integer, -- id of local web site note_private text, - key_account varchar(128), - date_last_login datetime, - date_previous_login datetime, + date_last_login datetime, + date_previous_login datetime, date_creation datetime NOT NULL, tms timestamp NOT NULL, fk_user_creat integer NOT NULL, From 4f6f0b302ef10d90ab9bdac16e6f57d73d7168d1 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 10:28:44 +0100 Subject: [PATCH 070/126] FIX for nondisplay of fk_element 's id in REST API response the fk_element don't display when the call is made with REST API (reason non found) --- htdocs/comm/action/class/actioncomm.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 9e0a0d6321d..f5209421694 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -164,6 +164,7 @@ class ActionComm extends CommonObject // Properties for links to other objects var $fk_element; // Id of record + var $elementid; // Id of record alternative for API var $elementtype; // Type of record. This if property ->element of object linked to. // Ical @@ -547,7 +548,7 @@ class ActionComm extends CommonObject $sql.= " a.fk_user_author, a.fk_user_mod,"; $sql.= " a.fk_user_action, a.fk_user_done,"; $sql.= " a.fk_contact, a.percent as percentage,"; - $sql.= " a.fk_element, a.elementtype,"; + $sql.= " a.fk_element as elementid, a.elementtype,"; $sql.= " a.priority, a.fulldayevent, a.location, a.punctual, a.transparency,"; $sql.= " c.id as type_id, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto,"; $sql.= " s.nom as socname,"; @@ -621,7 +622,8 @@ class ActionComm extends CommonObject $this->societe->id = $obj->fk_soc; // deprecated $this->contact->id = $obj->fk_contact; // deprecated - $this->fk_element = $obj->fk_element; + $this->fk_element = $obj->elementid; + $this->elementid = $obj->elementid; $this->elementtype = $obj->elementtype; $this->fetchResources(); From cd71e49762145eea793ae9fb383f07eb806d06e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 10:42:58 +0100 Subject: [PATCH 071/126] Picto ticket module --- htdocs/core/modules/modTicketsup.class.php | 20 ++++++------------ htdocs/theme/eldy/img/menus/ticketsup.png | Bin 0 -> 936 bytes .../theme/eldy/img/menus_black/ticketsup.png | Bin 0 -> 1044 bytes htdocs/theme/eldy/img/title_ticketsup.png | Bin 0 -> 1044 bytes htdocs/theme/eldy/style.css.php | 11 +++++++--- htdocs/theme/md/img/ticketsup.png | Bin 0 -> 1034 bytes htdocs/theme/md/img/title_ticketsup.png | Bin 0 -> 1044 bytes htdocs/ticketsup/index.php | 6 +++++- 8 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 htdocs/theme/eldy/img/menus/ticketsup.png create mode 100644 htdocs/theme/eldy/img/menus_black/ticketsup.png create mode 100644 htdocs/theme/eldy/img/title_ticketsup.png create mode 100644 htdocs/theme/md/img/ticketsup.png create mode 100644 htdocs/theme/md/img/title_ticketsup.png diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index 7e824cdf47b..4b79d472324 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -161,37 +161,31 @@ class modTicketsup extends DolibarrModules // Permissions $this->rights = array(); // Permission array used by this module - $r = 0; - $r++; $this->rights[$r][0] = 56001; // id de la permission $this->rights[$r][1] = "Read ticket"; // libelle de la permission $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'read'; - $r++; $this->rights[$r][0] = 56002; // id de la permission $this->rights[$r][1] = "Create les tickets"; // libelle de la permission $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'write'; - $r++; $this->rights[$r][0] = 56003; // id de la permission $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'delete'; - $r++; $this->rights[$r][0] = 56004; // id de la permission $this->rights[$r][1] = "Manage tickets"; // libelle de la permission //$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'manage'; - $r++; $this->rights[$r][0] = 56005; // id de la permission $this->rights[$r][1] = 'See all tickets, even if not assigned to (not effective for external users, always restricted to the thirdpardy they depends on)'; // libelle de la permission $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) @@ -211,7 +205,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/index.php', 'langs' => 'ticketsup', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position' => 100, - 'enabled' => '1', // Define condition to show or hide menu entry. Use '$conf->ticketsup->enabled' if entry must be visible if module is enabled. + 'enabled' => '$conf->ticketsup->enabled', // Define condition to show or hide menu entry. Use '$conf->ticketsup->enabled' if entry must be visible if module is enabled. 'perms' => '$user->rights->ticketsup->read', // Use 'perms'=>'$user->rights->ticketsup->level1->level2' if you want your menu with a permission rules 'target' => '', 'user' => 2); // 0=Menu for internal users, 1=external users, 2=both @@ -225,7 +219,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/index.php', 'langs' => 'ticketsup', 'position' => 101, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->read', 'target' => '', 'user' => 2); @@ -238,7 +232,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/new.php?action=create_ticket', 'langs' => 'ticketsup', 'position' => 102, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->write', 'target' => '', 'user' => 2); @@ -252,7 +246,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/list.php', 'langs' => 'ticketsup', 'position' => 103, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->read', 'target' => '', 'user' => 2); @@ -266,7 +260,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/list.php?search_fk_status=non_closed', 'langs' => 'ticketsup', 'position' => 104, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->read', 'target' => '', 'user' => 2); @@ -280,7 +274,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/list.php?mode=my_assign', 'langs' => 'ticketsup', 'position' => 105, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->read', 'target' => '', 'user' => 0); @@ -293,7 +287,7 @@ class modTicketsup extends DolibarrModules 'url' => '/ticketsup/list.php?mode=my_assign&search_fk_status=non_closed', 'langs' => 'ticketsup', 'position' => 106, - 'enabled' => 1, + 'enabled' => '$conf->ticketsup->enabled', 'perms' => '$user->rights->ticketsup->read', 'target' => '', 'user' => 0); diff --git a/htdocs/theme/eldy/img/menus/ticketsup.png b/htdocs/theme/eldy/img/menus/ticketsup.png new file mode 100644 index 0000000000000000000000000000000000000000..03354cc98e0b5d1506cf4f534c7877b51c9c567e GIT binary patch literal 936 zcmV;Z16TZsP)kdg00002VoOIv0063u zBQgL0010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXr{BPr2XW~KlD135`VK~zY` z&6V448b=g|zq1R=#ax2Z#Nc}yN0uu!X(RRjm#RKiQL9Fd-P8%eVDL>b7%yIS=bSz) z#$eosJhk&SnmOP6&TS6-*GsHHj$?6OZ)!dpgkl~UUJ%oi90Jf}{B2GFHT&(8AWsd<@Q&gh5(nG&mP)0R^h<-9liM4l`;vOr8k#8}_*wlD@; zVT~q(RI$v+s!*pNW$b5m$zy=W8OAdVfQUnW%g0nXmBBQKv!1z{y>Yu*147>Mg&`qO zq(qJHDS~(9AIR_imwTJcEFgL+J6_#Wx6dEaF5KLojFzm$5B?s{V`s-a4hSp!Xl1>~ zjxv}2;e6B!HypY(>m_+B@hUtkPF?V3ZoQ^~bMNF=FJrG468Fl>$}h>EIO@!tP65MB z{Z2*O9Qf}!V#jK8<~3e&T}O>|jiDm}X zc?DI&V(V9K0Z=kD@XVhyjYl0H1*qKGz!dDs0|34{!aL2x7&~c?iem?eC-sPi>eRRL z96&{lSak|Wh$*I-uo?wo+#LWV#+l3m`Wh*kyK6>z#29HRYd}no+sWOWqGKJ*yKqH> zlD`PjUxsu3La0vM6An2S1Go$*;E1@IE9LmwPjD;|Fb0s3eV|O5$O`BDEu+c%0R@!A zUC$|~DZgF;Gkdg00002VoOIv0RM-N z%)bBt010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXr{7YHUBg%1D#1EonsK~zY` z&6Vv>+f@|DKj+?GOI!Oe%0ttN3<`sdEyC0&NN_>-kSr`F#uvWx?=#VuMVTRPCT5Yr zP}vM5jFurAY!phN4;j$*_q)DmDJ{$w`bN*Yn{&ROdmeJ`h5y<#QQFC2{*|_yCP87* zN0FzL|AE*dj+&fVoe_65-(Z92B{Iloa0Y6 z;Jn9-FoK6BJh*@o2OM%B4|uS20K7>T2{M(89t#fnTLn{Kj%~800OBV^8}CT~lh5Sl?fd!d`exKwPxRI0 z{dnFvGpl~FlMDG{&!vD)nh$s1CloQh$ zeuhU36K#-38Rk*pp);pfRg)fk=i(`V88s1XW`9iri%fH+0dR$B7UB1&YDR2{$ml76 z6}B8}K`#RkB!)wKP2P?}j39tcSc}?N%_jgO5#<$2WmKi}1}_8D(&Qooc&q!8CoQ79 z!;uDnM3qb1YI~*tfQ^qK+_(U6;bsUQHo$B_?`XuWVvQxl#H)~8_2f{-%~eVOl(>qU zGEVifoD%VxXam5~T8kscOYPtgr3-*AqL?E&C`W89E~^2cQgWy)9jL}+Sp?kl0?>;a z!{X7ds-SYop-MHDu%QmM(&0~h)%%y2!b=>0I9{e$s^svoPqirI(5yEA{3%@&RGav# zz#S$@)-p&k$xgKce$}c(m;8+xd|xIf!iA~?AWec+T4rxDgI=|!9|E&exn;N zKa*#l9QK6eTxV3oJd~-VeFBiM`?As@t%S9!e`mQsj^|_%c35G99Hm<=e5A%yKrO2~ zchawU4-$J9EZw8Sa!&l`vmfLi+d#Tf{g+l(r`(Wh;#Yfe@4NZBN1%S?KJ{>oal*hB zQ*4ss0Pqkb!VMz8E_bq?S!@i3pUe;6?4693*MB@;G@Bl}O?TyEkyTb%`D&N{rTqo<%tv;ioLqST O0000kdg00002VoOIv0RM-N z%)bBt010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXr{7YHUBg%1D#1EonsK~zY` z&6Vv>+f@|DKj+?GOI!Oe%0ttN3<`sdEyC0&NN_>-kSr`F#uvWx?=#VuMVTRPCT5Yr zP}vM5jFurAY!phN4;j$*_q)DmDJ{$w`bN*Yn{&ROdmeJ`h5y<#QQFC2{*|_yCP87* zN0FzL|AE*dj+&fVoe_65-(Z92B{Iloa0Y6 z;Jn9-FoK6BJh*@o2OM%B4|uS20K7>T2{M(89t#fnTLn{Kj%~800OBV^8}CT~lh5Sl?fd!d`exKwPxRI0 z{dnFvGpl~FlMDG{&!vD)nh$s1CloQh$ zeuhU36K#-38Rk*pp);pfRg)fk=i(`V88s1XW`9iri%fH+0dR$B7UB1&YDR2{$ml76 z6}B8}K`#RkB!)wKP2P?}j39tcSc}?N%_jgO5#<$2WmKi}1}_8D(&Qooc&q!8CoQ79 z!;uDnM3qb1YI~*tfQ^qK+_(U6;bsUQHo$B_?`XuWVvQxl#H)~8_2f{-%~eVOl(>qU zGEVifoD%VxXam5~T8kscOYPtgr3-*AqL?E&C`W89E~^2cQgWy)9jL}+Sp?kl0?>;a z!{X7ds-SYop-MHDu%QmM(&0~h)%%y2!b=>0I9{e$s^svoPqirI(5yEA{3%@&RGav# zz#S$@)-p&k$xgKce$}c(m;8+xd|xIf!iA~?AWec+T4rxDgI=|!9|E&exn;N zKa*#l9QK6eTxV3oJd~-VeFBiM`?As@t%S9!e`mQsj^|_%c35G99Hm<=e5A%yKrO2~ zchawU4-$J9EZw8Sa!&l`vmfLi+d#Tf{g+l(r`(Wh;#Yfe@4NZBN1%S?KJ{>oal*hB zQ*4ss0Pqkb!VMz8E_bq?S!@i3pUe;6?4693*MB@;G@Bl}O?TyEkyTb%`D&N{rTqo<%tv;ioLqST O0000); } +div.mainmenu.ticketsup { + background-image: url(); +} + div.mainmenu.tools { background-image: url(); } @@ -1686,10 +1690,11 @@ div.mainmenu.website { 'name of class for div') -$moduletomainmenu=array('user'=>'','syslog'=>'','societe'=>'companies','projet'=>'project','propale'=>'commercial','commande'=>'commercial', +$moduletomainmenu=array( + 'user'=>'','syslog'=>'','societe'=>'companies','projet'=>'project','propale'=>'commercial','commande'=>'commercial', 'produit'=>'products','service'=>'products','stock'=>'products', 'don'=>'accountancy','tax'=>'accountancy','banque'=>'accountancy','facture'=>'accountancy','compta'=>'accountancy','accounting'=>'accountancy','adherent'=>'members','import'=>'tools','export'=>'tools','mailing'=>'tools', - 'contrat'=>'commercial','ficheinter'=>'commercial','deplacement'=>'commercial', + 'contrat'=>'commercial','ficheinter'=>'commercial','ticketsup'=>'ticketsup','deplacement'=>'commercial', 'fournisseur'=>'companies', 'barcode'=>'','fckeditor'=>'','categorie'=>'', ); @@ -1705,7 +1710,7 @@ $generic=1; // Put here list of menu entries when the div.mainmenu.menuentry was previously defined $divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','ftp','holiday','hrm','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','stripe','webservices','website'); // Put here list of menu entries we are sure we don't want -$divnotrequired=array('multicurrency','salaries','margin','opensurvey','paybox','expensereport','incoterm','prelevement','propal','workflow','notification','supplier_proposal','cron','product','productbatch','expedition'); +$divnotrequired=array('multicurrency','salaries','ticketsup','margin','opensurvey','paybox','expensereport','incoterm','prelevement','propal','workflow','notification','supplier_proposal','cron','product','productbatch','expedition'); foreach($mainmenuusedarray as $val) { if (empty($val) || in_array($val,$divalreadydefined)) continue; diff --git a/htdocs/theme/md/img/ticketsup.png b/htdocs/theme/md/img/ticketsup.png new file mode 100644 index 0000000000000000000000000000000000000000..3ee928e07b3524a319cab19f8ef91c012397df77 GIT binary patch literal 1034 zcmV+l1oiugP)kdg00002VoOIv0RM-N z%)bBt010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXr{7Ayk;P@ez*1Di=iK~zY` z&6VFzn`IQoKc{`$(Mnrd=t#Ti__eWt2#bm!VUxJT#Eh62O^i4GYu*`SjIv1J2Oi(Tn+_vSp`@AExB-tU3``iLe7@KnspL)FVU zUWj^dxImFbabE)L(1M>QxKjFjjRcP+cW~jMza~kNvz!GoWLVx=?k<+$5nku{zHTWq z#yHQP@(g~jk$(EA;S@FafIW8DWk*w_F71Gxp^162`-jUmI!g)(hwTThNr!E!>flF z=P1EKB6vB_60(~U_7`uuYwIxbC}h&|ZnT%kioQs5GQmttuKeA=YJ9sc8=kJLde;`y z`HN@Y|SUp{S|1_2)VE{Al&Kh;2#|Xw7Z9pBHwfmJ<0(4N8NhciyPyn`A zQ?Y?mV+DaGtj`#`+Ft;`5Tpmc`T*32pB{o3fWCrRH>lqxD^o~nz@qtsp~S_{HQ57@ zJ+9%$#g-n+ThV|dDhOP!@v2oloNFuzZ356H66gUOtW{%V6=E4phP6Dr-wF$?%< z1E38*$}FXS)rPH4ckN1L3eW7W@tD}{Ab?or7$ZOn04)Rkdg00002VoOIv0RM-N z%)bBt010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXr{7YHUBg%1D#1EonsK~zY` z&6Vv>+f@|DKj+?GOI!Oe%0ttN3<`sdEyC0&NN_>-kSr`F#uvWx?=#VuMVTRPCT5Yr zP}vM5jFurAY!phN4;j$*_q)DmDJ{$w`bN*Yn{&ROdmeJ`h5y<#QQFC2{*|_yCP87* zN0FzL|AE*dj+&fVoe_65-(Z92B{Iloa0Y6 z;Jn9-FoK6BJh*@o2OM%B4|uS20K7>T2{M(89t#fnTLn{Kj%~800OBV^8}CT~lh5Sl?fd!d`exKwPxRI0 z{dnFvGpl~FlMDG{&!vD)nh$s1CloQh$ zeuhU36K#-38Rk*pp);pfRg)fk=i(`V88s1XW`9iri%fH+0dR$B7UB1&YDR2{$ml76 z6}B8}K`#RkB!)wKP2P?}j39tcSc}?N%_jgO5#<$2WmKi}1}_8D(&Qooc&q!8CoQ79 z!;uDnM3qb1YI~*tfQ^qK+_(U6;bsUQHo$B_?`XuWVvQxl#H)~8_2f{-%~eVOl(>qU zGEVifoD%VxXam5~T8kscOYPtgr3-*AqL?E&C`W89E~^2cQgWy)9jL}+Sp?kl0?>;a z!{X7ds-SYop-MHDu%QmM(&0~h)%%y2!b=>0I9{e$s^svoPqirI(5yEA{3%@&RGav# zz#S$@)-p&k$xgKce$}c(m;8+xd|xIf!iA~?AWec+T4rxDgI=|!9|E&exn;N zKa*#l9QK6eTxV3oJd~-VeFBiM`?As@t%S9!e`mQsj^|_%c35G99Hm<=e5A%yKrO2~ zchawU4-$J9EZw8Sa!&l`vmfLi+d#Tf{g+l(r`(Wh;#Yfe@4NZBN1%S?KJ{>oal*hB zQ*4ss0Pqkb!VMz8E_bq?S!@i3pUe;6?4693*MB@;G@Bl}O?TyEkyTb%`D&N{rTqo<%tv;ioLqST O0000trans('TicketsIndex'), ''); -$form = new Form($db); +$linkback=''; +print load_fiche_titre($langs->trans('TicketsIndex'),$linkback,'title_ticketsup.png'); + $dir = ''; $filenamenb = $dir . "/" . $prefix . "ticketsupinyear-" . $endyear . ".png"; From 0f15f3c129feeefbab239e9d76124c8124ee5bb1 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 11:27:16 +0100 Subject: [PATCH 072/126] Fix database name --- htdocs/stripe/class/stripe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index cfeecd2bda8..d6d1601d405 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -101,7 +101,7 @@ class Stripe extends CommonObject global $conf; $sql = "SELECT sa.key_account as key_account, sa.entity"; - $sql.= " FROM " . MAIN_DB_PREFIX . "llx_societe_account as sa"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); From eabc5c0812b4adf6ea481debb439fcd24ec0af08 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 11:37:40 +0100 Subject: [PATCH 073/126] FIX with new database llx_societe_account --- htdocs/stripe/class/stripe.class.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index d6d1601d405..c46b554388d 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -123,11 +123,11 @@ class Stripe extends CommonObject } - /** - * customerStripe +/** + * customerStripe Call customer in stripe && create/update and save it on dolibarr * - * @param int $id ??? - * @param string $key ??? + * @param int $id Id of third party + * @return string Stripe account ref 'acc_xxxxxxxxxxxxx' * @return \Stripe\StripeObject|\Stripe\ApiResource */ public function customerStripe($id,$key) @@ -142,10 +142,11 @@ class Stripe extends CommonObject $mode = $conf->global->STRIPE_LIVE; } } - $sql = "SELECT rowid,fk_soc,fk_key,mode,entity"; - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe"; - $sql .= " WHERE fk_soc = " . $id . " "; - $sql .= " AND mode=" . $mode . " AND entity IN (" . getEntity('stripe') . ")"; + $sql = "SELECT sa.key_account as key_account, sa.entity"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; + $sql.= " WHERE sa.fk_soc = " . $id; + $sql.= " AND sa.entity IN (".getEntity('societe').")"; + $sql.= " AND sa.site = 'stripe' AND sa.status = 0".((int) $status); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -155,7 +156,7 @@ class Stripe extends CommonObject $num = $this->db->num_rows($resql); if ($num) { $obj = $this->db->fetch_object($resql); - $tiers = $obj->fk_key; + $tiers = $obj->key_account; if ($conf->entity == 1) { $customer = \Stripe\Customer::retrieve("$tiers"); } else { @@ -178,8 +179,8 @@ class Stripe extends CommonObject )); } $customer_id = "" . $customer->id . ""; - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_stripe (fk_soc,fk_key,mode,entity)"; - $sql .= " VALUES ($id,'$customer_id'," . $mode . "," . $conf->entity . ")"; + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc,key_account,site,status,entity)"; + $sql .= " VALUES ($id,'$customer_id','stripe'," . $mode . "," . $conf->entity . ")"; dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); } From 7feaeb1b89512416e69f20cc076cfb5cc5f265fd Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 12:07:53 +0100 Subject: [PATCH 074/126] more FIX for unified stripe's payment class --- htdocs/stripe/class/stripe.class.php | 51 +++++++++++++--------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index c46b554388d..7a6234575f7 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -123,8 +123,8 @@ class Stripe extends CommonObject } -/** - * customerStripe Call customer in stripe && create/update and save it on dolibarr + /** + * customerStripe * * @param int $id Id of third party * @return string Stripe account ref 'acc_xxxxxxxxxxxxx' @@ -146,7 +146,7 @@ class Stripe extends CommonObject $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; - $sql.= " AND sa.site = 'stripe' AND sa.status = 0".((int) $status); + $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -189,44 +189,41 @@ class Stripe extends CommonObject } /** - * createPaymentStripe + * createPaymentStripe Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API * - * @param unknown $amount ??? - * @param unknown $currency ??? - * @param unknown $origin ??? - * @param unknown $item ??? - * @param unknown $source ??? - * @param unknown $customer ??? - * @param unknown $account ??? + * @param int $amount amount to pay + * @param string $currency EUR, GPB... + * @param string $origin order, invoice, contract... + * @param int $item if of element to pay + * @param string $source src_xxxxx or card_xxxxx or ac_xxxxx + * @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe() + * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() + * @param int $status Status * @return Stripe */ - public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account) + public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0) { global $conf; - if (empty($conf->global->STRIPECONNECT_LIVE)) { - $mode = 0; - } else { - if (empty($conf->global->STRIPE_LIVE)) { - $mode = 0; - } else { - $mode = $conf->global->STRIPE_LIVE; - } - } - $sql = "SELECT fk_soc,fk_key,mode,entity"; - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe"; - $sql .= " WHERE fk_key = '$customer' "; - $sql .= " AND mode=" . $mode . " "; + $sql = "SELECT sa.key_account as key_account, sa.entity"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; + $sql.= " WHERE sa.key_account = " . $customer; + //$sql.= " AND sa.entity IN (".getEntity('societe').")"; + $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); - $entite = $obj->entity; - $fksoc = $obj->fk_soc; + $key = $obj->fk_soc; + } else { + $key = NULL; } + } else { + $key = NULL; } + $stripeamount = round($amount * 100); $societe = new Societe($this->db); $societe->fetch($fksoc); From 8048259733a5c32f63b5153df6caba2a3d94dfb0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 12:13:47 +0100 Subject: [PATCH 075/126] Work on ticket module integration --- .tx/config | 6 ++ htdocs/core/lib/admin.lib.php | 24 +++---- htdocs/core/modules/modApi.class.php | 15 ----- htdocs/core/modules/modTicketsup.class.php | 5 +- .../mysql/data/llx_c_ticketsup_category.sql | 20 ++++++ .../mysql/data/llx_c_ticketsup_severity.sql | 24 +++++-- .../mysql/data/llx_c_ticketsup_type.sql | 26 ++++++-- htdocs/install/mysql/data/llx_ticketsup.sql | 17 ----- .../install/mysql/migration/7.0.0-8.0.0.sql | 59 ++++++++++++------ .../tables/llx_c_ticketsup_category.key.sql | 2 +- .../mysql/tables/llx_c_ticketsup_category.sql | 1 + .../tables/llx_c_ticketsup_severity.key.sql | 2 +- .../mysql/tables/llx_c_ticketsup_severity.sql | 1 + .../mysql/tables/llx_c_ticketsup_type.key.sql | 2 +- .../mysql/tables/llx_c_ticketsup_type.sql | 1 + htdocs/langs/en_US/ticketsup.lang | 6 +- htdocs/theme/eldy/img/menus/README.md | 4 +- htdocs/ticketsup/img/ticketsup-32.png | Bin 1412 -> 0 bytes htdocs/ticketsup/list.php | 2 +- htdocs/ticketsup/new.php | 2 +- 20 files changed, 135 insertions(+), 84 deletions(-) create mode 100644 htdocs/install/mysql/data/llx_c_ticketsup_category.sql delete mode 100644 htdocs/install/mysql/data/llx_ticketsup.sql delete mode 100644 htdocs/ticketsup/img/ticketsup-32.png diff --git a/.tx/config b/.tx/config index 89d123b0362..14d735d8610 100644 --- a/.tx/config +++ b/.tx/config @@ -356,6 +356,12 @@ source_file = htdocs/langs/en_US/supplier_proposal.lang source_lang = en_US type = MOZILLAPROPERTIES +[dolibarr.ticketsup] +file_filter = htdocs/langs//ticketsup.lang +source_file = htdocs/langs/en_US/ticketsup.lang +source_lang = en_US +type = MOZILLAPROPERTIES + [dolibarr.trips] file_filter = htdocs/langs//trips.lang source_file = htdocs/langs/en_US/trips.lang diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 0f219a032cc..2c94dcf65ca 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1031,7 +1031,8 @@ function unActivateModule($value, $requiredby=1) /** - * Add external modules to list of dictionaries + * Add external modules to list of dictionaries. + * Addition is done into var $taborder, $tabname, etc... that are passed with pointers. * * @param array $taborder Taborder * @param array $tabname Tabname @@ -1097,23 +1098,20 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql if ($modulequalified) { // Load languages files of module - if (isset($objMod->langfiles) && is_array($objMod->langfiles)) - { - foreach($objMod->langfiles as $langfile) - { - $langs->load($langfile); - } - } + if (isset($objMod->langfiles) && is_array($objMod->langfiles)) { + foreach ($objMod->langfiles as $langfile) { + $langs->load($langfile); + } + } - // Complete arrays - //&$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond + // Complete the arrays &$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond if (empty($objMod->dictionaries) && ! empty($objMod->dictionnaries)) $objMod->dictionaries=$objMod->dictionnaries; // For backward compatibility if (! empty($objMod->dictionaries)) { //var_dump($objMod->dictionaries['tabname']); $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp=0; - foreach($objMod->dictionaries['tabname'] as $val) { $nbtabname++; $taborder[] = max($taborder)+1; $tabname[] = $val; } + foreach($objMod->dictionaries['tabname'] as $val) { $nbtabname++; $taborder[] = max($taborder)+1; $tabname[] = $val; } // Position foreach($objMod->dictionaries['tablib'] as $val) { $nbtablib++; $tablib[] = $val; } foreach($objMod->dictionaries['tabsql'] as $val) { $nbtabsql++; $tabsql[] = $val; } foreach($objMod->dictionaries['tabsqlsort'] as $val) { $nbtabsqlsort++; $tabsqlsort[] = $val; } @@ -1130,6 +1128,10 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql print 'Error in descriptor of module '.$const_name.'. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"'; //print "$const_name: $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp\n"; } + else + { + $taborder[] = 0; // Add an empty line + } } $j++; diff --git a/htdocs/core/modules/modApi.class.php b/htdocs/core/modules/modApi.class.php index 24d784585d3..86588f06ed4 100644 --- a/htdocs/core/modules/modApi.class.php +++ b/htdocs/core/modules/modApi.class.php @@ -125,21 +125,6 @@ class modApi extends DolibarrModules $conf->api->enabled=0; } $this->dictionaries=array(); - /* Example: - if (! isset($conf->api->enabled)) $conf->api->enabled=0; // This is to avoid warnings - $this->dictionaries=array( - 'langs'=>'mylangfile@api', - 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor - 'tablib'=>array("Table1","Table2","Table3"), // Label of tables - 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields - 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order - 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary) - 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record) - 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert) - 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid') - 'tabcond'=>array($conf->api->enabled,$conf->api->enabled,$conf->api->enabled) // Condition to show each dictionary - ); - */ // Boxes // Add here list of php file(s) stored in core/boxes that contains class to show a box. diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index 4b79d472324..c6a6ada09f9 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -311,8 +311,7 @@ class modTicketsup extends DolibarrModules array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticketsup', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1), array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110122, 'ticketsup', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1);", "ignoreerror" => 1), array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticketsup', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1), - array("sql" => "insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values ('','TICKETMESSAGE_SENTBYMAIL','Envoi message de réponse par mail','Executed when a response is made on a ticket','ticketsup','');", "ignoreerror" => 1), - + array("sql" => "insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values ('','TICKETMESSAGE_SENTBYMAIL','Send email for ticket','Executed when a response is made on a ticket','ticketsup','');", "ignoreerror" => 1), ); $result = $this->loadTables(); @@ -345,6 +344,6 @@ class modTicketsup extends DolibarrModules */ private function loadTables() { - return $this->_load_tables('/ticketsup/sql/'); + return $this->_load_tables(); } } diff --git a/htdocs/install/mysql/data/llx_c_ticketsup_category.sql b/htdocs/install/mysql/data/llx_c_ticketsup_category.sql new file mode 100644 index 00000000000..0f00ec77502 --- /dev/null +++ b/htdocs/install/mysql/data/llx_c_ticketsup_category.sql @@ -0,0 +1,20 @@ +-- Copyright (C) 2018 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 . +-- +-- +-- Contenu de la table llx_c_ticketsup_category +-- + +INSERT INTO llx_c_ticketsup_category (code, pos, label, active, use_default, description) VALUES('OTHER', '10', 'Other', 1, 1, NULL); diff --git a/htdocs/install/mysql/data/llx_c_ticketsup_severity.sql b/htdocs/install/mysql/data/llx_c_ticketsup_severity.sql index 9e356988256..1b9c3e42ca0 100644 --- a/htdocs/install/mysql/data/llx_c_ticketsup_severity.sql +++ b/htdocs/install/mysql/data/llx_c_ticketsup_severity.sql @@ -1,9 +1,23 @@ - +-- Copyright (C) 2018 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 . +-- -- -- Contenu de la table llx_c_ticketsup_severity -- -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(1, 'LOW', '10', 'Bas', '', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(2, 'NORMAL', '20', 'Normal', '', 1, 1, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(3, 'LOWHIGH', '30', 'Important', '', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(4, 'HIGH', '40', 'Critique / bloquant', '', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('LOW', '10', 'Low', '', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('NORMAL', '20', 'Normal', '', 1, 1, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('HIGH', '30', 'High', '', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('BLOCKING', '40', 'Critical / blocking', '', 1, 0, NULL); diff --git a/htdocs/install/mysql/data/llx_c_ticketsup_type.sql b/htdocs/install/mysql/data/llx_c_ticketsup_type.sql index e5bb1869e5d..310b075a604 100644 --- a/htdocs/install/mysql/data/llx_c_ticketsup_type.sql +++ b/htdocs/install/mysql/data/llx_c_ticketsup_type.sql @@ -1,8 +1,24 @@ - +-- Copyright (C) 2018 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 . +-- -- -- Contenu de la table llx_c_ticketsup_type -- -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(1, 'COM', '10', 'Question commerciale', 1, 1, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(2, 'INCIDENT', '20', 'Demande d''assistance', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(3, 'PROJET', '30', 'Suivi projet', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(4, 'OTHER', '40', 'Autre', 1, 0, NULL); + +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('COM', '10', 'Commercial question', 1, 1, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('ISSUE', '20', 'Issue or problem' , 1, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('REQUEST', '25', 'Change or enhancement request', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('PROJECT', '30', 'Project', 0, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('OTHER', '40', 'Other', 1, 0, NULL); diff --git a/htdocs/install/mysql/data/llx_ticketsup.sql b/htdocs/install/mysql/data/llx_ticketsup.sql deleted file mode 100644 index 41c78d32d21..00000000000 --- a/htdocs/install/mysql/data/llx_ticketsup.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- --- Contenu de la table llx_c_ticketsup_type --- -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(1, 'COM', '10', 'Question commerciale', 1, 1, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(2, 'INCIDENT', '20', 'Demande d''assistance', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(3, 'PROJET', '30', 'Suivi projet', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_type (rowid, code, pos, label, active, use_default, description) VALUES(4, 'OTHER', '40', 'Autre', 1, 0, NULL); - --- --- Contenu de la table llx_c_ticketsup_severity --- - -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(1, 'LOW', '10', 'Bas', '', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(2, 'NORMAL', '20', 'Normal', '', 1, 1, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(3, 'LOWHIGH', '30', 'Important', '', 1, 0, NULL); -INSERT INTO llx_c_ticketsup_severity (rowid, code, pos, label, color, active, use_default, description) VALUES(4, 'HIGH', '40', 'Critique / bloquant', '', 1, 0, NULL); diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 6ff739b5f40..9c65b4442d2 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -185,24 +185,13 @@ CREATE TABLE llx_ticketsup_extrafields import_key varchar(14) )ENGINE=innodb; -ALTER TABLE llx_c_ticketsup_category ADD INDEX idx_code (code); -CREATE TABLE llx_c_ticketsup_category -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - code varchar(32) NOT NULL, - pos varchar(32) NOT NULL, - label varchar(128) NOT NULL, - active integer DEFAULT 1, - use_default integer DEFAULT 1, - description varchar(255) -)ENGINE=innodb; - -ALTER TABLE llx_c_ticketsup_severity ADD INDEX idx_code (code); - -CREATE TABLE llx_c_ticketsup_severity + +-- Create dictionaries tables for ticket +create table llx_c_ticketsup_severity ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, code varchar(32) NOT NULL, pos varchar(32) NOT NULL, label varchar(128) NOT NULL, @@ -212,11 +201,10 @@ CREATE TABLE llx_c_ticketsup_severity description varchar(255) )ENGINE=innodb; -ALTER TABLE llx_c_ticketsup_type ADD INDEX idx_code (code); - -CREATE TABLE llx_c_ticketsup_type +create table llx_c_ticketsup_type ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, code varchar(32) NOT NULL, pos varchar(32) NOT NULL, label varchar(128) NOT NULL, @@ -225,6 +213,41 @@ CREATE TABLE llx_c_ticketsup_type description varchar(255) )ENGINE=innodb; +create table llx_c_ticketsup_category +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, + code varchar(32) NOT NULL, + pos varchar(32) NOT NULL, + label varchar(128) NOT NULL, + active integer DEFAULT 1, + use_default integer DEFAULT 1, + description varchar(255) +)ENGINE=innodb; + +ALTER TABLE llx_c_ticketsup_category ADD UNIQUE INDEX uk_code (code, entity); +ALTER TABLE llx_c_ticketsup_severity ADD UNIQUE INDEX uk_code (code, entity); +ALTER TABLE llx_c_ticketsup_type ADD UNIQUE INDEX uk_code (code, entity); + + + +-- Load data +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('LOW', '10', 'Low', '', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('NORMAL', '20', 'Normal', '', 1, 1, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('HIGH', '30', 'High', '', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_severity (code, pos, label, color, active, use_default, description) VALUES('BLOCKING', '40', 'Critical / blocking', '', 1, 0, NULL); + +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('COM', '10', 'Commercial question', 1, 1, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('ISSUE', '20', 'Issue or problem' , 1, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('REQUEST', '25', 'Change or enhancement request', 1, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('PROJECT', '30', 'Project', 0, 0, NULL); +INSERT INTO llx_c_ticketsup_type (code, pos, label, active, use_default, description) VALUES('OTHER', '40', 'Other', 1, 0, NULL); + +INSERT INTO llx_c_ticketsup_category (code, pos, label, active, use_default, description) VALUES('OTHER', '10', 'Other', 1, 1, NULL); + + + + ALTER TABLE llx_facturedet_rec ADD COLUMN date_start_fill integer DEFAULT 0; ALTER TABLE llx_facturedet_rec ADD COLUMN date_end_fill integer DEFAULT 0; diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_category.key.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_category.key.sql index 734fbcc8ece..a43346b87cf 100644 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_category.key.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_category.key.sql @@ -15,4 +15,4 @@ -- -- -ALTER TABLE llx_c_ticketsup_category ADD INDEX idx_code (code); +ALTER TABLE llx_c_ticketsup_category ADD UNIQUE INDEX uk_code (code, entity); diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_category.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_category.sql index 33b49b12df8..cce444d7f8a 100755 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_category.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_category.sql @@ -18,6 +18,7 @@ create table llx_c_ticketsup_category ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, code varchar(32) NOT NULL, pos varchar(32) NOT NULL, label varchar(128) NOT NULL, diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_severity.key.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_severity.key.sql index a873969876e..2772b0b545e 100644 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_severity.key.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_severity.key.sql @@ -15,4 +15,4 @@ -- -- -ALTER TABLE llx_c_ticketsup_severity ADD INDEX idx_code (code); +ALTER TABLE llx_c_ticketsup_severity ADD UNIQUE INDEX uk_code (code, entity); diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_severity.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_severity.sql index a825000831d..9c26ec5cc32 100755 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_severity.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_severity.sql @@ -18,6 +18,7 @@ create table llx_c_ticketsup_severity ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, code varchar(32) NOT NULL, pos varchar(32) NOT NULL, label varchar(128) NOT NULL, diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_type.key.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_type.key.sql index d451cc51a39..6dd4ec8fc9a 100644 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_type.key.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_type.key.sql @@ -15,4 +15,4 @@ -- -- -ALTER TABLE llx_c_ticketsup_type ADD INDEX idx_code (code); +ALTER TABLE llx_c_ticketsup_type ADD UNIQUE INDEX uk_code (code, entity); diff --git a/htdocs/install/mysql/tables/llx_c_ticketsup_type.sql b/htdocs/install/mysql/tables/llx_c_ticketsup_type.sql index 8983159ec0d..33f7b8a2973 100755 --- a/htdocs/install/mysql/tables/llx_c_ticketsup_type.sql +++ b/htdocs/install/mysql/tables/llx_c_ticketsup_type.sql @@ -18,6 +18,7 @@ create table llx_c_ticketsup_type ( rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1, code varchar(32) NOT NULL, pos varchar(32) NOT NULL, label varchar(128) NOT NULL, diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index 8187e8220d9..9064222637a 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -29,7 +29,7 @@ Permission56005=See tickets of all thirdparties (not effective for external user TicketsupDictType=Tickets type TicketsupDictCategory=Tickets categories -TicketsupDictSeverity=Severity classifications +TicketsupDictSeverity=Tickets severity TicketTypeShortBUGSOFT=Dysfonctionnement logiciel TicketTypeShortBUGHARD=Dysfonctionnement matériel TicketTypeShortCOM=Commercial question @@ -39,8 +39,8 @@ TicketTypeShortOTHER=Other TicketSeverityShortLOW=Low TicketSeverityShortNORMAL=Normal -TicketSeverityShortLOWHIGH=Important -TicketSeverityShortHIGH=Critical +TicketSeverityShortHIGH=High +TicketSeverityShortBLOCKING=Critical/Blocking ErrorBadEmailAddress=Field '%s' incorrect MenuTicketsupMyAssign=My tickets diff --git a/htdocs/theme/eldy/img/menus/README.md b/htdocs/theme/eldy/img/menus/README.md index 2c3e65e4e23..72f376c3f2b 100644 --- a/htdocs/theme/eldy/img/menus/README.md +++ b/htdocs/theme/eldy/img/menus/README.md @@ -2,8 +2,8 @@ Tutorial to create a new image for menu: 1) First find an image. -2) With Gimp, open image and check there is a alpha channel. If not add one. -3) Convert image into back and white (Menu Image - Mode - Grey levels). +2) With Gimp, open image and check there is a alpha channel. If not add one (Menu Color - Convert to alpha). +3) Convert image into black and white (Menu Image - Mode - Grey levels). 4) Use the degrade tool with option (Menu Tools - Paint - Degrade - CTRL+L): * Mode: Erase color (you can also try "Clear only") * Opacity: 50 +/- diff --git a/htdocs/ticketsup/img/ticketsup-32.png b/htdocs/ticketsup/img/ticketsup-32.png deleted file mode 100644 index ce4b71ca624f73ce0f0b56b945b2ec254b21b383..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1412 zcmV-~1$+95P)$^!`kVuT1S#0y?(pjMjr;)97O zBpRYGq)h>n#u&knmO|7Z4KYy(rd;I~C~~P3q(U#0NK@=?chC56zQUp1ZR>-+=$D-2 zd^7X?=YMAA%zW@)UmjpQkO6c6`Y-y;1p)$CfDf1nbOQ}Q_#blYGmeJ=r-87zlwKek z$OH}pxBDI6u+L9NcseixVLG-w6#&aRhjJD;!${v*HZ2Xsa6Sr{3p4>2fgS*f!7$ZC z;{wnKK-sP!wzn9S*ARk05J&)37=mfe@x)A*gtEYNSzMD|z zPJTIfBbJ+lxCEBIm(T5{HMCxy%(YWCnR)y1`ah?;`yks_w#Gd3W_2pw;31-+HC#Kn z7>(wUw=BS@%nR`d#E!uF+6mZHlHgxVTVosN4m5J_kMForzhOwVo;7zP!$&M&+M+B{ zCZ!Px)nQRe#fqzaO|6&!DkTW>iG(3NdoNubo4Hb-02B?ueGyj<`{-=nO#0+KL_#3U zN2Mf|aeo5q_dE@{9F+jVQ6k};G#>pLvlz zkw6w;1LI;iA7^w~#VgR+9}Rn%z|-ddpoIPV-?dFfRsyc}AD?&`fbK zdW$d7_=rP5B^O9U6jYk1DC%%&Bfz7;LLdP6T{^#!Ei^Wf`<14}eM;t+^> za!?szb~pQ0hiRb!;1yFNy(?s70b^tLIeXK5;0U6gocII;AA*GvMTy4xL3{snV46!l z&B%y3(tGg)3&9tkfW;-?F5tn^)IKn+z#;P<0P-h6Wo#a#z`+=g07@rO&c`PZ^fw^fGm|b8m9#!lXa=?d zr+_&w`5YtLYHZwvo#tQx!aaiihWG?Nd8P+wF(YCDwid*wgB!pJ^WSHfXPlAUh>`yS z&;~6Iun}1VtYPggpKE+afp38=z!>vvF|z3W5&!nC1Z;U3Sc0Iy0fXJ|cKYx-x;H{W z;Z0x)Do&U!kC%egzjCbl4$x*UuC3++dQ)=I=t7izHHN6X0lbPzGNSbeA5y;R`p|Dg zrL`pp?}MbFgg|#<$u^QR8`zZpXUsDn92-tYa}Kt>4%L@Hh9TO5vXROa+y35-NP2dl z-eh1M!ehYe*gQ!`Qw49;o}l`C2XgB}`z2jhASwly0hAJsfpH#~*NNzk9M?BkRd{?7kvi0d!jdBXY@ SHh8K40000'; print ''; -print_barre_liste($langs->trans('TicketList'), $page, 'list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'img/ticketsup-32.png', 1); +print_barre_liste($langs->trans('TicketList'), $page, 'list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'title_ticketsup'); if ($mode == 'my_assign') { print '
    ' . $langs->trans('TicketAssignedToMeInfos') . '

    '; diff --git a/htdocs/ticketsup/new.php b/htdocs/ticketsup/new.php index 3d1a3c7c9f2..e08361e1e77 100644 --- a/htdocs/ticketsup/new.php +++ b/htdocs/ticketsup/new.php @@ -72,7 +72,7 @@ $form = new Form($db); if ($action == 'create_ticket') { $formticket = new FormTicketsup($db); - print load_fiche_titre($langs->trans('NewTicket'), '', 'img/ticketsup-32.png', 1); + print load_fiche_titre($langs->trans('NewTicket'), '', 'title_ticketsup'); $formticket->withfromsocid = $socid ? $socid : $user->societe_id; $formticket->withfromcontactid = $contactid ? $contactid : ''; From c76dce64d349a7bfdc6e3a72f304d365ceb913af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 13 Mar 2018 12:15:03 +0100 Subject: [PATCH 076/126] add object in pdf_build_address source --- htdocs/core/modules/commande/doc/pdf_einstein.modules.php | 2 +- htdocs/core/modules/contract/doc/pdf_strato.modules.php | 2 +- htdocs/core/modules/expedition/doc/pdf_merou.modules.php | 2 +- htdocs/core/modules/expedition/doc/pdf_rouget.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 2 +- htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php | 2 +- htdocs/core/modules/livraison/doc/pdf_typhon.modules.php | 2 +- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 2 +- .../core/modules/supplier_invoice/pdf/pdf_canelle.modules.php | 2 +- htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php | 2 +- .../core/modules/supplier_proposal/doc/pdf_aurore.modules.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 7c24e49e89b..9d15b263b66 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -1330,7 +1330,7 @@ class pdf_einstein extends ModelePDFCommandes $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42+$top_shift; diff --git a/htdocs/core/modules/contract/doc/pdf_strato.modules.php b/htdocs/core/modules/contract/doc/pdf_strato.modules.php index 2cea64a72a6..74b5d43f489 100644 --- a/htdocs/core/modules/contract/doc/pdf_strato.modules.php +++ b/htdocs/core/modules/contract/doc/pdf_strato.modules.php @@ -583,7 +583,7 @@ class pdf_strato extends ModelePDFContract $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; diff --git a/htdocs/core/modules/expedition/doc/pdf_merou.modules.php b/htdocs/core/modules/expedition/doc/pdf_merou.modules.php index 68795126487..0ae6ed3ebe5 100644 --- a/htdocs/core/modules/expedition/doc/pdf_merou.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_merou.modules.php @@ -542,7 +542,7 @@ class pdf_merou extends ModelePdfExpedition $pdf->SetTextColor(0,0,0); // Sender properties - $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); $pdf->SetFont('','', $default_font_size - 3); $pdf->SetXY($blSocX,$blSocY+4); diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index f7eca910b7e..978f15d2ae8 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -935,7 +935,7 @@ class pdf_rouget extends ModelePdfExpedition $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 21adfe4edb4..6a063ec0e86 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1692,7 +1692,7 @@ class pdf_crabe extends ModelePDFFactures if ($showaddress) { // Sender properties - $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; diff --git a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php index f63f05b07f9..2307f896973 100644 --- a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php +++ b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php @@ -584,7 +584,7 @@ class pdf_soleil extends ModelePDFFicheinter $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; diff --git a/htdocs/core/modules/livraison/doc/pdf_typhon.modules.php b/htdocs/core/modules/livraison/doc/pdf_typhon.modules.php index fcb0bb6b057..06d6920e866 100644 --- a/htdocs/core/modules/livraison/doc/pdf_typhon.modules.php +++ b/htdocs/core/modules/livraison/doc/pdf_typhon.modules.php @@ -799,7 +799,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder if ($showaddress) { // Sender properties - $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur); + $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index a54cfbf212f..fba77613828 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -1515,7 +1515,7 @@ class pdf_azur extends ModelePDFPropales $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42+$top_shift; diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 9cdb9ebc6a0..f927b064a69 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -1086,7 +1086,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices if ($showaddress) { // Sender properties - $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php index d272957d80d..f61000d3b08 100644 --- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -1211,7 +1211,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders if ($showaddress) { // Sender properties - $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index 7411933dd26..46d4e35d10e 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -1306,7 +1306,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } - $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); // Show sender $posy=42; From 3aa0bdfe5c4a6dfe8e18311f28398ed3eb175854 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 12:17:57 +0100 Subject: [PATCH 077/126] ADD trigger when modify, delete thirdparty More fix todo with new class of stripe.class.php --- .../nterface_99_modStripe_Stripe.class.php | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php diff --git a/htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php b/htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php new file mode 100644 index 00000000000..e75d87c36f6 --- /dev/null +++ b/htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php @@ -0,0 +1,159 @@ + + * + * 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 . + */ + +/** + * \file htdocs/core/triggers/interface_50_modStripe_Stripe.class.php + * \ingroup core + * \brief Fichier + * \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci: + * - Le nom du fichier doit etre: interface_99_modMymodule_Mytrigger.class.php + * ou: interface_99_all_Mytrigger.class.php + * - Le fichier doit rester stocke dans core/triggers + * - Le nom de la classe doit etre InterfaceMytrigger + * - Le nom de la propriete name doit etre Mytrigger + */ +require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; +dol_include_once('/stripe/class/stripe.class.php'); +$path=dirname(__FILE__).'/'; +/** + * Class of triggers for stripe module + */ +class InterfaceStripe +{ + public $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = 'Stripeconnect'; + $this->description = "Triggers of the module Stripeconnect"; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'stripe@stripe'; + } + + /** + * Trigger name + * + * @return string Name of trigger file + */ + public function getName() + { + return $this->name; + } + + + /** + * Trigger description + * + * @return string Description of trigger file + */ + public function getDesc() + { + return $this->description; + } + + /** + * Trigger version + * + * @return string Version of trigger file + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') { + return $langs->trans("Development"); + } elseif ($this->version == 'experimental') { + return $langs->trans("Experimental"); + } elseif ($this->version == 'dolibarr') { + return DOL_VERSION; + } elseif ($this->version) { + return $this->version; + } else { + return $langs->trans("Unknown"); + } + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file + * is inside directory core/triggers + * + * @param string $action Event action code + * @param CommonObject $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) + { + // Put here code you want to execute when a Dolibarr business events occurs. + // Data and type of action are stored into $object and $action +global $langs,$db,$conf; +$langs->load("members"); +$langs->load("users"); +$langs->load("mails"); +$langs->load('other'); +/** Users */ +$ok=0; +$stripe=new Stripe($db); +if ($action == 'COMPANY_MODIFY') { + dol_syslog( + "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id + ); +if ($stripe->GetStripeAccount($conf->entity)&&$object->client!=0) { +$cu=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); +if ($cu) { + if ($conf->entity=='1'){ +$customer = \Stripe\Customer::retrieve("$cu->id"); + }else{ +$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); + } +if (!empty($object->email)) {$customer->email = "$object->email";} +$customer->description = "$object->name"; +$customer->save(); +}} + } +elseif ($action == 'COMPANY_DELETE') { + dol_syslog( + "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id + ); +$cu=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); +if ($cu) { + if ($conf->entity==1){ + $customer = \Stripe\Customer::retrieve("$cu->id"); + }else{ + $customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); + } +$customer->delete(); +} + } + + return $ok; + } +} From 43803679232e819feb9d3c92c4ff6f10a3fcc3f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 12:54:53 +0100 Subject: [PATCH 078/126] Error management --- htdocs/core/class/html.formsms.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formsms.class.php b/htdocs/core/class/html.formsms.class.php index 94e60ba8082..103b40e33df 100644 --- a/htdocs/core/class/html.formsms.class.php +++ b/htdocs/core/class/html.formsms.class.php @@ -205,8 +205,16 @@ function limitChars(textarea, limit, infodiv) try { $classname=ucfirst($classfile); - $sms = new $classname($this->db); - $resultsender = $sms->SmsSenderList(); + if (class_exists($classname)) + { + $sms = new $classname($this->db); + $resultsender = $sms->SmsSenderList(); + } + else + { + $sms = new stdClass(); + $sms->error='The SMS manager '.$classfile.' defined into SMS setup MAIN_SMS_SENDMODE is not found'; + } } catch(Exception $e) { From 3dd90a1f1a8b9f3ef25c7e4ed4bed9700a9d6245 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 13:21:36 +0100 Subject: [PATCH 079/126] FIX name of file --- ...e_Stripe.class.php => interface_99_modStripe_Stripe.class.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename htdocs/core/triggers/{nterface_99_modStripe_Stripe.class.php => interface_99_modStripe_Stripe.class.php} (100%) diff --git a/htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php similarity index 100% rename from htdocs/core/triggers/nterface_99_modStripe_Stripe.class.php rename to htdocs/core/triggers/interface_99_modStripe_Stripe.class.php From e6d8219396c37fea03c385a2ca495951b4c750f9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 13:26:03 +0100 Subject: [PATCH 080/126] Dolibarrize module ticket --- .../core/class/html.formticketsup.class.php | 29 ++++--- htdocs/core/lib/ticketsup.lib.php | 15 ++-- htdocs/ticketsup/card.php | 77 +++++++++++-------- htdocs/ticketsup/class/ticketsup.class.php | 17 ++-- .../ticketsup/{contacts.php => contact.php} | 21 +++-- htdocs/ticketsup/document.php | 2 +- htdocs/ticketsup/history.php | 2 +- htdocs/ticketsup/list.php | 43 +++++------ 8 files changed, 117 insertions(+), 89 deletions(-) rename htdocs/ticketsup/{contacts.php => contact.php} (94%) diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 47df19ae8f5..bb77649dfcc 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -418,9 +418,10 @@ class FormTicketsup * @param int $empty 1=peut etre vide, 0 sinon * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label + * @param string $morecss More CSS * @return void */ - public function selectTypesTickets($selected = '', $htmlname = 'tickettype', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0) + public function selectTypesTickets($selected = '', $htmlname = 'tickettype', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; @@ -436,7 +437,7 @@ class FormTicketsup $ticketstat->loadCacheTypesTickets(); - print ''; if ($empty) { print ''; } @@ -503,6 +504,8 @@ class FormTicketsup if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } + + print ajax_combobox('select'.$htmlname); } /** @@ -513,11 +516,12 @@ class FormTicketsup * @param string $filtertype To filter on field type in llx_c_ticketsup_category (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon - * @param int $noadmininfo 0=Add admin info, 1=Disable admin info + * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label - * @return void + * @param string $morecss More CSS + * @return void */ - public function selectCategoriesTickets($selected = '', $htmlname = 'ticketcategory', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0) + public function selectCategoriesTickets($selected = '', $htmlname = 'ticketcategory', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; @@ -533,7 +537,7 @@ class FormTicketsup $ticketstat->loadCacheCategoriesTickets(); - print ''; if ($empty) { print ''; } @@ -601,6 +605,8 @@ class FormTicketsup if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } + + print ajax_combobox('select'.$htmlname); } /** @@ -611,11 +617,12 @@ class FormTicketsup * @param string $filtertype To filter on field type in llx_c_ticketsup_severity (array('code'=>xx,'label'=>zz)) * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code * @param int $empty 1=peut etre vide, 0 sinon - * @param int $noadmininfo 0=Add admin info, 1=Disable admin info + * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label - * @return void + * @param string $morecss More CSS + * @return void */ - public function selectSeveritiesTickets($selected = '', $htmlname = 'ticketseverity', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0) + public function selectSeveritiesTickets($selected = '', $htmlname = 'ticketseverity', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss='') { global $langs, $user; @@ -631,7 +638,7 @@ class FormTicketsup $ticketstat->loadCacheSeveritiesTickets(); - print ''; if ($empty) { print ''; } @@ -698,6 +705,8 @@ class FormTicketsup if ($user->admin && !$noadmininfo) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } + + print ajax_combobox('select'.$htmlname); } /** diff --git a/htdocs/core/lib/ticketsup.lib.php b/htdocs/core/lib/ticketsup.lib.php index ca27e9e8024..68f8d820116 100644 --- a/htdocs/core/lib/ticketsup.lib.php +++ b/htdocs/core/lib/ticketsup.lib.php @@ -75,16 +75,19 @@ function ticketsup_prepare_head($object) $head[$h][2] = 'tabTicketsup'; $h++; - if (empty($user->socid)) { - $head[$h][0] = DOL_URL_ROOT.'/ticketsup/contacts.php?track_id=' . $object->track_id; - $head[$h][1] = $langs->trans('Contacts'); - $head[$h][2] = 'tabTicketContacts'; - $h++; + + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && empty($user->socid)) + { + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); + $head[$h][0] = DOL_URL_ROOT.'/ticketsup/contact.php?track_id='.$object->track_id; + $head[$h][1] = $langs->trans('ContactsAddresses'); + if ($nbContact > 0) $head[$h][1].= ' '.$nbContact.''; + $head[$h][2] = 'contact'; + $h++; } complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticketsup'); - // Attached files include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $upload_dir = $conf->ticketsup->dir_output . "/" . $object->track_id; diff --git a/htdocs/ticketsup/card.php b/htdocs/ticketsup/card.php index 5bf64d34cc8..dfc0704e824 100644 --- a/htdocs/ticketsup/card.php +++ b/htdocs/ticketsup/card.php @@ -77,10 +77,28 @@ if (GETPOST('modelselected')) { // Store current page url $url_page_current = dol_buildpath('/ticketsup/card.php', 1); -/*************************************************** - * PAGE - * - ****************************************************/ +if ($action == 'view' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' || $action == 'editsubject' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { + $res = $object->fetch($id, $track_id, $ref); +} + +// Security check +$result = restrictedArea($user, 'ticketsup', $object->dao->id); + + + +/* + * Actions + */ + +$permissiondellink = $user->rights->ticketsup->write; +include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + + + + +/* + * View + */ $userstat = new User($db); $form = new Form($db); @@ -90,21 +108,14 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti $res = $object->fetch($id, $track_id, $ref); if ($res > 0) { - // Security check - $result = restrictedArea($user, 'ticketsup', $object->dao->id); - // or for unauthorized internals users if (!$user->societe_id && ($conf->global->TICKETS_LIMIT_VIEW_ASSIGNED_ONLY && $object->dao->fk_user_assign != $user->id) && !$user->rights->ticketsup->manage) { accessforbidden('', 0); } - - - $permissiondellink = $user->rights->ticketsup->write; - include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once - $help_url = 'FR:DocumentationModuleTicket'; $page_title = $object->getTitle($action); + llxHeader('', $page_title, $help_url); // Confirmation close @@ -193,7 +204,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } else { print "ErrorRecordNotFound"; } - } elseif ($object->dao->fk_soc > 0) { + } elseif ($socid > 0) { $object->dao->fetch_thirdparty(); $head = societe_prepare_head($object->dao->thirdparty); dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), 0, 'company'); @@ -208,7 +219,9 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } $head = ticketsup_prepare_head($object->dao); - dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), 0, 'ticketsup'); + + dol_fiche_head($head, 'tabTicketsup', $langs->trans("Ticket"), -1, 'ticketsup'); + $object->dao->label = $object->dao->ref; // Author if ($object->dao->fk_user_create > 0) { @@ -409,11 +422,11 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } } print ''; - + // View Original message $object->viewTicketOriginalMessage($user, $action); - - + + // Fin colonne gauche et début colonne droite print '
    '; @@ -579,9 +592,9 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
    ' . $tab[$i]['libelle'] . '
    '; print '
    '; - + print dol_print_phone($tab[$i]['phone'], '', '', '', AC_TEL).'
    '; - + if (! empty($tab[$i]['phone_perso'])) { //print img_picto($langs->trans('PhonePerso'),'object_phoning.png','',0,0,0).' '; print '
    '.dol_print_phone($tab[$i]['phone_perso'], '', '', '', AC_TEL).'
    '; @@ -594,7 +607,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti print ''; - + // Contract if ($action == 'sel_contract') { if (!empty($conf->contrat->enabled)) { $langs->load('contrats'); print load_fiche_titre($langs->trans('LinkToAContract'), '', 'title_commercial.png'); - + $form_contract = new FormContract($db); $form_contract->formSelectContract( $url_page_current.'?track_id='.$object->dao->track_id, @@ -641,7 +654,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti print '
    '; print '
    '; - + print dol_fiche_end(); /* ActionBar */ @@ -650,7 +663,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti // Show button to mark as read if (($object->dao->fk_statut == '0' || empty($object->dao->date_read)) && !$user->societe_id) { print '
    '; - print '' . img_picto('', 'mark-read@ticketsup') . ' ' . $langs->trans('MarkAsRead') . ''; + print '' . img_picto('', 'mark-read@ticketsup', 'height="12px"') . ' ' . $langs->trans('MarkAsRead') . ''; print ''; print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticketsup'); @@ -724,7 +737,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $object->default_lang; } - + $formticket = new FormTicketsup($db); $formticket->action = $action; @@ -734,16 +747,16 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti $formticket->withfile = 2; $formticket->param = array('fk_user_create' => $user->id); $formticket->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); - + // Tableau des parametres complementaires du post $formticket->param['models']=$modelmail; $formticket->param['models_id']=GETPOST('modelmailselected', 'int'); //$formticket->param['socid']=$object->dao->fk_soc; $formticket->param['returnurl']=$_SERVER["PHP_SELF"].'?track_id='.$object->dao->track_id; - + $formticket->withsubstit = 1; - + if ($object->dao->fk_soc > 0) { $object->dao->fetch_thirdparty(); $formticket->substit['__THIRDPARTY_NAME__'] = $object->dao->thirdparty->name; @@ -761,13 +774,13 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti $userstat->fetch($object->dao->fk_user_assign); $formticket->substit['__TICKETSUP_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); } - + if ($object->dao->fk_user_create > 0) { $userstat->fetch($object->dao->fk_user_create); $formticket->substit['__TICKETSUP_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); } - - + + $formticket->showMessageForm('100%'); print '
    '; } diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index f1f23b09dcd..f35f73c33e5 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -169,19 +169,19 @@ class Ticketsup extends CommonObject public $regeximgext = '\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff'; public $fields=array( - 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id"), - 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1), + 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'position'=>1, 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id"), + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'notnull'=>1, 'index'=>1), + 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"), 'notify_tiers_at_create' => array('type'=>'integer', 'label'=>'NotifyThirdparty', 'visible'=>-2, 'enabled'=>0, 'position'=>20, 'notnull'=>1, 'index'=>1), - 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"), 'track_id' => array('type'=>'varchar(255)', 'label'=>'TrackID', 'visible'=>0, 'enabled'=>1, 'position'=>30, 'notnull'=>-1, 'searchall'=>1, 'help'=>"Help text"), 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>"LinkToThirparty"), 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php', 'label'=>'Project', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>"LinkToProject"), - 'origin_email' => array('type'=>'mail', 'label'=>'OriginEmail', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"), + 'origin_email' => array('type'=>'mail', 'label'=>'OriginEmail', 'visible'=>1, 'enabled'=>1, 'position'=>11, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"), 'fk_user_create' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Author', 'visible'=>1, 'enabled'=>1, 'position'=>510, 'notnull'=>1), 'fk_user_assign' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'AuthorAssign', 'visible'=>1, 'enabled'=>1, 'position'=>510, 'notnull'=>1), - 'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), + 'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>12, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), 'message' => array('type'=>'text', 'label'=>'Message', 'visible'=>-2, 'enabled'=>1, 'position'=>60, 'notnull'=>-1,), - 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'NotRead', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'Closed', 9 => 'Deleted')), + 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'NotRead', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'Closed', 9 => 'Deleted')), 'resolution' => array('type'=>'integer', 'label'=>'Resolution', 'visible'=>-2, 'enabled'=>1, 'position'=>40, 'notnull'=>1), 'progress' => array('type'=>'varchar(100)', 'label'=>'Progression', 'visible'=>1, 'enabled'=>1, 'position'=>41, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), 'timing' => array('type'=>'varchar(20)', 'label'=>'Timing', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), @@ -2411,9 +2411,10 @@ class Ticketsup extends CommonObject * @param int $nodbprefix Do not include DB prefix to forge table name * @param string $morehtmlleft More html code to show before ref * @param string $morehtmlright More html code to show before navigation arrows + * @param string $onlybanner 1 * @return void */ - public function ticketsupBannerTab($paramid, $morehtml = '', $shownav = 1, $fieldid = 'id', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlright = '') + public function ticketsupBannerTab($paramid, $morehtml = '', $shownav = 1, $fieldid = 'id', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlright = '', $onlybanner=0) { global $conf, $form, $user, $langs; @@ -2425,7 +2426,7 @@ class Ticketsup extends CommonObject } $modulepart = 'ticketsup'; - print '
    '; + print '
    '; $width = 80; $height = 70; diff --git a/htdocs/ticketsup/contacts.php b/htdocs/ticketsup/contact.php similarity index 94% rename from htdocs/ticketsup/contacts.php rename to htdocs/ticketsup/contact.php index 9ef592b22a7..356aa47ffd5 100644 --- a/htdocs/ticketsup/contacts.php +++ b/htdocs/ticketsup/contact.php @@ -19,9 +19,9 @@ */ /** - * \file ticketsup/contacts.php + * \file ticketsup/contact.php * \ingroup ticketsup - * \brief Contacts des tickets + * \brief Contacts of tickets */ require '../main.inc.php'; @@ -61,7 +61,7 @@ if ($user->societe_id > 0) { } // Store current page url -$url_page_current = dol_buildpath('/ticketsup/contacts.php', 1); +$url_page_current = dol_buildpath('/ticketsup/contact.php', 1); $object = new Ticketsup($db); @@ -129,8 +129,9 @@ $userstatic = new User($db); /* *************************************************************************** */ if ($id > 0 || !empty($track_id) || !empty($ref)) { - if ($object->fetch($id, $track_id, $ref) > 0) { - if ($object->fk_soc > 0) { + if ($object->fetch($id, $track_id, $ref) > 0) + { + if ($socid > 0) { $object->fetch_thirdparty(); $head = societe_prepare_head($object->thirdparty); dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), 0, 'company'); @@ -143,8 +144,11 @@ if ($id > 0 || !empty($track_id) || !empty($ref)) { } elseif ($user->societe_id > 0) { $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'"; } + $head = ticketsup_prepare_head($object); - dol_fiche_head($head, 'tabTicketContacts', $langs->trans("Ticket"), 0, 'ticketsup'); + + dol_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticketsup'); + $object->label = $object->ref; // Author if ($object->fk_user_create > 0) { @@ -155,10 +159,11 @@ if ($id > 0 || !empty($track_id) || !empty($ref)) { $object->label .= $fuser->getNomUrl(0); } $linkback = '' . $langs->trans("BackToList") . ' '; - $object->ticketsupBannerTab('ref', '', ($user->societe_id ? 0 : 1), 'ref', 'subject', '', '', '', $morehtmlleft, $linkback); + $object->ticketsupBannerTab('ref', '', ($user->societe_id ? 0 : 1), 'ref', 'subject', '', '', '', $morehtmlleft, $linkback, 1); dol_fiche_end(); - print '
    '; + + //print '
    '; $permission = $user->rights->ticketsup->write; diff --git a/htdocs/ticketsup/document.php b/htdocs/ticketsup/document.php index f221dce73c2..0f528ee17bb 100644 --- a/htdocs/ticketsup/document.php +++ b/htdocs/ticketsup/document.php @@ -109,7 +109,7 @@ if ($object->id) { } $form = new Form($db); - if ($object->fk_soc > 0) { + if ($socid > 0) { $object->fetch_thirdparty(); $head = societe_prepare_head($object->thirdparty); dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), 0, 'company'); diff --git a/htdocs/ticketsup/history.php b/htdocs/ticketsup/history.php index 9bd69ade897..b4e0e0e9249 100644 --- a/htdocs/ticketsup/history.php +++ b/htdocs/ticketsup/history.php @@ -88,7 +88,7 @@ if ($action == 'view') { accessforbidden('', 0); } - if ($object->dao->fk_soc > 0) { + if ($socid > 0) { $object->dao->fetch_thirdparty(); $head = societe_prepare_head($object->dao->thirdparty); dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), 0, 'company'); diff --git a/htdocs/ticketsup/list.php b/htdocs/ticketsup/list.php index 52102b53596..b4c208e270b 100644 --- a/htdocs/ticketsup/list.php +++ b/htdocs/ticketsup/list.php @@ -35,12 +35,7 @@ if (!empty($conf->projet->enabled)) { } // Load traductions files requiredby by page -$langs->loadLangs( - array( - "ticketsup", - "companies", - "other") - ); +$langs->loadLangs(array("ticketsup","companies","other")); // Get parameters @@ -143,8 +138,6 @@ $url_page_current = dol_buildpath('/ticketsup/list.php', 1); /* * Actions - * - * Put here all code to do according to value of "$action" parameter */ if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; } @@ -308,8 +301,13 @@ if ($socid && !$projectid && $user->rights->societe->lire) { $socstat = new Societe($db); $res = $socstat->fetch($socid); if ($res > 0) { + + $tmpobject = $object; + $object = $socstat; // $object must be of type Societe when calling societe_prepare_head $head = societe_prepare_head($socstat); - dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), 0, 'company'); + $object = $tmpobject; + + dol_fiche_head($head, 'ticketsup', $langs->trans("ThirdParty"), -1, 'company'); dol_banner_tab($socstat, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom'); @@ -320,7 +318,7 @@ if ($socid && !$projectid && $user->rights->societe->lire) { // Customer code if ($socstat->client && !empty($socstat->code_client)) { - print ''; + print ''; print $langs->trans('CustomerCode') . ''; print $socstat->code_client; if ($socstat->check_codeclient() != 0) { @@ -360,7 +358,7 @@ if ($projectid) { $linkback = '' . $langs->trans("BackToList") . ''; // Ref - print '' . $langs->trans('Ref') . ''; + print '' . $langs->trans('Ref') . ''; // Define a complementary filter for search of next/prev ref. if (!$user->rights->projet->all->lire) { $objectsListId = $projectstat->getProjectsAuthorizedForUser($user, $mine, 0); @@ -374,7 +372,7 @@ if ($projectid) { // Customer print "" . $langs->trans("ThirdParty") . ""; - print ''; + print ''; if ($projectstat->thirdparty->id > 0) { print $projectstat->thirdparty->getNomUrl(1); } else { @@ -504,25 +502,24 @@ foreach($object->fields as $key => $val) if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; if ($key == 'status') $align.=($align?' ':'').'center'; if (! empty($arrayfields['t.'.$key]['checked'])) { - if ($key == 'fk_statut') { + if ($key == 'type_code') { print ''; - $object->printSelectStatus(dol_escape_htmltag($search[$key])); - print ''; - - } elseif ($key == 'type_code') { - print ''; - $formTicket->selectTypesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 2, 1, 1); + $formTicket->selectTypesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, 'maxwidth200'); print ''; } elseif ($key == 'category_code') { print ''; - $formTicket->selectCategoriesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 2, 1, 1); + $formTicket->selectCategoriesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, 'maxwidth200'); print ''; } elseif ($key == 'severity_code') { print ''; - $formTicket->selectSeveritiesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 2, 1, 1); + $formTicket->selectSeveritiesTickets(dol_escape_htmltag($search[$key]), 'search_'.$key.'', '', 0, 1, 1, 0, 'maxwidth200'); print ''; - } else { - + } elseif ($key == 'fk_statut') { + print ''; + $object->printSelectStatus(dol_escape_htmltag($search[$key])); + print ''; + } + else { print ''; } } From e6dd312bd5cf8683488c038e13a3094f379fc364 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 13:56:45 +0100 Subject: [PATCH 081/126] Debug ticket module --- htdocs/core/boxes/box_last_modified_ticketsup.php | 6 +++--- htdocs/core/boxes/box_last_ticketsup.php | 6 +++--- htdocs/core/modules/modTicketsup.class.php | 5 +++++ htdocs/langs/en_US/ticketsup.lang | 8 ++++---- htdocs/modulebuilder/template/myobject_list.php | 1 + htdocs/ticketsup/class/ticketsup.class.php | 5 ++--- htdocs/ticketsup/list.php | 10 ++++------ 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/htdocs/core/boxes/box_last_modified_ticketsup.php b/htdocs/core/boxes/box_last_modified_ticketsup.php index fd49653eced..c63864b0fe0 100644 --- a/htdocs/core/boxes/box_last_modified_ticketsup.php +++ b/htdocs/core/boxes/box_last_modified_ticketsup.php @@ -18,9 +18,9 @@ */ /** - * \file ticketsup/core/boxes/ticketsup_latest.php - * \ingroup ticketsup - * \brief This box shows latest UNREAD tickets + * \file core/boxes/box_last_modified_ticketsup.php + * \ingroup ticketsup + * \brief This box shows latest modified tickets */ require_once DOL_DOCUMENT_ROOT . "/core/boxes/modules_boxes.php"; diff --git a/htdocs/core/boxes/box_last_ticketsup.php b/htdocs/core/boxes/box_last_ticketsup.php index 6044bb179f5..5c39229835b 100644 --- a/htdocs/core/boxes/box_last_ticketsup.php +++ b/htdocs/core/boxes/box_last_ticketsup.php @@ -18,9 +18,9 @@ */ /** - * \file ticketsup/core/boxes/ticketsup_latest.php - * \ingroup ticketsup - * \brief This box shows latest tickets + * \file core/boxes/box_ticketsup_latest.php + * \ingroup ticketsup + * \brief This box shows latest created tickets */ require_once DOL_DOCUMENT_ROOT . "/core/boxes/modules_boxes.php"; diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index c6a6ada09f9..235ab092478 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -162,30 +162,35 @@ class modTicketsup extends DolibarrModules // Permissions $this->rights = array(); // Permission array used by this module + $r=0; $this->rights[$r][0] = 56001; // id de la permission $this->rights[$r][1] = "Read ticket"; // libelle de la permission $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'read'; + $r++; $this->rights[$r][0] = 56002; // id de la permission $this->rights[$r][1] = "Create les tickets"; // libelle de la permission $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'write'; + $r++; $this->rights[$r][0] = 56003; // id de la permission $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'delete'; + $r++; $this->rights[$r][0] = 56004; // id de la permission $this->rights[$r][1] = "Manage tickets"; // libelle de la permission //$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'manage'; + $r++; $this->rights[$r][0] = 56005; // id de la permission $this->rights[$r][1] = 'See all tickets, even if not assigned to (not effective for external users, always restricted to the thirdpardy they depends on)'; // libelle de la permission $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour) diff --git a/htdocs/langs/en_US/ticketsup.lang b/htdocs/langs/en_US/ticketsup.lang index 9064222637a..a4e04930def 100644 --- a/htdocs/langs/en_US/ticketsup.lang +++ b/htdocs/langs/en_US/ticketsup.lang @@ -291,11 +291,11 @@ TicketNotificationNumberEmailSent=Notification email sent : %s # # Boxes # -BoxLastTicketsup=Last tickets -BoxLastTicketsupDescription=Last %s tickets saved +BoxLastTicketsup=Latest created tickets +BoxLastTicketsupDescription=Latest %s created tickets BoxLastTicketsupContent= BoxLastTicketsupNoRecordedTickets=No recent unread tickets -BoxLastModifiedTicketsup=Last modified tickets -BoxLastModifiedTicketsupDescription=Last %s tickets modified +BoxLastModifiedTicketsup=Latest modified tickets +BoxLastModifiedTicketsupDescription=Latest %s modified tickets BoxLastModifiedTicketsupContent= BoxLastModifiedTicketsupNoRecordedTickets=No recent modified tickets diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 2ef8fa97030..2ac18cb5db4 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -220,6 +220,7 @@ if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity( else $sql.=" WHERE 1 = 1"; foreach($search as $key => $val) { + if ($key == 'status' && $search[$key] == -1) continue; $mode_search=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0); if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:$mode_search)); } diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index f35f73c33e5..a7b95bedbbe 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -181,7 +181,6 @@ class Ticketsup extends CommonObject 'fk_user_assign' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'AuthorAssign', 'visible'=>1, 'enabled'=>1, 'position'=>510, 'notnull'=>1), 'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>12, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), 'message' => array('type'=>'text', 'label'=>'Message', 'visible'=>-2, 'enabled'=>1, 'position'=>60, 'notnull'=>-1,), - 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'NotRead', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'Closed', 9 => 'Deleted')), 'resolution' => array('type'=>'integer', 'label'=>'Resolution', 'visible'=>-2, 'enabled'=>1, 'position'=>40, 'notnull'=>1), 'progress' => array('type'=>'varchar(100)', 'label'=>'Progression', 'visible'=>1, 'enabled'=>1, 'position'=>41, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), 'timing' => array('type'=>'varchar(20)', 'label'=>'Timing', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'help'=>""), @@ -191,8 +190,8 @@ class Ticketsup extends CommonObject 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1), 'date_read' => array('type'=>'datetime', 'label'=>'TicketReadOn', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1), 'date_close' => array('type'=>'datetime', 'label'=>'TicketCloseOn', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1), - 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>501, 'notnull'=>1) - + 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>501, 'notnull'=>1), + 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'NotRead', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'Closed', 9 => 'Deleted')) ); /** diff --git a/htdocs/ticketsup/list.php b/htdocs/ticketsup/list.php index b4c208e270b..a54394522f8 100644 --- a/htdocs/ticketsup/list.php +++ b/htdocs/ticketsup/list.php @@ -214,8 +214,9 @@ if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity( else $sql.=" WHERE 1 = 1"; foreach($search as $key => $val) { + if ($key == 'fk_statut' && $search[$key] == -1) continue; $mode_search=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0); - if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:$mode_search)); + if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'fk_statut')?2:$mode_search)); } if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all); @@ -436,8 +437,9 @@ print ''; print ''; print ''; +$buttontocreate = ''; -print_barre_liste($langs->trans('TicketList'), $page, 'list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'title_ticketsup'); +print_barre_liste($langs->trans('TicketList'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_ticketsup', 0, $buttontocreate, '', $limit); if ($mode == 'my_assign') { print '
    ' . $langs->trans('TicketAssignedToMeInfos') . '

    '; @@ -674,10 +676,6 @@ print '
    '."\n"; print ''."\n"; -print ''; - if (in_array('builddoc',$arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { From 9f07ff0f9bca3529f740cb09bec93e212e3642ef Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:00:35 +0100 Subject: [PATCH 082/126] Fix travis --- htdocs/core/modules/modTicketsup.class.php | 40 +++------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/htdocs/core/modules/modTicketsup.class.php b/htdocs/core/modules/modTicketsup.class.php index 235ab092478..00d01031294 100644 --- a/htdocs/core/modules/modTicketsup.class.php +++ b/htdocs/core/modules/modTicketsup.class.php @@ -300,13 +300,12 @@ class modTicketsup extends DolibarrModules } /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus - * (defined in constructor) into Dolibarr database. - * It also creates data directories + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO */ public function init($options = '') { @@ -319,36 +318,7 @@ class modTicketsup extends DolibarrModules array("sql" => "insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values ('','TICKETMESSAGE_SENTBYMAIL','Send email for ticket','Executed when a response is made on a ticket','ticketsup','');", "ignoreerror" => 1), ); - $result = $this->loadTables(); - return $this->_init($sql, $options); } - /** - * Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - public function remove($options = '') - { - $sql = array(); - - return $this->_remove($sql, $options); - } - - /** - * Create tables, keys and data required by module - * Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys - * and create data commands must be stored in directory /ticketsup/sql/ - * This function is called by this->init - * - * @return int <=0 if KO, >0 if OK - */ - private function loadTables() - { - return $this->_load_tables(); - } } From b25f3ba3223f0a5dc4b6797fde5fd436516afed2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:13:32 +0100 Subject: [PATCH 083/126] Fix to avoid stripe live mode beeing disabled when stripeconnect off --- htdocs/stripe/charge.php | 2 +- htdocs/stripe/class/actions_stripe.class.php | 14 +++++++------- htdocs/stripe/class/stripe.class.php | 2 +- htdocs/stripe/transaction.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/stripe/charge.php b/htdocs/stripe/charge.php index 2c937e318a4..413ed3ec815 100644 --- a/htdocs/stripe/charge.php +++ b/htdocs/stripe/charge.php @@ -61,7 +61,7 @@ $societestatic = new Societe($db); $memberstatic = new Adherent($db); $acc = new Account($db); $stripe=new Stripe($db); -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) { $service = 'StripeTest'; dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); diff --git a/htdocs/stripe/class/actions_stripe.class.php b/htdocs/stripe/class/actions_stripe.class.php index 1dc4082a4f0..baeba001edf 100644 --- a/htdocs/stripe/class/actions_stripe.class.php +++ b/htdocs/stripe/class/actions_stripe.class.php @@ -55,11 +55,11 @@ class ActionsStripeconnect { $this->db = $db; } - + /** * formObjectOptions - * + * * @param array $parameters Parameters * @param Object $object Object * @param string $action Action @@ -68,7 +68,7 @@ class ActionsStripeconnect { global $db,$conf,$user,$langs,$form; - if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) + if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) { $service = 'StripeTest'; dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); @@ -85,7 +85,7 @@ class ActionsStripeconnect $key=$value; } } - + if (is_object($object) && $object->element == 'societe') { @@ -106,7 +106,7 @@ class ActionsStripeconnect $this->resprints.= $langs->trans("NoStripe"); } $this->resprints.= ''; - + } elseif (is_object($object) && $object->element == 'member'){ $this->resprints.= ''; @@ -125,7 +125,7 @@ class ActionsStripeconnect $this->resprints.= $langs->trans("NoStripe"); } $this->resprints.= ''; - + $this->resprints.= ''; $this->resprints.= ''; } @@ -460,22 +471,23 @@ if ($socid && $action != 'edit' && $action != "create") print '
    '; $this->resprints.= $langs->trans('SubscriptionStripe'); @@ -167,7 +167,7 @@ class ActionsStripeconnect /** * addMoreActionsButtons - * + * * @param arra $parameters Parameters * @param Object $object Object * @param string $action action diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index d6d1601d405..efc7415327c 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -295,7 +295,7 @@ class Stripe extends CommonObject if (isset($charge->id)) {} } - if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; + if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; else $service = 'StripeLive'; $return->statut = 'success'; diff --git a/htdocs/stripe/transaction.php b/htdocs/stripe/transaction.php index 56d94c36dee..5390b3a170c 100644 --- a/htdocs/stripe/transaction.php +++ b/htdocs/stripe/transaction.php @@ -55,7 +55,7 @@ $societestatic = new societe($db); $acc = new Account($db); $stripe = new Stripe($db); -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox', 'alpha'))) +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { $service = 'StripeTest'; dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); From d6e8872af4a37b985481507b0a499c6c3060abdf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:14:33 +0100 Subject: [PATCH 084/126] Update interface_99_modStripe_Stripe.class.php --- .../interface_99_modStripe_Stripe.class.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php index e75d87c36f6..0fff7b6a58e 100644 --- a/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php @@ -121,18 +121,27 @@ $langs->load("mails"); $langs->load('other'); /** Users */ $ok=0; -$stripe=new Stripe($db); +$stripe=new Stripe($db); +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) +{ + $service = 'StripeTest'; +} +else +{ + $service = 'StripeLive'; +} + if ($action == 'COMPANY_MODIFY') { dol_syslog( "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id ); -if ($stripe->GetStripeAccount($conf->entity)&&$object->client!=0) { -$cu=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); +if ($stripe->getStripeAccount($service) && $object->client!=0) { +$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); if ($cu) { if ($conf->entity=='1'){ $customer = \Stripe\Customer::retrieve("$cu->id"); }else{ -$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); +$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); } if (!empty($object->email)) {$customer->email = "$object->email";} $customer->description = "$object->name"; @@ -143,12 +152,12 @@ elseif ($action == 'COMPANY_DELETE') { dol_syslog( "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id ); -$cu=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); +$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); if ($cu) { if ($conf->entity==1){ $customer = \Stripe\Customer::retrieve("$cu->id"); }else{ - $customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); + $customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); } $customer->delete(); } From 4b7f4d29d1d5d29d0d0d10ccde26acf6b895e4ce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:19:26 +0100 Subject: [PATCH 085/126] Update interface_99_modStripe_Stripe.class.php --- htdocs/core/triggers/interface_99_modStripe_Stripe.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php index 0fff7b6a58e..f639695cc40 100644 --- a/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php @@ -122,7 +122,9 @@ $langs->load('other'); /** Users */ $ok=0; $stripe=new Stripe($db); -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) +if (empty($conf->stripe->enabled)) return 0; + +if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) { $service = 'StripeTest'; } From 59b7187501f26acac7077fe62279c775343ec8f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:20:23 +0100 Subject: [PATCH 086/126] Rename interface_99_modStripe_Stripe.class.php to interface_80_modStripe_Stripe.class.php --- ...e_Stripe.class.php => interface_80_modStripe_Stripe.class.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename htdocs/core/triggers/{interface_99_modStripe_Stripe.class.php => interface_80_modStripe_Stripe.class.php} (100%) diff --git a/htdocs/core/triggers/interface_99_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php similarity index 100% rename from htdocs/core/triggers/interface_99_modStripe_Stripe.class.php rename to htdocs/core/triggers/interface_80_modStripe_Stripe.class.php From f7dd7e89de2b700967a3729c6e9b05fb3532272d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:44:35 +0100 Subject: [PATCH 087/126] Add option to create stripe customer if not found (so we can use function to find without side effect) --- htdocs/stripe/class/stripe.class.php | 58 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 4964b0bda38..a0f6008b6f8 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -124,25 +124,19 @@ class Stripe extends CommonObject /** - * customerStripe + * Get the Stripe customer of a thirdparty (with option to create it if not linked yet) * - * @param int $id Id of third party - * @return string Stripe account ref 'acc_xxxxxxxxxxxxx' - * @return \Stripe\StripeObject|\Stripe\ApiResource + * @param int $id Id of third party + * @param string $key Stripe account acc_.... + * @param int $status Status (0=test, 1=live) + * @param int $createifnotlinkedtostripe 1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer + * @return \Stripe\StripeObject|\Stripe\ApiResource|null Stripe Customer or null if not found */ - public function customerStripe($id,$key) + public function customerStripe($id, $key, $status=0, $createifnotlinkedtostripe=0) { global $conf; - if (empty($conf->global->STRIPECONNECT_LIVE)) { - $mode = 0; - } else { - if (empty($conf->global->STRIPE_LIVE)) { - $mode = 0; - } else { - $mode = $conf->global->STRIPE_LIVE; - } - } - $sql = "SELECT sa.key_account as key_account, sa.entity"; + + $sql = "SELECT sa.key_account as key_account, sa.entity"; // key_account is cu_.... $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; @@ -164,24 +158,28 @@ class Stripe extends CommonObject "stripe_account" => $key )); } - } else { + } + else + { if ($conf->entity == 1) { $customer = \Stripe\Customer::create(array( "email" => $soc->email, + "business_vat_id" => $soc->tva_intra, "description" => $soc->name )); } else { $customer = \Stripe\Customer::create(array( "email" => $soc->email, + "business_vat_id" => $soc->tva_intra, "description" => $soc->name ), array( "stripe_account" => $key )); } - $customer_id = "" . $customer->id . ""; - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc,key_account,site,status,entity)"; - $sql .= " VALUES ($id,'$customer_id','stripe'," . $mode . "," . $conf->entity . ")"; - dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); + $customer_id = $customer->id; + + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, key_account, site, status, entity)"; + $sql .= " VALUES (".$id.", '".$this->db->escape($customer_id)."', 'stripe', " . $status . "," . $conf->entity . ")"; $resql = $this->db->query($sql); } } @@ -189,25 +187,28 @@ class Stripe extends CommonObject } /** - * createPaymentStripe Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API + * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API * - * @param int $amount amount to pay - * @param string $currency EUR, GPB... + * @param int $amount Amount to pay + * @param string $currency EUR, GPB... * @param string $origin order, invoice, contract... * @param int $item if of element to pay * @param string $source src_xxxxx or card_xxxxx or ac_xxxxx - * @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe() + * @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe() * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() - * @param int $status Status + * @param int $status Status (0=test, 1=live) * @return Stripe */ public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0) { global $conf; + if (empty($status)) $service = 'StripeTest'; + else $service = 'StripeLive'; + $sql = "SELECT sa.key_account as key_account, sa.entity"; $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; - $sql.= " WHERE sa.key_account = " . $customer; + $sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'"; //$sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); @@ -223,7 +224,7 @@ class Stripe extends CommonObject } else { $key = NULL; } - + $stripeamount = round($amount * 100); $societe = new Societe($this->db); $societe->fetch($fksoc); @@ -293,9 +294,6 @@ class Stripe extends CommonObject if (isset($charge->id)) {} } - if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; - else $service = 'StripeLive'; - $return->statut = 'success'; $return->id = $charge->id; if ($charge->source->type == 'card') { From 9c92e092954b927efcbd251c7e445388e41a7e50 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:48:01 +0100 Subject: [PATCH 088/126] Fix syntax --- .../interface_80_modStripe_Stripe.class.php | 117 +++++++++--------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index f639695cc40..a41ade1e01b 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -29,7 +29,7 @@ */ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; dol_include_once('/stripe/class/stripe.class.php'); -$path=dirname(__FILE__).'/'; +$path=dirname(__FILE__).'/'; /** * Class of triggers for stripe module */ @@ -102,69 +102,70 @@ class InterfaceStripe * All functions "runTrigger" are triggered if file * is inside directory core/triggers * - * @param string $action Event action code - * @param CommonObject $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param Conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK + * @param string $action Event action code + * @param CommonObject $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action -global $langs,$db,$conf; -$langs->load("members"); -$langs->load("users"); -$langs->load("mails"); -$langs->load('other'); -/** Users */ -$ok=0; -$stripe=new Stripe($db); -if (empty($conf->stripe->enabled)) return 0; + global $langs, $db, $conf; + $langs->load("members"); + $langs->load("users"); + $langs->load("mails"); + $langs->load('other'); + + $ok = 0; + $stripe = new Stripe($db); + if (empty($conf->stripe->enabled)) return 0; + + if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')) + { + $service = 'StripeTest'; + } + else + { + $service = 'StripeLive'; + } + + if ($action == 'COMPANY_MODIFY') { + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + if ($stripe->getStripeAccount($service) && $object->client != 0) { + $cu = $stripe->customerStripe($object->id, $stripe->getStripeAccount($service)); + if ($cu) { + if ($conf->entity == '1') { + $customer = \Stripe\Customer::retrieve("$cu->id"); + } else { + $customer = \Stripe\Customer::retrieve("$cu->id", array( + "stripe_account" => $stripe->getStripeAccount($service) + )); + } + if (! empty($object->email)) { + $customer->email = "$object->email"; + } + $customer->description = "$object->name"; + $customer->save(); + } + } + } elseif ($action == 'COMPANY_DELETE') { + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + $cu = $stripe->customerStripe($object->id, $stripe->getStripeAccount($service)); + if ($cu) { + if ($conf->entity == 1) { + $customer = \Stripe\Customer::retrieve("$cu->id"); + } else { + $customer = \Stripe\Customer::retrieve("$cu->id", array( + "stripe_account" => $stripe->getStripeAccount($service) + )); + } + $customer->delete(); + } + } -if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) -{ - $service = 'StripeTest'; -} -else -{ - $service = 'StripeLive'; -} - -if ($action == 'COMPANY_MODIFY') { - dol_syslog( - "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id - ); -if ($stripe->getStripeAccount($service) && $object->client!=0) { -$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); -if ($cu) { - if ($conf->entity=='1'){ -$customer = \Stripe\Customer::retrieve("$cu->id"); - }else{ -$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); - } -if (!empty($object->email)) {$customer->email = "$object->email";} -$customer->description = "$object->name"; -$customer->save(); -}} - } -elseif ($action == 'COMPANY_DELETE') { - dol_syslog( - "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id - ); -$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); -if ($cu) { - if ($conf->entity==1){ - $customer = \Stripe\Customer::retrieve("$cu->id"); - }else{ - $customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); - } -$customer->delete(); -} - } - return $ok; } } From a955e743291a5282cd317ecd8d889633960b44f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 15:19:31 +0100 Subject: [PATCH 089/126] Better MVC --- htdocs/societe/paymentmodes.php | 85 ++++++++++++++++------------ htdocs/stripe/class/stripe.class.php | 14 +++-- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index f4d9f1b6173..53f714b414c 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -69,6 +69,21 @@ $hookmanager->initHooks(array('thirdpartybancard','globalcard')); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('thirdpartybancard')); +if (! empty($conf->stripe->enabled)) +{ + $service = 'StripeTest'; + $servicestatus = 0; + if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) + { + $service = 'StripeLive'; + $servicestatus = 0; + } + + $stripe = new Stripe($db); + $stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here) + $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get thirdparty cu_... +} + /* @@ -91,7 +106,6 @@ if (empty($reshook)) } } - if ($action == 'update' && ! $_POST["cancel"]) { // Modification @@ -332,32 +346,29 @@ if (empty($reshook)) $id = $savid; } +// Action for stripe if (! empty($conf->stripe->enabled) && class_exists('Stripe')) { - $stripe=new Stripe($db); - - if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; - else $service = 'StripeLive'; - - $customerstripe=$stripe->customerStripe($socid, $stripe->getStripeAccount($service)); - if ($customerstripe->id) { - $cu = \Stripe\Customer::retrieve("".$customerstripe->id."");} - - $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; if ($action == 'setassourcedefault') { - $cu->default_source = "$source"; // obtained with Stripe.js - $cu->save(); + $cu = \Stripe\Customer::retrieve($stripecu); - header('Location: '.$url); - exit; + $cu->default_source = "$source"; // obtained with Stripe.js + $cu->save(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; } elseif ($action == 'delete') { - $cu->sources->retrieve("$source")->detach(); + $cu = \Stripe\Customer::retrieve($stripecu); - header('Location: '.$url); - exit; + $cu->sources->retrieve("$source")->detach(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; } } @@ -446,13 +457,13 @@ if ($socid && $action != 'edit' && $action != "create") if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); } - if (! (empty($conf->stripe->enabled))) + if (! empty($conf->stripe->enabled)) { - $stripe = new Stripe($db); - // Prospect/Customer + + // Stripe customer key 'cu_....' stored into llx_societe_account print '
    '.$langs->trans('StripeCustomerId').''; - print $stripe->getStripeCustomerAccount($object->id); + print $stripecu; print '
    '; print '
    '; + print '
    '; + if (! (empty($conf->stripe->enabled))) { - print load_fiche_titre($langs->trans('StripeGateways'), '', ''); + print load_fiche_titre($langs->trans('StripeGateways').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); - if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; - else $service = 'StripeLive'; - - if (is_object($stripe) && $stripe->getStripeAccount($service)) + $listofsources = array(); + if (is_object($stripe) && $stripeacc) { - $customerstripe=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service)); - } - - if ($customerstripe->id) { - $input=$customerstripe->sources->data; + $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); + + if ($customerstripe->id) { + $listofsources=$customerstripe->sources->data; + } } + print '
    '; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; print ''; print ''; @@ -484,9 +496,9 @@ if ($socid && $action != 'edit' && $action != "create") print ''; print "\n"; - if (is_array($input)) + if (is_array($listofsources)) { - foreach ($input as $src) + foreach ($listofsources as $src) { print ''; print ''; } } - if (empty($input)) + if (empty($listofsources)) { print ''; } print "
    '.$langs->trans('Type').''.$langs->trans('Default').'
    '; @@ -581,11 +593,12 @@ if ($socid && $action != 'edit' && $action != "create") print '
    '.$langs->trans("NoSource").'
    "; + print "
    "; } @@ -599,7 +612,7 @@ if ($socid && $action != 'edit' && $action != "create") $var = false; if (is_array($rib_list)) { - print '
    '; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print '
    '; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index a0f6008b6f8..dfecc56a172 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -55,7 +55,7 @@ class Stripe extends CommonObject * Return main company OAuth Connect stripe account * * @param string $mode 'StripeTest' or 'StripeLive' - * @return int ??? + * @return string Stripe account 'acc_....' */ public function getStripeAccount($mode='StripeTest') { @@ -106,7 +106,7 @@ class Stripe extends CommonObject $sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); - dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + dol_syslog(get_class($this) . "::getStripeCustomerAccount Try to find the cu_.... of thirdparty id=".$id, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { @@ -145,10 +145,9 @@ class Stripe extends CommonObject dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $soc = new Societe($this->db); - $soc->fetch($id); $num = $this->db->num_rows($resql); - if ($num) { + if ($num) + { $obj = $this->db->fetch_object($resql); $tiers = $obj->key_account; if ($conf->entity == 1) { @@ -159,8 +158,11 @@ class Stripe extends CommonObject )); } } - else + elseif ($createifnotlinkedtostripe) { + $soc = new Societe($this->db); + $soc->fetch($id); + if ($conf->entity == 1) { $customer = \Stripe\Customer::create(array( "email" => $soc->email, From 17b7c6268e81a0a13e1bc74e99e6efa9b489b3a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 15:29:52 +0100 Subject: [PATCH 090/126] FIX avoid "Array" on screen --- htdocs/projet/element.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 2b753a50468..8b791b7a9c7 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -1137,9 +1137,12 @@ foreach ($listofreferent as $key => $value) print ''; print ''; } - else // error + else { - print $elementarray; + if (! is_array($elementarray)) // error + { + print $elementarray; + } } print "
     
    "; print "
    \n"; From 1ff13cff7afc10f041cb21bb64b2d92b7ff27ca7 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 13 Mar 2018 15:43:11 +0100 Subject: [PATCH 091/126] Fix select by default gateway's icon --- htdocs/societe/paymentmodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 53f714b414c..abaaf0e694d 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -570,7 +570,7 @@ if ($socid && $action != 'edit' && $action != "create") print ''; // Default print ''; - if (($cu->default_source!=$src->id)) + if (($customerstripe->default_source!=$src->id)) { print ''; print ""; From af09a3714b3ea937730cb171b008635429d94bc8 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Tue, 13 Mar 2018 17:12:03 +0100 Subject: [PATCH 092/126] FIX reverse field to have object loaded in doaction --- htdocs/societe/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 42abde0e09b..204eff383d5 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -73,7 +73,7 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('thirdpartycard','globalcard')); -if ($action == 'view' && $object->fetch($socid)<=0) +if ($object->fetch($socid)<=0 && $action == 'view') { $langs->load("errors"); print($langs->trans('ErrorRecordNotFound')); From 944ba69cd8d35dfe5b41ee86a74bb83733f18055 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 17:32:49 +0100 Subject: [PATCH 093/126] Add unique key. Dolibarrize view of stripe card. --- htdocs/core/class/html.form.class.php | 10 +- htdocs/core/lib/company.lib.php | 3 + .../install/mysql/migration/7.0.0-8.0.0.sql | 4 +- .../mysql/tables/llx_societe_account.key.sql | 1 + .../mysql/tables/llx_societe_account.sql | 2 +- .../class/societeaccount.class.php} | 54 +++--- htdocs/societe/paymentmodes.php | 159 +++++++++++++----- 7 files changed, 158 insertions(+), 75 deletions(-) rename htdocs/{website/class/websiteaccount.class.php => societe/class/societeaccount.class.php} (91%) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 70274040fd3..4d263611390 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -81,9 +81,10 @@ class Form * @param string $moreparam More param to add on a href URL. * @param int $fieldrequired 1 if we want to show field as mandatory using the "fieldrequired" CSS. * @param int $notabletag 1=Do not output table tags but output a ':', 2=Do not output table tags and no ':', 3=Do not output table tags but output a ' ' + * @param string $paramid Key of parameter for id ('id', 'socid') * @return string HTML edit field */ - function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0, $notabletag=0) + function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0, $notabletag=0, $paramid='id') { global $conf,$langs; @@ -117,7 +118,7 @@ class Form if (! empty($notabletag)) $ret.=' '; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; - if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; + if ($htmlname && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.='id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; if (! empty($notabletag) && $notabletag == 1) $ret.=' : '; if (! empty($notabletag) && $notabletag == 3) $ret.=' '; if (empty($notabletag) && GETPOST('action','aZ09') != 'edit'.$htmlname && $perm) $ret.=''; @@ -142,9 +143,10 @@ class Form * @param string $moreparam More param to add on a href URL * @param int $notabletag Do no output table tags * @param string $formatfunc Call a specific function to output field + * @param string $paramid Key of parameter for id ('id', 'socid') * @return string HTML edit field */ - function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0, $formatfunc='') + function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0, $formatfunc='', $paramid='id') { global $conf,$langs,$db; @@ -166,7 +168,7 @@ class Form $ret.='
    '; $ret.=''; $ret.=''; - $ret.=''; + $ret.=''; if (empty($notabletag)) $ret.=''; if (empty($notabletag)) $ret.=''; - } print '
    '; if (preg_match('/^(string|email)/',$typeofdata)) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 023729e680d..ea9a46bc54e 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -208,6 +208,9 @@ function societe_prepare_head(Societe $object) else { dol_print_error($db); } + + //if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number + if ($nbBankAccount > 0) $head[$h][1].= ' '.$nbBankAccount.''; $head[$h][2] = 'rib'; $h++; diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 9c65b4442d2..6f36d760c18 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -260,7 +260,7 @@ CREATE TABLE llx_societe_account( entity integer DEFAULT 1, key_account varchar(128), login varchar(128) NOT NULL, - pass_encoding varchar(24) NOT NULL, + pass_encoding varchar(24), pass_crypted varchar(128), pass_temp varchar(128), -- temporary password when asked for forget password fk_soc integer, @@ -278,6 +278,7 @@ CREATE TABLE llx_societe_account( -- END MODULEBUILDER FIELDS ) ENGINE=innodb; +-- VMYSQL4.3 ALTER TABLE llx_societe_account MODIFY COLUMN pass_encoding varchar(24) NULL; ALTER TABLE llx_societe_account ADD COLUMN key_account varchar(128); @@ -288,6 +289,7 @@ ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_website (fk_web ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_soc (fk_soc); ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_login_website_soc(entity, fk_soc, login, site, fk_website); +ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_key_account_soc(entity, fk_soc, key_account, site, fk_website); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_website FOREIGN KEY (fk_website) REFERENCES llx_website(rowid); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_account.key.sql b/htdocs/install/mysql/tables/llx_societe_account.key.sql index ece860300c1..3e0dc130554 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.key.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.key.sql @@ -23,6 +23,7 @@ ALTER TABLE llx_societe_account ADD INDEX idx_societe_account_fk_soc (fk_soc); -- END MODULEBUILDER INDEXES ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_login_website_soc(entity, fk_soc, login, site, fk_website); +ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_key_account_soc(entity, fk_soc, key_account, site, fk_website); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_website FOREIGN KEY (fk_website) REFERENCES llx_website(rowid); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_account.sql b/htdocs/install/mysql/tables/llx_societe_account.sql index 4dd17f441ed..7a0f87cbe5d 100644 --- a/htdocs/install/mysql/tables/llx_societe_account.sql +++ b/htdocs/install/mysql/tables/llx_societe_account.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_societe_account( entity integer DEFAULT 1, key_account varchar(128), login varchar(128) NOT NULL, - pass_encoding varchar(24) NOT NULL, + pass_encoding varchar(24), pass_crypted varchar(128), pass_temp varchar(128), -- temporary password when asked for forget password fk_soc integer, diff --git a/htdocs/website/class/websiteaccount.class.php b/htdocs/societe/class/societeaccount.class.php similarity index 91% rename from htdocs/website/class/websiteaccount.class.php rename to htdocs/societe/class/societeaccount.class.php index f24847a4601..05ce15a8c94 100644 --- a/htdocs/website/class/websiteaccount.class.php +++ b/htdocs/societe/class/societeaccount.class.php @@ -20,9 +20,9 @@ */ /** - * \file class/websiteaccount.class.php - * \ingroup website - * \brief This file is a CRUD class file for WebsiteAccount (Create/Read/Update/Delete) + * \file class/societeaccount.class.php + * \ingroup societe + * \brief This file is a CRUD class file for SocieteAccount (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -31,24 +31,24 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** - * Class for WebsiteAccount + * Class for SocieteAccount */ -class WebsiteAccount extends CommonObject +class SocieteAccount extends CommonObject { /** * @var string ID to identify managed object */ - public $element = 'websiteaccount'; + public $element = 'societeaccount'; /** * @var string Name of table without prefix where object is stored */ - public $table_element = 'website_account'; + public $table_element = 'societe_account'; /** - * @var array Does websiteaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + * @var array Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ public $ismultientitymanaged = 0; /** - * @var string String with name of icon for websiteaccount. Must be the part after the 'object_' into object_myobject.png + * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png */ public $picto = 'lock'; @@ -76,12 +76,15 @@ class WebsiteAccount extends CommonObject */ public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',), - 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Login',), + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1), + 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',), + 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10), 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30), 'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1), 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,), 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1), - 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>41, 'notnull'=>1, 'index'=>1), + 'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41), + 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>1, 'index'=>1), 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,), 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,), //'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,), @@ -94,9 +97,13 @@ class WebsiteAccount extends CommonObject 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')), ); public $rowid; - public $login; + public $entity; + public $key_account; public $pass_encoding; public $pass_crypted; + public $pass_temp; + public $fk_soc; + public $site; public $date_last_login; public $date_previous_login; public $note_private; @@ -106,7 +113,6 @@ class WebsiteAccount extends CommonObject public $fk_user_modif; public $import_key; public $status; - public $fk_soc; // END MODULEBUILDER PROPERTIES @@ -117,21 +123,21 @@ class WebsiteAccount extends CommonObject /** * @var int Name of subtable line */ - //public $table_element_line = 'website_accountdet'; + //public $table_element_line = 'societe_accountdet'; /** * @var int Field with ID of parent key if this field has a parent */ - //public $fk_element = 'fk_website_account'; + //public $fk_element = 'fk_societe_account'; /** * @var int Name of subtable class that manage subtable lines */ - //public $class_element_line = 'WebsiteAccountline'; + //public $class_element_line = 'societeAccountline'; /** * @var array Array of child tables (child tables to delete before deleting a record) */ - //protected $childtables=array('website_accountdet'); + //protected $childtables=array('societe_accountdet'); /** - * @var WebsiteAccountLine[] Array of subtable lines + * @var societeAccountLine[] Array of subtable lines */ //public $lines = array(); @@ -235,7 +241,7 @@ class WebsiteAccount extends CommonObject { $this->lines=array(); - // Load lines with object WebsiteAccountLine + // Load lines with object societeAccountLine return count($this->lines)?1:0; } @@ -287,12 +293,12 @@ class WebsiteAccount extends CommonObject $this->ref = $this->login; - $label = '' . $langs->trans("WebsiteAccount") . ''; + $label = '' . $langs->trans("SocieteAccount") . ''; $label.= '
    '; $label.= '' . $langs->trans('Login') . ': ' . $this->ref; //$label.= '' . $langs->trans('WebSite') . ': ' . $this->ref; - $url = dol_buildpath('/website/websiteaccount_card.php',1).'?id='.$this->id; + $url = dol_buildpath('/societe/societeaccount_card.php',1).'?id='.$this->id; if ($option != 'nolink') { @@ -307,7 +313,7 @@ class WebsiteAccount extends CommonObject { if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowWebsiteAccount"); + $label=$langs->trans("ShowsocieteAccount"); $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; @@ -486,10 +492,10 @@ class WebsiteAccount extends CommonObject } /** - * Class WebsiteAccountLine. You can also remove this and generate a CRUD class for lines objects. + * Class societeAccountLine. You can also remove this and generate a CRUD class for lines objects. */ /* -class WebsiteAccountLine +class societeAccountLine { // @var int ID public $id; diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 53f714b414c..898c442b755 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -33,13 +33,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; -$langs->load("companies"); -$langs->load("commercial"); -$langs->load("banks"); -$langs->load("bills"); +$langs->loadLangs(array("companies","commercial","banks","bills")); // Security check $socid = GETPOST("socid","int"); @@ -50,6 +48,7 @@ $id=GETPOST("id","int"); $source=GETPOST("source","alpha"); $ribid=GETPOST("ribid","int"); $action=GETPOST("action", 'alpha', 3); +$cancel=GETPOST('cancel', 'alpha'); $object = new Societe($db); $object->fetch($socid); @@ -90,6 +89,11 @@ if (! empty($conf->stripe->enabled)) * Actions */ +if ($cancel) +{ + $action=''; +} + $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -344,35 +348,88 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; $id = $savid; -} -// Action for stripe -if (! empty($conf->stripe->enabled) && class_exists('Stripe')) -{ - if ($action == 'setassourcedefault') + // Action for stripe + if (! empty($conf->stripe->enabled) && class_exists('Stripe')) { - $cu = \Stripe\Customer::retrieve($stripecu); + if ($action == 'setkey_account') + { + $error = 0; - $cu->default_source = "$source"; // obtained with Stripe.js - $cu->save(); + $newcu = GETPOST('key_account', 'alpha'); - $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - elseif ($action == 'delete') - { - $cu = \Stripe\Customer::retrieve($stripecu); + $db->begin(); - $cu->sources->retrieve("$source")->detach(); + $sql = 'UPDATE '.MAIN_DB_PREFIX."societe_account"; + $sql.= " SET key_account = '".$db->escape(GETPOST('key_account', 'alpha'))."'"; + $sql.= " WHERE site = 'stripe' AND fk_soc = ".$object->id." AND status = ".$servicestatus." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified ! - $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; - header('Location: '.$url); - exit; + $resql = $db->query($sql); + $num = $db->num_rows($resql); + if (empty($num)) + { + $societeaccount = new SocieteAccount($db); + $societeaccount->fk_soc = $object->id; + $societeaccount->login = ''; + $societeaccount->pass_encoding = ''; + $societeaccount->site = 'stripe'; + $societeaccount->status = $servicestatus; + $societeaccount->key_account = $newcu; + $result = $societeaccount->create($user); + if ($result < 0) + { + $error++; + } + } + + if (! $error) + { + $stripecu = $newcu; + $db->commit(); + } + else + { + $db->rollback(); + } + } + + if ($action == 'setassourcedefault') + { + try { + $cu = \Stripe\Customer::retrieve($stripecu); + $cu->default_source = (string) $source; + $result = $cu->save(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + catch(Exception $e) + { + + } + } + elseif ($action == 'delete') + { + try { + $cu = \Stripe\Customer::retrieve($stripecu); + + $cu->sources->retrieve("$source")->detach(); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + catch(Exception $e) + { + + } + } } } + /* * View */ @@ -459,13 +516,15 @@ if ($socid && $action != 'edit' && $action != "create") if (! empty($conf->stripe->enabled)) { - - + $permissiontowrite = $user->rights->societe->creer; // Stripe customer key 'cu_....' stored into llx_societe_account - print '
    '.$langs->trans('StripeCustomerId').''; - print $stripecu; + print '
    '; + //print $langs->trans('StripeCustomerId'); + print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 1, 'socid'); + print ''; + //print $stripecu; + print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 1, '', 'socid'); print '
    '; @@ -475,24 +534,30 @@ if ($socid && $action != 'edit' && $action != "create") if (! (empty($conf->stripe->enabled))) { - print load_fiche_titre($langs->trans('StripeGateways').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); $listofsources = array(); if (is_object($stripe) && $stripeacc) { - $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); - - if ($customerstripe->id) { - $listofsources=$customerstripe->sources->data; + try { + $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); + if ($customerstripe->id) { + $listofsources=$customerstripe->sources->data; + } + } + catch(Exception $e) + { + dol_syslog("Failed to get strip customer for thirdparty id =".$object->id); } } print '
    '; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; print "\n"; @@ -500,7 +565,10 @@ if ($socid && $action != 'edit' && $action != "create") { foreach ($listofsources as $src) { - print ''; + print ''; + print ''; print ''; // Default print ''; print ''; @@ -603,8 +671,9 @@ if ($socid && $action != 'edit' && $action != "create") // List of bank accounts + print '
    '; - $morehtmlright=''.$langs->trans("Add").''; + $morehtmlright=''.$langs->trans("Add").''; print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); From 2566170c68a769aef767f15510ece3b633ca0e48 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 17:47:43 +0100 Subject: [PATCH 094/126] Use code of societeaccount --- htdocs/core/lib/company.lib.php | 18 +++++++--- htdocs/societe/class/societeaccount.class.php | 34 +++++++++++++++++++ htdocs/stripe/class/stripe.class.php | 25 +++----------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index ea9a46bc54e..3a295f7a941 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -178,6 +178,8 @@ function societe_prepare_head(Societe $object) // Bank accounts if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT)) { + $nbBankAccount=0; + $foundonexternalonlinesystem=0; $langs->load("banks"); $title = $langs->trans("BankAccounts"); @@ -185,11 +187,16 @@ function societe_prepare_head(Societe $object) { $langs->load("stripe"); $title = $langs->trans("BankAccountsAndGateways"); + + $servicestatus = 0; + if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) $servicestatus = 1; + + include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; + $societeaccount = new SocieteAccount($db); + $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_... + if ($stripecu) $foundonexternalonlinesystem++; } - $nbBankAccount=0; - $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id; - $head[$h][1] = $title; $sql = "SELECT COUNT(n.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n"; $sql.= " WHERE fk_soc = ".$object->id; @@ -211,7 +218,10 @@ function societe_prepare_head(Societe $object) //if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number - if ($nbBankAccount > 0) $head[$h][1].= ' '.$nbBankAccount.''; + $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id; + $head[$h][1] = $title; + if ($foundonexternalonlinesystem) $head[$h][1].= ' ...'; + elseif ($nbBankAccount > 0) $head[$h][1].= ' '.$nbBankAccount.''; $head[$h][2] = 'rib'; $h++; } diff --git a/htdocs/societe/class/societeaccount.class.php b/htdocs/societe/class/societeaccount.class.php index 05ce15a8c94..08b3617e540 100644 --- a/htdocs/societe/class/societeaccount.class.php +++ b/htdocs/societe/class/societeaccount.class.php @@ -246,6 +246,40 @@ class SocieteAccount extends CommonObject return count($this->lines)?1:0; } + /** + * Try to find the external customer id of a thirdparty for an another site/system. + * + * @param int $id Id of third party + * @param string $site Site (example: 'stripe', '...') + * @param int $status Status (0=test, 1=live) + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' + */ + public function getCustomerAccount($id, $site, $status=0) + { + global $conf; + + $sql = "SELECT sa.key_account as key_account, sa.entity"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; + $sql.= " WHERE sa.fk_soc = " . $id; + $sql.= " AND sa.entity IN (".getEntity('societe').")"; + $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status); + + dol_syslog(get_class($this) . "::getCustomerAccount Try to find the system customer id of thirdparty id=".$id." (exemple: cu_.... for stripe)", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + if ($this->db->num_rows($result)) { + $obj = $this->db->fetch_object($result); + $key = $obj->key_account; + } else { + $key = ''; + } + } else { + $key = ''; + } + + return $key; + } + /** * Update object into database * diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index dfecc56a172..1053f3236c3 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -94,32 +94,15 @@ class Stripe extends CommonObject * * @param int $id Id of third party * @param int $status Status - * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' */ public function getStripeCustomerAccount($id, $status=0) { global $conf; - $sql = "SELECT sa.key_account as key_account, sa.entity"; - $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; - $sql.= " WHERE sa.fk_soc = " . $id; - $sql.= " AND sa.entity IN (".getEntity('societe').")"; - $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); - - dol_syslog(get_class($this) . "::getStripeCustomerAccount Try to find the cu_.... of thirdparty id=".$id, LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $key = $obj->key_account; - } else { - $key = NULL; - } - } else { - $key = NULL; - } - - return $key; + include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; + $societeaccount = new SocieteAccount($this->db); + return $societeaccount->getCustomerAccount($object->id, 'stripe', $status); // Get thirdparty cu_... } From 0a642a2656eba44d53f5813d8999ad8a88643fb3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 17:49:30 +0100 Subject: [PATCH 095/126] Fix regression --- htdocs/stripe/class/stripe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 1053f3236c3..5f86c45f696 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -102,7 +102,7 @@ class Stripe extends CommonObject include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; $societeaccount = new SocieteAccount($this->db); - return $societeaccount->getCustomerAccount($object->id, 'stripe', $status); // Get thirdparty cu_... + return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cu_... } From 3f490906f9c372eaed7c8f08e84d909c82b55d08 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 17:52:15 +0100 Subject: [PATCH 096/126] Trans --- htdocs/langs/en_US/stripe.lang | 3 ++- htdocs/societe/paymentmodes.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 15d20dc0f1b..b1169eb776d 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -49,4 +49,5 @@ OAUTH_STRIPE_LIVE_ID=Stripe Connect Client ID (ca_...) BankAccountForBankTransfer=Bank account for fund payouts StripeAccount=Stripe account StripeChargeList=List of Stripe charges -StripeCustomerId=Stripe customer id \ No newline at end of file +StripeCustomerId=Stripe customer id +StripePaymentModes=Stripe payment modes \ No newline at end of file diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 898c442b755..273b5e53bb5 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -675,7 +675,7 @@ if ($socid && $action != 'edit' && $action != "create") $morehtmlright=''.$langs->trans("Add").''; - print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); + print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, ''); $rib_list = $object->get_all_rib(); $var = false; From 60283a8205ef7a75b90e53bd1e25b198cb22f0ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 18:07:22 +0100 Subject: [PATCH 097/126] Remove file incoterm.lang --- htdocs/langs/ar_SA/incoterm.lang | 3 --- htdocs/langs/bg_BG/incoterm.lang | 3 --- htdocs/langs/bn_BD/incoterm.lang | 3 --- htdocs/langs/bs_BA/incoterm.lang | 3 --- htdocs/langs/ca_ES/incoterm.lang | 3 --- htdocs/langs/cs_CZ/incoterm.lang | 3 --- htdocs/langs/da_DK/incoterm.lang | 3 --- htdocs/langs/de_DE/incoterm.lang | 3 --- htdocs/langs/el_GR/incoterm.lang | 3 --- htdocs/langs/en_US/admin.lang | 2 ++ htdocs/langs/en_US/incoterm.lang | 3 --- htdocs/langs/en_US/main.lang | 1 + htdocs/langs/es_ES/incoterm.lang | 3 --- htdocs/langs/et_EE/incoterm.lang | 3 --- htdocs/langs/eu_ES/incoterm.lang | 3 --- htdocs/langs/fa_IR/incoterm.lang | 3 --- htdocs/langs/fi_FI/incoterm.lang | 3 --- htdocs/langs/fr_CA/incoterm.lang | 2 -- htdocs/langs/fr_FR/incoterm.lang | 3 --- htdocs/langs/he_IL/incoterm.lang | 3 --- htdocs/langs/hr_HR/incoterm.lang | 3 --- htdocs/langs/hu_HU/incoterm.lang | 3 --- htdocs/langs/id_ID/incoterm.lang | 3 --- htdocs/langs/is_IS/incoterm.lang | 3 --- htdocs/langs/it_IT/incoterm.lang | 3 --- htdocs/langs/ja_JP/incoterm.lang | 3 --- htdocs/langs/ka_GE/incoterm.lang | 3 --- htdocs/langs/kn_IN/incoterm.lang | 3 --- htdocs/langs/ko_KR/incoterm.lang | 3 --- htdocs/langs/lo_LA/incoterm.lang | 3 --- htdocs/langs/lt_LT/incoterm.lang | 3 --- htdocs/langs/lv_LV/incoterm.lang | 3 --- htdocs/langs/mk_MK/incoterm.lang | 3 --- htdocs/langs/mn_MN/incoterm.lang | 3 --- htdocs/langs/nb_NO/incoterm.lang | 3 --- htdocs/langs/nl_NL/incoterm.lang | 3 --- htdocs/langs/pl_PL/incoterm.lang | 3 --- htdocs/langs/pt_BR/incoterm.lang | 2 -- htdocs/langs/pt_PT/incoterm.lang | 3 --- htdocs/langs/ro_RO/incoterm.lang | 3 --- htdocs/langs/ru_RU/incoterm.lang | 3 --- htdocs/langs/sk_SK/incoterm.lang | 3 --- htdocs/langs/sl_SI/incoterm.lang | 3 --- htdocs/langs/sq_AL/incoterm.lang | 3 --- htdocs/langs/sr_RS/incoterm.lang | 3 --- htdocs/langs/sv_SE/incoterm.lang | 3 --- htdocs/langs/sw_SW/incoterm.lang | 3 --- htdocs/langs/th_TH/incoterm.lang | 3 --- htdocs/langs/tr_TR/incoterm.lang | 3 --- htdocs/langs/uk_UA/incoterm.lang | 3 --- htdocs/langs/uz_UZ/incoterm.lang | 3 --- htdocs/langs/vi_VN/incoterm.lang | 3 --- htdocs/langs/zh_CN/incoterm.lang | 3 --- htdocs/langs/zh_TW/incoterm.lang | 3 --- 54 files changed, 3 insertions(+), 154 deletions(-) delete mode 100644 htdocs/langs/ar_SA/incoterm.lang delete mode 100644 htdocs/langs/bg_BG/incoterm.lang delete mode 100644 htdocs/langs/bn_BD/incoterm.lang delete mode 100644 htdocs/langs/bs_BA/incoterm.lang delete mode 100644 htdocs/langs/ca_ES/incoterm.lang delete mode 100644 htdocs/langs/cs_CZ/incoterm.lang delete mode 100644 htdocs/langs/da_DK/incoterm.lang delete mode 100644 htdocs/langs/de_DE/incoterm.lang delete mode 100644 htdocs/langs/el_GR/incoterm.lang delete mode 100644 htdocs/langs/en_US/incoterm.lang delete mode 100644 htdocs/langs/es_ES/incoterm.lang delete mode 100644 htdocs/langs/et_EE/incoterm.lang delete mode 100644 htdocs/langs/eu_ES/incoterm.lang delete mode 100644 htdocs/langs/fa_IR/incoterm.lang delete mode 100644 htdocs/langs/fi_FI/incoterm.lang delete mode 100644 htdocs/langs/fr_CA/incoterm.lang delete mode 100644 htdocs/langs/fr_FR/incoterm.lang delete mode 100644 htdocs/langs/he_IL/incoterm.lang delete mode 100644 htdocs/langs/hr_HR/incoterm.lang delete mode 100644 htdocs/langs/hu_HU/incoterm.lang delete mode 100644 htdocs/langs/id_ID/incoterm.lang delete mode 100644 htdocs/langs/is_IS/incoterm.lang delete mode 100644 htdocs/langs/it_IT/incoterm.lang delete mode 100644 htdocs/langs/ja_JP/incoterm.lang delete mode 100644 htdocs/langs/ka_GE/incoterm.lang delete mode 100644 htdocs/langs/kn_IN/incoterm.lang delete mode 100644 htdocs/langs/ko_KR/incoterm.lang delete mode 100644 htdocs/langs/lo_LA/incoterm.lang delete mode 100644 htdocs/langs/lt_LT/incoterm.lang delete mode 100644 htdocs/langs/lv_LV/incoterm.lang delete mode 100644 htdocs/langs/mk_MK/incoterm.lang delete mode 100644 htdocs/langs/mn_MN/incoterm.lang delete mode 100644 htdocs/langs/nb_NO/incoterm.lang delete mode 100644 htdocs/langs/nl_NL/incoterm.lang delete mode 100644 htdocs/langs/pl_PL/incoterm.lang delete mode 100644 htdocs/langs/pt_BR/incoterm.lang delete mode 100644 htdocs/langs/pt_PT/incoterm.lang delete mode 100644 htdocs/langs/ro_RO/incoterm.lang delete mode 100644 htdocs/langs/ru_RU/incoterm.lang delete mode 100644 htdocs/langs/sk_SK/incoterm.lang delete mode 100644 htdocs/langs/sl_SI/incoterm.lang delete mode 100644 htdocs/langs/sq_AL/incoterm.lang delete mode 100644 htdocs/langs/sr_RS/incoterm.lang delete mode 100644 htdocs/langs/sv_SE/incoterm.lang delete mode 100644 htdocs/langs/sw_SW/incoterm.lang delete mode 100644 htdocs/langs/th_TH/incoterm.lang delete mode 100644 htdocs/langs/tr_TR/incoterm.lang delete mode 100644 htdocs/langs/uk_UA/incoterm.lang delete mode 100644 htdocs/langs/uz_UZ/incoterm.lang delete mode 100644 htdocs/langs/vi_VN/incoterm.lang delete mode 100644 htdocs/langs/zh_CN/incoterm.lang delete mode 100644 htdocs/langs/zh_TW/incoterm.lang diff --git a/htdocs/langs/ar_SA/incoterm.lang b/htdocs/langs/ar_SA/incoterm.lang deleted file mode 100644 index e37b2fd78f8..00000000000 --- a/htdocs/langs/ar_SA/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=شروط التجارة الدولية -Module62000Desc=إضافة ميزات لإدارة شروط التجارة الدولية -IncotermLabel=شروط التجارة الدولية diff --git a/htdocs/langs/bg_BG/incoterm.lang b/htdocs/langs/bg_BG/incoterm.lang deleted file mode 100644 index 48ef90b01a5..00000000000 --- a/htdocs/langs/bg_BG/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Инкотерм -Module62000Desc=Добяване на свойства за управление на Инкотерм -IncotermLabel=Инкотермс diff --git a/htdocs/langs/bn_BD/incoterm.lang b/htdocs/langs/bn_BD/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/bn_BD/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/bs_BA/incoterm.lang b/htdocs/langs/bs_BA/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/bs_BA/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/ca_ES/incoterm.lang b/htdocs/langs/ca_ES/incoterm.lang deleted file mode 100644 index 259ec38c7cb..00000000000 --- a/htdocs/langs/ca_ES/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Afegir funcions per gestionar Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/cs_CZ/incoterm.lang b/htdocs/langs/cs_CZ/incoterm.lang deleted file mode 100644 index e0f966a95cb..00000000000 --- a/htdocs/langs/cs_CZ/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Přidat funkce pro správu Incotermu -IncotermLabel=Incoterms diff --git a/htdocs/langs/da_DK/incoterm.lang b/htdocs/langs/da_DK/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/da_DK/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/de_DE/incoterm.lang b/htdocs/langs/de_DE/incoterm.lang deleted file mode 100644 index c84e313a70c..00000000000 --- a/htdocs/langs/de_DE/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Funktion hinzufügen um Incoterms zu verwalten -IncotermLabel=Incoterms diff --git a/htdocs/langs/el_GR/incoterm.lang b/htdocs/langs/el_GR/incoterm.lang deleted file mode 100644 index e1b8fddb2dc..00000000000 --- a/htdocs/langs/el_GR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Διεθνείς Εμπορικός Όρος -Module62000Desc=Προσθέστε δυνατότητες για τη διαχείριση του Διεθνή Εμπορικού Όρου -IncotermLabel=Διεθνείς Εμπορικοί Όροι diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 6648e43501e..b9e4c33f227 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -621,6 +621,8 @@ Module59000Name=Margins Module59000Desc=Module to manage margins Module60000Name=Commissions Module60000Desc=Module to manage commissions +Module62000Name=Incoterm +Module62000Desc=Add features to manage Incoterm Module63000Name=Resources Module63000Desc=Manage resources (printers, cars, room, ...) you can then share into events Permission11=Read customer invoices diff --git a/htdocs/langs/en_US/incoterm.lang b/htdocs/langs/en_US/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/en_US/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 4f402501c9a..063ea39127b 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -864,6 +864,7 @@ Project=Project Projects=Projects Rights=Permissions LineNb=Line nb +IncotermLabel=Incoterms # Week day Monday=Monday Tuesday=Tuesday diff --git a/htdocs/langs/es_ES/incoterm.lang b/htdocs/langs/es_ES/incoterm.lang deleted file mode 100644 index 0b5aa9e1153..00000000000 --- a/htdocs/langs/es_ES/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Añade funciones para gestionar Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/et_EE/incoterm.lang b/htdocs/langs/et_EE/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/et_EE/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/eu_ES/incoterm.lang b/htdocs/langs/eu_ES/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/eu_ES/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/fa_IR/incoterm.lang b/htdocs/langs/fa_IR/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/fa_IR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/fi_FI/incoterm.lang b/htdocs/langs/fi_FI/incoterm.lang deleted file mode 100644 index 847faa62288..00000000000 --- a/htdocs/langs/fi_FI/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Lisää Incoterm ominaisuuksia -IncotermLabel=Incoterm-ehdot diff --git a/htdocs/langs/fr_CA/incoterm.lang b/htdocs/langs/fr_CA/incoterm.lang deleted file mode 100644 index d982800ae3e..00000000000 --- a/htdocs/langs/fr_CA/incoterm.lang +++ /dev/null @@ -1,2 +0,0 @@ -# Dolibarr language file - Source file is en_US - incoterm -Module62000Desc=Ajouter des fonctionnalités pour gérer Incoterm diff --git a/htdocs/langs/fr_FR/incoterm.lang b/htdocs/langs/fr_FR/incoterm.lang deleted file mode 100644 index dc5c853590c..00000000000 --- a/htdocs/langs/fr_FR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Ajouts de fonctionnalités pour gérer les incoterms -IncotermLabel=Incoterms diff --git a/htdocs/langs/he_IL/incoterm.lang b/htdocs/langs/he_IL/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/he_IL/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/hr_HR/incoterm.lang b/htdocs/langs/hr_HR/incoterm.lang deleted file mode 100644 index b6e33607c35..00000000000 --- a/htdocs/langs/hr_HR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Dodaj mogučnosti za upravljanje Incoterm-om -IncotermLabel=Incoterms diff --git a/htdocs/langs/hu_HU/incoterm.lang b/htdocs/langs/hu_HU/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/hu_HU/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/id_ID/incoterm.lang b/htdocs/langs/id_ID/incoterm.lang deleted file mode 100644 index bd7ab196fca..00000000000 --- a/htdocs/langs/id_ID/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Istilah Ekonomi Internasional -Module62000Desc=Tambah fitur untuk mengatur Istilah Ekonomi Internasional -IncotermLabel=Istilah Ekonomi Internasional diff --git a/htdocs/langs/is_IS/incoterm.lang b/htdocs/langs/is_IS/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/is_IS/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/it_IT/incoterm.lang b/htdocs/langs/it_IT/incoterm.lang deleted file mode 100644 index f3181020491..00000000000 --- a/htdocs/langs/it_IT/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Aggiunge funzioni per la gestione Incoterm -IncotermLabel=Import-Export diff --git a/htdocs/langs/ja_JP/incoterm.lang b/htdocs/langs/ja_JP/incoterm.lang deleted file mode 100644 index dc4c473efa9..00000000000 --- a/htdocs/langs/ja_JP/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=インコターム -Module62000Desc=インコタームを管理する機能を追加 -IncotermLabel=インコタームズ diff --git a/htdocs/langs/ka_GE/incoterm.lang b/htdocs/langs/ka_GE/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/ka_GE/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/kn_IN/incoterm.lang b/htdocs/langs/kn_IN/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/kn_IN/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/ko_KR/incoterm.lang b/htdocs/langs/ko_KR/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/ko_KR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/lo_LA/incoterm.lang b/htdocs/langs/lo_LA/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/lo_LA/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/lt_LT/incoterm.lang b/htdocs/langs/lt_LT/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/lt_LT/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/lv_LV/incoterm.lang b/htdocs/langs/lv_LV/incoterm.lang deleted file mode 100644 index 1b96e667fb5..00000000000 --- a/htdocs/langs/lv_LV/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Inkoterms -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Inkoterms diff --git a/htdocs/langs/mk_MK/incoterm.lang b/htdocs/langs/mk_MK/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/mk_MK/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/mn_MN/incoterm.lang b/htdocs/langs/mn_MN/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/mn_MN/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/nb_NO/incoterm.lang b/htdocs/langs/nb_NO/incoterm.lang deleted file mode 100644 index 7fa8aee4c19..00000000000 --- a/htdocs/langs/nb_NO/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Legg til egenskaper for å administrere Incoterm -IncotermLabel=Incotermer diff --git a/htdocs/langs/nl_NL/incoterm.lang b/htdocs/langs/nl_NL/incoterm.lang deleted file mode 100644 index b70a7de1612..00000000000 --- a/htdocs/langs/nl_NL/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Onderdelen toevoegen voor Incoterms -IncotermLabel=Incoterms diff --git a/htdocs/langs/pl_PL/incoterm.lang b/htdocs/langs/pl_PL/incoterm.lang deleted file mode 100644 index 8278ec220a4..00000000000 --- a/htdocs/langs/pl_PL/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Międzynarodowe Reguły Handlu -Module62000Desc=Dodaj funkcje do zarządzania Międzynarodowymi Regułami Handlu -IncotermLabel=Formuły handlowe diff --git a/htdocs/langs/pt_BR/incoterm.lang b/htdocs/langs/pt_BR/incoterm.lang deleted file mode 100644 index 8aa2070c3e8..00000000000 --- a/htdocs/langs/pt_BR/incoterm.lang +++ /dev/null @@ -1,2 +0,0 @@ -# Dolibarr language file - Source file is en_US - incoterm -Module62000Desc=Adicionar recursos para gerenciar Incoterm diff --git a/htdocs/langs/pt_PT/incoterm.lang b/htdocs/langs/pt_PT/incoterm.lang deleted file mode 100644 index 8cb400335b1..00000000000 --- a/htdocs/langs/pt_PT/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Adione funções para gerir Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/ro_RO/incoterm.lang b/htdocs/langs/ro_RO/incoterm.lang deleted file mode 100644 index 7d95bf2b65a..00000000000 --- a/htdocs/langs/ro_RO/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Adaugă functionalitati pentru gestionarea Incoterm -IncotermLabel=Incoterm diff --git a/htdocs/langs/ru_RU/incoterm.lang b/htdocs/langs/ru_RU/incoterm.lang deleted file mode 100644 index ef59e2cfa93..00000000000 --- a/htdocs/langs/ru_RU/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Обязанности по доставке товаров -Module62000Desc=Добавить функции для управления обязанностями по доставке товаров -IncotermLabel=Обязанности по доставке товаров diff --git a/htdocs/langs/sk_SK/incoterm.lang b/htdocs/langs/sk_SK/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/sk_SK/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/sl_SI/incoterm.lang b/htdocs/langs/sl_SI/incoterm.lang deleted file mode 100644 index 57641257ec0..00000000000 --- a/htdocs/langs/sl_SI/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Mednarodni poslovni izraz -Module62000Desc=Mednarodnemu poslovnemu izrazu dodaj lastnost -IncotermLabel=Mednarodni Poslovni Izrazi diff --git a/htdocs/langs/sq_AL/incoterm.lang b/htdocs/langs/sq_AL/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/sq_AL/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/sr_RS/incoterm.lang b/htdocs/langs/sr_RS/incoterm.lang deleted file mode 100644 index 196cf598381..00000000000 --- a/htdocs/langs/sr_RS/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Dodavanje funkcionalnosti za upravljanje Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/sv_SE/incoterm.lang b/htdocs/langs/sv_SE/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/sv_SE/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/sw_SW/incoterm.lang b/htdocs/langs/sw_SW/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/sw_SW/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/th_TH/incoterm.lang b/htdocs/langs/th_TH/incoterm.lang deleted file mode 100644 index 4f05bda372b..00000000000 --- a/htdocs/langs/th_TH/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=เพิ่มคุณสมบัติในการจัดการ Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/tr_TR/incoterm.lang b/htdocs/langs/tr_TR/incoterm.lang deleted file mode 100644 index d08b03c056c..00000000000 --- a/htdocs/langs/tr_TR/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Uluslararası ticari terimleri -Module62000Desc=Uluslararası ticari terimleri yönetmek için özellik ekle -IncotermLabel=Uluslararası Ticaret Terimleri diff --git a/htdocs/langs/uk_UA/incoterm.lang b/htdocs/langs/uk_UA/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/uk_UA/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/uz_UZ/incoterm.lang b/htdocs/langs/uz_UZ/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/uz_UZ/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/vi_VN/incoterm.lang b/htdocs/langs/vi_VN/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/vi_VN/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms diff --git a/htdocs/langs/zh_CN/incoterm.lang b/htdocs/langs/zh_CN/incoterm.lang deleted file mode 100644 index f4ebcdeecbf..00000000000 --- a/htdocs/langs/zh_CN/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=国际贸易术语 -Module62000Desc=添加功能来管理国际贸易术语 -IncotermLabel=国际贸易术语解释通则 diff --git a/htdocs/langs/zh_TW/incoterm.lang b/htdocs/langs/zh_TW/incoterm.lang deleted file mode 100644 index 7ff371e3a95..00000000000 --- a/htdocs/langs/zh_TW/incoterm.lang +++ /dev/null @@ -1,3 +0,0 @@ -Module62000Name=Incoterm -Module62000Desc=Add features to manage Incoterm -IncotermLabel=Incoterms From a86da671badcef4595dba95b7d87c35f8be8e6b2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 18:13:31 +0100 Subject: [PATCH 098/126] Remove verbose log --- htdocs/core/class/translate.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 62abbbbcc18..858b57d4c87 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -205,7 +205,7 @@ class Translate // Check cache if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain { - dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); + //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); return 0; } From c78e5d23eaefc486d6fb4f1946c284093fd87f3c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 20:23:59 +0100 Subject: [PATCH 099/126] Work on the customer payment mode tab --- .../install/mysql/migration/7.0.0-8.0.0.sql | 4 + htdocs/langs/en_US/modulebuilder.lang | 3 +- htdocs/modulebuilder/index.php | 76 ++- .../class/companypaymentmode.class.php | 473 ++++++++++++++++++ 4 files changed, 551 insertions(+), 5 deletions(-) create mode 100644 htdocs/societe/class/companypaymentmode.class.php diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 6f36d760c18..e4c0c406d72 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -294,3 +294,7 @@ ALTER TABLE llx_societe_account ADD UNIQUE INDEX uk_societe_account_key_account_ ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_website FOREIGN KEY (fk_website) REFERENCES llx_website(rowid); ALTER TABLE llx_societe_account ADD CONSTRAINT llx_societe_account_fk_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); + +ALTER TABLE llx_societe_rib MODIFY COLUMN max_total_amount_of_all_payments double(24,8); +ALTER TABLE llx_societe_rib MODIFY COLUMN total_amount_of_all_payments double(24,8); + diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 9e30ee6f1de..6638e1fa674 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -93,4 +93,5 @@ AddLanguageFile=Add language file YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages") DropTableIfEmpty=(Delete table if empty) TableDoesNotExists=The table %s does not exists -TableDropped=Table %s deleted \ No newline at end of file +TableDropped=Table %s deleted +InitStructureFromExistingTable=Build the structure array string of an existing table \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index dbc69c943dd..51ca2b9debb 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -181,6 +181,61 @@ if ($dirins && $action == 'addlanguage' && !empty($module)) $result = dolCopyDir($srcfile, $destfile, 0, 0); } +if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray','alpha')) +{ + $tablename = GETPOST('initfromtablename','alpha'); + $_results = $db->DDLDescTable($tablename); + if (empty($_results)) + { + setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors'); + } + else + { + /*public $fields=array( + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), + 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'), + 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'), + 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirparty'), + 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60), + 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), + 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62), + 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), + 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), + //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502), + 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510), + 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511), + //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000), + 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')), + );*/ + + $string = 'public $fields=array('."\n"; + $string.="
    "; + $i=10; + while ($obj = $db->fetch_object($_results)) + { + $fieldname = $obj->Field; + $type = $obj->Type; + if ($type == 'int(11)') $type='integer'; + $notnull = ($obj->Null == 'YES'?0:1); + $label = preg_replace('/_/', ' ', ucfirst($fieldname)); + if ($fieldname == 'rowid') $label='ID'; + + $string.= "'".$obj->Field."' =>array('type'=>'".$type."', 'label'=>'".$label."', 'enabled'=>1, 'visible'=>-2"; + if ($notnull) $string.= ", 'notnull'=>".$notnull; + $string.= ", 'position'=>".$i."),\n"; + $string.="
    "; + $i+=5; + } + $string.= ');'."\n"; + $string.="
    "; + print $string; + exit; + } +} + if ($dirins && $action == 'initobject' && $module && $objectname) { if (preg_match('/[^a-z0-9_]/i', $objectname)) @@ -490,7 +545,7 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj)) setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null); clearstatcache(true); - + // Make a redirect to reload all data header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname.'&nocache='.time()); @@ -525,7 +580,7 @@ if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null); clearstatcache(true); - + // Make a redirect to reload all data header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname); @@ -1413,7 +1468,20 @@ elseif (! empty($module)) print $langs->trans("EnterNameOfObjectDesc").'

    '; print ''; - print ''; + print ''; + print '
    '; + print '
    '; + print '
    '; + print $langs->trans("Or"); + print '
    '; + print '
    '; + print '
    '; + //print ' '; + print $langs->trans("InitStructureFromExistingTable"); + print ''; + print ''; + print '
    '; + print ''; } elseif ($tabobj == 'deleteobject') @@ -1549,7 +1617,7 @@ elseif (! empty($module)) print '


    '; if(function_exists('opcache_invalidate')) opcache_invalidate($dirread.'/'.$pathtoclass,true); // remove the include cache hell ! - + if (empty($forceddirread)) { $result = dol_include_once($pathtoclass); diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php new file mode 100644 index 00000000000..4dc509c251e --- /dev/null +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -0,0 +1,473 @@ + + * Copyright (C) ---Put here your own copyright and developer email--- + * + * 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 . + */ + +/** + * \file class/companypaymentmode.class.php + * \ingroup monmodule + * \brief This file is a CRUD class file for CompanyPaymentMode (Create/Read/Update/Delete) + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + +/** + * Class for CompanyPaymentMode + */ +class CompanyPaymentMode extends CommonObject +{ + /** + * @var string ID to identify managed object + */ + public $element = 'companypaymentmode'; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'societe_rib'; + /** + * @var int Does companypaymentmode support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + */ + public $ismultientitymanaged = 2; + /** + * @var int Does companypaymentmode support extrafields ? 0=No, 1=Yes + */ + public $isextrafieldmanaged = 0; + /** + * @var string String with name of icon for companypaymentmode. Must be the part after the 'object_' into object_companypaymentmode.png + */ + public $picto = 'generic'; + + + /** + * 'type' if the field format. + * 'label' the translation key. + * 'enabled' is a condition when the field must be managed. + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). + * 'index' if we want an index in database. + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). + * 'position' is the sort order of field. + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. + * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). + * 'help' is a string visible as a tooltip on field + * 'comment' is not used. You can store here any text of your choice. It is not used by application. + * 'default' is a default value for creation (can still be replaced by the global setup of default values) + * 'showoncombobox' if field must be shown into the label of combobox + */ + + // BEGIN MODULEBUILDER PROPERTIES + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields=array( + 'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10), + 'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20), + 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25), + 'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30), + 'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35), + 'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40), + 'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45), + 'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50), + 'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55), + 'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60), + 'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65), + 'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70), + 'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75), + 'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80), + 'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85), + 'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90), + 'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95), + 'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105), + 'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110), + 'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115), + 'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120), + 'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125), + 'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130), + 'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135), + 'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140), + 'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145), + 'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150), + 'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155), + 'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160), + 'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165), + 'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170), + 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175), + 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180), + 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185), + ); + public $rowid; + public $fk_soc; + public $entity; + public $label; + public $amount; + public $description; + public $note_public; + public $note_private; + public $date_creation; + public $tms; + public $fk_user_creat; + public $fk_user_modif; + public $import_key; + public $status; + // END MODULEBUILDER PROPERTIES + + + + // If this object has a subtable with lines + + /** + * @var int Name of subtable line + */ + //public $table_element_line = 'companypaymentmodedet'; + /** + * @var int Field with ID of parent key if this field has a parent + */ + //public $fk_element = 'fk_companypaymentmode'; + /** + * @var int Name of subtable class that manage subtable lines + */ + //public $class_element_line = 'CompanyPaymentModeline'; + /** + * @var array Array of child tables (child tables to delete before deleting a record) + */ + //protected $childtables=array('companypaymentmodedet'); + /** + * @var CompanyPaymentModeLine[] Array of subtable lines + */ + //public $lines = array(); + + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + global $conf; + + $this->db = $db; + + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; + if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + public function create(User $user, $notrigger = false) + { + return $this->createCommon($user, $notrigger); + } + + /** + * Clone and object into another one + * + * @param User $user User that creates + * @param int $fromid Id of object to clone + * @return mixed New object created, <0 if KO + */ + public function createFromClone(User $user, $fromid) + { + global $hookmanager, $langs; + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = "copy_of_".$object->ref; + $object->title = $langs->trans("CopyOf")." ".$object->title; + // ... + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + // End + if (!$error) { + $this->db->commit(); + return $object; + } else { + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id, $ref = null) + { + $result = $this->fetchCommon($id, $ref); + if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); + return $result; + } + + /** + * Load object lines in memory from the database + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + /*public function fetchLines() + { + $this->lines=array(); + + // Load lines with object CompanyPaymentModeLine + + return count($this->lines)?1:0; + }*/ + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + return $this->updateCommon($user, $notrigger); + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user, $notrigger = false) + { + return $this->deleteCommon($user, $notrigger); + } + + /** + * Return a link to the object card (with optionaly the picto) + * + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param string $option On what the link point to ('nolink', ...) + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL + */ + function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1) + { + global $db, $conf, $langs; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips + + $result = ''; + $companylink = ''; + + $label = '' . $langs->trans("CompanyPaymentMode") . ''; + $label.= '
    '; + $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; + + $url = dol_buildpath('/monmodule/companypaymentmode_card.php',1).'?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + } + + $linkclose=''; + if (empty($notooltip)) + { + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowCompanyPaymentMode"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; + } + else $linkclose = ($morecss?' class="'.$morecss.'"':''); + + $linkstart = ''; + $linkend=''; + + $result .= $linkstart; + if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); + if ($withpicto != 2) $result.= $this->ref; + $result .= $linkend; + //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); + + return $result; + } + + /** + * Retourne le libelle du status d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->status,$mode); + } + + /** + * Return the status + * + * @param int $status Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status + */ + static function LibStatut($status,$mode=0) + { + global $langs; + + if ($mode == 0) + { + $prefix=''; + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 1) + { + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 2) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 3) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); + } + if ($mode == 4) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 5) + { + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); + } + if ($mode == 6) + { + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); + } + } + + /** + * Charge les informations d'ordre info dans l'objet commande + * + * @param int $id Id of order + * @return void + */ + function info($id) + { + $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; + $sql.= ' fk_user_creat, fk_user_modif'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql.= ' WHERE t.rowid = '.$id; + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db); + $cluser->fetch($obj->fk_user_cloture); + $this->user_cloture = $cluser; + } + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + $this->date_validation = $this->db->jdate($obj->datev); + } + + $this->db->free($result); + + } + else + { + dol_print_error($this->db); + } + } + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->initAsSpecimenCommon(); + } + +} From da617f7d3215ada6235f4a0b74632ecebfe0d35b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 22:43:50 +0100 Subject: [PATCH 100/126] Can work both with remote and local payment modes --- htdocs/core/class/commonobject.class.php | 5 +- htdocs/core/lib/functions.lib.php | 18 ++ htdocs/loan/class/loanschedule.class.php | 4 +- htdocs/loan/createschedule.php | 2 +- .../template/class/myobject.class.php | 15 +- .../class/companypaymentmode.class.php | 6 +- htdocs/societe/paymentmodes.php | 156 ++++++++++++++---- 7 files changed, 166 insertions(+), 40 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6616745888b..4600cefbdc3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5527,7 +5527,7 @@ abstract class CommonObject $label = $val['label']; $type = $val['type']; $size = $val['css']; - + // Convert var to be able to share same code than showOutputField of extrafields if (preg_match('/varchar\((\d+)\)/', $type, $reg)) { @@ -6675,6 +6675,9 @@ abstract class CommonObject // TODO... } + + /* Part for comments */ + /** * Load comments linked with current task * @return boolean 1 if ok diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 80c4c12a68c..65753457000 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3525,6 +3525,24 @@ function img_allow($allow, $titlealt = 'default') return '-'; } +/** + * Return image of a credit card according to its brand name + * + * @param string $brand Brand name of credit card + * @return string Return img tag + */ +function img_credit_card($brand) +{ + if ($brand == 'Visa') {$brand='cc-visa';} + elseif ($brand == 'MasterCard') {$brand='cc-mastercard';} + elseif ($brand == 'American Express') {$brand='cc-amex';} + elseif ($brand == 'Discover') {$brand='cc-discover';} + elseif ($brand == 'JCB') {$brand='cc-jcb';} + elseif ($brand == 'Diners Club') {$brand='cc-diners-club';} + elseif (! in_array($brand, array('cc-visa','cc-mastercard','cc-amex','cc-discover','cc-jcb','cc-diners-club'))) {$brand='credit-card';} + + return ''; +} /** * Show MIME img of a file diff --git a/htdocs/loan/class/loanschedule.class.php b/htdocs/loan/class/loanschedule.class.php index ebb1820bca0..a430f79366e 100644 --- a/htdocs/loan/class/loanschedule.class.php +++ b/htdocs/loan/class/loanschedule.class.php @@ -386,7 +386,7 @@ class LoanSchedule extends CommonObject * @param int $loanid Id object * @return int <0 if KO, >0 if OK */ - function fetchall($loanid) + function fetchAll($loanid) { global $langs; @@ -409,7 +409,7 @@ class LoanSchedule extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " WHERE t.fk_loan = ".$loanid; - dol_syslog(get_class($this)."::fetchall", LOG_DEBUG); + dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/loan/createschedule.php b/htdocs/loan/createschedule.php index 4ab2499c265..0ecc0038835 100644 --- a/htdocs/loan/createschedule.php +++ b/htdocs/loan/createschedule.php @@ -89,7 +89,7 @@ if ($action == 'updateecheancier') { } $echeance = new LoanSchedule($db); -$echeance->fetchall($object->id); +$echeance->fetchAll($object->id); top_htmlhead('', ''); $var = ! $var; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index e40b6b178e6..267a869fb46 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -142,12 +142,21 @@ class MyObject extends CommonObject */ public function __construct(DoliDB $db) { - global $conf; + global $conf, $user; $this->db = $db; - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; - if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0; + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; + if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; + + // Unset fields that are disabled + foreach($this->fields as $key => $val) + { + if (isset($val['enabled']) && empty($val['enabled'])) + { + unset($this->fields[$key]); + } + } } /** diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 4dc509c251e..baba6252284 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -112,10 +112,10 @@ class CompanyPaymentMode extends CommonObject 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175), 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180), 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185), + //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185), ); public $rowid; public $fk_soc; - public $entity; public $label; public $amount; public $description; @@ -167,8 +167,8 @@ class CompanyPaymentMode extends CommonObject $this->db = $db; - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; - if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0; + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; + if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; } /** diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 273b5e53bb5..845bc3e4c1e 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -33,6 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; @@ -409,7 +410,7 @@ if (empty($reshook)) } } - elseif ($action == 'delete') + elseif ($action == 'deletecard') { try { $cu = \Stripe\Customer::retrieve($stripecu); @@ -534,7 +535,12 @@ if ($socid && $action != 'edit' && $action != "create") if (! (empty($conf->stripe->enabled))) { - print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); + $morehtmlright=''; + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + $morehtmlright=''.$langs->trans("Add").''; + } + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':''), $morehtmlright, ''); $listofsources = array(); if (is_object($stripe) && $stripeacc) @@ -554,43 +560,131 @@ if ($socid && $action != 'edit' && $action != "create") print '
    '; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '
    '.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('ID').''.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').'
    '; + print $src->id; + print ''; if ($src->object=='card') { @@ -511,7 +579,7 @@ if ($socid && $action != 'edit' && $action != "create") elseif ($src->brand == 'JCB') {$brand='cc-jcb';} elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} else {$brand='credit-card';} - print ''; + print ''; } elseif ($src->object=='source' && $src->type=='card') { @@ -522,11 +590,11 @@ if ($socid && $action != 'edit' && $action != "create") elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} else {$brand='credit-card';} - print ''; + print ''; } elseif ($src->object=='source' && $src->type=='sepa_debit') { - print ''; + print ''; } print''; @@ -570,13 +638,13 @@ if ($socid && $action != 'edit' && $action != "create") print ''; - if (($cu->default_source!=$src->id)) + if (($customerstripe->default_source != $src->id)) { print ''; - print ""; + print img_picto($langs->trans("Default"),'off'); print ''; } else { - print ""; + print img_picto($langs->trans("Default"),'on'); } print ''; @@ -587,7 +655,7 @@ if ($socid && $action != 'edit' && $action != "create") // print ''; // print ' '; print ''; - print ""; + print img_delete($langs->trans("Delete")); print ''; } print '
    '."\n"; print ''; - print ''; + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + print ''; + } + print ''; print ''; print ''; print ''; print ''; + print ''; print "\n"; - if (is_array($listofsources)) + $nbremote = 0; + $nblocal = 0; + $arrayofstripecard = array(); + + // Show local sources + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + //$societeaccount = new SocieteAccount($db); + $companypaymentmodetemp = new CompanyPaymentMode($db); + + $sql='SELECT rowid FROM '.MAIN_DB_PREFIX."societe_rib"; + $sql.=" WHERE type in ('card', 'paypal')"; + $sql.=" AND fk_soc = ".$object->id; + + $resql = $db->query($sql); + if ($resql) + { + $num_rows = $db->num_rows($resql); + if ($num_rows) + { + $i=0; + while ($i < $num_rows) + { + $nblocal++; + + $obj = $db->fetch_object($resql); + if ($obj) + { + $companypaymentmodetemp->fetch($obj->rowid); + + $arrayofstripecard[$obj->stripe_card_ref]=$obj->stripe_card_ref; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + $i++; + } + } + else + { + print $langs->trans("NoPaymentMethodOnFile"); + } + } + else dol_print_error($db); + } + + // Show remote sources (not already shown as local source) + if (is_array($listofsources) && count($listofsources)) { foreach ($listofsources as $src) { + if (! empty($arrayofstripecard[$src->id])) continue; // Already in previous list + + $nbremote++; + print ''; + // Local ID + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + print ''; + } print ''; print ''; + print ''; print ''; + print ''; + + print ''; } } - if (empty($listofsources)) + + if ($nbremote == 0 && $nblocal == 0) { - print ''; + print ''; } print "
    '.$langs->trans('ID').''.$langs->trans('LocalID').''.$langs->trans('StripeID').''.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').''.$langs->trans('Note').'
    '; + print $obj->rowid; + print ''; + print $obj->stripe_card_ref; + print ''; + print img_credit_card($companypaymentmodetemp->type); + print ''; + if ($companypaymentmodetemp->last_four) print '**** '.$companypaymentmodetemp->last_four; + if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.$companypaymentmodetemp->exp_date_month.'/'.$companypaymentmodetemp->exp_date_year.''; + print ''; + if ($companypaymentmodetemp->country_code) + { + $img=picto_from_langcode($companypaymentmodetemp->country_code); + print $img?$img.' ':''; + print getCountry($companypaymentmodetemp->country_code,1); + } + else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + print ''; + print yn($obj->default_rib); + print ''; + if (empty($obj->stripe_card_ref)) print $langs->trans("Local"); + else print $langs->trans("LocalAndRemote"); + print ''; + if ($user->rights->societe->creer) + { + print ''; + print img_picto($langs->trans("Modify"),'edit'); + print ''; + print ' '; + print ''; + print img_delete($langs->trans("Delete")); + print ''; + } + print '
    '; + print ''; print $src->id; print ''; if ($src->object=='card') { - if ($src->brand == 'Visa') {$brand='cc-visa';} - elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';} - elseif ($src->brand == 'American Express') {$brand='cc-amex';} - elseif ($src->brand == 'Discover') {$brand='cc-discover';} - elseif ($src->brand == 'JCB') {$brand='cc-jcb';} - elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} - else {$brand='credit-card';} - print ''; + print img_credit_card($src->brand); } elseif ($src->object=='source' && $src->type=='card') { - if ($src->card->brand == 'Visa') {$brand='cc-visa';} - elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';} - elseif ($src->card->brand == 'American Express') {$brand='cc-amex';} - elseif ($src->card->brand == 'Discover') {$brand='cc-discover';} - elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} - elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} - else {$brand='credit-card';} - print ''; + print img_credit_card($src->card->brand); } elseif ($src->object=='source' && $src->type=='sepa_debit') { @@ -647,23 +741,25 @@ if ($socid && $action != 'edit' && $action != "create") print img_picto($langs->trans("Default"),'on'); } print ''; + print $langs->trans("Remote"); + print ''; if ($user->rights->societe->creer) { - // print ''; - // print img_picto($langs->trans("Modify"),'edit'); - // print ''; - // print ' '; - print ''; - print img_delete($langs->trans("Delete")); - print ''; + print ''; + print img_delete($langs->trans("Delete")); + print ''; } - print '
    '.$langs->trans("NoSource").'
    '.$langs->trans("None").'
    "; print "
    "; From fe68e8acddef8cdaeb6fb082dbf0c4d204bbcc1d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 22:54:28 +0100 Subject: [PATCH 101/126] Trans --- htdocs/langs/en_US/stripe.lang | 4 +++- htdocs/societe/paymentmodes.php | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index b1169eb776d..51aaad35165 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -50,4 +50,6 @@ BankAccountForBankTransfer=Bank account for fund payouts StripeAccount=Stripe account StripeChargeList=List of Stripe charges StripeCustomerId=Stripe customer id -StripePaymentModes=Stripe payment modes \ No newline at end of file +StripePaymentModes=Stripe payment modes +LocalID=Local ID +StripeID=Stripe ID \ No newline at end of file diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 845bc3e4c1e..ae446a047d3 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -626,8 +626,16 @@ if ($socid && $action != 'edit' && $action != "create") } else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; print ''; + // Default print ''; - print yn($obj->default_rib); + if (empty($obj->default_rib)) + { + //print ''; + print img_picto($langs->trans("Default"),'off'); + //print ''; + } else { + print img_picto($langs->trans("Default"),'on'); + } print ''; print ''; if (empty($obj->stripe_card_ref)) print $langs->trans("Local"); @@ -734,9 +742,9 @@ if ($socid && $action != 'edit' && $action != "create") print ''; if (($customerstripe->default_source != $src->id)) { - print ''; - print img_picto($langs->trans("Default"),'off'); - print ''; + print ''; + print img_picto($langs->trans("Default"),'off'); + print ''; } else { print img_picto($langs->trans("Default"),'on'); } From e62df03681d9bcb735f394606f5d6cf7efe2f669 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 14 Mar 2018 08:59:05 +0100 Subject: [PATCH 102/126] Fix delete customer stripe with new database --- htdocs/public/stripe/ipn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index bbd2d46a12f..19f9b8c80bc 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -323,7 +323,7 @@ elseif (($event->type == 'source.chargeable') && ($event->data->object->type == } elseif ($event->type == 'customer.deleted') { $db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_stripe WHERE fk_key = '".$event->data->object->id."' "; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE key_account = '".$event->data->object->id."' and site='stripe' "; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); $db->query($sql); $db->commit(); From 9a1588df1385567b527c1f78d3ed32637c925ca6 Mon Sep 17 00:00:00 2001 From: Sean Wang Date: Wed, 14 Mar 2018 16:38:22 +0800 Subject: [PATCH 103/126] Add missing $mode in BookKeeping::createStd() In accountancy ledger, creating new transaction, there is 'ERROR: 55000: currval of sequence "llx_accounting_bookkeeping_rowid_seq" is not yet defined in this session' occurred. According to dolibarr.log, this error will show up after createStd() {...Insert request to llx_accounting_bookkeeping_tmp...}. It query the "llx_accounting_bookkeeping_rowid_seq" instead of "llx_accounting_bookkeeping_tmp_rowid_seq", due to missing $mode at bookkeeping.class.php line504:last_insert_id(). --- htdocs/accountancy/class/bookkeeping.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 16f40139a38..d027b7c425b 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -501,7 +501,7 @@ class BookKeeping extends CommonObject } if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element . $mode); if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you From 304595ee4f91c0bae0f4aa1e4403d05b692ccc65 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Wed, 14 Mar 2018 09:48:39 +0100 Subject: [PATCH 104/126] Fix: Can't activate tasks on projects configuration --- htdocs/projet/admin/project.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 0252ab58f36..67317583273 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -1,11 +1,11 @@ * Copyright (C) 2011-2016 Laurent Destailleur - * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2011-2015 Juanjo Menent * Copyright (C) 2011-2015 Philippe Grand * Copyright (C) 2013 Florian Henry - * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2015 Marcos García + * Copyright (C) 2018 Ferran Marcet * * 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 @@ -59,7 +59,7 @@ if ($action == 'setmainoptions') else dolibarr_del_const($db, "PROJECT_USE_OPPORTUNITIES", $conf->entity); // Warning, the constant saved and used in code is PROJECT_HIDE_TASKS - if (GETPOST('PROJECT_USE_TASKS')) dolibarr_del_const($db, "PROJECT_USE_TASKS", $conf->entity); + if (GETPOST('PROJECT_USE_TASKS')) dolibarr_del_const($db, "PROJECT_HIDE_TASKS", $conf->entity); else dolibarr_set_const($db, "PROJECT_HIDE_TASKS",1,'chaine',0,'',$conf->entity); } From 35fbcb2c849d2decdf9146a7b833aad39fa72398 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 10:48:56 +0100 Subject: [PATCH 105/126] Update company.lib.php --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index d8b9d090473..7400d9d8471 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -466,7 +466,7 @@ function getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entc * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output * @return mixed String with state code or state name or Array('id','code','label')/Array('id','code','label','region_code','region') */ -function getState($id,$withcode='',$dbtouse=0,$withregion='',$outputlangs='',$entconv=1) +function getState($id,$withcode='',$dbtouse=0,$withregion=0,$outputlangs='',$entconv=1) { global $db,$langs; From e47dda72e7f2fc99f33860f847b89801ca09ae85 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Wed, 14 Mar 2018 11:08:38 +0100 Subject: [PATCH 106/126] Fix: Activate all also if there are inactive services --- htdocs/contrat/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 08c43551509..0ad017a94c8 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -6,7 +6,7 @@ * Copyright (C) 2010-2017 Juanjo Menent * Copyright (C) 2013 Christophe Battarel * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2014-2016 Ferran Marcet + * Copyright (C) 2014-2018 Ferran Marcet * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Jean-François Ferry * @@ -2115,7 +2115,7 @@ else print ''; } - if ($object->nbofservicesclosed > 0) + if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) { print ''; } From 268b07bcf0fbff4570fb716f0341e18ce0a13ef5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 11:51:13 +0100 Subject: [PATCH 107/126] Can add/delete credit card localy --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/class/translate.class.php | 2 +- .../install/mysql/migration/7.0.0-8.0.0.sql | 4 + .../install/mysql/tables/llx_societe_rib.sql | 2 +- htdocs/langs/en_US/stripe.lang | 8 +- .../class/companypaymentmode.class.php | 49 +++-- htdocs/societe/paymentmodes.php | 207 +++++++++++++++--- 7 files changed, 231 insertions(+), 43 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4d263611390..2dc47e6e900 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4780,7 +4780,7 @@ class Form * @param string $addplusone Add a link "+1 hour". Value must be name of another select_date field. * @param datetime $adddateof Add a link "Date of invoice" using the following date. * @return string|null Nothing or string if nooutput is 1 - * @see form_date + * @see form_date, select_month, select_year, select_dayofweek */ function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowlink=0, $nooutput=0, $disabled=0, $fullday='', $addplusone='', $adddateof='') { diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 858b57d4c87..69fe031459d 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -231,7 +231,7 @@ class Translate $filelangexists=is_file($file_lang_osencoded); - dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); + //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); if ($filelangexists) { diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index e4c0c406d72..534cba912d5 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -119,6 +119,10 @@ ALTER TABLE llx_societe_rib ADD COLUMN starting_date date; ALTER TABLE llx_societe_rib ADD COLUMN total_amount_of_all_payments double(24,8); ALTER TABLE llx_societe_rib ADD COLUMN stripe_card_ref varchar(128); ALTER TABLE llx_societe_rib ADD COLUMN status integer NOT NULL DEFAULT 1; + +UPDATE llx_societe_rib set type = 'ban' where type = '' OR type IS NULL; +-- VMYSQL4.3 ALTER TABLE llx_societe_rib MODIFY COLUMN type varchar(32) NOT NULL; +-- VPGSQL8.2 ALTER TABLE llx_societe_rib ALTER COLUMN type SET NOT NULL; CREATE TABLE llx_ticketsup ( diff --git a/htdocs/install/mysql/tables/llx_societe_rib.sql b/htdocs/install/mysql/tables/llx_societe_rib.sql index 6157af37830..2463378067a 100644 --- a/htdocs/install/mysql/tables/llx_societe_rib.sql +++ b/htdocs/install/mysql/tables/llx_societe_rib.sql @@ -23,7 +23,7 @@ create table llx_societe_rib ( rowid integer AUTO_INCREMENT PRIMARY KEY, - type varchar(32) DEFAULT 'ban', -- 'ban' or 'paypal' or 'card' or 'stripe' + type varchar(32) DEFAULT 'ban' NOT NULL, -- 'ban' or 'paypal' or 'card' or 'stripe' label varchar(30), fk_soc integer NOT NULL, datec datetime, diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 51aaad35165..3db64381797 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -52,4 +52,10 @@ StripeChargeList=List of Stripe charges StripeCustomerId=Stripe customer id StripePaymentModes=Stripe payment modes LocalID=Local ID -StripeID=Stripe ID \ No newline at end of file +StripeID=Stripe ID +NameOnCard=Name on card +CardNumber=Card Number +ExpiryDate=Expiry Date +CVN=CVN +DeleteACard=Delete Card record +ConfirmDeleteCard=Are you sure you want to delete this Card record? diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index baba6252284..6a2095883c1 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -78,8 +78,6 @@ class CompanyPaymentMode extends CommonObject public $fields=array( 'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10), 'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15), - 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20), - 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25), 'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30), 'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35), 'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40), @@ -95,7 +93,6 @@ class CompanyPaymentMode extends CommonObject 'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90), 'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95), 'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100), - 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105), 'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110), 'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115), 'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120), @@ -112,21 +109,47 @@ class CompanyPaymentMode extends CommonObject 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175), 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180), 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185), - //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20), + 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105), + //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185), ); public $rowid; public $fk_soc; public $label; - public $amount; - public $description; - public $note_public; - public $note_private; - public $date_creation; - public $tms; - public $fk_user_creat; - public $fk_user_modif; - public $import_key; + public $bank; + public $code_banque; + public $code_guichet; + public $number; + public $cle_rib; + public $bic; + public $iban_prefix; + public $domiciliation; + public $proprio; + public $owner_address; + public $default_rib; + public $rum; + public $date_rum; + public $frstrecur; + public $type; + public $last_four; + public $card_type; + public $cvn; + public $exp_date_month; + public $exp_date_year; + public $country_code; + public $approved; + public $email; + public $max_total_amount_of_all_payments; + public $preapproval_key; + public $total_amount_of_all_payments; + public $stripe_card_ref; public $status; + public $starting_date; + public $ending_date; + public $datec; + public $tms; + public $import_key; // END MODULEBUILDER PROPERTIES diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index ae446a047d3..d24f4dd5f32 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -32,6 +32,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; @@ -111,7 +112,7 @@ if (empty($reshook)) } } - if ($action == 'update' && ! $_POST["cancel"]) + if ($action == 'update') { // Modification if (! GETPOST('label')) @@ -188,19 +189,14 @@ if (empty($reshook)) } } - if ($action == 'add' && ! $_POST["cancel"]) + if ($action == 'add') { $error=0; - if (! GETPOST('label')) + if (! GETPOST('label','alpha') || ! GETPOST('bank','alpha')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='create'; - $error++; - } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('bank','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); $action='create'; $error++; } @@ -291,6 +287,68 @@ if (empty($reshook)) } } + if ($action == 'addcard') + { + $error=0; + + if (! GETPOST('label','alpha') || ! GETPOST('proprio','alpha') || ! GETPOST('cardnumber','alpha') || ! GETPOST('exp_date_month','alpha') || ! GETPOST('exp_date_year','alpha') || ! GETPOST('cvn','alpha')) + { + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('proprio','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); + if (! GETPOST('cardnumber','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); + if (! (GETPOST('exp_date_month','alpha') > 0) || ! (GETPOST('exp_date_year','alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); + if (! GETPOST('cvn','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); + $action='createcard'; + $error++; + } + + if (! $error) + { + // Ajout + $paymentmode = new CompanyPaymentMode($db); + + $paymentmode->fk_soc = $object->id; + $paymentmode->bank = GETPOST('bank','alpha'); + $paymentmode->label = GETPOST('label','alpha'); + $paymentmode->number = GETPOST('cardnumber','alpha'); + $paymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); + $paymentmode->proprio = GETPOST('proprio','alpha'); + $paymentmode->exp_date_month = GETPOST('exp_date_month','int'); + $paymentmode->exp_date_year = GETPOST('exp_date_year','int'); + $paymentmode->cvn = GETPOST('cvn','alpha'); + $paymentmode->datec = dol_now(); + $paymentmode->default_rib = 0; + $paymentmode->type = 'card'; + $paymentmode->country_code = $mysoc->country_code; + + $db->begin(); + + if (! $error) + { + $result = $paymentmode->create($user); + if ($result < 0) + { + $error++; + setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + $action='createcard'; // Force chargement page création + } + } + + if (! $error) + { + $db->commit(); + + $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; + header('Location: '.$url); + exit; + } + else + { + $db->rollback(); + } + } + } + if ($action == 'setasbankdefault') { $account = new CompanyBankAccount($db); @@ -307,7 +365,29 @@ if (empty($reshook)) } } - if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes') + if ($action == 'confirm_deletecard' && GETPOST('confirm','alpha') == 'yes') + { + $paymentmode = new CompanyPaymentMode($db); + if ($paymentmode->fetch($ribid?$ribid:$id)) + { + $result = $paymentmode->delete($user); + if ($result > 0) + { + $url = $_SERVER['PHP_SELF']."?socid=".$object->id; + header('Location: '.$url); + exit; + } + else + { + setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + } + } + else + { + setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + } + } + if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes') { $account = new CompanyBankAccount($db); if ($account->fetch($ribid?$ribid:$id)) @@ -393,8 +473,25 @@ if (empty($reshook)) $db->rollback(); } } + if ($action == 'setlocalassourcedefault') + { + try { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 0 WHERE type = 'card' AND default_rib <> 0"; + $db->query($sql); - if ($action == 'setassourcedefault') + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 1 WHERE type = 'card' AND rowid = ".GETPOST('id','int'); + $db->query($sql); + + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + catch(Exception $e) + { + + } + } + elseif ($action == 'setassourcedefault') { try { $cu = \Stripe\Customer::retrieve($stripecu); @@ -436,6 +533,7 @@ if (empty($reshook)) */ $form = new Form($db); +$formother = new FormOther($db); $formfile = new FormFile($db); llxHeader(); @@ -452,31 +550,38 @@ else } if (empty($account->socid)) $account->socid=$object->id; -if ($socid && $action == 'edit' && $user->rights->societe->creer) +if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer) { print '
    '; print ''; print ''; print ''; } -if ($socid && $action == 'create' && $user->rights->societe->creer) +if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) { print ''; print ''; - print ''; + $actionforadd='add'; + if ($action == 'createcard') $actionforadd='addcard'; + print ''; } // View -if ($socid && $action != 'edit' && $action != "create") +if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard') { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); - // Confirm delete third party + // Confirm delete ban if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); } + // Confirm delete card + if ($action == 'deletecard') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $account->getRibLabel()), "confirm_deletecard", '', 0, 1); + } $linkback = ''.$langs->trans("BackToList").''; @@ -533,6 +638,7 @@ if ($socid && $action != 'edit' && $action != "create") print '
    '; + // Stripe payment modes if (! (empty($conf->stripe->enabled))) { $morehtmlright=''; @@ -628,17 +734,17 @@ if ($socid && $action != 'edit' && $action != "create") print ''; // Default print ''; - if (empty($obj->default_rib)) + if (empty($companypaymentmodetemp->default_rib)) { - //print ''; + print ''; print img_picto($langs->trans("Default"),'off'); - //print ''; + print ''; } else { print img_picto($langs->trans("Default"),'on'); } print ''; print ''; - if (empty($obj->stripe_card_ref)) print $langs->trans("Local"); + if (empty($companypaymentmodetemp->stripe_card_ref)) print $langs->trans("Local"); else print $langs->trans("LocalAndRemote"); print ''; print ''; @@ -973,7 +1079,7 @@ if ($socid && $action != 'edit' && $action != "create") dol_fiche_end(); /* - if ($socid && $action != 'edit' && $action != 'create') + if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard') { // Barre d'actions print '
    '; @@ -1031,7 +1137,7 @@ if ($socid && $action != 'edit' && $action != "create") */ } -// Edit +// Edit BAN if ($socid && $action == 'edit' && $user->rights->societe->creer) { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); @@ -1136,7 +1242,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) } -// Create +// Create BAN if ($socid && $action == 'create' && $user->rights->societe->creer) { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); @@ -1151,7 +1257,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; print ''; @@ -1225,6 +1331,55 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) dol_fiche_end(); + dol_set_focus('#label'); + + print '
    '; + print ''; + print '     '; + print ''; + print '
    '; +} + +// Create Card +if ($socid && $action == 'createcard' && $user->rights->societe->creer) +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
    '; + + print '
    '; + print '
    '.$langs->trans("LabelRIB").'
    '.$langs->trans("Bank").'
    '; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print '
    '.$langs->trans("Label").'
    '.$langs->trans("NameOnCard").'
    '.$langs->trans("CardNumber").'
    '.$langs->trans("ExpiryDate").''; + print $formother->select_month(GETPOST('exp_date_month','int'), 'exp_date_month', 1); + print $formother->select_year(GETPOST('exp_date_year','int'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); + print '
    '.$langs->trans("CVN").'
    '; + + print '
    '; + + dol_fiche_end(); + + dol_set_focus('#label'); + print '
    '; print ''; print '     '; @@ -1236,7 +1391,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) { print ''; } -if ($socid && $action == 'create' && $user->rights->societe->creer) +if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) { print ''; } From e179161bfac2c7c19dd7a699bcc1b213e919f40e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 14 Mar 2018 12:01:15 +0100 Subject: [PATCH 108/126] FIX support for stripeconnect mode --- htdocs/societe/paymentmodes.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index ae446a047d3..8088cec0ebb 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015-2016 Marcos García @@ -76,7 +76,7 @@ if (! empty($conf->stripe->enabled)) if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) { $service = 'StripeLive'; - $servicestatus = 0; + $servicestatus = 1; } $stripe = new Stripe($db); @@ -397,7 +397,7 @@ if (empty($reshook)) if ($action == 'setassourcedefault') { try { - $cu = \Stripe\Customer::retrieve($stripecu); + $cu=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); $cu->default_source = (string) $source; $result = $cu->save(); @@ -413,7 +413,7 @@ if (empty($reshook)) elseif ($action == 'deletecard') { try { - $cu = \Stripe\Customer::retrieve($stripecu); + $cu=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); $cu->sources->retrieve("$source")->detach(); From 5140c1c5d2002451cedf88aebc6848a6ba6e316a Mon Sep 17 00:00:00 2001 From: fmarcet Date: Wed, 14 Mar 2018 13:25:05 +0100 Subject: [PATCH 109/126] Fix: Merge categories when merging thirds --- htdocs/societe/card.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 090afd3e935..c28d0d9db68 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -11,6 +11,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2018 Ferran Marcet * * 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 @@ -180,9 +181,12 @@ if (empty($reshook)) // Merge categories $static_cat = new Categorie($db); - $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); + $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id'); + $custcats = $static_cat->containing($object->id, 'customer', 'id'); + $custcats = array_merge($custcats,$custcats_ori); $object->setCategories($custcats, 'customer'); - $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); + $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id'); + $suppcats = $static_cat->containing($object->id, 'supplier', 'id'); $object->setCategories($suppcats, 'supplier'); // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. @@ -210,7 +214,7 @@ if (empty($reshook)) $objects = array( 'Adherent' => '/adherents/class/adherent.class.php', 'Societe' => '/societe/class/societe.class.php', - 'Categorie' => '/categories/class/categorie.class.php', + //'Categorie' => '/categories/class/categorie.class.php', 'ActionComm' => '/comm/action/class/actioncomm.class.php', 'Propal' => '/comm/propal/class/propal.class.php', 'Commande' => '/commande/class/commande.class.php', From 5c2a005e75e44677fa335cc6f66a81eff0242453 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 13:56:21 +0100 Subject: [PATCH 110/126] Work on generic customer payment modes --- htdocs/core/class/commonobject.class.php | 12 +- htdocs/langs/en_US/main.lang | 5 +- .../class/companybankaccount.class.php | 4 +- .../class/companypaymentmode.class.php | 76 +++- htdocs/societe/paymentmodes.php | 376 +++++++++++------- 5 files changed, 317 insertions(+), 156 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4600cefbdc3..43275b22afc 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6481,19 +6481,21 @@ abstract class CommonObject /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @param string $morewhere More SQL filters (' AND ...') + * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetchCommon($id, $ref = null) + public function fetchCommon($id, $ref = null, $morewhere = '') { if (empty($id) && empty($ref)) return false; $sql = 'SELECT '.$this->get_field_list(); $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - if(!empty($id)) $sql.= ' WHERE rowid = '.$id; + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); + if ($morewhere) $sql.=$morewhere; $res = $this->db->query($sql); if ($res) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 063ea39127b..6473869be21 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -932,4 +932,7 @@ PayedBy=Payed by PayedTo=Payed to Monthly=Monthly Quarterly=Quarterly -Annual=Annual \ No newline at end of file +Annual=Annual +Local=Local +Remote=Remote +LocalAndRemote=Local and remote \ No newline at end of file diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 97c8871202e..187f7c5ec65 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -197,7 +197,7 @@ class CompanyBankAccount extends Account * Load record from database * * @param int $id Id of record - * @param int $socid Id of company. If this is filled, function will return the default RIB of company + * @param int $socid Id of company. If this is filled, function will return the first default RIB of company * @return int <0 if KO, >0 if OK */ function fetch($id, $socid=0) @@ -208,7 +208,7 @@ class CompanyBankAccount extends Account $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($id) $sql.= " WHERE rowid = ".$id; - if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1"; + if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1 AND type ='ban'"; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 6a2095883c1..662361a619d 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -258,13 +258,18 @@ class CompanyPaymentMode extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @param int $socid Id of company to get first default payment mode + * @param string $type Filter on type ('ban', 'card', ...) + * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null) + public function fetch($id, $ref = null, $socid = 0, $type = '') { - $result = $this->fetchCommon($id, $ref); + if ($socid) $sql.= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1"; + if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; + + $result = $this->fetchCommon($id, $ref, $morewhere); if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); return $result; } @@ -368,6 +373,67 @@ class CompanyPaymentMode extends CommonObject return $result; } + /** + * Set a Payment mode as Default + * + * @param int $id Payment mode ID + * @param string $alltypes 1=The default is for all payment types instead of per type + * @return int 0 if KO, 1 if OK + */ + function setAsDefault($id=0, $alltypes=0) + { + $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib"; + $sql1.= " WHERE rowid = ".($id?$id:$this->id); + + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result1 = $this->db->query($sql1); + if ($result1) + { + if ($this->db->num_rows($result1) == 0) + { + return 0; + } + else + { + $obj = $this->db->fetch_object($result1); + + $type = ''; + if (empty($alltypes)) $type = $obj->type; + + $this->db->begin(); + + $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0"; + $sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc; + if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'"; + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result2 = $this->db->query($sql2); + + $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1"; + $sql3.= " WHERE rowid = ".$obj->id; + if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'"; + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result3 = $this->db->query($sql3); + + if (!$result2 || !$result3) + { + dol_print_error($this->db); + $this->db->rollback(); + return -1; + } + else + { + $this->db->commit(); + return 1; + } + } + } + else + { + dol_print_error($this->db); + return -1; + } + } + /** * Retourne le libelle du status d'un user (actif, inactif) * diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index d24f4dd5f32..9365511b78d 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -55,7 +55,8 @@ $cancel=GETPOST('cancel', 'alpha'); $object = new Societe($db); $object->fetch($socid); -$account = new CompanyBankAccount($db); +$companybankaccount = new CompanyBankAccount($db); +$companypaymentmode = new CompanyPaymentMode($db); $prelevement = new BonPrelevement($db); $extrafields = new ExtraFields($db); @@ -115,19 +116,14 @@ if (empty($reshook)) if ($action == 'update') { // Modification - if (! GETPOST('label')) + if (! GETPOST('label','alpha') || ! GETPOST('bank','alpha')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('bank','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); $action='edit'; $error++; } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='edit'; - $error++; - } - if ($account->needIBAN() == 1) + if ($companybankaccount->needIBAN() == 1) { if (! GETPOST('iban')) { @@ -143,43 +139,94 @@ if (empty($reshook)) } } - $account->fetch($id); + $companybankaccount->fetch($id); if (! $error) { - $account->socid = $object->id; + $companybankaccount->socid = $object->id; - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur','alpha'); - $account->rum = GETPOST('rum','alpha'); - if (empty($account->rum)) + $companybankaccount->bank = GETPOST('bank','alpha'); + $companybankaccount->label = GETPOST('label','alpha'); + $companybankaccount->courant = GETPOST('courant','alpha'); + $companybankaccount->clos = GETPOST('clos','alpha'); + $companybankaccount->code_banque = GETPOST('code_banque','alpha'); + $companybankaccount->code_guichet = GETPOST('code_guichet','alpha'); + $companybankaccount->number = GETPOST('number','alpha'); + $companybankaccount->cle_rib = GETPOST('cle_rib','alpha'); + $companybankaccount->bic = GETPOST('bic','alpha'); + $companybankaccount->iban = GETPOST('iban','alpha'); + $companybankaccount->domiciliation = GETPOST('domiciliation','alpha'); + $companybankaccount->proprio = GETPOST('proprio','alpha'); + $companybankaccount->owner_address = GETPOST('owner_address','alpha'); + $companybankaccount->frstrecur = GETPOST('frstrecur','alpha'); + $companybankaccount->rum = GETPOST('rum','alpha'); + if (empty($companybankaccount->rum)) { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); + $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); + $companybankaccount->date_rum = dol_now(); } - $result = $account->update($user); + $result = $companybankaccount->update($user); if (! $result) { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } else { // If this account is the default bank account, we disable others - if ($account->default_rib) + if ($companybankaccount->default_rib) { - $account->setAsDefault($id); // This will make sure there is only one default rib + $companybankaccount->setAsDefault($id); // This will make sure there is only one default rib + } + + $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; + header('Location: '.$url); + exit; + } + } + } + + if ($action == 'updatecard') + { + // Modification + if (! GETPOST('label','alpha') || ! GETPOST('proprio','alpha') || ! GETPOST('cardnumber','alpha') || ! GETPOST('exp_date_month','alpha') || ! GETPOST('exp_date_year','alpha') || ! GETPOST('cvn','alpha')) + { + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('proprio','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); + if (! GETPOST('cardnumber','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); + if (! (GETPOST('exp_date_month','alpha') > 0) || ! (GETPOST('exp_date_year','alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); + if (! GETPOST('cvn','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); + $action='createcard'; + $error++; + } + + $companypaymentmode->fetch($id); + if (! $error) + { + $companypaymentmode->fk_soc = $object->id; + + $companypaymentmode->bank = GETPOST('bank','alpha'); + $companypaymentmode->label = GETPOST('label','alpha'); + $companypaymentmode->number = GETPOST('cardnumber','alpha'); + $companypaymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); + $companypaymentmode->proprio = GETPOST('proprio','alpha'); + $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); + $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); + $companypaymentmode->cvn = GETPOST('cvn','alpha'); + $companypaymentmode->country_code = $mysoc->country_code; + + $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha'); + + $result = $companypaymentmode->update($user); + if (! $result) + { + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); + } + else + { + // If this account is the default bank account, we disable others + if ($companypaymentmode->default_rib) + { + $companypaymentmode->setAsDefault($id); // This will make sure there is only one default rib } $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; @@ -204,31 +251,32 @@ if (empty($reshook)) if (! $error) { // Ajout - $account = new CompanyBankAccount($db); + $companybankaccount = new CompanyBankAccount($db); - $account->socid = $object->id; + $companybankaccount->socid = $object->id; - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur'); - $account->rum = GETPOST('rum','alpha'); - $account->datec = dol_now(); + $companybankaccount->bank = GETPOST('bank','alpha'); + $companybankaccount->label = GETPOST('label','alpha'); + $companybankaccount->courant = GETPOST('courant','alpha'); + $companybankaccount->clos = GETPOST('clos','alpha'); + $companybankaccount->code_banque = GETPOST('code_banque','alpha'); + $companybankaccount->code_guichet = GETPOST('code_guichet','alpha'); + $companybankaccount->number = GETPOST('number','alpha'); + $companybankaccount->cle_rib = GETPOST('cle_rib','alpha'); + $companybankaccount->bic = GETPOST('bic','alpha'); + $companybankaccount->iban = GETPOST('iban','alpha'); + $companybankaccount->domiciliation = GETPOST('domiciliation','alpha'); + $companybankaccount->proprio = GETPOST('proprio','alpha'); + $companybankaccount->owner_address = GETPOST('owner_address','alpha'); + $companybankaccount->frstrecur = GETPOST('frstrecur'); + $companybankaccount->rum = GETPOST('rum','alpha'); + $companybankaccount->datec = dol_now(); + $companybankaccount->status = 1; $db->begin(); // This test can be done only once properties were set - if ($account->needIBAN() == 1) + if ($companybankaccount->needIBAN() == 1) { if (! GETPOST('iban')) { @@ -246,28 +294,28 @@ if (empty($reshook)) if (! $error) { - $result = $account->create($user); + $result = $companybankaccount->create($user); if ($result < 0) { $error++; - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); $action='create'; // Force chargement page création } - if (empty($account->rum)) + if (empty($companybankaccount->rum)) { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); + $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); + $companybankaccount->date_rum = dol_now(); } } if (! $error) { - $result = $account->update($user); // This will set the UMR number. + $result = $companybankaccount->update($user); // This will set the UMR number. if ($result < 0) { $error++; - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); $action='create'; } } @@ -305,31 +353,34 @@ if (empty($reshook)) if (! $error) { // Ajout - $paymentmode = new CompanyPaymentMode($db); + $companypaymentmode = new CompanyPaymentMode($db); - $paymentmode->fk_soc = $object->id; - $paymentmode->bank = GETPOST('bank','alpha'); - $paymentmode->label = GETPOST('label','alpha'); - $paymentmode->number = GETPOST('cardnumber','alpha'); - $paymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); - $paymentmode->proprio = GETPOST('proprio','alpha'); - $paymentmode->exp_date_month = GETPOST('exp_date_month','int'); - $paymentmode->exp_date_year = GETPOST('exp_date_year','int'); - $paymentmode->cvn = GETPOST('cvn','alpha'); - $paymentmode->datec = dol_now(); - $paymentmode->default_rib = 0; - $paymentmode->type = 'card'; - $paymentmode->country_code = $mysoc->country_code; + $companypaymentmode->fk_soc = $object->id; + $companypaymentmode->bank = GETPOST('bank','alpha'); + $companypaymentmode->label = GETPOST('label','alpha'); + $companypaymentmode->number = GETPOST('cardnumber','alpha'); + $companypaymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); + $companypaymentmode->proprio = GETPOST('proprio','alpha'); + $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); + $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); + $companypaymentmode->cvn = GETPOST('cvn','alpha'); + $companypaymentmode->datec = dol_now(); + $companypaymentmode->default_rib = 0; + $companypaymentmode->type = 'card'; + $companypaymentmode->country_code = $mysoc->country_code; + $companypaymentmode->status = 1; + + $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha'); $db->begin(); if (! $error) { - $result = $paymentmode->create($user); + $result = $companypaymentmode->create($user); if ($result < 0) { $error++; - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); $action='createcard'; // Force chargement page création } } @@ -349,10 +400,10 @@ if (empty($reshook)) } } - if ($action == 'setasbankdefault') + if ($action == 'setasbankdefault' && GETPOST('ribid','int') > 0) { - $account = new CompanyBankAccount($db); - $res = $account->setAsDefault(GETPOST('ribid','int')); + $companybankaccount = new CompanyBankAccount($db); + $res = $companybankaccount->setAsDefault(GETPOST('ribid','int')); if ($res) { $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; @@ -367,10 +418,10 @@ if (empty($reshook)) if ($action == 'confirm_deletecard' && GETPOST('confirm','alpha') == 'yes') { - $paymentmode = new CompanyPaymentMode($db); - if ($paymentmode->fetch($ribid?$ribid:$id)) + $companypaymentmode = new CompanyPaymentMode($db); + if ($companypaymentmode->fetch($ribid?$ribid:$id)) { - $result = $paymentmode->delete($user); + $result = $companypaymentmode->delete($user); if ($result > 0) { $url = $_SERVER['PHP_SELF']."?socid=".$object->id; @@ -379,20 +430,20 @@ if (empty($reshook)) } else { - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); } } else { - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); } } if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes') { - $account = new CompanyBankAccount($db); - if ($account->fetch($ribid?$ribid:$id)) + $companybankaccount = new CompanyBankAccount($db); + if ($companybankaccount->fetch($ribid?$ribid:$id)) { - $result = $account->delete($user); + $result = $companybankaccount->delete($user); if ($result > 0) { $url = $_SERVER['PHP_SELF']."?socid=".$object->id; @@ -401,12 +452,12 @@ if (empty($reshook)) } else { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } } else { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } } @@ -476,11 +527,7 @@ if (empty($reshook)) if ($action == 'setlocalassourcedefault') { try { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 0 WHERE type = 'card' AND default_rib <> 0"; - $db->query($sql); - - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 1 WHERE type = 'card' AND rowid = ".GETPOST('id','int'); - $db->query($sql); + $companypaymentmode->setAsDefault($id); $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; header('Location: '.$url); @@ -540,21 +587,26 @@ llxHeader(); $head=societe_prepare_head($object); +// Load Bank account if (! $id) { - $account->fetch(0,$object->id); + $companybankaccount->fetch(0, $object->id); + $companypaymentmode->fetch(0, null, $object->id, 'card'); } else { - $account->fetch($id); + $companybankaccount->fetch($id); + $companypaymentmode->fetch($id); } -if (empty($account->socid)) $account->socid=$object->id; +if (empty($companybankaccount->socid)) $companybankaccount->socid=$object->id; if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer) { print '
    '; print ''; - print ''; + $actionforadd='update'; + if ($action == 'editcard') $actionforadd='updatecard'; + print ''; print ''; } if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) @@ -575,12 +627,12 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' // Confirm delete ban if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $companybankaccount->getRibLabel()), "confirm_delete", '', 0, 1); } // Confirm delete card if ($action == 'deletecard') { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $account->getRibLabel()), "confirm_deletecard", '', 0, 1); + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $companybankaccount->getRibLabel()), "confirm_deletecard", '', 0, 1); } $linkback = ''.$langs->trans("BackToList").''; @@ -638,7 +690,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print '
    '; - // Stripe payment modes + // List of Stripe payment modes if (! (empty($conf->stripe->enabled))) { $morehtmlright=''; @@ -708,14 +760,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $companypaymentmodetemp->fetch($obj->rowid); - $arrayofstripecard[$obj->stripe_card_ref]=$obj->stripe_card_ref; + $arrayofstripecard[$companypaymentmodetemp->stripe_card_ref]=$companypaymentmodetemp->stripe_card_ref; print ''; print ''; - print $obj->rowid; + print $companypaymentmodetemp->id; print ''; print ''; - print $obj->stripe_card_ref; + print $companypaymentmodetemp->stripe_card_ref; print ''; print ''; print img_credit_card($companypaymentmodetemp->type); @@ -1078,20 +1130,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } dol_fiche_end(); -/* - if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard') - { - // Barre d'actions - print '
    '; - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Add").''; - } - print '
    '; - } -*/ if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) { print '
    '; @@ -1152,41 +1192,41 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { + foreach ($companybankaccount->getFieldsToShow(1) as $val) { $require=false; if ($val == 'BankCode') { $name = 'code_banque'; $size = 8; - $content = $account->code_banque; + $content = $companybankaccount->code_banque; } elseif ($val == 'DeskCode') { $name = 'code_guichet'; $size = 8; - $content = $account->code_guichet; + $content = $companybankaccount->code_guichet; } elseif ($val == 'BankAccountNumber') { $name = 'number'; $size = 18; - $content = $account->number; + $content = $companybankaccount->number; } elseif ($val == 'BankAccountNumberKey') { $name = 'cle_rib'; $size = 3; - $content = $account->cle_rib; + $content = $companybankaccount->cle_rib; } elseif ($val == 'IBAN') { $name = 'iban'; $size = 30; - $content = $account->iban; - if ($account->needIBAN()) $require=true; + $content = $companybankaccount->iban; + if ($companybankaccount->needIBAN()) $require=true; } elseif ($val == 'BIC') { $name = 'bic'; $size = 12; - $content = $account->bic; - if ($account->needIBAN()) $require=true; + $content = $companybankaccount->bic; + if ($companybankaccount->needIBAN()) $require=true; } print ''.$langs->trans($val).''; @@ -1196,16 +1236,16 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print '"; print ''; - print ''; + print ''; print "\n"; print '"; print '
    '.$langs->trans("LabelRIB").'
    '.$langs->trans("BankName").'
    '.$langs->trans("BankAccountDomiciliation").''; print '
    '.$langs->trans("BankAccountOwner").'
    '.$langs->trans("BankAccountOwnerAddress").''; print '
    '; @@ -1216,15 +1256,15 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; - if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); + if (empty($companybankaccount->rum)) $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); // RUM print ''; - print ''; + print ''; print ''; print '
    '.$langs->trans("RUM").'
    '.$langs->trans("WithdrawMode").''; $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur','alpha')?GETPOST('frstrecur','alpha'):$account->frstrecur), 0); + print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur','alpha')?GETPOST('frstrecur','alpha'):$companybankaccount->frstrecur), 0); print '
    '; @@ -1241,6 +1281,53 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print '
    '; } +// Edit Card +if ($socid && $action == 'editcard' && $user->rights->societe->creer) +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
    '; + + print '
    '; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print '"; + print ''; + + print '
    '.$langs->trans("Label").'
    '.$langs->trans("NameOnCard").'
    '.$langs->trans("CardNumber").'
    '.$langs->trans("ExpiryDate").''; + print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1); + print $formother->select_year($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); + print '
    '.$langs->trans("CVN").'
    '.$langs->trans("StripeID")." ('card_....')
    '; + print '
    '; + + dol_fiche_end(); + + print '
    '; + print ''; + print '     '; + print ''; + print '
    '; +} + // Create BAN if ($socid && $action == 'create' && $user->rights->societe->creer) @@ -1257,13 +1344,13 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { + foreach ($companybankaccount->getFieldsToShow(1) as $val) { $require=false; if ($val == 'BankCode') { @@ -1281,11 +1368,11 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) } elseif ($val == 'IBAN') { $name = 'iban'; $size = 30; - if ($account->needIBAN()) $require=true; + if ($companybankaccount->needIBAN()) $require=true; } elseif ($val == 'BIC') { $name = 'bic'; $size = 12; - if ($account->needIBAN()) $require=true; + if ($companybankaccount->needIBAN()) $require=true; } print ''.$langs->trans($val).''; @@ -1299,7 +1386,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ""; print ''; - print ''; + print ''; print "\n"; print ''; @@ -682,6 +707,17 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; } @@ -698,20 +734,20 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $morehtmlright=''.$langs->trans("Add").''; } - print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':''), $morehtmlright, ''); + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':' (API mode)'), $morehtmlright, ''); $listofsources = array(); - if (is_object($stripe) && $stripeacc) + if (is_object($stripe)) { try { - $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus); + $customerstripe=$stripe->customerStripe($object, $stripeacc, $servicestatus); if ($customerstripe->id) { $listofsources=$customerstripe->sources->data; } } catch(Exception $e) { - dol_syslog("Failed to get strip customer for thirdparty id =".$object->id); + dol_syslog("Error when searching/loading Stripe customer for thirdparty id =".$object->id); } } @@ -816,10 +852,6 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' $i++; } } - else - { - print $langs->trans("NoPaymentMethodOnFile"); - } } else dol_print_error($db); } diff --git a/htdocs/stripe/class/actions_stripe.class.php b/htdocs/stripe/class/actions_stripe.class.php index baeba001edf..0451c1d4782 100644 --- a/htdocs/stripe/class/actions_stripe.class.php +++ b/htdocs/stripe/class/actions_stripe.class.php @@ -99,7 +99,7 @@ class ActionsStripeconnect $this->resprints.= ''; $this->resprints.= ''; $addcolumforpicto=($delallowed || $printer || $morepicto); - $out.= ''; } else $out = $hookmanager->resPrint; // Replace line @@ -811,7 +811,7 @@ class FormFile if (count($file_list) == 0 && count($link_list) == 0 && $headershown) { - $out.=''."\n"; + $out.=''."\n"; } } @@ -861,7 +861,7 @@ class FormFile preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir).'$/', $filedir, $regs); $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : $conf->entity); } - + $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+'; $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 28eaa1abacc..433d81e523b 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -734,7 +734,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $morehtmlright=''.$langs->trans("Add").''; } - print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':' (API mode)'), $morehtmlright, ''); + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' (Stripe connection with Stripe Connect account '.$stripeacc.')':' (Stripe connection with default API credentials)'), $morehtmlright, ''); $listofsources = array(); if (is_object($stripe)) @@ -1152,7 +1152,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $colspan=8; if (! empty($conf->prelevement->enabled)) $colspan+=2; - print ''; + print ''; } print '
    '.$langs->trans("LabelRIB").'
    '.$langs->trans("Bank").'
    '.$langs->trans("BankAccountOwner").'
    '.$langs->trans("BankAccountOwnerAddress").''; @@ -1355,13 +1442,13 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; + print '"; + print ''; + print '
    '.$langs->trans("Label").'
    '.$langs->trans("NameOnCard").'
    '.$langs->trans("CardNumber").'
    '.$langs->trans("ExpiryDate").''; @@ -1372,6 +1459,9 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print '
    '.$langs->trans("CVN").'
    '.$langs->trans("StripeID")." ('card_....')
    '; print ''; @@ -1387,7 +1477,7 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print ''; } -if ($socid && $action == 'edit' && $user->rights->societe->creer) +if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer) { print ''; } From b2326813180c9855eba9410e41d7e04e0207e97d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 16:53:16 +0100 Subject: [PATCH 111/126] NEW Add a button to create Stripe customer from the Payment mode tab --- .../interface_80_modStripe_Stripe.class.php | 4 +- htdocs/langs/en_US/stripe.lang | 1 + htdocs/societe/class/societeaccount.class.php | 4 +- htdocs/societe/paymentmodes.php | 54 ++++++++--- htdocs/stripe/class/actions_stripe.class.php | 13 ++- htdocs/stripe/class/stripe.class.php | 93 +++++++++++-------- htdocs/stripe/config.php | 22 ++--- 7 files changed, 119 insertions(+), 72 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index a41ade1e01b..495f439eb09 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -135,7 +135,7 @@ class InterfaceStripe if ($action == 'COMPANY_MODIFY') { dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); if ($stripe->getStripeAccount($service) && $object->client != 0) { - $cu = $stripe->customerStripe($object->id, $stripe->getStripeAccount($service)); + $cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service)); if ($cu) { if ($conf->entity == '1') { $customer = \Stripe\Customer::retrieve("$cu->id"); @@ -153,7 +153,7 @@ class InterfaceStripe } } elseif ($action == 'COMPANY_DELETE') { dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); - $cu = $stripe->customerStripe($object->id, $stripe->getStripeAccount($service)); + $cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service)); if ($cu) { if ($conf->entity == 1) { $customer = \Stripe\Customer::retrieve("$cu->id"); diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 3db64381797..f096248bc39 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -59,3 +59,4 @@ ExpiryDate=Expiry Date CVN=CVN DeleteACard=Delete Card record ConfirmDeleteCard=Are you sure you want to delete this Card record? +CreateCustomerOnStripe=Create customer on Stripe diff --git a/htdocs/societe/class/societeaccount.class.php b/htdocs/societe/class/societeaccount.class.php index 08b3617e540..111da0c46ea 100644 --- a/htdocs/societe/class/societeaccount.class.php +++ b/htdocs/societe/class/societeaccount.class.php @@ -263,8 +263,10 @@ class SocieteAccount extends CommonObject $sql.= " WHERE sa.fk_soc = " . $id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status); + $sql.= " AND key_account IS NOT NULL AND key_account <> ''"; + //$sql.= " ORDER BY sa.key_account DESC"; - dol_syslog(get_class($this) . "::getCustomerAccount Try to find the system customer id of thirdparty id=".$id." (exemple: cu_.... for stripe)", LOG_DEBUG); + dol_syslog(get_class($this) . "::getCustomerAccount Try to find the system customer id of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 9365511b78d..28eaa1abacc 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -41,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $langs->loadLangs(array("companies","commercial","banks","bills")); + // Security check $socid = GETPOST("socid","int"); if ($user->societe_id) $socid=$user->societe_id; @@ -82,8 +83,8 @@ if (! empty($conf->stripe->enabled)) } $stripe = new Stripe($db); - $stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here) - $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get thirdparty cu_... + $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no network access here) + $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get remote Stripe customer 'cus_...' (no network access here) } @@ -474,6 +475,7 @@ if (empty($reshook)) $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid')); $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid')); } + $id = $socid; $upload_dir = $conf->societe->multidir_output[$object->entity]; $permissioncreate=$user->rights->societe->creer; @@ -484,6 +486,29 @@ if (empty($reshook)) // Action for stripe if (! empty($conf->stripe->enabled) && class_exists('Stripe')) { + if ($action == 'synccustomertostripe') + { + if ($object->client == 0) + { + $error++; + setEventMessages('ThisThirdpartyIsNotACustomer', null, 'errors'); + } + else + { + // Creation of Stripe customer + update of societe_account + $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus, 1); + if (! $cu) + { + $error++; + setEventMessages($stripe->error, $stripe->errors, 'errors'); + } + else + { + $stripecu = $cu->id; + } + } + } + if ($action == 'setkey_account') { $error = 0; @@ -655,7 +680,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' if ($object->client) { print '
    '; - print $langs->trans('CustomerCode').''; + print $langs->trans('CustomerCode').''; print $object->code_client; if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; print '
    '; //print $stripecu; print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 1, '', 'socid'); + print ''; + if (empty($stripecu)) + { + print '
    '; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
    '; + } print '
    '; $stripe=new Stripe($db); if ($stripe->getStripeAccount($service)&&$object->client!=0) { - $customer=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service)); + $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service)); $this->resprints.= $customer->id; } else { @@ -117,8 +117,9 @@ class ActionsStripeconnect $this->resprints.= ''; $stripe=new Stripe($db); - if ($stripe->getStripeAccount($service)&&$object->fk_soc>'0') { - $customer=$stripe->customerStripe($object->fk_soc,$stripe->getStripeAccount($service)); + if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) { + $object->fetch_thirdparty(); + $customer=$stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service)); $this->resprints.= $customer->id; } else { @@ -135,7 +136,8 @@ class ActionsStripeconnect $this->resprints.= ''; $stripe=new Stripe($db); if (7==4) { - $customer=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service)); + $object->fetch_thirdparty(); + $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service)); $this->resprints.= $customer->id; } else { @@ -154,7 +156,8 @@ class ActionsStripeconnect $this->resprints.= ''; $stripe=new Stripe($db); if (7==4) { - $customer=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service)); + $object->fetch_thirdparty(); + $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service)); $this->resprints.= $customer->id; } else { diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 5f86c45f696..cf02ec6b65b 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -20,7 +20,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; // This set stripe global env /** @@ -86,6 +86,7 @@ class Stripe extends CommonObject dol_print_error($this->db); } + dol_syslog("No dedicated Stipe Connect account available for entity".$conf->entity); return $key; } @@ -102,30 +103,33 @@ class Stripe extends CommonObject include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; $societeaccount = new SocieteAccount($this->db); - return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cu_... + return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cus_... } /** * Get the Stripe customer of a thirdparty (with option to create it if not linked yet) * - * @param int $id Id of third party - * @param string $key Stripe account acc_.... + * @param Societe $object Object thirdparty to check, or create on stripe (create on strip also update the stripe_account table for current entity) + * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect * @param int $status Status (0=test, 1=live) * @param int $createifnotlinkedtostripe 1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer - * @return \Stripe\StripeObject|\Stripe\ApiResource|null Stripe Customer or null if not found + * @return \Stripe\StripeCustomer|null Stripe Customer or null if not found */ - public function customerStripe($id, $key, $status=0, $createifnotlinkedtostripe=0) + public function customerStripe($object, $key='', $status=0, $createifnotlinkedtostripe=0) { - global $conf; + global $conf, $user; - $sql = "SELECT sa.key_account as key_account, sa.entity"; // key_account is cu_.... + $customer = null; + + $sql = "SELECT sa.key_account as key_account, sa.entity"; // key_account is cus_.... $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; - $sql.= " WHERE sa.fk_soc = " . $id; + $sql.= " WHERE sa.fk_soc = " . $object->id; $sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); + $sql.= " AND key_account IS NOT NULL AND key_account <> ''"; - dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + dol_syslog(get_class($this) . "::fetch search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -133,41 +137,52 @@ class Stripe extends CommonObject { $obj = $this->db->fetch_object($resql); $tiers = $obj->key_account; - if ($conf->entity == 1) { - $customer = \Stripe\Customer::retrieve("$tiers"); - } else { - $customer = \Stripe\Customer::retrieve("$tiers", array( - "stripe_account" => $key - )); + try { + if (empty($key)) { // If the Stripe connect account not set, we use common API usage + $customer = \Stripe\Customer::retrieve("$tiers"); + } else { + $customer = \Stripe\Customer::retrieve("$tiers", array("stripe_account" => $key)); + } + } + catch(Exception $e) + { + } } elseif ($createifnotlinkedtostripe) { - $soc = new Societe($this->db); - $soc->fetch($id); + $dataforcustomer = array( + "email" => $object->email, + "business_vat_id" => $object->tva_intra, + "description" => $object->name, + "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity) + ); - if ($conf->entity == 1) { - $customer = \Stripe\Customer::create(array( - "email" => $soc->email, - "business_vat_id" => $soc->tva_intra, - "description" => $soc->name - )); - } else { - $customer = \Stripe\Customer::create(array( - "email" => $soc->email, - "business_vat_id" => $soc->tva_intra, - "description" => $soc->name - ), array( - "stripe_account" => $key - )); + //$a = \Stripe\Stripe::getApiKey(); + //var_dump($a);var_dump($key);exit; + try { + if (empty($key)) { // If the Stripe connect account not set, we use common API usage + $customer = \Stripe\Customer::create($dataforcustomer); + } else { + $customer = \Stripe\Customer::create($dataforcustomer, array("stripe_account" => $key)); + } + $customer_id = $customer->id; + + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)"; + $sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer_id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")"; + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error = $this->db->lasterror(); + } + } + catch(Exception $e) + { + //print $e->getMessage(); } - $customer_id = $customer->id; - - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, key_account, site, status, entity)"; - $sql .= " VALUES (".$id.", '".$this->db->escape($customer_id)."', 'stripe', " . $status . "," . $conf->entity . ")"; - $resql = $this->db->query($sql); } } + return $customer; } @@ -178,8 +193,8 @@ class Stripe extends CommonObject * @param string $currency EUR, GPB... * @param string $origin order, invoice, contract... * @param int $item if of element to pay - * @param string $source src_xxxxx or card_xxxxx or ac_xxxxx - * @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe() + * @param string $source src_xxxxx or card_xxxxx + * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() * @param int $status Status (0=test, 1=live) * @return Stripe diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index 31959b3516f..db982e878f9 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -15,44 +15,38 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Set Stripe environment: set the ApiKey and AppInfo */ /** -* \file htdocs/public/stripe/config.php +* \file htdocs/stripe/config.php * \ingroup Stripe * \brief Page to move config in api */ -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php'; require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php'; +require_once DOL_DOCUMENT_ROOT.'/includes/stripe/lib/Stripe.php'; global $stripe; global $conf; -//use \includes\stripe as stripe; -$stripe = array(); +$stripearrayofkeys = array(); if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')) { - $stripe = array( + $stripearrayofkeys = array( "secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY, "publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY ); } else { - $stripe = array( + $stripearrayofkeys = array( "secret_key" => $conf->global->STRIPE_LIVE_SECRET_KEY, "publishable_key" => $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY ); } -require_once DOL_DOCUMENT_ROOT."/includes/stripe/lib/Stripe.php"; -require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - -\Stripe\Stripe::setApiKey($stripe['secret_key']); - -require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - +\Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setAppInfo("Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version From 9994b1f1330cc9c461c6ce826b08fbf222acb43b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 17:12:32 +0100 Subject: [PATCH 112/126] Work on stripe interface --- htdocs/core/class/html.formfile.class.php | 8 ++++---- htdocs/societe/paymentmodes.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 077a29d4595..4a07f096a5d 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -616,7 +616,7 @@ class FormFile $out.= '
    '; + $out.= ''; // Model if (! empty($modellist)) @@ -778,7 +778,7 @@ class FormFile $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file); if (empty($res)) { - $out .= $hookmanager->resPrint; // Complete line + $out.= $hookmanager->resPrint; // Complete line $out.= '
    '.$langs->trans("None").'
    '.$langs->trans("None").'
    '.$langs->trans("NoBANRecord").'
    '.$langs->trans("NoBANRecord").'
    '; From 8c535db04c2b019c22d86ab721925f95974d63b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 17:15:31 +0100 Subject: [PATCH 113/126] Use .... before end of card number --- htdocs/societe/paymentmodes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 433d81e523b..7ae6c4eadfd 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -809,7 +809,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print img_credit_card($companypaymentmodetemp->type); print ''; print ''; - if ($companypaymentmodetemp->last_four) print '**** '.$companypaymentmodetemp->last_four; + if ($companypaymentmodetemp->last_four) print '....'.$companypaymentmodetemp->last_four; if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.$companypaymentmodetemp->exp_date_month.'/'.$companypaymentmodetemp->exp_date_year.''; print ''; if ($companypaymentmodetemp->country_code) @@ -892,7 +892,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print''; if ($src->object=='card') { - print '**** '.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; + print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; print ''; if ($src->country) { @@ -904,7 +904,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } elseif ($src->object=='source' && $src->type=='card') { - print $src->owner->name.'
    **** '.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; + print $src->owner->name.'
    ....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; print ''; if ($src->card->country) From 302fed86464db7e6e23d455585efd90c0b407c58 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 20:08:44 +0100 Subject: [PATCH 114/126] More fa image to replace png picto --- htdocs/accountancy/bookkeeping/list.php | 2 +- htdocs/core/class/html.formfile.class.php | 4 ++-- htdocs/core/lib/functions.lib.php | 25 ++++++++++++++------- htdocs/product/class/product.class.php | 10 ++++----- htdocs/societe/paymentmodes.php | 20 ++++++++--------- htdocs/theme/eldy/style.css.php | 9 +++++--- htdocs/theme/md/img/menus/ticketsup.png | Bin 0 -> 916 bytes htdocs/theme/md/style.css.php | 16 ++++++++++--- htdocs/ticketsup/class/ticketsup.class.php | 4 ++-- 9 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 htdocs/theme/md/img/menus/ticketsup.png diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index ad8be2608c1..749033f8392 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -694,7 +694,7 @@ if ($num > 0) } // Action column - print ''; + print ''; print '' . img_edit() . ' '; print '' . img_delete() . ''; print ''; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 4a07f096a5d..5eef895bb0c 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -755,7 +755,7 @@ class FormFile $out.= ($param?'&'.$param:''); //$out.= '&modulepart='.$modulepart; // TODO obsolete ? //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? - $out.= '">'.img_picto($langs->trans("Delete"), 'delete.png').''; + $out.= '">'.img_picto($langs->trans("Delete"), 'delete').''; } if ($printer) { @@ -1233,7 +1233,7 @@ class FormFile if ($permtoeditline) { // Link to resize - print ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','class="paddingrightonly"',1).''; + print ''.img_picto($langs->trans("Resize"),'resize','class="paddingrightonly"').''; } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 65753457000..bed4bcc8d6a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3052,18 +3052,26 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ } else { + $pictowithoutext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto); + //if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on'))) - if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on'))) + if (in_array($pictowithoutext, array('delete', 'edit', 'off', 'on', 'resize', 'switch_off', 'switch_on'))) { - $fakey = $picto; $facolor=''; $fasize=''; - if ($picto == 'switch_off') { $fakey = 'fa-toggle-off'; $facolor='#999'; $fasize='2em'; } - if ($picto == 'switch_on') { $fakey = 'fa-toggle-on'; $facolor='#227722'; $fasize='2em'; } - if ($picto == 'off') { $fakey = 'fa-square-o'; $fasize='1.3em'; } - if ($picto == 'on') { $fakey = 'fa-check-square-o'; $fasize='1.3em'; } - $enabledisablehtml=''; - $enabledisablehtml.=''; + $fakey = $pictowithoutext; $facolor=''; $fasize=''; + if ($pictowithoutext == 'switch_off') { $fakey = 'fa-toggle-off'; $facolor='#999'; $fasize='2em'; } + elseif ($pictowithoutext == 'switch_on') { $fakey = 'fa-toggle-on'; $facolor='#227722'; $fasize='2em'; } + elseif ($pictowithoutext == 'off') { $fakey = 'fa-square-o'; $fasize='1.3em'; } + elseif ($pictowithoutext == 'on') { $fakey = 'fa-check-square-o'; $fasize='1.3em'; } + elseif ($pictowithoutext == 'delete') { $fakey = 'fa-trash'; $facolor='#444'; } + elseif ($pictowithoutext == 'edit') { $fakey = 'fa-pencil'; $facolor='#444'; } + elseif ($pictowithoutext == 'resize') { $fakey = 'fa-crop'; $facolor='#444'; } + else { $fakey = 'fa-'.$pictowithoutext; $facolor='#999'; } + + if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) { $morecss.=($morecss?' ':'').$reg[1]; } + $enabledisablehtml =''; if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $enabledisablehtml.=$titlealt; $enabledisablehtml.=''; + return $enabledisablehtml; } @@ -3306,6 +3314,7 @@ function img_delete($titlealt = 'default', $other = 'class="pictodelete"') if ($titlealt == 'default') $titlealt = $langs->trans('Delete'); return img_picto($titlealt, 'delete.png', $other); + //return ''; } /** diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 8b6cc95368e..633d85e854b 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1716,7 +1716,7 @@ class Product extends CommonObject $price_ttc = price2num($price_ttc,'MU'); if ( $newminprice !== '' || $newminprice === 0) - { + { $price_min = price2num($newminprice,'MU'); $price_min_ttc = price2num($newminprice) * (1 + ($newvat / 100)); $price_min_ttc = price2num($price_min_ttc,'MU'); @@ -2279,8 +2279,8 @@ class Product extends CommonObject } } } - - // If stock decrease is on invoice validation, the theorical stock continue to + + // If stock decrease is on invoice validation, the theorical stock continue to // count the orders to ship in theorical stock when some are already removed b invoice validation. // If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation. if (! empty($conf->global->STOCK_CALCULATE_ON_BILL)) @@ -4285,7 +4285,7 @@ class Product extends CommonObject if ($user->rights->produit->creer || $user->rights->service->creer) { // Link to resize - $return.= ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'   '; + $return.= ''.img_picto($langs->trans("Resize"), 'resize', '').'   '; // Link to delete $return.= ''; @@ -4311,7 +4311,7 @@ class Product extends CommonObject if ($user->rights->produit->creer || $user->rights->service->creer) { // Link to resize - $return.= ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'   '; + $return.= ''.img_picto($langs->trans("Resize"), 'resize', '').'   '; // Link to delete $return.= ''; diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 7ae6c4eadfd..73a6b62c181 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -1,12 +1,12 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2018 ptibogxiv + * Copyright (C) 2018 ptibogxiv * * 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 @@ -703,10 +703,10 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' // Stripe customer key 'cu_....' stored into llx_societe_account print ''; //print $langs->trans('StripeCustomerId'); - print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 1, 'socid'); + print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); print ''; //print $stripecu; - print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 1, '', 'socid'); + print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); print ''; if (empty($stripecu)) { @@ -734,7 +734,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $morehtmlright=''.$langs->trans("Add").''; } - print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' (Stripe connection with Stripe Connect account '.$stripeacc.')':' (Stripe connection with default API credentials)'), $morehtmlright, ''); + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')':' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, ''); $listofsources = array(); if (is_object($stripe)) @@ -835,7 +835,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' if (empty($companypaymentmodetemp->stripe_card_ref)) print $langs->trans("Local"); else print $langs->trans("LocalAndRemote"); print ''; - print ''; + print ''; if ($user->rights->societe->creer) { print ''; @@ -843,7 +843,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print ' '; print ''; - print img_delete($langs->trans("Delete")); + print img_picto($langs->trans("Delete"), 'delete'); print ''; } print ''; @@ -942,11 +942,11 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print $langs->trans("Remote"); print ''; - print ''; + print ''; if ($user->rights->societe->creer) { print ''; - print img_delete($langs->trans("Delete")); + print img_picto($langs->trans("Delete"), 'delete'); print ''; } print ''; @@ -1130,7 +1130,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; // Edit/Delete - print ''; + print ''; if ($user->rights->societe->creer) { print ''; diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index cba140486db..6293802540e 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -801,6 +801,9 @@ select.flat.selectlimit { .fa-file-text-o, .fa-file-code-o, .fa-file-powerpoint-o, .fa-file-excel-o, .fa-file-word-o, .fa-file-o, .fa-file-image-o, .fa-file-video-o, .fa-file-audio-o, .fa-file-archive-o, .fa-file-pdf-o { color: #055; } +.fa-trash, .fa-crop, .fa-pencil { + font-size: 1.4em; +} /* DOL_XXX for future usage (when left menu has been removed). If we do not use datatable */ /*.table-responsive { @@ -1325,11 +1328,11 @@ div.nopadding { .pictowarning, .pictopreview { padding-: 3px; } -.pictoedit, .pictowarning, .pictodelete { +.pictowarning { vertical-align: text-bottom; } -.fiche img.pictoedit { - opacity: 0.7; +.fiche img.pictoedit, .fiche span.pictoedit { + opacity: 0.4; } .colorthumb { padding-left: 1px !important; diff --git a/htdocs/theme/md/img/menus/ticketsup.png b/htdocs/theme/md/img/menus/ticketsup.png new file mode 100644 index 0000000000000000000000000000000000000000..98beeaf593ac4baf79eb72d410a706d124a1ed7c GIT binary patch literal 916 zcmV;F18e+=P)kdg00002VoOIv0063u zBQgL0010qNS#tmY4c7nw4c7reD4Tcy000McNliru;sXv72QWw9ricIl10_jBK~zY` z&6Q0|lvfmnpAU3|aZqCs44nY#v{Xbb5-?PvCPqz&37d*d+J#%%CT>^|ckPO#ach$X zcWf$YH%(z@+DIx%Z7HUrf(dA({DhJygz`7@bTJTSo&wJhr|8)eG z5#w=?eEm{$d55{c93s5S0)xTQYZOPQB#+-%3IN&uo;26g_MiuZo4;bJ< zu$V#Lpq^2l1k39fjeE&M0Pggf13q=!IaTKz_o)M3b0>g@yky)+cn9mYRm9s&P)G}n z6o!j~KxH_drkgLBWH@A>(r_-FPyp>}&nIo4!wNt!!zd72mDei4VRi%K;Vi`xQLd)dA1rc}C`+V5 zbR5{t;cS8kIV4$YYJr4D0X#|~TuDcgBsoN~35Iw@F01OB;w})S27nr(z+G1LUqmji z7|JGi$ShEneySivA06zX8h~nc(LrC3Nb=qQwKmD{oD-3 z!pvgIfq4eA2!drMfpeV9ob(0vDK&1KQtq?Xej4qzo8u#YirZNDFc zfwX1WU_)r4SYoRqYOl3hIYNsQ>Vh5Cn4g8@d%~~$OP#P~YqO4d-RG)4@l(%w#B$3$ z;#oiOv8vC#ZtR~OztLV7O~;IPyyHwbTeR24fAeV+d&8H`I`6Wo%g#INOK(`b$=9|8 qNeQ*oaDr-}pI`ZfpMyX6U&h~dzpw7?&g63d0000: 3px; } -.pictoedit, .pictowarning, .pictodelete { +.pictowarning { vertical-align: text-bottom; } +.fiche img.pictoedit, .fiche span.pictoedit { + opacity: 0.9; +} img.hideonsmartphone.pictoactionview { vertical-align: bottom; } @@ -1682,6 +1688,10 @@ div.mainmenu.project { background-image: url(); } +div.mainmenu.ticketsup { + background-image: url(); +} + div.mainmenu.tools { background-image: url(); } @@ -1696,7 +1706,7 @@ div.mainmenu.website { $moduletomainmenu=array('user'=>'','syslog'=>'','societe'=>'companies','projet'=>'project','propale'=>'commercial','commande'=>'commercial', 'produit'=>'products','service'=>'products','stock'=>'products', 'don'=>'accountancy','tax'=>'accountancy','banque'=>'accountancy','facture'=>'accountancy','compta'=>'accountancy','accounting'=>'accountancy','adherent'=>'members','import'=>'tools','export'=>'tools','mailing'=>'tools', - 'contrat'=>'commercial','ficheinter'=>'commercial','deplacement'=>'commercial', + 'contrat'=>'commercial','ficheinter'=>'commercial','ticketsup'=>'ticketsup','deplacement'=>'commercial', 'fournisseur'=>'companies', 'barcode'=>'','fckeditor'=>'','categorie'=>'', ); @@ -1712,7 +1722,7 @@ $generic=1; // Put here list of menu entries when the div.mainmenu.menuentry was previously defined $divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','ftp','holiday','hrm','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','stripe','webservices','website'); // Put here list of menu entries we are sure we don't want -$divnotrequired=array('multicurrency','salaries','margin','opensurvey','paybox','expensereport','incoterm','prelevement','propal','workflow','notification','supplier_proposal','cron','product','productbatch','expedition'); +$divnotrequired=array('multicurrency','salaries','ticketsup','margin','opensurvey','paybox','expensereport','incoterm','prelevement','propal','workflow','notification','supplier_proposal','cron','product','productbatch','expedition'); foreach($mainmenuusedarray as $val) { if (empty($val) || in_array($val,$divalreadydefined)) continue; diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index a7b95bedbbe..3795978289e 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -2612,7 +2612,7 @@ class Ticketsup extends CommonObject } if ($user->rights->produit->creer || $user->rights->service->creer) { // Link to resize - $return .= '' . img_picto($langs->trans("Resize"), DOL_URL_ROOT . '/theme/common/transform-crop-and-resize', '', 1) . '   '; + $return .= '' . img_picto($langs->trans("Resize"), 'resize', '') . '   '; // Link to delete $return .= ''; @@ -2641,7 +2641,7 @@ class Ticketsup extends CommonObject if ($showaction) { if ($user->rights->produit->creer || $user->rights->service->creer) { // Link to resize - $return .= '' . img_picto($langs->trans("Resize"), DOL_URL_ROOT . '/theme/common/transform-crop-and-resize', '', 1) . '   '; + $return .= '' . img_picto($langs->trans("Resize"), 'resize', '') . '   '; // Link to delete $return .= ''; From bf4a0e46aa3bdd56aee844c7646be6569d8b6a6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 21:07:45 +0100 Subject: [PATCH 115/126] Add a credit card on stripe --- htdocs/langs/en_US/stripe.lang | 1 + htdocs/societe/paymentmodes.php | 53 ++++++++++++++- htdocs/stripe/class/stripe.class.php | 96 ++++++++++++++++++++++++++-- 3 files changed, 144 insertions(+), 6 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index f096248bc39..df42e31878a 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -60,3 +60,4 @@ CVN=CVN DeleteACard=Delete Card record ConfirmDeleteCard=Are you sure you want to delete this Card record? CreateCustomerOnStripe=Create customer on Stripe +CreateCardOnStripe=Create card on Stripe diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 73a6b62c181..6fe4b0c64a0 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -508,6 +508,42 @@ if (empty($reshook)) } } } + if ($action == 'synccardtostripe') + { + $companypaymentmode = new CompanyPaymentMode($db); + $companypaymentmode->fetch($id); + + if ($companypaymentmode->type != 'card') + { + $error++; + setEventMessages('ThisPaymentModeIsNotACard', null, 'errors'); + } + else + { + // Get the Stripe customer + $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus); + if (! $cu) + { + $error++; + setEventMessages($stripe->error, $stripe->errors, 'errors'); + } + + if (! $error) + { + // Creation of Stripe card + update of societe_account + $card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1); + if (! $card) + { + $error++; + setEventMessages($stripe->error, $stripe->errors, 'errors'); + } + else + { + $stripecard = $card->id; + } + } + } + } if ($action == 'setkey_account') { @@ -612,6 +648,16 @@ llxHeader(); $head=societe_prepare_head($object); +// Show sandbox warning +/*if (! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox' +{ + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning'); +}*/ +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) +{ + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); +} + // Load Bank account if (! $id) { @@ -810,7 +856,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print ''; if ($companypaymentmodetemp->last_four) print '....'.$companypaymentmodetemp->last_four; - if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.$companypaymentmodetemp->exp_date_month.'/'.$companypaymentmodetemp->exp_date_year.''; + if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.sprintf("%02d", $companypaymentmodetemp->exp_date_month).'/'.$companypaymentmodetemp->exp_date_year.''; print ''; if ($companypaymentmodetemp->country_code) { @@ -838,6 +884,11 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; if ($user->rights->societe->creer) { + if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref)) + { + print ''.$langs->trans("CreateCardOnStripe").''; + } + print ''; print img_picto($langs->trans("Modify"),'edit'); print ''; diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index cf02ec6b65b..82aca6580ef 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -110,13 +110,13 @@ class Stripe extends CommonObject /** * Get the Stripe customer of a thirdparty (with option to create it if not linked yet) * - * @param Societe $object Object thirdparty to check, or create on stripe (create on strip also update the stripe_account table for current entity) + * @param Societe $object Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity) * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect * @param int $status Status (0=test, 1=live) * @param int $createifnotlinkedtostripe 1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer * @return \Stripe\StripeCustomer|null Stripe Customer or null if not found */ - public function customerStripe($object, $key='', $status=0, $createifnotlinkedtostripe=0) + public function customerStripe(Societe $object, $key='', $status=0, $createifnotlinkedtostripe=0) { global $conf, $user; @@ -166,10 +166,9 @@ class Stripe extends CommonObject } else { $customer = \Stripe\Customer::create($dataforcustomer, array("stripe_account" => $key)); } - $customer_id = $customer->id; $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)"; - $sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer_id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")"; + $sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer->id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")"; $resql = $this->db->query($sql); if (! $resql) { @@ -178,14 +177,101 @@ class Stripe extends CommonObject } catch(Exception $e) { - //print $e->getMessage(); + $this->error = $e->getMessage(); } } } + else + { + dol_print_error($this->db); + } return $customer; } + /** + * Get the Stripe card of a company payment mode (with option to create it if not linked yet) + * + * @param \Stripe\StripeCustomer $cu Object stripe customer + * @param CompanyPaymentMode $object Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity) + * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect + * @param int $status Status (0=test, 1=live) + * @param int $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card + * @return \Stripe\StripeCard|null Stripe Card or null if not found + */ + public function cardStripe($cu, CompanyPaymentMode $object, $key='', $status=0, $createifnotlinkedtostripe=0) + { + global $conf, $user; + + $customer = null; + + $sql = "SELECT sa.stripe_card_ref as stripe_card_ref"; // key_account is cus_.... + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa"; + $sql.= " WHERE sa.rowid = " . $object->id; + //$sql.= " AND sa.entity IN (".getEntity('societe').")"; + $sql.= " AND sa.type = 'card'"; + + dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + if ($num) + { + $obj = $this->db->fetch_object($resql); + $cardref = $obj->stripe_card_ref; + if ($cardref) + { + try { + if (empty($key)) { // If the Stripe connect account not set, we use common API usage + $card = \Stripe\Card::retrieve("$cardref"); + } else { + $card = \Stripe\Card::retrieve("$cardref", array("stripe_account" => $key)); + } + } + catch(Exception $e) + { + + } + } + elseif ($createifnotlinkedtostripe) + { + $dataforcard = array( + "source" => 'eee', + "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity) + ); + + //$a = \Stripe\Stripe::getApiKey(); + //var_dump($a);var_dump($key);exit; + try { + if (empty($key)) { // If the Stripe connect account not set, we use common API usage + $card = $cu->sources->create($dataforcard); + } else { + $card = $cu->sources->create($dataforcard, array("stripe_account" => $key)); + } + + $sql = "UPDATE INTO " . MAIN_DB_PREFIX . "societe_rib (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)"; + $sql .= " VALUES (".$object->id.", '', '".$this->db->escape($card->id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")"; + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error = $this->db->lasterror(); + } + } + catch(Exception $e) + { + $this->error = $e->getMessage(); + } + } + } + } + else + { + dol_print_error($this->db); + } + + return $card; + } + /** * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API * From 3c8c5102c34da6cdb46c99ddda8dcbc42892e676 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 23:34:05 +0100 Subject: [PATCH 116/126] Rename var to avoid conflicts --- htdocs/public/payment/newpayment.php | 4 ++-- htdocs/public/stripe/newpayment.php | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 3ad3f2d33fd..7230170e1aa 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1384,7 +1384,7 @@ if (preg_match('/^dopayment/',$action)) /* print '