';
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index a521f05269b..8fa3ef38872 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -247,13 +247,63 @@ class Contrat extends CommonObject
}
+ /**
+ * Open all lines of a contract
+ *
+ * @param User $user Object User making action
+ * @param int|string $date_start Date start (now if empty)
+ * @return int <0 if KO, >0 if OK
+ */
+ function activateAll($user, $date_start='')
+ {
+ if (empty($date_start)) $date_start = dol_now();
+
+ $this->db->begin();
+
+ // Load lines
+ $this->fetch_lines();
+
+ $ok=true;
+ foreach($this->lines as $contratline)
+ {
+ // Open lines not already open
+ if ($contratline->statut != 4)
+ {
+ $result = $contratline->active_line($user, $date_start, -1);
+ if ($result < 0)
+ {
+ $ok=false;
+ break;
+ }
+ }
+ }
+
+ if ($this->statut == 0)
+ {
+ $result=$this->validate($user);
+ if ($result < 0) $ok=false;
+ }
+
+ if ($ok)
+ {
+ $this->db->commit();
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db,'Error in activateAll function');
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
/**
* Close all lines of a contract
*
- * @param User $user Object User making action
- * @return void
+ * @param User $user Object User making action
+ * @return int <0 if KO, >0 if OK
*/
- function cloture($user)
+ function closeAll($user)
{
$this->db->begin();
@@ -263,7 +313,7 @@ class Contrat extends CommonObject
$ok=true;
foreach($this->lines as $contratline)
{
- // Close line not already closed
+ // Close lines not already closed
if ($contratline->statut != 5)
{
$contratline->date_cloture=dol_now();
@@ -287,11 +337,13 @@ class Contrat extends CommonObject
if ($ok)
{
$this->db->commit();
+ return 1;
}
else
{
- dol_print_error($this->db,'Error in cloture function');
+ dol_print_error($this->db,'Error in closeAll function');
$this->db->rollback();
+ return -1;
}
}
@@ -920,8 +972,8 @@ class Contrat extends CommonObject
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
- $result=$this->insertExtraFields();
- if ($result < 0)
+ $result=$this->insertExtraFields();
+ if ($result < 0)
{
$error++;
}
@@ -1278,7 +1330,7 @@ class Contrat extends CommonObject
//// End call triggers
}
}
-
+
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
@@ -1361,7 +1413,8 @@ class Contrat extends CommonObject
if (empty($info_bits)) $info_bits=0;
if (empty($pu_ht) || ! is_numeric($pu_ht)) $pu_ht=0;
if (empty($pu_ttc)) $pu_ttc=0;
- if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0;
+ if (empty($txtva) || ! is_numeric($txtva)) $txtva=0;
+ if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0;
if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0;
if ($price_base_type=='HT')
@@ -1464,6 +1517,8 @@ class Contrat extends CommonObject
$resql=$this->db->query($sql);
if ($resql)
{
+ $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX.$contractline->table_element);
+
$result=$this->update_statut($user);
if ($result > 0)
{
@@ -1472,7 +1527,7 @@ class Contrat extends CommonObject
{
$contractline = new ContratLigne($this->db);
$contractline->array_options=$array_options;
- $contractline->id= $this->db->last_insert_id(MAIN_DB_PREFIX.$contractline->table_element);
+ $contractline->id=$contractlineid;
$result=$contractline->insertExtraFields();
if ($result < 0)
{
@@ -1486,13 +1541,20 @@ class Contrat extends CommonObject
$result=$this->call_trigger('LINECONTRACT_INSERT',$user);
if ($result < 0)
{
- $this->db->rollback();
- return -1;
+ $error++;
}
// End call triggers
+ }
+ if ($error)
+ {
+ $this->db->rollback();
+ return -1;
+ }
+ else
+ {
$this->db->commit();
- return 1;
+ return $contractlineid;
}
}
else
@@ -2998,11 +3060,11 @@ class ContratLigne extends CommonObjectLine
/**
* Activate a contract line
*
- * @param User $user Objet User who activate contract
- * @param int $date Date d'ouverture
- * @param int|string $date_end Date fin prevue
- * @param string $comment A comment typed by user
- * @return int <0 if KO, >0 if OK
+ * @param User $user Objet User who activate contract
+ * @param int $date Date activation
+ * @param int|string $date_end Date planned end. Use '-1' to keep it unchanged.
+ * @param string $comment A comment typed by user
+ * @return int <0 if KO, >0 if OK
*/
function active_line($user, $date, $date_end = '', $comment = '')
{
@@ -3021,7 +3083,7 @@ class ContratLigne extends CommonObjectLine
$sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 4,";
$sql .= " date_ouverture = " . (dol_strlen($date) != 0 ? "'" . $this->db->idate($date) . "'" : "null") . ",";
- $sql .= " date_fin_validite = " . (dol_strlen($date_end) != 0 ? "'" . $this->db->idate($date_end) . "'" : "null") . ",";
+ if ($date_end >= 0) $sql .= " date_fin_validite = " . (dol_strlen($date_end) != 0 ? "'" . $this->db->idate($date_end) . "'" : "null") . ",";
$sql .= " fk_user_ouverture = " . $user->id . ",";
$sql .= " date_cloture = null,";
$sql .= " commentaire = '" . $this->db->escape($comment) . "'";
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index b84f9887abb..8d7e0309a1d 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4349,7 +4349,7 @@ abstract class CommonObject
}
elseif ($value=='')
{
- $this->array_options[$key] = null;
+ $new_array_options[$key] = null;
}
break;
/*case 'select': // Not required, we chosed value='0' for undefined values
@@ -4359,13 +4359,13 @@ abstract class CommonObject
}
break;*/
case 'price':
- $this->array_options[$key] = price2num($this->array_options[$key]);
+ $new_array_options[$key] = price2num($this->array_options[$key]);
break;
case 'date':
- $this->array_options[$key]=$this->db->idate($this->array_options[$key]);
+ $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
break;
case 'datetime':
- $this->array_options[$key]=$this->db->idate($this->array_options[$key]);
+ $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
break;
case 'link':
$param_list=array_keys($attributeParam ['options']);
@@ -4381,7 +4381,7 @@ abstract class CommonObject
if (is_numeric($value)) $res=$object->fetch($value);
else $res=$object->fetch('',$value);
- if ($res > 0) $this->array_options[$key]=$object->id;
+ if ($res > 0) $new_array_options[$key]=$object->id;
else
{
$this->error="Ref '".$value."' for object '".$object->element."' not found";
@@ -4421,9 +4421,9 @@ abstract class CommonObject
// Add field o fattribut
if($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate)
{
- if ($this->array_options[$key] != '')
+ if ($new_array_options[$key] != '')
{
- $sql.=",'".$this->db->escape($this->array_options[$key])."'";
+ $sql.=",'".$this->db->escape($new_array_options[$key])."'";
}
else
{
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index e25809559d2..d3b76345ccb 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -660,7 +660,7 @@ class ExtraFields
$sql.= " '".$param."',";
$sql.= " ".$list.", ";
$sql.= " ".$ishidden.", ";
- $sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
+ $sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
$sql .= " " . $user->id . ",";
$sql .= " " . $user->id . ",";
@@ -1128,13 +1128,13 @@ class ExtraFields
$form = new Form($db);
$value_arr=explode(',',$value);
- $out=$form->multiselectarray($keysuffix.'options_'.$key.$keyprefix, $param['options'], $value_arr, '', 0, '', 0, '100%');
+ $out=$form->multiselectarray($keysuffix.'options_'.$key.$keyprefix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
}
elseif ($type == 'radio')
{
$out='';
- foreach ($param['options'] as $keyopt=>$val )
+ foreach ($param['options'] as $keyopt => $val)
{
$out.='
escape($field_desc['default']);
+ if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
}
diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php
index 0448789fc50..bc967ffb0b7 100644
--- a/htdocs/core/db/pgsql.class.php
+++ b/htdocs/core/db/pgsql.class.php
@@ -1084,7 +1084,7 @@ class DoliDBPgsql extends DoliDB
{
$sql = "ALTER TABLE ".$table;
$sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
- if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') {
+ if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') {
$sql.="(".$field_desc['value'].")";
}
@@ -1103,9 +1103,9 @@ class DoliDBPgsql extends DoliDB
}
}
- if ($field_desc['default'])
+ if ($field_desc['default'] != '')
{
- if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
+ if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
}
diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php
index 55f0f96c546..f72fb6abe20 100644
--- a/htdocs/core/modules/modCron.class.php
+++ b/htdocs/core/modules/modCron.class.php
@@ -97,8 +97,8 @@ class modCron extends DolibarrModules
// Cronjobs
$this->cronjobs = array(
- 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>true),
- 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>in_array($db->type, array('mysql','mysqli'))),
+ 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true),
+ 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql','mysqli'))),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
);
diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php
index 40e2a03d161..5f28a3db54d 100644
--- a/htdocs/core/modules/modFacture.class.php
+++ b/htdocs/core/modules/modFacture.class.php
@@ -117,15 +117,9 @@ class modFacture extends DolibarrModules
// Cronjobs
$this->cronjobs = array(
- 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24),
+ 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24, 'priority'=>50, 'status'=>1, 'test'=>true),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
);
- // List of cron jobs entries to add
- // Example:
- // $this->cronjobs=array(
- // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600),
- // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600)
- // );
// Permissions
$this->rights = array();
diff --git a/htdocs/core/modules/modGravatar.class.php b/htdocs/core/modules/modGravatar.class.php
index 237778309c2..495ad152f2a 100644
--- a/htdocs/core/modules/modGravatar.class.php
+++ b/htdocs/core/modules/modGravatar.class.php
@@ -99,13 +99,6 @@ class modGravatar extends DolibarrModules
//$r++;
- // Cronjobs
- $this->cronjobs = array(); // List of cron jobs entries to add
- // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600),
- // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
- // );
- $r=0;
-
// Permissions
$this->rights = array(); // Permission array used by this module
$r=0;
diff --git a/htdocs/core/modules/modMultiCurrency.class.php b/htdocs/core/modules/modMultiCurrency.class.php
index 7eb58e32a3a..5e921e83597 100644
--- a/htdocs/core/modules/modMultiCurrency.class.php
+++ b/htdocs/core/modules/modMultiCurrency.class.php
@@ -3,7 +3,7 @@
* Copyright (C) 2004-2015 Laurent Destailleur
* Copyright (C) 2005-2016 Regis Houssin
* Copyright (C) 2016 Pierre-Henry Favre
- *
+ *
* 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
@@ -60,7 +60,7 @@ class modMultiCurrency extends DolibarrModules
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Module to enter elements with a foreign currency";
-
+
// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
$this->version = 'dolibarr';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
@@ -175,12 +175,6 @@ class modMultiCurrency extends DolibarrModules
// 2=>array('file'=>'myboxc.php@multicurrency','note'=>'')
//);
- // Cronjobs
- $this->cronjobs = array(); // List of cron jobs entries to add
- // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600),
- // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
- // );
-
// Permissions
$this->rights = array(); // Permission array used by this module
$r=0;
@@ -266,12 +260,12 @@ class modMultiCurrency extends DolibarrModules
//$this->_load_tables('/multicurrency/sql/');
$res = $this->_init($sql, $options);
-
+
if ($res)
{
$this->createFirstCurrency();
}
-
+
return $res;
}
@@ -293,22 +287,22 @@ class modMultiCurrency extends DolibarrModules
/**
* Function called when module is enabled
* Create the currency from general setting
- *
+ *
* @return int 1 if OK, 0 if KO
*/
private function createFirstCurrency()
{
global $conf,$user,$langs;
-
+
if (!MultiCurrency::checkCodeAlreadyExists($conf->currency))
{
$langs->loadCacheCurrencies('');
-
+
$multicurrency = new MultiCurrency($this->db);
$multicurrency->code = $conf->currency;
$multicurrency->name = $langs->cache_currencies[$conf->currency]['label'].' ('.$langs->getCurrencySymbol($conf->currency).')';
$r = $multicurrency->create($user);
-
+
if ($r > 0) $multicurrency->addRate(1);
}
}
diff --git a/htdocs/langs/en_US/contracts.lang b/htdocs/langs/en_US/contracts.lang
index f742ca4cecd..63d3c403e50 100644
--- a/htdocs/langs/en_US/contracts.lang
+++ b/htdocs/langs/en_US/contracts.lang
@@ -31,9 +31,11 @@ NewContract=New contract
NewContractSubscription=New contract/subscription
AddContract=Create contract
DeleteAContract=Delete a contract
+ActivateAllOnContract=Activate all services
CloseAContract=Close a contract
ConfirmDeleteAContract=Are you sure you want to delete this contract and all its services?
ConfirmValidateContract=Are you sure you want to validate this contract under name %s?
+ConfirmActivateAllOnContract=This will open all services (not yet active). Are you sure you want to open all services?
ConfirmCloseContract=This will close all services (active or not). Are you sure you want to close this contract?
ConfirmCloseService=Are you sure you want to close this service with date %s?
ValidateAContract=Validate a contract
@@ -67,6 +69,7 @@ BoardRunningServices=Expired running services
ServiceStatus=Status of service
DraftContracts=Drafts contracts
CloseRefusedBecauseOneServiceActive=Contract can't be closed as ther is at least one open service on it
+ActivateAllContracts=Activate all contract lines
CloseAllContracts=Close all contract lines
DeleteContractLine=Delete a contract line
ConfirmDeleteContractLine=Are you sure you want to delete this contract line?
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index bc62e71dd04..cfaf6932b73 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -95,6 +95,7 @@ $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'ro
+
/*
* Actions
*/
@@ -310,19 +311,19 @@ if (empty($reshook))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
$error++;
- $action='create';
+ $action=($action=='add'?'create':'edit');
}
if (GETPOST('client') < 0)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
$error++;
- $action='create';
+ $action=($action=='add'?'create':'edit');
}
if (GETPOST('fournisseur') < 0)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
$error++;
- $action='create';
+ $action=($action=='add'?'create':'edit');
}
if ($action == 'update')
@@ -653,7 +654,7 @@ if (empty($reshook))
}
}
else
- {
+ {
switch($_FILES['photo']['error'])
{
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
@@ -683,7 +684,7 @@ if (empty($reshook))
if (! $error && ! count($errors))
{
- if (! empty($backtopage))
+ if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
@@ -703,7 +704,7 @@ if (empty($reshook))
}
else
{
- $action='create';
+ $action = ($action=='add'?'create':'edit');
}
}
@@ -756,7 +757,6 @@ if (empty($reshook))
}
-
/*
* View
*/
@@ -1356,11 +1356,12 @@ else
* Edition
*/
+
//print load_fiche_titre($langs->trans("EditCompany"));
if ($socid)
{
- $res=$object->fetch_optionals($object->id,$extralabels);
+ $res=$object->fetch_optionals($object->id,$extralabels);
//if ($res < 0) { dol_print_error($db); exit; }
$head = societe_prepare_head($object);
@@ -1466,8 +1467,6 @@ else
}
}
- dol_htmloutput_errors($error,$errors);
-
if($object->localtax1_assuj==0){
$sub=0;
}else{$sub=1;}
@@ -1475,7 +1474,6 @@ else
$sub2=0;
}else{$sub2=1;}
-
print "\n".'