diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index 92d1011b923..fde828fd6d4 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -24,20 +24,22 @@
// $massaction must be defined
// $objectclass and $$objectlabel must be defined
-// $uploaddir (example $conf->projet->dir_output . "/";)
+// $parameters, $object, $action must be defined for the hook.
+
+// $uploaddir may be defined (example to $conf->projet->dir_output."/";)
// $toselect may be defined
// Protection
-if (empty($objectclass) || empty($uploaddir))
+if (empty($objectclass) || empty($uploaddir))
{
dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
exit;
}
-// Mass actions. Controls on number of lines checked
-$maxformassaction=1000;
+// Mass actions. Controls on number of lines checked.
+$maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
if (! empty($massaction) && count($toselect) < 1)
{
$error++;
@@ -87,7 +89,7 @@ if (! $error && $massaction == 'confirm_presend')
}
}
//var_dump($listofobjectthirdparties);exit;
-
+
foreach ($listofobjectthirdparties as $thirdpartyid)
{
$result = $thirdparty->fetch($thirdpartyid);
@@ -144,7 +146,7 @@ if (! $error && $massaction == 'confirm_presend')
{
//var_dump($object);
//var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
-
+
if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED)
{
$nbignored++;
@@ -157,7 +159,7 @@ if (! $error && $massaction == 'confirm_presend')
$resaction.='
';
continue;
}
-
+
// Read document
// TODO Use future field $object->fullpathdoc to know where is stored default file
// TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
@@ -202,7 +204,7 @@ if (! $error && $massaction == 'confirm_presend')
dol_syslog('Failed to read file: '.$file, LOG_WARNING);
continue;
}
-
+
//var_dump($listofqualifiedref);
}
@@ -252,9 +254,9 @@ if (! $error && $massaction == 'confirm_presend')
$filepath = $attachedfiles['paths'];
$filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes'];
-
+
//var_dump($filepath);
-
+
// Send mail
require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
@@ -280,7 +282,7 @@ if (! $error && $massaction == 'confirm_presend')
if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
-
+
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
if ($message)
{
@@ -290,7 +292,7 @@ if (! $error && $massaction == 'confirm_presend')
$actionmsg = dol_concatdesc($actionmsg, $message);
}
$actionmsg2='';
-
+
// Initialisation donnees
$object->sendtoid = 0;
$object->actionmsg = $actionmsg; // Long text
@@ -335,7 +337,7 @@ if (! $error && $massaction == 'confirm_presend')
$resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n ";
$resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n ";
$resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n ";
-
+
if ($nbsent)
{
$action=''; // Do not show form post if there was at least one successfull sent
@@ -359,7 +361,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-
+
$objecttmp=new $objectclass($db);
$listofobjectid=array();
$listofobjectthirdparties=array();
@@ -425,21 +427,21 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
if (count($files)>0)
{
-
+
$now=dol_now();
$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
-
+
$input_files = '';
foreach($files as $f) {
$input_files.=' '.escapeshellarg($f);
}
-
+
$cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
exec($cmd);
-
+
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
-
+
$langs->load("exports");
setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
}
@@ -447,7 +449,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
{
setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
}
-
+
}
else {
// Create empty PDF
@@ -481,7 +483,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
// Defined name of merged file
$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
$filename=preg_replace('/\s/','_',$filename);
-
+
// Save merged file
if ($filter=='paye:0')
{
@@ -565,6 +567,11 @@ if (! $error && $massaction == 'delete' && $permtodelete)
//var_dump($listofobjectthirdparties);exit;
}
+$parameters['toselect']=$toselect;
+$parameters['uploaddir']=$uploaddir;
+
+$reshook=$hookmanager->executeHooks('doMassActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php
new file mode 100644
index 00000000000..03b33b19eb1
--- /dev/null
+++ b/htdocs/core/actions_setmoduleoptions.inc.php
@@ -0,0 +1,86 @@
+
+ *
+ * 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 .
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file htdocs/core/actions_setnotes.inc.php
+ * \brief Code for actions on setting notes of object page
+ */
+
+
+// $action must be defined
+// $_FILES may be defined
+// $nomessageinsetmoduleoptions can be set to 1
+
+// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
+if ($action == 'setModuleOptions')
+{
+ $db->begin();
+
+ // Process common param fields
+ foreach($_POST as $key => $val)
+ {
+ if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ...
+ {
+ $param=GETPOST("param".$reg[1],'alpha');
+ $value=GETPOST("value".$reg[1],'alpha');
+ if ($param)
+ {
+ $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
+ if (! $res > 0) $error++;
+ }
+ }
+ }
+
+ // Process upload fields
+ if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
+ {
+ include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
+ $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
+ 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)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
+ else
+ {
+ $upload_dir=$tmpdir;
+ }
+ }
+ if ($upload_dir)
+ {
+ $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
+ if ($result <= 0) $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
+ }
+ else
+ {
+ $db->rollback();
+ if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
+ }
+}
+
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index c89fc593745..bd1daca8886 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -1681,7 +1681,7 @@ class ExtraFields
// Clean parameters
$value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]);
}
- else if (in_array($key_type,array('checkbox')))
+ else if (in_array($key_type,array('checkbox', 'chkbxlst')))
{
$value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
// Make sure we get an array even if there's only one checkbox
diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php
index 590f8060296..40ed4153060 100644
--- a/htdocs/core/class/hookmanager.class.php
+++ b/htdocs/core/class/hookmanager.class.php
@@ -133,11 +133,14 @@ class HookManager
if (in_array(
$method,
array(
- 'addMoreActionsButtons',
+ 'addCalendarChoice',
+ 'addMoreActionsButtons',
+ 'addMoreMassActions',
'addSearchEntry',
'addStatisticLine',
- 'deleteFile',
+ 'deleteFile',
'doActions',
+ 'doMassActions',
'formCreateThirdpartyOptions',
'formObjectOptions',
'formattachOptions',
@@ -169,7 +172,6 @@ class HookManager
'printSearchForm',
'printTabsHead',
'formatEvent',
- 'addCalendarChoice',
'printObjectLine',
'printObjectSubLine',
'createDictionaryFieldList',
@@ -181,14 +183,16 @@ class HookManager
if ($method == 'insertExtraFields')
{
- $hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
+ $hooktype='returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
}
+ // Init return properties
+ $this->resPrint=''; $this->resArray=array();
+
// Loop on each hook to qualify modules that have declared context
$modulealreadyexecuted=array();
$resaction=0; $error=0; $result='';
- $this->resPrint=''; $this->resArray=array();
foreach($this->hooks as $context => $modules) // $this->hooks is an array with context as key and value is an array of modules that handle this context
{
if (! empty($modules))
@@ -202,9 +206,9 @@ class HookManager
// test to avoid running twice a hook, when a module implements several active contexts
if (in_array($module,$modulealreadyexecuted)) continue;
-
+
dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context);
-
+
$modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice
// Clean class (an error may have been set from a previous call of another method for same module/hook)
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 34693cba67a..b14f72a1b7b 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -545,11 +545,20 @@ class Form
$disabled=0;
$ret='
';
$ret.='';
// Warning: if you set submit button to disabled, post using 'Enter' will no more work.
$ret.='';
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index 71de341a769..a79f17b1fdc 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -50,13 +50,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
* @since 4.0.0
*/
public $editor_name;
-
+
/**
* @var string URL of module at publisher site
* @since 4.0.0
*/
public $editor_url;
-
+
/**
* @var string Family
* @see familyinfo
@@ -80,13 +80,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
*
*/
public $familyinfo;
-
+
/**
* @var int Module position
* @since 3.9.0
*/
public $module_position=500;
-
+
/**
* @var string Module name
*
@@ -214,7 +214,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
* HTML content supported.
*/
public $descriptionlong;
-
+
/**
* @var string Module export code
*/
@@ -249,7 +249,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
* @var bool Module is enabled globally (Multicompany support)
*/
public $core_enabled;
-
+
/**
* @var string Relative path to module style sheet
* @deprecated
@@ -286,7 +286,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
*/
public $config_page_url;
-
+
/**
* @var string[] List of module class names that must be enabled if this module is enabled.
*
@@ -309,22 +309,22 @@ class DolibarrModules // Can not be abstract, because we need to insta
* @var string[] Module language files
*/
public $langfiles;
-
+
/**
* @var string[] Array of warnings to show when we activate the module
- *
+ *
* array('always'='text') or array('FR'='text')
*/
public $warnings_activation;
-
+
/**
* @var string[] Array of warnings to show when we activate an external module
- *
+ *
* array('always'='text') or array('FR'='text')
*/
public $warnings_activation_ext;
-
-
+
+
/**
* @var array() Minimum version of PHP required by module.
* e.g.: PHP ≥ 5.3 = array(5, 3)
@@ -342,7 +342,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
*/
public $hidden = false;
-
+
/**
* Constructor. Define names, constants, directories, boxes, permissions
*
@@ -538,8 +538,8 @@ class DolibarrModules // Can not be abstract, because we need to insta
return $langs->trans("Module".$this->numero."Name");
}
else
- {
- // If module name translation using it's unique id does not exists, we take use its name to find translation
+ {
+ // If module name translation using it's unique id does not exists, we try to use its name to find translation
if (is_array($this->langfiles))
{
foreach($this->langfiles as $val)
@@ -547,6 +547,14 @@ class DolibarrModules // Can not be abstract, because we need to insta
if ($val) $langs->load($val);
}
}
+
+ if ($langs->trans("Module".$this->name."Name") != ("Module".$this->name."Name"))
+ {
+ // If module name translation exists
+ return $langs->trans("Module".$this->name."Name");
+ }
+
+ // Last change with simple product label
return $langs->trans($this->name);
}
}
@@ -591,13 +599,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
{
global $langs;
$langs->load("admin");
-
+
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
$filefound= false;
-
- // Define path to file README.md.
+
+ // Define path to file README.md.
// First check README-la_LA.md then README.md
$pathoffile = dol_buildpath(strtolower($this->name).'/README-'.$langs->defaultlang.'.md', 0);
if (dol_is_file($pathoffile))
@@ -612,11 +620,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
$filefound = true;
}
}
-
+
if ($filefound) // Mostly for external modules
{
$content = file_get_contents($pathoffile);
-
+
if ((float) DOL_VERSION >= 6.0)
{
@include_once DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
@@ -638,14 +646,14 @@ class DolibarrModules // Can not be abstract, because we need to insta
if ($val) $langs->load($val);
}
}
-
+
$content = $langs->trans($this->descriptionlong);
}
}
-
+
return $content;
}
-
+
/**
* Gives the publisher name
*
@@ -655,7 +663,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
{
return $this->editor_name;
}
-
+
/**
* Gives the publisher url
*
@@ -665,7 +673,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
{
return $this->editor_url;
}
-
+
/**
* Gives module version (translated if param $translated is on)
* For 'experimental' modules, gives 'experimental' translation
@@ -768,7 +776,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
}
}
-
+
/**
* Gives the last date of activation
*
@@ -777,11 +785,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
function getLastActivationDate()
{
global $conf;
-
+
$sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
$sql.= " AND entity IN (0, ".$conf->entity.")";
-
+
dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql) $err++;
@@ -790,11 +798,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
$obj=$this->db->fetch_object($resql);
if ($obj) return $this->db->jdate($obj->tms);
}
-
+
return '';
}
-
-
+
+
/**
* Gives the last author of activation
*
@@ -803,11 +811,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
function getLastActivationInfo()
{
global $conf;
-
+
$sql = "SELECT tms, note FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'";
$sql.= " AND entity IN (0, ".$conf->entity.")";
-
+
dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql) $err++;
@@ -821,11 +829,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
}
if ($obj) return array('authorid'=>$tmp['authorid'], 'ip'=>$tmp['ip'], 'lastactivationdate'=>$this->db->jdate($obj->tms));
}
-
+
return array();
}
-
-
+
+
/**
* Insert constants for module activation
*
@@ -929,7 +937,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file;
}
sort($files);
- foreach ($files as $file)
+ foreach ($files as $file)
{
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{
@@ -947,7 +955,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file;
}
sort($files);
- foreach ($files as $file)
+ foreach ($files as $file)
{
if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{
@@ -965,7 +973,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file;
}
sort($files);
- foreach ($files as $file)
+ foreach ($files as $file)
{
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data')
{
@@ -983,7 +991,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file;
}
sort($files);
- foreach ($files as $file)
+ foreach ($files as $file)
{
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update')
{
@@ -1123,19 +1131,19 @@ class DolibarrModules // Can not be abstract, because we need to insta
//$titre = $this->boxes[$key][0];
$file = $this->boxes[$key]['file'];
//$note = $this->boxes[$key][2];
-
+
// TODO If the box is also included by another module and the other module is still on, we should not remove it.
// For the moment, we manage this with hard coded exception
//print "Remove box ".$file.' ';
if ($file == 'box_graph_product_distribution.php')
{
- if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled))
+ if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled))
{
dol_syslog("We discard disabling of module ".$file." because another module still active require it.");
continue;
}
}
-
+
if (empty($file)) $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:''; // For backward compatibility
if ($this->db->type == 'sqlite3') {
@@ -1210,7 +1218,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:'';
$priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:'';
$test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:''; // Line must be visible
-
+
// Search if boxes def already present
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
@@ -1645,7 +1653,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
/**
* Removes access rights
- *
+ *
* @return int Error count (0 if OK)
*/
function delete_permissions()
@@ -1678,7 +1686,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
global $user;
if (! is_array($this->menu) || empty($this->menu)) return 0;
-
+
require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php';
$err=0;
diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
index 4680d451e39..d7e68346511 100644
--- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
+++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
@@ -359,3 +359,23 @@ delete from llx_categorie_contact where fk_categorie not in (select rowid from l
delete from llx_categorie_project where fk_categorie not in (select rowid from llx_categorie where type = 5);
ALTER TABLE llx_inventory ADD COLUMN ref varchar(48);
+
+create table llx_loan_schedule
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_loan integer,
+ datec datetime,
+ tms timestamp,
+ datep datetime,
+ amount_capital real DEFAULT 0,
+ amount_insurance real DEFAULT 0,
+ amount_interest real DEFAULT 0,
+ fk_typepayment integer NOT NULL,
+ num_payment varchar(50),
+ note_private text,
+ note_public text,
+ fk_bank integer NOT NULL,
+ fk_user_creat integer,
+ fk_user_modif integer
+)ENGINE=innodb;
+
diff --git a/htdocs/install/mysql/tables/llx_loan_schedule.sql b/htdocs/install/mysql/tables/llx_loan_schedule.sql
new file mode 100644
index 00000000000..c682b22f276
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_loan_schedule.sql
@@ -0,0 +1,37 @@
+-- ===================================================================
+-- Copyright (C) 2014 Alexandre Spangaro
+-- Copyright (C) 2015 Frederic France
+--
+-- 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 .
+--
+-- ===================================================================
+
+create table llx_loan_schedule
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_loan integer,
+ datec datetime, -- creation date
+ tms timestamp,
+ datep datetime, -- payment date
+ amount_capital real DEFAULT 0,
+ amount_insurance real DEFAULT 0,
+ amount_interest real DEFAULT 0,
+ fk_typepayment integer NOT NULL,
+ num_payment varchar(50),
+ note_private text,
+ note_public text,
+ fk_bank integer NOT NULL,
+ fk_user_creat integer, -- creation user
+ fk_user_modif integer -- last modification user
+)ENGINE=innodb;
diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang
index 927aab2abf4..d00b11738be 100644
--- a/htdocs/langs/en_US/loan.lang
+++ b/htdocs/langs/en_US/loan.lang
@@ -50,3 +50,4 @@ 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
diff --git a/htdocs/loan/calcmens.php b/htdocs/loan/calcmens.php
new file mode 100644
index 00000000000..3778f455b04
--- /dev/null
+++ b/htdocs/loan/calcmens.php
@@ -0,0 +1,72 @@
+
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * \file tvi/ajax/list.php
+ * \brief File to return datables output
+ */
+if (! defined('NOTOKENRENEWAL'))
+ define('NOTOKENRENEWAL', '1'); // Disables token renewal
+if (! defined('NOREQUIREMENU'))
+ define('NOREQUIREMENU', '1');
+ // if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
+if (! defined('NOREQUIREAJAX'))
+ define('NOREQUIREAJAX', '1');
+ // if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
+ // if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
+
+
+require '../main.inc.php';
+require DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
+
+$mens=GETPOST('mens');
+$capital=GETPOST('capital');
+$rate=GETPOST('rate');
+$echance=GETPOST('echeance');
+$nbterm=GETPOST('nbterm');
+
+top_httphead();
+
+$output=array();
+
+$object = new LoanSchedule($db);
+
+$int = ($capital*($rate/12));
+$int = round($int ,2,PHP_ROUND_HALF_UP);
+$cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP);
+$output[$echance]=array('cap_rest'=>$cap_rest,'cap_rest_str'=>price($cap_rest),'interet'=>$int,'interet_str'=>price($int,0,'',1),'mens'=>$mens);
+
+$echance++;
+$capital=$cap_rest;
+while ($echance<=$nbterm) {
+
+ $mens = round($object->calc_mens($capital,$rate,$nbterm-$echance+1),2,PHP_ROUND_HALF_UP);
+
+ $int = ($capital*($rate/12));
+ $int = round($int ,2,PHP_ROUND_HALF_UP);
+ $cap_rest = round($capital - ($mens-$int),2,PHP_ROUND_HALF_UP);
+
+ $output[$echance]=array('cap_rest'=>$cap_rest,'cap_rest_str'=>price($cap_rest),'interet'=>$int,'interet_str'=>price($int,0,'',1),'mens'=>$mens);
+
+ $capital=$cap_rest;
+ $echance++;
+}
+
+echo json_encode($output);
+
diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php
index 81d43e46ab0..557d48be680 100644
--- a/htdocs/loan/card.php
+++ b/htdocs/loan/card.php
@@ -72,7 +72,7 @@ if (empty($reshook))
setEventMessages($loan->error, null, 'errors');
}
}
-
+
// Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes')
{
@@ -89,7 +89,7 @@ if (empty($reshook))
setEventMessages($loan->error, null, 'errors');
}
}
-
+
// Add loan
if ($action == 'add' && $user->rights->loan->write)
{
@@ -99,7 +99,7 @@ if (empty($reshook))
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
$capital = price2num(GETPOST('capital'));
$rate = GETPOST('rate');
-
+
if (! $capital)
{
$error++; $action = 'create';
@@ -120,7 +120,7 @@ if (empty($reshook))
$error++; $action = 'create';
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors');
}
-
+
if (! $error)
{
$object->label = GETPOST('label');
@@ -133,15 +133,15 @@ if (empty($reshook))
$object->note_private = GETPOST('note_private');
$object->note_public = GETPOST('note_public');
$object->fk_project = GETPOST('fk_project');
-
+
$accountancy_account_capital = GETPOST('accountancy_account_capital');
$accountancy_account_insurance = GETPOST('accountancy_account_insurance');
$accountancy_account_interest = GETPOST('accountancy_account_interest');
-
+
if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
-
+
$id=$object->create($user);
if ($id <= 0)
{
@@ -157,7 +157,7 @@ if (empty($reshook))
exit();
}
}
-
+
// Update record
else if ($action == 'update' && $user->rights->loan->write)
{
@@ -168,7 +168,7 @@ if (empty($reshook))
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
$capital = price2num(GETPOST('capital'));
-
+
if (! $capital)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
@@ -185,14 +185,14 @@ if (empty($reshook))
$accountancy_account_capital = GETPOST('accountancy_account_capital');
$accountancy_account_insurance = GETPOST('accountancy_account_insurance');
$accountancy_account_interest = GETPOST('accountancy_account_interest');
-
+
if ($accountancy_account_capital <= 0) { $object->account_capital = ''; } else { $object->account_capital = $accountancy_account_capital; }
if ($accountancy_account_insurance <= 0) { $object->account_insurance = ''; } else { $object->account_insurance = $accountancy_account_insurance; }
if ($accountancy_account_interest <= 0) { $object->account_interest = ''; } else { $object->account_interest = $accountancy_account_interest; }
}
-
+
$result = $object->update($user);
-
+
if ($result > 0)
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
@@ -209,7 +209,7 @@ if (empty($reshook))
exit;
}
}
-
+
// Link to a project
if ($action == 'classin' && $user->rights->loan->write)
{
@@ -307,12 +307,12 @@ if ($action == 'create')
$langs->load("projects");
print '
';
-
+
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
@@ -652,7 +664,7 @@ if ($id > 0)
while ($i < $num)
{
$objp = $db->fetch_object($resql);
-
+
print '