From ec0d2771238bcd5e5d6ce50daa17eb2d5a49f416 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 00:46:28 +0200 Subject: [PATCH 01/14] Code comment --- htdocs/societe/class/societe.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 00f49046d45..22dc96a0c8b 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -393,7 +393,8 @@ class Societe extends CommonObject /** - * Create third party in database + * Create third party in database. + * $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement. * * @param User $user Object of user that ask creation * @return int >= 0 if OK, < 0 if KO From cf5c34c8fb88964b9861e7edc126d75e1560ebb1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 02:13:55 +0200 Subject: [PATCH 02/14] Remove useless link --- htdocs/compta/facture/card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 1349d3b9199..23b310fd9f7 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2235,7 +2235,6 @@ if ($action == 'create') print ' / ' . price($soc->outstanding_limit, '', $langs, 0, 0, -1, $conf->currency); } print ')'; - print ' '.$langs->trans("AddThirdParty").''; print ''; } else From a3d5d97d05f75abe542cd0707d28bee5abd644ba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 02:19:38 +0200 Subject: [PATCH 03/14] Fix translation --- htdocs/compta/facture/fiche-rec.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 025940c8b3a..5c1d33e7808 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -402,16 +402,16 @@ if (empty($reshook)) $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error ++; - + if (! $error) { - + $result = $object->insertExtraFields(); if ($result < 0) { $error ++; } } else if ($reshook < 0) $error ++; - + if ($error) { $action = 'edit_extras'; setEventMessages($object->error, $object->errors, 'errors'); @@ -760,7 +760,7 @@ if (empty($reshook)) $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); - + $objectline = new FactureLigneRec($db); if ($objectline->fetch(GETPOST('lineid'))) { @@ -771,7 +771,7 @@ if (empty($reshook)) setEventMessages($langs->trans('Error').$result, null, 'errors'); } } - + // Unset extrafield if (is_array($extralabelsline)) { @@ -1054,7 +1054,7 @@ if ($action == 'create') // Bank account if ($object->fk_account > 0) { - print "".$langs->trans('RIB').""; + print "".$langs->trans('BankAccount').""; $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); print ""; } @@ -1361,11 +1361,11 @@ else print ""; print ''; - + // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + print ''; print ''; From ca93be5eed8287359f17a13822cebe2fe7b299d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 02:40:00 +0200 Subject: [PATCH 04/14] Fix priority of crons --- htdocs/core/modules/modCron.class.php | 4 ++-- htdocs/core/modules/modFacture.class.php | 8 +------ htdocs/core/modules/modGravatar.class.php | 7 ------ .../core/modules/modMultiCurrency.class.php | 22 +++++++------------ 4 files changed, 11 insertions(+), 30 deletions(-) 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); } } From e549e6cde1edbb8c72ac097c050f14fdfb9969fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 04:16:43 +0200 Subject: [PATCH 05/14] Error management --- htdocs/comm/card.php | 4 ++-- htdocs/contrat/class/contrat.class.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index cf7b5bf3dc0..f4a634aad6c 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -206,7 +206,7 @@ if ($id > 0 && empty($object->id)) { // Load data of third party $res=$object->fetch($id); - if ($object->id <= 0) dol_print_error($db,$object->error); + if ($object->id <= 0) dol_print_error($db,$object->error,$object->errors); } $title=$langs->trans("CustomerCard"); @@ -608,7 +608,7 @@ if ($id > 0) if(empty($reshook)){ $boxstat.= $hookmanager->resPrint; } - + $boxstat.=''; $boxstat.=''; $boxstat.=''; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index a521f05269b..21df722bf9d 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1278,7 +1278,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(); From acb87ad8eaad86477516f9ffb97867b6ec3f6530 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 12:02:48 +0200 Subject: [PATCH 06/14] addline must return id of contract --- htdocs/contrat/class/contrat.class.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 21df722bf9d..747eb747441 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1464,6 +1464,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 +1474,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 +1488,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 From a4d3e487734f1faff8f1fe0831fa7e5150c860a2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 12:40:49 +0200 Subject: [PATCH 07/14] FIX inert of extra field must not change extrafield values in memory --- htdocs/core/class/commonobject.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 { From c6cbf2345d7f05170026c6601f1a6c4680ac35f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 14:25:54 +0200 Subject: [PATCH 08/14] FIX Management of default value in extrafields when default is '0' --- htdocs/core/class/extrafields.class.php | 2 +- htdocs/core/db/mysqli.class.php | 6 +++--- htdocs/core/db/pgsql.class.php | 6 +++--- htdocs/langs/en_US/contracts.lang | 3 +++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index e25809559d2..920ddefb964 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 . ","; diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 14256b37d29..1e5306a93f4 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -776,7 +776,7 @@ class DoliDBMysqli 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'].")"; } if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') @@ -796,9 +796,9 @@ class DoliDBMysqli extends DoliDB $sql.=" NOT NULL"; } - 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/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/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? From 07fc0ed3ff3811856de03b107cba632a01adf0e1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 14:26:27 +0200 Subject: [PATCH 09/14] NEW Add a button "Activate all services" on contracts --- htdocs/contrat/card.php | 35 ++++++++---- htdocs/contrat/class/contrat.class.php | 73 +++++++++++++++++++++----- 2 files changed, 86 insertions(+), 22 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index a39698cd815..787f69de4a3 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -752,7 +752,13 @@ if (empty($reshook)) // Close all lines else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->cloture($user); + $object->closeAll($user); + } + + // Close all lines + else if ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer) + { + $object->activateAll($user); } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) @@ -1313,6 +1319,11 @@ else { print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1); + } + if ($action == 'activate') + { + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ActivateAllOnContract"),$langs->trans("ConfirmActivateAllOnContract"),"confirm_activate",'',0,1); + } /* @@ -1617,7 +1628,7 @@ else print $langs->trans("DateStartPlanned").': '; if ($objp->date_debut) { - print dol_print_date($db->jdate($objp->date_debut)); + print dol_print_date($db->jdate($objp->date_debut), 'day'); // Warning si date prevu passee et pas en service if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { $warning_delay=$conf->contrat->services->inactifs->warning_delay / 3600 / 24; @@ -1630,7 +1641,7 @@ else print $langs->trans("DateEndPlanned").': '; if ($objp->date_fin) { - print dol_print_date($db->jdate($objp->date_fin)); + print dol_print_date($db->jdate($objp->date_fin), 'day'); if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); @@ -1849,21 +1860,21 @@ else // Si pas encore active if (! $objp->date_debut_reelle) { print $langs->trans("DateStartReal").': '; - if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle); + if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle, 'day'); else print $langs->trans("ContractStatusNotRunning"); } // Si active et en cours if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { print $langs->trans("DateStartReal").': '; - print dol_print_date($objp->date_debut_reelle); + print dol_print_date($objp->date_debut_reelle, 'day'); } // Si desactive if ($objp->date_debut_reelle && $objp->date_fin_reelle) { print $langs->trans("DateStartReal").': '; - print dol_print_date($objp->date_debut_reelle); + print dol_print_date($objp->date_debut_reelle, 'day'); print '  -  '; print $langs->trans("DateEndReal").': '; - print dol_print_date($objp->date_fin_reelle); + print dol_print_date($objp->date_fin_reelle, 'day'); } if (! empty($objp->comment)) print "
".$objp->comment; print ''; @@ -2071,6 +2082,10 @@ else print ''; } + if ($object->nbofservicesclosed > 0) + { + print ''; + } if ($object->nbofservicesclosed < $nbofservices) { //if (! $numactive) @@ -2121,9 +2136,9 @@ else print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); - // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat')); - $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat')); + $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); print '
'; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 747eb747441..9d6f4cce856 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -247,13 +247,61 @@ 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 void + */ + 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(); + } + else + { + dol_print_error($this->db,'Error in activateAll function'); + $this->db->rollback(); + } + } + /** * Close all lines of a contract * * @param User $user Object User making action * @return void */ - function cloture($user) + function closeAll($user) { $this->db->begin(); @@ -263,7 +311,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(); @@ -290,7 +338,7 @@ class Contrat extends CommonObject } else { - dol_print_error($this->db,'Error in cloture function'); + dol_print_error($this->db,'Error in closeAll function'); $this->db->rollback(); } } @@ -920,8 +968,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++; } @@ -1361,7 +1409,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') @@ -3007,11 +3056,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 = '') { @@ -3030,7 +3079,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) . "'"; From f963afa50528f30c1c0bc58cf1e902bbdf0b5624 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 15:21:17 +0200 Subject: [PATCH 10/14] Fix warning --- htdocs/core/class/extrafields.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 920ddefb964..d3b76345ccb 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -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.=' Date: Sun, 3 Sep 2017 15:40:36 +0200 Subject: [PATCH 11/14] Use return code on activateAll and closeAll --- htdocs/contrat/class/contrat.class.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 9d6f4cce856..9a5edc845b4 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -252,7 +252,7 @@ class Contrat extends CommonObject * * @param User $user Object User making action * @param int|string $date_start Date start (now if empty) - * @return void + * @return int <0 if KO, >0 if OK */ function activateAll($user, $date_start='') { @@ -287,19 +287,21 @@ class Contrat extends CommonObject if ($ok) { $this->db->commit(); + return 0; } 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 closeAll($user) { @@ -335,11 +337,13 @@ class Contrat extends CommonObject if ($ok) { $this->db->commit(); + return 1; } else { dol_print_error($this->db,'Error in closeAll function'); $this->db->rollback(); + return -1; } } From 084ea049d8443c68c3d435dd2309dc39f0646e7f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 16:07:21 +0200 Subject: [PATCH 12/14] Minor bugs --- ChangeLog | 5 +++++ htdocs/compta/facture/class/facture.class.php | 8 ++++---- htdocs/contrat/class/contrat.class.php | 2 +- htdocs/societe/class/societe.class.php | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 481f86bcb31..144f39a574b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ English Dolibarr ChangeLog ***** ChangeLog for 7.0.0 compared to 6.0.* ***** +WARNING: + +Following changes may create regression for some external modules, but were necessary to make Dolibarr better: +* The methode "cloture" on contact were renamed into "closeAll". + ***** ChangeLog for 6.0.0 compared to 5.0.* ***** diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f864b363cc4..0aa2408a9cc 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -316,7 +316,7 @@ class Facture extends CommonInvoice $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); $this->array_options=$_facrec->array_options; - + //if (! $this->remise) $this->remise = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; @@ -636,7 +636,7 @@ class Facture extends CommonInvoice if (empty($tva_tx)) $tva_npr=0; $localtax1_tx=get_localtax($tva_tx,1,$soc,$mysoc,$tva_npr); $localtax2_tx=get_localtax($tva_tx,2,$soc,$mysoc,$tva_npr); - + $result_insert = $this->addline( $_facrec->lines[$i]->desc, $_facrec->lines[$i]->subprice, @@ -750,12 +750,12 @@ class Facture extends CommonInvoice // Charge facture source $facture=new Facture($this->db); - + $this->fetch_optionals(); if(!empty($this->array_options)){ $facture->array_options = $this->array_options; } - + foreach($this->lines as &$line){ $line->fetch_optionals();//fetch extrafields } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 9a5edc845b4..8fa3ef38872 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -287,7 +287,7 @@ class Contrat extends CommonObject if ($ok) { $this->db->commit(); - return 0; + return 1; } else { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 22dc96a0c8b..5360350c75c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -673,7 +673,7 @@ class Societe extends CommonObject if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { $langs->load("errors"); - $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; + $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } } From 75b8462c03db84cc0c8b38bf8fe6ae2ee98c88de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 17:47:45 +0200 Subject: [PATCH 13/14] Fix error output --- htdocs/societe/card.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) 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".'