From 047aa8ea29f7ef92dc4701fd5f3b3b0c4b048fce Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 14 May 2013 15:58:20 +0200 Subject: [PATCH 01/33] Fix: avoid error when multiple files uploaded --- htdocs/core/tpl/ajax/fileupload_main.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/ajax/fileupload_main.tpl.php b/htdocs/core/tpl/ajax/fileupload_main.tpl.php index be6906faf04..b7437af4616 100644 --- a/htdocs/core/tpl/ajax/fileupload_main.tpl.php +++ b/htdocs/core/tpl/ajax/fileupload_main.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2013 Regis Houssin * * 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 @@ -44,7 +44,7 @@ $(function () { // Events $('#fileupload').fileupload({ - completed: function (e, data) { + stop: function (e, data) { location.href=''; }, destroy: function (e, data) { From 658f0af428aeffcf9d46fc8ba37c798d92c3542e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 16 May 2013 12:37:46 +0200 Subject: [PATCH 02/33] Fix: Removed warning --- 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 35271325247..b5f2dfce9c3 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -194,7 +194,7 @@ class Translate // Redefine alt $langarray=explode('_',$langofdir); - if ($alt < 1 && strtolower($langarray[0]) == strtolower($langarray[1])) $alt=1; + if ($alt < 1 && isset($langarray[1]) && strtolower($langarray[0]) == strtolower($langarray[1])) $alt=1; if ($alt < 2 && (strtolower($langofdir) == 'en_us' || strtolower($langofdir) == 'fr_fr' || strtolower($langofdir) == 'es_es')) $alt=2; foreach($this->dir as $keydir => $searchdir) From bab4e1e5090a49b46bd426cbd72172905b54e831 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 16 May 2013 15:02:26 +0200 Subject: [PATCH 03/33] Fix: PHP version was lost Fix: split of long text to avoid horizontal scrolls --- htdocs/admin/system/phpinfo.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/system/phpinfo.php b/htdocs/admin/system/phpinfo.php index dc29a53141f..c6e2819f5d7 100644 --- a/htdocs/admin/system/phpinfo.php +++ b/htdocs/admin/system/phpinfo.php @@ -23,7 +23,8 @@ */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("admin"); @@ -45,6 +46,23 @@ if (isset($title)) print_fiche_titre($langs->trans($title), '', 'setup'); } + + +print ''; +print ''; +print "\n"; + +$var=false; + +// Recupere la version de l'OS +$phpversion=version_php(); +print "\n"; + +print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("Version")."".$phpversion."
'; +print '
'; + + + // Get php_info array $phparray=phpinfo_array(); foreach($phparray as $key => $value) @@ -68,7 +86,12 @@ foreach($phparray as $key => $value) print ''.$keyparam.''; $valtoshow=$keyvalue; if ($keyparam == 'X-ChromePhp-Data') $valtoshow=dol_trunc($keyvalue,80); - print ''.$valtoshow.''; + print ''; + if ($keyparam == 'Path') $valtoshow=join('; ',explode(';',trim($valtoshow))); + if ($keyparam == 'PATH') $valtoshow=join('; ',explode(';',trim($valtoshow))); + if ($keyparam == '_SERVER["PATH"]') $valtoshow=join('; ',explode(';',trim($valtoshow))); + print $valtoshow; + print ''; print ''; } else @@ -82,7 +105,7 @@ foreach($phparray as $key => $value) print ''; $valtoshow=$keyvalue2; if ($keyparam == 'disable_functions') $valtoshow=join(', ',explode(',',trim($valtoshow))); - //print $keyparam2.' = '; + //print $keyparam; print $valtoshow; $i++; print ''; From 20b3a9873e01b9a99cd88a2c775287b75e2dff83 Mon Sep 17 00:00:00 2001 From: fhenry Date: Thu, 16 May 2013 21:47:51 +0200 Subject: [PATCH 04/33] remove pom.xml --- pom.xml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 pom.xml diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 713f22ea001..00000000000 --- a/pom.xml +++ /dev/null @@ -1,14 +0,0 @@ - - -4.0.0 -org.dolibarr -dolibarr -dolibarr -1.0 -pom - - test/report - htdocs - test/phpunit - - \ No newline at end of file From b3adbf53e5bd2f3fcabfcb4024c22ea015d04173 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 May 2013 00:47:50 +0200 Subject: [PATCH 05/33] Fix data for greece --- htdocs/install/mysql/data/llx_20_c_departements.sql | 2 +- htdocs/install/mysql/data/llx_c_tva.sql | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/data/llx_20_c_departements.sql b/htdocs/install/mysql/data/llx_20_c_departements.sql index 8624df28102..4d13d502a4d 100644 --- a/htdocs/install/mysql/data/llx_20_c_departements.sql +++ b/htdocs/install/mysql/data/llx_20_c_departements.sql @@ -358,7 +358,7 @@ INSERT INTO llx_c_departements (fk_region, code_departement, ncc, nom, active) V -- Provinces Greece (id country=102) INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('66', 10201, NULL, NULL, NULL, 'Αθήνα', 1); -INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('00', 10205, NULL, NULL, NULL, 'Δράμα', 1); +INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('67', 10205, NULL, NULL, NULL, 'Δράμα', 1); INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('01', 10205, NULL, NULL, NULL, 'Έβρος', 1); INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('02', 10205, NULL, NULL, NULL, 'Θάσος', 1); INSERT INTO llx_c_departements (code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('03', 10205, NULL, NULL, NULL, 'Καβάλα', 1); diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index 33b5e84a563..86adc112413 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -101,6 +101,15 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 5 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 54, 5, '5.5','0','USt. Forst', 0); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 55, 5, '10.7','0','USt. Landwirtschaft', 0); +-- GREECE (id country=102) +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2462, 102, 23, 0, '0', 0, '0', 0, 'Κανονικός Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2463, 102, 0, 0, '0', 0, '0', 0, 'Μηδενικό Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2464, 102, 13, 0, '0', 0, '0', 0, 'Μειωμένος Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2465, 102, 6.5, 0, '0', 0, '0', 0, 'Υπερμειωμένος Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2466, 102, 16, 0, '0', 0, '0', 0, 'Νήσων κανονικός Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2467, 102, 9, 0, '0', 0, '0', 0, 'Νήσων μειωμένος Φ.Π.Α.', 1); +insert into llx_c_tva(rowid,fk_pays,taux,localtax1,localtax1_type,localtax2,localtax2_type,recuperableonly,note,active) values (2468, 102, 5, 0, '0', 0, '0', 0, 'Νήσων υπερμειωμένος Φ.Π.Α.', 1); + -- ICELAND (id country=116) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1161, 116,'25.5','0','VAT standard rate',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1162, 116, '7','0','VAT reduced rate',1); From fdd8d2cc5e8d3d523a5b5c0c2a68fc18037a2676 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 May 2013 01:30:39 +0200 Subject: [PATCH 06/33] Fix: to large a href --- htdocs/core/tpl/login.tpl.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index bef263763de..58710d9f0e4 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -136,22 +136,19 @@ if ($forgetpasslink || $helpcenterlink) if ($forgetpasslink) { echo '('; echo $langs->trans('PasswordForgotten'); - if (! $helpcenterlink) { - echo ')'; - } + if (! $helpcenterlink) echo ')'; echo ''; } + if ($forgetpasslink && $helpcenterlink) echo ' - '; + if ($helpcenterlink) { $url=DOL_URL_ROOT.'/support/index.php'.$moreparam; if (! empty($conf->global->MAIN_HELPCENTER_LINKTOUSE)) $url=$conf->global->MAIN_HELPCENTER_LINKTOUSE; echo ''; - if ($forgetpasslink) { - echo ' - '; - } else { - echo '('; - } - echo $langs->trans('NeedHelpCenter').')'; + if (! $forgetpasslink) echo '('; + echo $langs->trans('NeedHelpCenter'); + echo ')'; } echo ''; } From f7f59f962b3cc8f5372ef8c3158f65eefc7ef4b0 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Fri, 17 May 2013 10:35:42 +0200 Subject: [PATCH 07/33] missing translation for script --- htdocs/langs/en_US/bills.lang | 1 + htdocs/langs/fr_FR/bills.lang | 1 + scripts/invoices/email_unpaid_invoices_to_representatives.php | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index a76156142d6..e5df33ec55f 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -393,6 +393,7 @@ AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be ToMakePayment=Pay ToMakePaymentBack=Pay back ListOfYourUnpaidInvoices=List of unpaid invoices +NoteListOfYourUnpaidInvoices=Note: This list contains only invoices for third parties you are linked to as a sale representative. RevenueStamp=Revenue stamp ##### Types de contacts ##### TypeContact_facture_internal_SALESREPFOLL=Representative following-up customer invoice diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index adfa9a34bdc..2b18917442b 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -390,6 +390,7 @@ AllCompletelyPayedInvoiceWillBeClosed=Toutes les factures avec un reste à payer ToMakePayment=Payer ToMakePaymentBack=Rembourser ListOfYourUnpaidInvoices=Liste des factures impayées +NoteListOfYourUnpaidInvoices=Remarque: Cette liste ne contient que les Tiers dont vous êtes le commercial. RevenueStamp=Timbre fiscal ##### Types de contacts ##### TypeContact_facture_internal_SALESREPFOLL=Responsable suivi facture client diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 74ceed75729..3f4eac8e819 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -196,7 +196,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta else { $allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); - $allmessage.= "Note: This list contains only invoices for third parties you are linked to as a sale representative.".($usehtml?"
\n":"\n"); + $allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"
\n":"\n"); } $allmessage.= $message.($usehtml?"
\n":"\n"); $allmessage.= $langs->trans("Total")." = ".price($total).($usehtml?"
\n":"\n"); From bd92adf092163afae50f5aa9a018be19078f653a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 May 2013 11:20:44 +0200 Subject: [PATCH 08/33] Better trans --- htdocs/langs/fr_FR/bills.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 2b18917442b..debbe4f4d33 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -390,7 +390,7 @@ AllCompletelyPayedInvoiceWillBeClosed=Toutes les factures avec un reste à payer ToMakePayment=Payer ToMakePaymentBack=Rembourser ListOfYourUnpaidInvoices=Liste des factures impayées -NoteListOfYourUnpaidInvoices=Remarque: Cette liste ne contient que les Tiers dont vous êtes le commercial. +NoteListOfYourUnpaidInvoices=Remarque: Cette liste ne contient que les factures des Tiers pour lesquels vous êtes le commercial affecté. RevenueStamp=Timbre fiscal ##### Types de contacts ##### TypeContact_facture_internal_SALESREPFOLL=Responsable suivi facture client From 5acdbfa8f00a7e0a316a7628c9a32762413d43ae Mon Sep 17 00:00:00 2001 From: fhenry Date: Fri, 17 May 2013 14:45:54 +0200 Subject: [PATCH 09/33] Fix error management and SQL resquest in action comm --- htdocs/comm/action/class/actioncomm.class.php | 4 ++-- htdocs/comm/action/fiche.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 9b15634945e..067b36f989c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -188,8 +188,8 @@ class ActionComm extends CommonObject $sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").","; $sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").","; $sql.= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").","; - $sql.= " '".$this->type_id."',"; - $sql.= " '".$this->code."',"; + $sql.= (isset($this->type_id)?$this->type_id:"null"); + $sql.= (isset($this->code)?" '".$this->code."'":"null")."," ; $sql.= (isset($this->societe->id) && $this->societe->id > 0?" '".$this->societe->id."'":"null").","; $sql.= (isset($this->fk_project) && $this->fk_project > 0?" '".$this->fk_project."'":"null").","; $sql.= " '".$this->db->escape($this->note)."',"; diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 8b93bf23590..3a74a2881bf 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -243,6 +243,7 @@ if ($action == 'add_action') $db->rollback(); $langs->load("errors"); $error=$langs->trans($actioncomm->error); + setEventMessage($error,'errors'); $action = 'create'; } } @@ -251,6 +252,7 @@ if ($action == 'add_action') $db->rollback(); $langs->load("errors"); $error=$langs->trans($actioncomm->error); + setEventMessage($error,'errors'); $action = 'create'; } } @@ -277,6 +279,7 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') else { $mesg=$actioncomm->error; + setEventMessage($mesg,'errors'); } } } From e3615d43bd762a206ee2a5968edf886ceb4de0fa Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Fri, 17 May 2013 15:02:27 +0200 Subject: [PATCH 10/33] fix bug : external users should not see costprice and margin infos --- htdocs/core/class/commonobject.class.php | 7 ++++--- htdocs/core/tpl/objectline_view.tpl.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1b1466a664c..8b9e210b4f9 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2632,7 +2632,7 @@ abstract class CommonObject */ function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0, $hookmanager=false) { - global $conf,$langs; + global $conf,$langs,$user; print ''; if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) @@ -2646,7 +2646,7 @@ abstract class CommonObject print ' '; print ''.$langs->trans('Qty').''; print ''.$langs->trans('ReductionShort').''; - if (! empty($conf->margin->enabled)) { + if (! empty($conf->margin->enabled) && empty($user->societe_id)) { if ($conf->global->MARGIN_TYPE == "1") print ''.$langs->trans('BuyingPrice').''; else @@ -3044,7 +3044,8 @@ abstract class CommonObject } function displayMarginInfos($force_price=false) { - global $langs, $conf; + global $langs, $conf,$user; + if (! empty($user->societe_id)) return; $marginInfo = $this->getMarginInfos($force_price); print ''; print ''; diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index abaef7a1910..75620334a08 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -117,7 +117,7 @@ margin->enabled)) { + if (! empty($conf->margin->enabled) && empty($user->societe_id)) { ?> global->DISPLAY_MARGIN_RATES)) {?> From 7efe39495a0d5ec0416f515c1460d00117811940 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Fri, 17 May 2013 15:18:50 +0200 Subject: [PATCH 11/33] french translation for CostPrice --- htdocs/langs/fr_FR/margins.lang | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/fr_FR/margins.lang b/htdocs/langs/fr_FR/margins.lang index b30e79a3e7b..0ab270891b3 100644 --- a/htdocs/langs/fr_FR/margins.lang +++ b/htdocs/langs/fr_FR/margins.lang @@ -45,8 +45,8 @@ MargeBrute=Marge brute MargeNette=Marge nette MARGIN_TYPE_DETAILS=Marge brute : Prix de vente HT - Prix d'achat HT
Marge nette : Prix de vente HT - Coût de revient -CostPrice=Prix ​​d'achat -BuyingCost=Coût de revient +BuyingPrice=Prix ​​d'achat +CostPrice=Prix de revient UnitCharges=Charge unitaire Charges=Charges From 1c1736fa2000056d2d40e94f4fbad1f77a692741 Mon Sep 17 00:00:00 2001 From: fhenry Date: Fri, 17 May 2013 19:30:48 +0200 Subject: [PATCH 12/33] Fix bad Warning: Bad formed request converted PGSQL --- 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 e283c977f5f..5678936ea5d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -187,7 +187,7 @@ abstract class CommonObject $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.= "'".$this->db->idate($datecreate)."'"; $sql.= ", 4, '". $id_type_contact . "' "; $sql.= ")"; dol_syslog(get_class($this)."::add_contact sql=".$sql); From 1eddd869500a1a2b05bc807185b8dec0fe06405f Mon Sep 17 00:00:00 2001 From: fhenry Date: Fri, 17 May 2013 21:20:02 +0200 Subject: [PATCH 13/33] Fix Bad Formed Request PGSQL --- htdocs/fichinter/class/fichinter.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index a748ef0f549..213b3f4f075 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -1021,7 +1021,7 @@ class FichinterLigne $sql.= ' (fk_fichinter, description, date, duree, rang)'; $sql.= " VALUES (".$this->fk_fichinter.","; $sql.= " '".$this->db->escape($this->desc)."',"; - $sql.= " ".$this->db->idate($this->datei).","; + $sql.= " '".$this->db->idate($this->datei)."',"; $sql.= " ".$this->duration.","; $sql.= ' '.$rangToUse; $sql.= ')'; From e19e9e1c639ee632e07633295e2263d06f7c4c56 Mon Sep 17 00:00:00 2001 From: fhenry Date: Fri, 17 May 2013 21:27:15 +0200 Subject: [PATCH 14/33] Add dol_syslog --- htdocs/comm/propal/class/propal.class.php | 1 + htdocs/compta/facture/class/facture.class.php | 1 + 2 files changed, 2 insertions(+) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 7dc63fdace9..c8d0bfeebde 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2554,6 +2554,7 @@ class Propal extends CommonObject $sql.= ' WHERE pt.fk_propal = '.$this->id; $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; + dol_syslog(get_class($this).'::getLinesArray sql='.$sql,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e7276a46845..c45e52bec39 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3203,6 +3203,7 @@ class Facture extends CommonInvoice $sql.= ' WHERE l.fk_facture = '.$this->id; $sql.= ' ORDER BY l.rang ASC, l.rowid'; + dol_syslog(get_class($this).'::getLinesArray sql='.$sql,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { From 2879a09a03f204bf86429b9b1cf05593c124d6e1 Mon Sep 17 00:00:00 2001 From: simnandez Date: Sat, 18 May 2013 09:11:24 +0200 Subject: [PATCH 15/33] Fix: Remove windows CR/LF --- htdocs/comm/propal.php | 3812 ++++++++--------- .../core/tpl/freeproductline_create.tpl.php | 310 +- 2 files changed, 2061 insertions(+), 2061 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 19d9f89cc48..330585b1e9d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1,1907 +1,1907 @@ - - * Copyright (C) 2004-2013 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2012 Juanjo Menent - * Copyright (C) 2010-2011 Philippe Grand - * Copyright (C) 2012 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 - * 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/comm/propal.php - * \ingroup propale - * \brief Page of commercial proposals card and list - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php'; -require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - -$langs->load('companies'); -$langs->load('propal'); -$langs->load('compta'); -$langs->load('bills'); -$langs->load('orders'); -$langs->load('products'); -if (! empty($conf->margin->enabled)) - $langs->load('margins'); - -$error=0; - -$id=GETPOST('id','int'); -$ref=GETPOST('ref','alpha'); -$socid=GETPOST('socid','int'); -$action=GETPOST('action','alpha'); -$confirm=GETPOST('confirm','alpha'); -$lineid=GETPOST('lineid','int'); - -//PDF -$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); -$hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); -$hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); - -// Nombre de ligne pour choix de produit/service predefinis -$NBLINES=4; - -// Security check -if (! empty($user->societe_id)) $socid=$user->societe_id; -$result = restrictedArea($user, 'propal', $id); - -$object = new Propal($db); - -// Load object -if ($id > 0 || ! empty($ref)) -{ - if ($action != 'add') - { - $ret=$object->fetch($id, $ref); - if ($ret == 0) - { - $langs->load("errors"); - setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors'); - $error++; - } - else if ($ret < 0) - { - setEventMessage($object->error, 'errors'); - $error++; - } - else $object->fetch_thirdparty(); - } -} -else -{ - header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); - exit; -} - -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); -$hookmanager->initHooks(array('propalcard')); - - - -/* - * Actions - */ - -$parameters=array('socid'=>$socid); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - -// Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes') -{ - if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) - { - setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); - } - else - { - if ($object->id > 0) - { - $result=$object->createFromClone($socid, $hookmanager); - if ($result > 0) - { - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); - exit; - } - else - { - setEventMessage($object->error, 'errors'); - $action=''; - } - } - } -} - -// Suppression de la propale -else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) -{ - $result=$object->delete($user); - if ($result > 0) - { - header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); - exit; - } - else - { - $langs->load("errors"); - setEventMessage($langs->trans($object->error), 'errors'); - } -} - -// Remove line -else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) -{ - $result = $object->deleteline($lineid); - // reorder lines - if ($result) $object->line_order(true); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; -} - -// Validation -else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) -{ - $result=$object->valid($user); - if ($result >= 0) - { - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - } - else - { - $langs->load("errors"); - setEventMessage($langs->trans($object->error), 'errors'); - } -} - -else if ($action == 'setdate' && $user->rights->propal->creer) -{ - $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - - if (empty($datep)) - { - $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); - } - - if (! $error) - { - $result=$object->set_date($user,$datep); - if ($result < 0) dol_print_error($db,$object->error); - } -} -else if ($action == 'setecheance' && $user->rights->propal->creer) -{ - $result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); - if ($result < 0) dol_print_error($db,$object->error); -} -else if ($action == 'setdate_livraison' && $user->rights->propal->creer) -{ - $result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); - if ($result < 0) dol_print_error($db,$object->error); -} - -// Positionne ref client -else if ($action == 'set_ref_client' && $user->rights->propal->creer) -{ - $object->set_ref_client($user, $_POST['ref_client']); -} - -else if ($action == 'setnote_public' && $user->rights->propal->creer) -{ - $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); - if ($result < 0) dol_print_error($db,$object->error); -} - -else if ($action == 'setnote' && $user->rights->propal->creer) -{ - $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); - if ($result < 0) dol_print_error($db,$object->error); -} - -// Create proposal -else if ($action == 'add' && $user->rights->propal->creer) -{ - $object->socid=$socid; - $object->fetch_thirdparty(); - - $datep=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $date_delivery=dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); - $duration=GETPOST('duree_validite'); - - if (empty($datep)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); - header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); - exit; - } - if (empty($duration)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ValidityDuration")), 'errors'); - header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); - exit; - } - - if (! $error) - { - $db->begin(); - - // Si on a selectionne une propal a copier, on realise la copie - if (GETPOST('createmode')=='copy' && GETPOST('copie_propal')) - { - if ($object->fetch(GETPOST('copie_propal')) > 0) - { - $object->ref = GETPOST('ref'); - $object->datep = $datep; - $object->date_livraison = $date_delivery; - $object->availability_id = GETPOST('availability_id'); - $object->demand_reason_id = GETPOST('demand_reason_id'); - $object->fk_delivery_address = GETPOST('fk_address'); - $object->duree_validite = $duration; - $object->cond_reglement_id = GETPOST('cond_reglement_id'); - $object->mode_reglement_id = GETPOST('mode_reglement_id'); - $object->remise_percent = GETPOST('remise_percent'); - $object->remise_absolue = GETPOST('remise_absolue'); - $object->socid = GETPOST('socid'); - $object->contactid = GETPOST('contactidp'); - $object->fk_project = GETPOST('projectid'); - $object->modelpdf = GETPOST('model'); - $object->author = $user->id; // deprecated - $object->note = GETPOST('note'); - $object->statut = 0; - - $id = $object->create_from($user); - } - else - { - setEventMessage($langs->trans("ErrorFailedToCopyProposal",GETPOST('copie_propal')), 'errors'); - } - } - else - { - $object->ref = GETPOST('ref'); - $object->ref_client = GETPOST('ref_client'); - $object->datep = $datep; - $object->date_livraison = $date_delivery; - $object->availability_id = GETPOST('availability_id'); - $object->demand_reason_id = GETPOST('demand_reason_id'); - $object->fk_delivery_address = GETPOST('fk_address'); - $object->duree_validite = GETPOST('duree_validite'); - $object->cond_reglement_id = GETPOST('cond_reglement_id'); - $object->mode_reglement_id = GETPOST('mode_reglement_id'); - - $object->contactid = GETPOST('contactidp'); - $object->fk_project = GETPOST('projectid'); - $object->modelpdf = GETPOST('model'); - $object->author = $user->id; // deprecated - $object->note = GETPOST('note'); - - $object->origin = GETPOST('origin'); - $object->origin_id = GETPOST('originid'); - - for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) - { - if ($_POST['idprod'.$i]) - { - $xid = 'idprod'.$i; - $xqty = 'qty'.$i; - $xremise = 'remise'.$i; - $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); - } - } - - $id = $object->create($user); - } - - if ($id > 0) - { - // Insertion contact par defaut si defini - if (GETPOST('contactidp')) - { - $result=$object->add_contact(GETPOST('contactidp'),'CUSTOMER','external'); - if ($result < 0) - { - $error++; - setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); - } - } - - if (! $error) - { - $db->commit(); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } - else - { - $db->rollback(); - } - } - else - { - dol_print_error($db,$object->error); - $db->rollback(); - exit; - } - } -} - -// Classify billed -else if ($action == 'classifybilled' && $user->rights->propal->cloturer) -{ - $object->cloture($user, 4, ''); -} - -// Reopen proposal -else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel')) -{ - // prevent browser refresh from reopening proposal several times - if ($object->statut==2 || $object->statut==3) - { - $object->setStatut(1); - } -} - -// Close proposal -else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel')) -{ - if (! GETPOST('statut')) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("CloseAs")), 'errors'); - $action='statut'; - } - else - { - // prevent browser refresh from closing proposal several times - if ($object->statut==1) - { - $object->cloture($user, GETPOST('statut'), GETPOST('note')); - } - } -} - -/* - * Add file in email form - */ -if (GETPOST('addfile')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory TODO Use a dedicated directory for temp mails files - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - dol_add_file_process($upload_dir_tmp,0,0); - $action='presend'; -} - -/* - * Remove file in email form - */ -if (GETPOST('removedfile')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - // TODO Delete only files that was uploaded from email form - dol_remove_file_process($_POST['removedfile'],0); - $action='presend'; -} - -/* - * Send mail - */ -if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) -{ - $langs->load('mails'); - - if ($object->id > 0) - { - if ($_POST['sendto']) - { - // Le destinataire a ete fourni via le champ libre - $sendto = $_POST['sendto']; - $sendtoid = 0; - } - elseif ($_POST['receiver'] != '-1') - { - // Recipient was provided from combo list - if ($_POST['receiver'] == 'thirdparty') // Id of third party - { - $sendto = $object->client->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); - $sendtoid = $_POST['receiver']; - } - } - - if (dol_strlen($sendto)) - { - $langs->load("commercial"); - - $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; - $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; - $message = $_POST['message']; - $sendtocc = $_POST['sendtocc']; - $deliveryreceipt = $_POST['deliveryreceipt']; - - if (dol_strlen($_POST['subject'])) $subject = $_POST['subject']; - else $subject = $langs->transnoentities('Propal').' '.$object->ref; - $actiontypecode='AC_PROP'; - $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; - if ($message) - { - $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; - $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; - $actionmsg.=$message; - } - $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); - - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - - $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - - // Envoi de la propal - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); - if ($mailfile->error) - { - setEventMessage($mailfile->error, 'errors'); - } - else - { - $result=$mailfile->sendfile(); - if ($result) - { - // Initialisation donnees - $object->sendtoid = $sendtoid; - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; - $object->actionmsg2 = $actionmsg2; - $object->fk_element = $object->id; - $object->elementtype = $object->element; - - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers('PROPAL_SENTBYMAIL',$object,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - - if (! $error) - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); - setEventMessage($mesg); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - dol_print_error($db); - } - } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; - } - else - { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } - setEventMessage($mesg, 'errors'); - } - } - } - else - { - $langs->load("other"); - setEventMessage($langs->trans('ErrorMailRecipientIsEmpty').'!', 'errors'); - dol_syslog($langs->trans('ErrorMailRecipientIsEmpty')); - } - } - else - { - $langs->load("other"); - setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")), 'errors'); - dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal"))); - } -} - -// Go back to draft -if ($action == 'modif' && $user->rights->propal->creer) -{ - $object->set_draft($user); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } -} - -else if ($action == "setabsolutediscount" && $user->rights->propal->creer) -{ - if ($_POST["remise_id"]) - { - if ($object->id > 0) - { - $result=$object->insert_discount($_POST["remise_id"]); - if ($result < 0) - { - setEventMessage($object->error, 'errors'); - } - } - } -} - -//Ajout d'une ligne produit dans la propale -else if ($action == "addline" && $user->rights->propal->creer) -{ - $idprod=GETPOST('idprod', 'int'); - $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):''))); - $price_ht = GETPOST('price_ht'); - $tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0); - - if (empty($idprod) && GETPOST('type') < 0) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); - $error++; - } - if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht != 0) || $price_ht == '')) // Unit price can be 0 but not ''. Also price can be negative for proposal. - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); - $error++; - } - if (empty($idprod) && empty($product_desc)) - { - setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), 'errors'); - $error++; - } - - if (! $error && (GETPOST('qty') >= 0) && (! empty($product_desc) || ! empty($idprod))) - { - $pu_ht=0; - $pu_ttc=0; - $price_min=0; - $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); - - // Ecrase $pu par celui du produit - // Ecrase $desc par celui du produit - // Ecrase $txtva par celui du produit - if (! empty($idprod)) - { - $prod = new Product($db); - $prod->fetch($idprod); - - $label = ((GETPOST('product_label') && GETPOST('product_label')!=$prod->label)?GETPOST('product_label'):''); - - // If prices fields are update - if (GETPOST('usenewaddlineform')) - { - $pu_ht=price2num($price_ht, 'MU'); - $pu_ttc=price2num(GETPOST('price_ttc'), 'MU'); - $tva_npr=(preg_match('/\*/', $tva_tx)?1:0); - $tva_tx=str_replace('*','', $tva_tx); - $desc = $product_desc; - } - else - { - $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); - $tva_npr = get_default_npr($mysoc,$object->client,$prod->id); - - // On defini prix unitaire - if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level) - { - $pu_ht = $prod->multiprices[$object->client->price_level]; - $pu_ttc = $prod->multiprices_ttc[$object->client->price_level]; - $price_min = $prod->multiprices_min[$object->client->price_level]; - $price_base_type = $prod->multiprices_base_type[$object->client->price_level]; - } - else - { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_min = $prod->price_min; - $price_base_type = $prod->price_base_type; - } - - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $prod->tva_tx) - { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); - } - } - - $desc=''; - - // Define output language - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { - $outputlangs = $langs; - $newlang=''; - if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); - if (empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - - $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description; - } - else - { - $desc = $prod->description; - } - - $desc=dol_concatdesc($desc,$product_desc); - - // Add custom code and origin country into description - if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) - { - $tmptxt='('; - if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode; - if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - '; - if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0); - $tmptxt.=')'; - $desc= dol_concatdesc($desc, $tmptxt); - } - } - - $type = $prod->type; - } - else - { - $pu_ht = price2num($price_ht, 'MU'); - $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); - $tva_npr = (preg_match('/\*/', $tva_tx)?1:0); - $tva_tx = str_replace('*', '', $tva_tx); - $label = (GETPOST('product_label')?GETPOST('product_label'):''); - $desc = $product_desc; - $type = GETPOST('type'); - } - - // Margin - $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); - $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); - - // Local Taxes - $localtax1_tx= get_localtax($tva_tx, 1, $object->client); - $localtax2_tx= get_localtax($tva_tx, 2, $object->client); - - $info_bits=0; - if ($tva_npr) $info_bits |= 0x01; - - if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) - { - $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').getCurrencySymbol($conf->currency)); - setEventMessage($mesg, 'errors'); - } - else - { - // Insert line - $result=$object->addline( - $id, - $desc, - $pu_ht, - GETPOST('qty'), - $tva_tx, - $localtax1_tx, - $localtax2_tx, - $idprod, - GETPOST('remise_percent'), - $price_base_type, - $pu_ttc, - $info_bits, - $type, - -1, - 0, - GETPOST('fk_parent_line'), - $fournprice, - $buyingprice, - $label - ); - - if ($result > 0) - { - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['idprod']); - unset($_POST['remise_percent']); - unset($_POST['price_ht']); - unset($_POST['price_ttc']); - unset($_POST['tva_tx']); - unset($_POST['product_ref']); - unset($_POST['product_label']); - unset($_POST['product_desc']); - unset($_POST['fournprice']); - unset($_POST['buying_price']); - - // old method - unset($_POST['np_desc']); - unset($_POST['dp_desc']); - } - else - { - setEventMessage($object->error, 'errors'); - } - } - } -} - -// Mise a jour d'une ligne dans la propale -else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save') == $langs->trans("Save")) -{ - // Define info_bits - $info_bits=0; - if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; - - // Clean parameters - $description=dol_htmlcleanlastbr(GETPOST('product_desc')); - - // Define vat_rate - $vat_rate=(GETPOST('tva_tx')?GETPOST('tva_tx'):0); - $vat_rate=str_replace('*','',$vat_rate); - $localtax1_rate=get_localtax($vat_rate,1,$object->client); - $localtax2_rate=get_localtax($vat_rate,2,$object->client); - $pu_ht=GETPOST('price_ht'); - - // Add buying price - $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); - $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); - - // Define special_code for special lines - $special_code=0; - if (! GETPOST('qty')) $special_code=3; - - // Check minimum price - $productid = GETPOST('productid', 'int'); - if (! empty($productid)) - { - $product = new Product($db); - $res=$product->fetch($productid); - - $type=$product->type; - - $price_min = $product->price_min; - if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) - $price_min = $product->multiprices_min[$object->client->price_level]; - - $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):''); - - if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) - { - setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min,'MU')).getCurrencySymbol($conf->currency), 'errors'); - $error++; - } - } - else - { - $type = GETPOST('type'); - $label = (GETPOST('product_label') ? GETPOST('product_label'):''); - - // Check parameters - if (GETPOST('type') < 0) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); - $error++; - } - } - - if (! $error) - { - $result = $object->updateline( - GETPOST('lineid'), - $pu_ht, - GETPOST('qty'), - GETPOST('remise_percent'), - $vat_rate, - $localtax1_rate, - $localtax2_rate, - $description, - 'HT', - $info_bits, - $special_code, - GETPOST('fk_parent_line'), - 0, - $fournprice, - $buyingprice, - $label, - $type - ); - - if ($result >= 0) - { - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['productid']); - unset($_POST['remise_percent']); - unset($_POST['price_ht']); - unset($_POST['price_ttc']); - unset($_POST['tva_tx']); - unset($_POST['product_ref']); - unset($_POST['product_label']); - unset($_POST['product_desc']); - unset($_POST['fournprice']); - unset($_POST['buying_price']); - } - else - { - setEventMessage($object->error, 'errors'); - } - } -} - -else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel') == $langs->trans('Cancel')) -{ - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition - exit; -} - -// Generation doc (depuis lien ou depuis cartouche doc) -else if ($action == 'builddoc' && $user->rights->propal->creer) -{ - if (GETPOST('model')) - { - $object->setDocModel($user, GETPOST('model')); - } - - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - $result=propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } -} - -// Remove file in doc form -else if ($action == 'remove_file' && $user->rights->propal->creer) -{ - if ($object->id > 0) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - $langs->load("other"); - $upload_dir = $conf->propal->dir_output; - $file = $upload_dir . '/' . GETPOST('file'); - $ret=dol_delete_file($file,0,0,0,$object); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); - } -} - -// Set project -else if ($action == 'classin' && $user->rights->propal->creer) -{ - $object->setProject($_POST['projectid']); -} - -// Delai de livraison -else if ($action == 'setavailability' && $user->rights->propal->creer) -{ - $result = $object->availability($_POST['availability_id']); -} - -// Origine de la propale -else if ($action == 'setdemandreason' && $user->rights->propal->creer) -{ - $result = $object->demand_reason($_POST['demand_reason_id']); -} - -// Conditions de reglement -else if ($action == 'setconditions' && $user->rights->propal->creer) -{ - $result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int')); -} - -else if ($action == 'setremisepercent' && $user->rights->propal->creer) -{ - $result = $object->set_remise_percent($user, $_POST['remise_percent']); -} - -else if ($action == 'setremiseabsolue' && $user->rights->propal->creer) -{ - $result = $object->set_remise_absolue($user, $_POST['remise_absolue']); -} - -// Mode de reglement -else if ($action == 'setmode' && $user->rights->propal->creer) -{ - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); -} - -/* - * Ordonnancement des lignes - */ - -else if ($action == 'up' && $user->rights->propal->creer) -{ - $object->line_up(GETPOST('rowid')); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); - exit; -} - -else if ($action == 'down' && $user->rights->propal->creer) -{ - $object->line_down(GETPOST('rowid')); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) - { - $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); - exit; -} - -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) -{ - if ($action == 'addcontact') - { - if ($object->id > 0) - { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); - } - - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else - { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $langs->load("errors"); - setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors'); - } - else - { - setEventMessage($object->error, 'errors'); - } - } - } - - // Bascule du statut d'un contact - else if ($action == 'swapstatut') - { - if ($object->fetch($id) > 0) - { - $result=$object->swapContactStatus(GETPOST('ligne')); - } - else - { - dol_print_error($db); - } - } - - // Efface un contact - else if ($action == 'deletecontact') - { - $object->fetch($id); - $result = $object->delete_contact($lineid); - - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else - { - dol_print_error($db); - } - } -} - - -/* - * View - */ - -llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); - -$form = new Form($db); -$formother = new FormOther($db); -$formfile = new FormFile($db); -$formpropal = new FormPropal($db); -$companystatic=new Societe($db); - -$now=dol_now(); - -/* - * Show object in view mode - */ - -$soc = new Societe($db); -$soc->fetch($object->socid); - -$head = propal_prepare_head($object); -dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal'); - -$formconfirm=''; - -// Clone confirmation -if ($action == 'clone') -{ - // Create an array for form - $formquestion=array( - //'text' => $langs->trans("ConfirmClone"), - //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), - //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), - array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)')) - ); - // Paiement incomplet. On demande si motif = escompte ou autre - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1); -} - -// Confirm delete -else if ($action == 'delete') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1); -} - -// Confirm reopen -else if ($action == 'reopen') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1); -} - -// Confirmation delete product/service line -else if ($action == 'ask_deleteline') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); -} - -// Confirm validate proposal -else if ($action == 'validate') -{ - $error=0; - - // on verifie si l'objet est en numerotation provisoire - $ref = substr($object->ref, 1, 4); - if ($ref == 'PROV') - { - $numref = $object->getNextNumRef($soc); - if (empty($numref)) - { - $error++; - dol_htmloutput_errors($object->error); - } - } - else - { - $numref = $object->ref; - } - - $text=$langs->trans('ConfirmValidateProp',$numref); - if (! empty($conf->notification->enabled)) - { - require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; - $notify=new Notify($db); - $text.='
'; - $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid); - } - - if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); -} - -if (! $formconfirm) -{ - $parameters=array('lineid'=>$lineid); - $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook -} - -// Print form confirm -print $formconfirm; - - -print '
  pa_ht); ?>
'; - -$linkback = ''.$langs->trans("BackToList").''; - -// Ref -print ''; - -// Ref client -print ''; -print ''; - -// Company -print ''; -print ''; - -// Ligne info remises tiers -print ''; - -// Date of proposal -print ''; -print ''; - -// Date end proposal -print ''; -print ''; -print ''; - -// Payment term -print ''; -print ''; - -// Delivery date -$langs->load('deliveries'); -print ''; -print ''; - -// Delivery delay -print ''; -print ''; - -// Origin of demand -print ''; -print ''; - -// Payment mode -print ''; -print ''; - -// Project -if (! empty($conf->projet->enabled)) -{ - $langs->load("projects"); - print ''; - } - else - { - print '
'.$langs->trans('Ref').''; -print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); -print '
'; -print ''; -if ($action != 'refclient' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('RefCustomer').''; -print ''.img_edit($langs->trans('Modify')).'
'; -print '
'; -if ($user->rights->propal->creer && $action == 'refclient') -{ - print '
'; - print ''; - print ''; - print ''; - print ' '; - print '
'; -} -else -{ - print $object->ref_client; -} -print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans('Discounts').''; -if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); -else print $langs->trans("CompanyHasNoRelativeDiscount"); -print '. '; -$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); -$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); -$absolute_discount=price2num($absolute_discount,'MT'); -$absolute_creditnote=price2num($absolute_creditnote,'MT'); -if ($absolute_discount) -{ - if ($object->statut > 0) - { - print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); - } - else - { - // Remise dispo de type non avoir - $filter='fk_facture_source IS NULL'; - print '
'; - $form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter); - } -} -if ($absolute_creditnote) -{ - print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. '; -} -if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; -print '
'; -print ''; -if ($action != 'editdate' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('Date'); -print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; -print '
'; -if (! empty($object->brouillon) && $action == 'editdate') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->date,'re','','',0,"editdate"); - print ''; - print '
'; -} -else -{ - if ($object->date) - { - print dol_print_date($object->date,'daytext'); - } - else - { - print ' '; - } -} -print '
'; -print ''; -if ($action != 'editecheance' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('DateEndPropal'); -print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; -print '
'; -if (! empty($object->brouillon) && $action == 'editecheance') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->fin_validite,'ech','','','',"editecheance"); - print ''; - print '
'; -} -else -{ - if (! empty($object->fin_validite)) - { - print dol_print_date($object->fin_validite,'daytext'); - if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); - } - else - { - print ' '; - } -} -print '
'; -print ''; -if ($action != 'editconditions' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('PaymentConditionsShort'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'
'; -print '
'; -if ($action == 'editconditions') -{ - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); -} -else -{ - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); -} -print '
'; -print ''; -if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('DeliveryDate'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'
'; -print '
'; -if ($action == 'editdate_livraison') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison"); - print ''; - print '
'; -} -else -{ - print dol_print_date($object->date_livraison,'daytext'); -} -print '
'; -print ''; -if ($action != 'editavailability' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('AvailabilityPeriod'); -if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')'; -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'
'; -print '
'; -if ($action == 'editavailability') -{ - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1); -} -else -{ - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1); -} - -print '
'; -print ''; -if ($action != 'editdemandreason' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('Source'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'
'; -print '
'; -//print $object->demand_reason_id; -if ($action == 'editdemandreason') -{ - $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1); -} -else -{ - $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none'); -} - -print '
'; -print ''; -if ($action != 'editmode' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('PaymentMode'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'
'; -print '
'; -if ($action == 'editmode') -{ - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); -} -else -{ - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); -} -print '
'; - print ''; - if ($user->rights->propal->creer) - { - if ($action != 'classify') print ''; - print '
'; - print $langs->trans('Project').''.img_edit($langs->transnoentitiesnoconv('SetProject')).'
'; - print '
'; - if ($action == 'classify') - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); - } - else - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none'); - } - print '
'; - if (! empty($object->fk_project)) - { - print ''; - $proj = new Project($db); - $proj->fetch($object->fk_project); - print ''; - print $proj->ref; - print ''; - print ''; - } - else { - print ' '; - } - } - print ''; -} - -// Other attributes -$parameters=array('colspan' => ' colspan="3"'); -$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook -if (empty($reshook) && ! empty($extrafields->attribute_label)) -{ - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } -} - -// Amount HT -print ''.$langs->trans('AmountHT').''; -print ''.price($object->total_ht).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Margin Infos -if (! empty($conf->margin->enabled)) { - print ''; - $object->displayMarginInfos(); - print ''; -} -print ''; - -// Amount VAT -print ''.$langs->trans('AmountVAT').''; -print ''.price($object->total_tva).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Amount Local Taxes -if ($mysoc->localtax1_assuj=="1") //Localtax1 -{ - print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).''; - print ''.price($object->total_localtax1).''; - print ''.$langs->trans("Currency".$conf->currency).''; -} -if ($mysoc->localtax2_assuj=="1") //Localtax2 -{ - print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).''; - print ''.price($object->total_localtax2).''; - print ''.$langs->trans("Currency".$conf->currency).''; -} - - -// Amount TTC -print ''.$langs->trans('AmountTTC').''; -print ''.price($object->total_ttc).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Statut -print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; - -print '
'; - -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) -{ - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; -} - -if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) -{ - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; -} - -/* - * Lines - */ - -if (! empty($conf->use_javascript_ajax) && $object->statut == 0) -{ - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; -} - -print ''; - -// Show object lines -$result = $object->getLinesArray(); -if (! empty($object->lines)) - $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager); - -// Form to add new line -if ($object->statut == 0 && $user->rights->propal->creer) -{ - if ($action != 'editline') - { - $var=true; - - if ($conf->global->MAIN_FEATURES_LEVEL > 1) - { - // Add free or predefined products/services - $object->formAddObjectLine(0,$mysoc,$soc,$hookmanager); - } - else - { - // Add free products/services - $object->formAddFreeProduct(0,$mysoc,$soc,$hookmanager); - - // Add predefined products/services - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) - { - $var=!$var; - $object->formAddPredefinedProduct(0,$mysoc,$soc,$hookmanager); - } - } - - $parameters=array(); - $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - } -} - -print '
'; - -print ''; -print "\n"; - -if ($action == 'statut') -{ - /* - * Formulaire cloture (signe ou non) - */ - $form_close = '
'; - $form_close.= ''; - $form_close.= ''; - $form_close.= ''; - $form_close.= ''; - $form_close.= ''; - $form_close.= '
'.$langs->trans("CloseAs").''; - $form_close.= ''; - $form_close.= ''; - $form_close.= '
'.$langs->trans('Note').'
'; - $form_close.= ''; - $form_close.= '   '; - $form_close.= ' '; - $form_close.= '
'; - - print $form_close; -} - - -/* - * Boutons Actions - */ -if ($action != 'presend') -{ - print '
'; - - if ($action != 'statut' && $action <> 'editline') - { - // Validate - if ($object->statut == 0 && $user->rights->propal->valider) - { - if (count($object->lines) > 0) print ''.$langs->trans('Validate').''; - else print ''.$langs->trans('Validate').''; - } - - // Edit - if ($object->statut == 1 && $user->rights->propal->creer) - { - print ''.$langs->trans('Modify').''; - } - - // ReOpen - if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) - { - print 'global->MAIN_JUMP_TAG)?'':'#reopen').'"'; - print '>'.$langs->trans('ReOpen').''; - } - - // Send - if ($object->statut == 1 || $object->statut == 2) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; - } - - // Create an order - if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0) - { - if ($user->rights->commande->creer) - { - print ''.$langs->trans("AddOrder").''; - } - } - - // Create an invoice and classify billed - if ($object->statut == 2 && $user->societe_id == 0) - { - if (! empty($conf->facture->enabled) && $user->rights->facture->creer) - { - print ''.$langs->trans("AddBill").''; - } - - $arraypropal=$object->getInvoiceArrayList(); - if (is_array($arraypropal) && count($arraypropal) > 0) - { - print 'socid.'">'.$langs->trans("ClassifyBilled").''; - } - } - - // Close - if ($object->statut == 1 && $user->rights->propal->cloturer) - { - print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; - print '>'.$langs->trans('Close').''; - } - - // Clone - if ($user->rights->propal->creer) - { - print ''.$langs->trans("ToClone").''; - } - - // Delete - if ($user->rights->propal->supprimer) - { - print ''.$langs->trans('Delete').''; - } - - } - - print '
'; - print "
\n"; -} - -if ($action != 'presend') -{ - print '
'; - print ''; // ancre - - - /* - * Documents generes - */ - $filename=dol_sanitizeFileName($object->ref); - $filedir=$conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); - $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed=$user->rights->propal->creer; - $delallowed=$user->rights->propal->supprimer; - - $var=true; - - $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'',0,'',$soc->default_lang,$hookmanager); - - - /* - * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); - - print ''; - - // List of actions on element - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - $somethingshown=$formactions->showactions($object,'propal',$socid); - - print '
'; -} - - -/* - * Action presend - * - */ -if ($action == 'presend') -{ - $ref = dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref,'/')); - $file=$fileparams['fullname']; - - // Build document if it not exists - if (! $file || ! is_readable($file)) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - - $result=propale_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref,'/')); - $file=$fileparams['fullname']; - } - - print '
'; - print_titre($langs->trans('SendPropalByMail')); - - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->fromtype = 'user'; - $formmail->fromid = $user->id; - $formmail->fromname = $user->getFullName($langs); - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; - $formmail->withtosocid=$soc->id; - $formmail->withtocc=1; - $formmail->withtoccsocid=0; - $formmail->withtoccc=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false); - $formmail->withtocccsocid=0; - $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__'); - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; - - // Tableau des substitutions - $formmail->substit['__PROPREF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - // Tableau des parametres complementaires - $formmail->param['action']='send'; - $formmail->param['models']='propal_send'; - $formmail->param['id']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - - // Init list of files - if (GETPOST("mode")=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); - } - - $formmail->show_form(); - - print '
'; -} - - -// End of page -llxFooter(); -$db->close(); + + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2010-2011 Philippe Grand + * Copyright (C) 2012 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 + * 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/comm/propal.php + * \ingroup propale + * \brief Page of commercial proposals card and list + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php'; +require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + +$langs->load('companies'); +$langs->load('propal'); +$langs->load('compta'); +$langs->load('bills'); +$langs->load('orders'); +$langs->load('products'); +if (! empty($conf->margin->enabled)) + $langs->load('margins'); + +$error=0; + +$id=GETPOST('id','int'); +$ref=GETPOST('ref','alpha'); +$socid=GETPOST('socid','int'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); +$lineid=GETPOST('lineid','int'); + +//PDF +$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); +$hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); +$hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); + +// Nombre de ligne pour choix de produit/service predefinis +$NBLINES=4; + +// Security check +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result = restrictedArea($user, 'propal', $id); + +$object = new Propal($db); + +// Load object +if ($id > 0 || ! empty($ref)) +{ + if ($action != 'add') + { + $ret=$object->fetch($id, $ref); + if ($ret == 0) + { + $langs->load("errors"); + setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors'); + $error++; + } + else if ($ret < 0) + { + setEventMessage($object->error, 'errors'); + $error++; + } + else $object->fetch_thirdparty(); + } +} +else +{ + header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); + exit; +} + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('propalcard')); + + + +/* + * Actions + */ + +$parameters=array('socid'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + +// Action clone object +if ($action == 'confirm_clone' && $confirm == 'yes') +{ + if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) + { + setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); + } + else + { + if ($object->id > 0) + { + $result=$object->createFromClone($socid, $hookmanager); + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); + exit; + } + else + { + setEventMessage($object->error, 'errors'); + $action=''; + } + } + } +} + +// Suppression de la propale +else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) +{ + $result=$object->delete($user); + if ($result > 0) + { + header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); + exit; + } + else + { + $langs->load("errors"); + setEventMessage($langs->trans($object->error), 'errors'); + } +} + +// Remove line +else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) +{ + $result = $object->deleteline($lineid); + // reorder lines + if ($result) $object->line_order(true); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; +} + +// Validation +else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) +{ + $result=$object->valid($user); + if ($result >= 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + } + else + { + $langs->load("errors"); + setEventMessage($langs->trans($object->error), 'errors'); + } +} + +else if ($action == 'setdate' && $user->rights->propal->creer) +{ + $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + + if (empty($datep)) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); + } + + if (! $error) + { + $result=$object->set_date($user,$datep); + if ($result < 0) dol_print_error($db,$object->error); + } +} +else if ($action == 'setecheance' && $user->rights->propal->creer) +{ + $result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); + if ($result < 0) dol_print_error($db,$object->error); +} +else if ($action == 'setdate_livraison' && $user->rights->propal->creer) +{ + $result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); + if ($result < 0) dol_print_error($db,$object->error); +} + +// Positionne ref client +else if ($action == 'set_ref_client' && $user->rights->propal->creer) +{ + $object->set_ref_client($user, $_POST['ref_client']); +} + +else if ($action == 'setnote_public' && $user->rights->propal->creer) +{ + $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); + if ($result < 0) dol_print_error($db,$object->error); +} + +else if ($action == 'setnote' && $user->rights->propal->creer) +{ + $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); + if ($result < 0) dol_print_error($db,$object->error); +} + +// Create proposal +else if ($action == 'add' && $user->rights->propal->creer) +{ + $object->socid=$socid; + $object->fetch_thirdparty(); + + $datep=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $date_delivery=dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); + $duration=GETPOST('duree_validite'); + + if (empty($datep)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); + header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); + exit; + } + if (empty($duration)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ValidityDuration")), 'errors'); + header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); + exit; + } + + if (! $error) + { + $db->begin(); + + // Si on a selectionne une propal a copier, on realise la copie + if (GETPOST('createmode')=='copy' && GETPOST('copie_propal')) + { + if ($object->fetch(GETPOST('copie_propal')) > 0) + { + $object->ref = GETPOST('ref'); + $object->datep = $datep; + $object->date_livraison = $date_delivery; + $object->availability_id = GETPOST('availability_id'); + $object->demand_reason_id = GETPOST('demand_reason_id'); + $object->fk_delivery_address = GETPOST('fk_address'); + $object->duree_validite = $duration; + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->remise_percent = GETPOST('remise_percent'); + $object->remise_absolue = GETPOST('remise_absolue'); + $object->socid = GETPOST('socid'); + $object->contactid = GETPOST('contactidp'); + $object->fk_project = GETPOST('projectid'); + $object->modelpdf = GETPOST('model'); + $object->author = $user->id; // deprecated + $object->note = GETPOST('note'); + $object->statut = 0; + + $id = $object->create_from($user); + } + else + { + setEventMessage($langs->trans("ErrorFailedToCopyProposal",GETPOST('copie_propal')), 'errors'); + } + } + else + { + $object->ref = GETPOST('ref'); + $object->ref_client = GETPOST('ref_client'); + $object->datep = $datep; + $object->date_livraison = $date_delivery; + $object->availability_id = GETPOST('availability_id'); + $object->demand_reason_id = GETPOST('demand_reason_id'); + $object->fk_delivery_address = GETPOST('fk_address'); + $object->duree_validite = GETPOST('duree_validite'); + $object->cond_reglement_id = GETPOST('cond_reglement_id'); + $object->mode_reglement_id = GETPOST('mode_reglement_id'); + + $object->contactid = GETPOST('contactidp'); + $object->fk_project = GETPOST('projectid'); + $object->modelpdf = GETPOST('model'); + $object->author = $user->id; // deprecated + $object->note = GETPOST('note'); + + $object->origin = GETPOST('origin'); + $object->origin_id = GETPOST('originid'); + + for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) + { + if ($_POST['idprod'.$i]) + { + $xid = 'idprod'.$i; + $xqty = 'qty'.$i; + $xremise = 'remise'.$i; + $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); + } + } + + $id = $object->create($user); + } + + if ($id > 0) + { + // Insertion contact par defaut si defini + if (GETPOST('contactidp')) + { + $result=$object->add_contact(GETPOST('contactidp'),'CUSTOMER','external'); + if ($result < 0) + { + $error++; + setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); + } + } + + if (! $error) + { + $db->commit(); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit; + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db,$object->error); + $db->rollback(); + exit; + } + } +} + +// Classify billed +else if ($action == 'classifybilled' && $user->rights->propal->cloturer) +{ + $object->cloture($user, 4, ''); +} + +// Reopen proposal +else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel')) +{ + // prevent browser refresh from reopening proposal several times + if ($object->statut==2 || $object->statut==3) + { + $object->setStatut(1); + } +} + +// Close proposal +else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel')) +{ + if (! GETPOST('statut')) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("CloseAs")), 'errors'); + $action='statut'; + } + else + { + // prevent browser refresh from closing proposal several times + if ($object->statut==1) + { + $object->cloture($user, GETPOST('statut'), GETPOST('note')); + } + } +} + +/* + * Add file in email form + */ +if (GETPOST('addfile')) +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory TODO Use a dedicated directory for temp mails files + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + dol_add_file_process($upload_dir_tmp,0,0); + $action='presend'; +} + +/* + * Remove file in email form + */ +if (GETPOST('removedfile')) +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + // TODO Delete only files that was uploaded from email form + dol_remove_file_process($_POST['removedfile'],0); + $action='presend'; +} + +/* + * Send mail + */ +if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) +{ + $langs->load('mails'); + + if ($object->id > 0) + { + if ($_POST['sendto']) + { + // Le destinataire a ete fourni via le champ libre + $sendto = $_POST['sendto']; + $sendtoid = 0; + } + elseif ($_POST['receiver'] != '-1') + { + // Recipient was provided from combo list + if ($_POST['receiver'] == 'thirdparty') // Id of third party + { + $sendto = $object->client->email; + $sendtoid = 0; + } + else // Id du contact + { + $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); + $sendtoid = $_POST['receiver']; + } + } + + if (dol_strlen($sendto)) + { + $langs->load("commercial"); + + $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; + $message = $_POST['message']; + $sendtocc = $_POST['sendtocc']; + $deliveryreceipt = $_POST['deliveryreceipt']; + + if (dol_strlen($_POST['subject'])) $subject = $_POST['subject']; + else $subject = $langs->transnoentities('Propal').' '.$object->ref; + $actiontypecode='AC_PROP'; + $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; + if ($message) + { + $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; + $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; + $actionmsg.=$message; + } + $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); + + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Envoi de la propal + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); + if ($mailfile->error) + { + setEventMessage($mailfile->error, 'errors'); + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + // Initialisation donnees + $object->sendtoid = $sendtoid; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; + $object->actionmsg2 = $actionmsg2; + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('PROPAL_SENTBYMAIL',$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + + if (! $error) + { + // Redirect here + // This avoid sending mail twice if going out and then back to page + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); + setEventMessage($mesg); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + dol_print_error($db); + } + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + setEventMessage($mesg, 'errors'); + } + } + } + else + { + $langs->load("other"); + setEventMessage($langs->trans('ErrorMailRecipientIsEmpty').'!', 'errors'); + dol_syslog($langs->trans('ErrorMailRecipientIsEmpty')); + } + } + else + { + $langs->load("other"); + setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")), 'errors'); + dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal"))); + } +} + +// Go back to draft +if ($action == 'modif' && $user->rights->propal->creer) +{ + $object->set_draft($user); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } +} + +else if ($action == "setabsolutediscount" && $user->rights->propal->creer) +{ + if ($_POST["remise_id"]) + { + if ($object->id > 0) + { + $result=$object->insert_discount($_POST["remise_id"]); + if ($result < 0) + { + setEventMessage($object->error, 'errors'); + } + } + } +} + +//Ajout d'une ligne produit dans la propale +else if ($action == "addline" && $user->rights->propal->creer) +{ + $idprod=GETPOST('idprod', 'int'); + $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):''))); + $price_ht = GETPOST('price_ht'); + $tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0); + + if (empty($idprod) && GETPOST('type') < 0) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); + $error++; + } + if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht != 0) || $price_ht == '')) // Unit price can be 0 but not ''. Also price can be negative for proposal. + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); + $error++; + } + if (empty($idprod) && empty($product_desc)) + { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), 'errors'); + $error++; + } + + if (! $error && (GETPOST('qty') >= 0) && (! empty($product_desc) || ! empty($idprod))) + { + $pu_ht=0; + $pu_ttc=0; + $price_min=0; + $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); + + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $txtva par celui du produit + if (! empty($idprod)) + { + $prod = new Product($db); + $prod->fetch($idprod); + + $label = ((GETPOST('product_label') && GETPOST('product_label')!=$prod->label)?GETPOST('product_label'):''); + + // If prices fields are update + if (GETPOST('usenewaddlineform')) + { + $pu_ht=price2num($price_ht, 'MU'); + $pu_ttc=price2num(GETPOST('price_ttc'), 'MU'); + $tva_npr=(preg_match('/\*/', $tva_tx)?1:0); + $tva_tx=str_replace('*','', $tva_tx); + $desc = $product_desc; + } + else + { + $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); + $tva_npr = get_default_npr($mysoc,$object->client,$prod->id); + + // On defini prix unitaire + if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level) + { + $pu_ht = $prod->multiprices[$object->client->price_level]; + $pu_ttc = $prod->multiprices_ttc[$object->client->price_level]; + $price_min = $prod->multiprices_min[$object->client->price_level]; + $price_base_type = $prod->multiprices_base_type[$object->client->price_level]; + } + else + { + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; + } + + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + + $desc=''; + + // Define output language + if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) + { + $outputlangs = $langs; + $newlang=''; + if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if (empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description; + } + else + { + $desc = $prod->description; + } + + $desc=dol_concatdesc($desc,$product_desc); + + // Add custom code and origin country into description + if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) + { + $tmptxt='('; + if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode; + if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - '; + if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0); + $tmptxt.=')'; + $desc= dol_concatdesc($desc, $tmptxt); + } + } + + $type = $prod->type; + } + else + { + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); + $tva_npr = (preg_match('/\*/', $tva_tx)?1:0); + $tva_tx = str_replace('*', '', $tva_tx); + $label = (GETPOST('product_label')?GETPOST('product_label'):''); + $desc = $product_desc; + $type = GETPOST('type'); + } + + // Margin + $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); + $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); + + // Local Taxes + $localtax1_tx= get_localtax($tva_tx, 1, $object->client); + $localtax2_tx= get_localtax($tva_tx, 2, $object->client); + + $info_bits=0; + if ($tva_npr) $info_bits |= 0x01; + + if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) + { + $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').getCurrencySymbol($conf->currency)); + setEventMessage($mesg, 'errors'); + } + else + { + // Insert line + $result=$object->addline( + $id, + $desc, + $pu_ht, + GETPOST('qty'), + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $idprod, + GETPOST('remise_percent'), + $price_base_type, + $pu_ttc, + $info_bits, + $type, + -1, + 0, + GETPOST('fk_parent_line'), + $fournprice, + $buyingprice, + $label + ); + + if ($result > 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['idprod']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + + // old method + unset($_POST['np_desc']); + unset($_POST['dp_desc']); + } + else + { + setEventMessage($object->error, 'errors'); + } + } + } +} + +// Mise a jour d'une ligne dans la propale +else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save') == $langs->trans("Save")) +{ + // Define info_bits + $info_bits=0; + if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; + + // Clean parameters + $description=dol_htmlcleanlastbr(GETPOST('product_desc')); + + // Define vat_rate + $vat_rate=(GETPOST('tva_tx')?GETPOST('tva_tx'):0); + $vat_rate=str_replace('*','',$vat_rate); + $localtax1_rate=get_localtax($vat_rate,1,$object->client); + $localtax2_rate=get_localtax($vat_rate,2,$object->client); + $pu_ht=GETPOST('price_ht'); + + // Add buying price + $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); + $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); + + // Define special_code for special lines + $special_code=0; + if (! GETPOST('qty')) $special_code=3; + + // Check minimum price + $productid = GETPOST('productid', 'int'); + if (! empty($productid)) + { + $product = new Product($db); + $res=$product->fetch($productid); + + $type=$product->type; + + $price_min = $product->price_min; + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) + $price_min = $product->multiprices_min[$object->client->price_level]; + + $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):''); + + if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) + { + setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min,'MU')).getCurrencySymbol($conf->currency), 'errors'); + $error++; + } + } + else + { + $type = GETPOST('type'); + $label = (GETPOST('product_label') ? GETPOST('product_label'):''); + + // Check parameters + if (GETPOST('type') < 0) { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); + $error++; + } + } + + if (! $error) + { + $result = $object->updateline( + GETPOST('lineid'), + $pu_ht, + GETPOST('qty'), + GETPOST('remise_percent'), + $vat_rate, + $localtax1_rate, + $localtax2_rate, + $description, + 'HT', + $info_bits, + $special_code, + GETPOST('fk_parent_line'), + 0, + $fournprice, + $buyingprice, + $label, + $type + ); + + if ($result >= 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['productid']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + } + else + { + setEventMessage($object->error, 'errors'); + } + } +} + +else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel') == $langs->trans('Cancel')) +{ + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition + exit; +} + +// Generation doc (depuis lien ou depuis cartouche doc) +else if ($action == 'builddoc' && $user->rights->propal->creer) +{ + if (GETPOST('model')) + { + $object->setDocModel($user, GETPOST('model')); + } + + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + $result=propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); + exit; + } +} + +// Remove file in doc form +else if ($action == 'remove_file' && $user->rights->propal->creer) +{ + if ($object->id > 0) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $langs->load("other"); + $upload_dir = $conf->propal->dir_output; + $file = $upload_dir . '/' . GETPOST('file'); + $ret=dol_delete_file($file,0,0,0,$object); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); + } +} + +// Set project +else if ($action == 'classin' && $user->rights->propal->creer) +{ + $object->setProject($_POST['projectid']); +} + +// Delai de livraison +else if ($action == 'setavailability' && $user->rights->propal->creer) +{ + $result = $object->availability($_POST['availability_id']); +} + +// Origine de la propale +else if ($action == 'setdemandreason' && $user->rights->propal->creer) +{ + $result = $object->demand_reason($_POST['demand_reason_id']); +} + +// Conditions de reglement +else if ($action == 'setconditions' && $user->rights->propal->creer) +{ + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int')); +} + +else if ($action == 'setremisepercent' && $user->rights->propal->creer) +{ + $result = $object->set_remise_percent($user, $_POST['remise_percent']); +} + +else if ($action == 'setremiseabsolue' && $user->rights->propal->creer) +{ + $result = $object->set_remise_absolue($user, $_POST['remise_absolue']); +} + +// Mode de reglement +else if ($action == 'setmode' && $user->rights->propal->creer) +{ + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); +} + +/* + * Ordonnancement des lignes + */ + +else if ($action == 'up' && $user->rights->propal->creer) +{ + $object->line_up(GETPOST('rowid')); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); + exit; +} + +else if ($action == 'down' && $user->rights->propal->creer) +{ + $object->line_down(GETPOST('rowid')); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) + { + $outputlangs = new Translate("",$conf); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); + exit; +} + +if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) +{ + if ($action == 'addcontact') + { + if ($object->id > 0) + { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); + } + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors'); + } + else + { + setEventMessage($object->error, 'errors'); + } + } + } + + // Bascule du statut d'un contact + else if ($action == 'swapstatut') + { + if ($object->fetch($id) > 0) + { + $result=$object->swapContactStatus(GETPOST('ligne')); + } + else + { + dol_print_error($db); + } + } + + // Efface un contact + else if ($action == 'deletecontact') + { + $object->fetch($id); + $result = $object->delete_contact($lineid); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + dol_print_error($db); + } + } +} + + +/* + * View + */ + +llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); + +$form = new Form($db); +$formother = new FormOther($db); +$formfile = new FormFile($db); +$formpropal = new FormPropal($db); +$companystatic=new Societe($db); + +$now=dol_now(); + +/* + * Show object in view mode + */ + +$soc = new Societe($db); +$soc->fetch($object->socid); + +$head = propal_prepare_head($object); +dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal'); + +$formconfirm=''; + +// Clone confirmation +if ($action == 'clone') +{ + // Create an array for form + $formquestion=array( + //'text' => $langs->trans("ConfirmClone"), + //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), + //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), + array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)')) + ); + // Paiement incomplet. On demande si motif = escompte ou autre + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1); +} + +// Confirm delete +else if ($action == 'delete') +{ + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1); +} + +// Confirm reopen +else if ($action == 'reopen') +{ + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1); +} + +// Confirmation delete product/service line +else if ($action == 'ask_deleteline') +{ + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); +} + +// Confirm validate proposal +else if ($action == 'validate') +{ + $error=0; + + // on verifie si l'objet est en numerotation provisoire + $ref = substr($object->ref, 1, 4); + if ($ref == 'PROV') + { + $numref = $object->getNextNumRef($soc); + if (empty($numref)) + { + $error++; + dol_htmloutput_errors($object->error); + } + } + else + { + $numref = $object->ref; + } + + $text=$langs->trans('ConfirmValidateProp',$numref); + if (! empty($conf->notification->enabled)) + { + require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; + $notify=new Notify($db); + $text.='
'; + $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid); + } + + if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); +} + +if (! $formconfirm) +{ + $parameters=array('lineid'=>$lineid); + $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook +} + +// Print form confirm +print $formconfirm; + + +print ''; + +$linkback = ''.$langs->trans("BackToList").''; + +// Ref +print ''; + +// Ref client +print ''; +print ''; + +// Company +print ''; +print ''; + +// Ligne info remises tiers +print ''; + +// Date of proposal +print ''; +print ''; + +// Date end proposal +print ''; +print ''; +print ''; + +// Payment term +print ''; +print ''; + +// Delivery date +$langs->load('deliveries'); +print ''; +print ''; + +// Delivery delay +print ''; +print ''; + +// Origin of demand +print ''; +print ''; + +// Payment mode +print ''; +print ''; + +// Project +if (! empty($conf->projet->enabled)) +{ + $langs->load("projects"); + print ''; + } + else + { + print '
'.$langs->trans('Ref').''; +print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); +print '
'; +print ''; +if ($action != 'refclient' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('RefCustomer').''; +print ''.img_edit($langs->trans('Modify')).'
'; +print '
'; +if ($user->rights->propal->creer && $action == 'refclient') +{ + print '
'; + print ''; + print ''; + print ''; + print ' '; + print '
'; +} +else +{ + print $object->ref_client; +} +print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans('Discounts').''; +if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); +else print $langs->trans("CompanyHasNoRelativeDiscount"); +print '. '; +$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); +$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); +$absolute_discount=price2num($absolute_discount,'MT'); +$absolute_creditnote=price2num($absolute_creditnote,'MT'); +if ($absolute_discount) +{ + if ($object->statut > 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); + } + else + { + // Remise dispo de type non avoir + $filter='fk_facture_source IS NULL'; + print '
'; + $form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter); + } +} +if ($absolute_creditnote) +{ + print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. '; +} +if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; +print '
'; +print ''; +if ($action != 'editdate' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('Date'); +print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; +print '
'; +if (! empty($object->brouillon) && $action == 'editdate') +{ + print '
'; + print ''; + print ''; + $form->select_date($object->date,'re','','',0,"editdate"); + print ''; + print '
'; +} +else +{ + if ($object->date) + { + print dol_print_date($object->date,'daytext'); + } + else + { + print ' '; + } +} +print '
'; +print ''; +if ($action != 'editecheance' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('DateEndPropal'); +print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; +print '
'; +if (! empty($object->brouillon) && $action == 'editecheance') +{ + print '
'; + print ''; + print ''; + $form->select_date($object->fin_validite,'ech','','','',"editecheance"); + print ''; + print '
'; +} +else +{ + if (! empty($object->fin_validite)) + { + print dol_print_date($object->fin_validite,'daytext'); + if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); + } + else + { + print ' '; + } +} +print '
'; +print ''; +if ($action != 'editconditions' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('PaymentConditionsShort'); +print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'
'; +print '
'; +if ($action == 'editconditions') +{ + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); +} +else +{ + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); +} +print '
'; +print ''; +if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('DeliveryDate'); +print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'
'; +print '
'; +if ($action == 'editdate_livraison') +{ + print '
'; + print ''; + print ''; + $form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison"); + print ''; + print '
'; +} +else +{ + print dol_print_date($object->date_livraison,'daytext'); +} +print '
'; +print ''; +if ($action != 'editavailability' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('AvailabilityPeriod'); +if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')'; +print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'
'; +print '
'; +if ($action == 'editavailability') +{ + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1); +} +else +{ + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1); +} + +print '
'; +print ''; +if ($action != 'editdemandreason' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('Source'); +print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'
'; +print '
'; +//print $object->demand_reason_id; +if ($action == 'editdemandreason') +{ + $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1); +} +else +{ + $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none'); +} + +print '
'; +print ''; +if ($action != 'editmode' && ! empty($object->brouillon)) print ''; +print '
'; +print $langs->trans('PaymentMode'); +print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'
'; +print '
'; +if ($action == 'editmode') +{ + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); +} +else +{ + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); +} +print '
'; + print ''; + if ($user->rights->propal->creer) + { + if ($action != 'classify') print ''; + print '
'; + print $langs->trans('Project').''.img_edit($langs->transnoentitiesnoconv('SetProject')).'
'; + print '
'; + if ($action == 'classify') + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); + } + else + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none'); + } + print '
'; + if (! empty($object->fk_project)) + { + print ''; + $proj = new Project($db); + $proj->fetch($object->fk_project); + print ''; + print $proj->ref; + print ''; + print ''; + } + else { + print ' '; + } + } + print ''; +} + +// Other attributes +$parameters=array('colspan' => ' colspan="3"'); +$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook +if (empty($reshook) && ! empty($extrafields->attribute_label)) +{ + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; + print $extrafields->showInputField($key,$value); + print ''."\n"; + } +} + +// Amount HT +print ''.$langs->trans('AmountHT').''; +print ''.price($object->total_ht).''; +print ''.$langs->trans("Currency".$conf->currency).''; + +// Margin Infos +if (! empty($conf->margin->enabled)) { + print ''; + $object->displayMarginInfos(); + print ''; +} +print ''; + +// Amount VAT +print ''.$langs->trans('AmountVAT').''; +print ''.price($object->total_tva).''; +print ''.$langs->trans("Currency".$conf->currency).''; + +// Amount Local Taxes +if ($mysoc->localtax1_assuj=="1") //Localtax1 +{ + print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).''; + print ''.price($object->total_localtax1).''; + print ''.$langs->trans("Currency".$conf->currency).''; +} +if ($mysoc->localtax2_assuj=="1") //Localtax2 +{ + print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).''; + print ''.price($object->total_localtax2).''; + print ''.$langs->trans("Currency".$conf->currency).''; +} + + +// Amount TTC +print ''.$langs->trans('AmountTTC').''; +print ''.price($object->total_ttc).''; +print ''.$langs->trans("Currency".$conf->currency).''; + +// Statut +print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; + +print '
'; + +if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) +{ + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; +} + +if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) +{ + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; +} + +/* + * Lines + */ + +if (! empty($conf->use_javascript_ajax) && $object->statut == 0) +{ + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; +} + +print ''; + +// Show object lines +$result = $object->getLinesArray(); +if (! empty($object->lines)) + $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager); + +// Form to add new line +if ($object->statut == 0 && $user->rights->propal->creer) +{ + if ($action != 'editline') + { + $var=true; + + if ($conf->global->MAIN_FEATURES_LEVEL > 1) + { + // Add free or predefined products/services + $object->formAddObjectLine(0,$mysoc,$soc,$hookmanager); + } + else + { + // Add free products/services + $object->formAddFreeProduct(0,$mysoc,$soc,$hookmanager); + + // Add predefined products/services + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) + { + $var=!$var; + $object->formAddPredefinedProduct(0,$mysoc,$soc,$hookmanager); + } + } + + $parameters=array(); + $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + } +} + +print '
'; + +print ''; +print "\n"; + +if ($action == 'statut') +{ + /* + * Formulaire cloture (signe ou non) + */ + $form_close = '
'; + $form_close.= ''; + $form_close.= ''; + $form_close.= ''; + $form_close.= ''; + $form_close.= ''; + $form_close.= '
'.$langs->trans("CloseAs").''; + $form_close.= ''; + $form_close.= ''; + $form_close.= '
'.$langs->trans('Note').'
'; + $form_close.= ''; + $form_close.= '   '; + $form_close.= ' '; + $form_close.= '
'; + + print $form_close; +} + + +/* + * Boutons Actions + */ +if ($action != 'presend') +{ + print '
'; + + if ($action != 'statut' && $action <> 'editline') + { + // Validate + if ($object->statut == 0 && $user->rights->propal->valider) + { + if (count($object->lines) > 0) print ''.$langs->trans('Validate').''; + else print ''.$langs->trans('Validate').''; + } + + // Edit + if ($object->statut == 1 && $user->rights->propal->creer) + { + print ''.$langs->trans('Modify').''; + } + + // ReOpen + if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) + { + print 'global->MAIN_JUMP_TAG)?'':'#reopen').'"'; + print '>'.$langs->trans('ReOpen').''; + } + + // Send + if ($object->statut == 1 || $object->statut == 2) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) + { + print ''.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; + } + + // Create an order + if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0) + { + if ($user->rights->commande->creer) + { + print ''.$langs->trans("AddOrder").''; + } + } + + // Create an invoice and classify billed + if ($object->statut == 2 && $user->societe_id == 0) + { + if (! empty($conf->facture->enabled) && $user->rights->facture->creer) + { + print ''.$langs->trans("AddBill").''; + } + + $arraypropal=$object->getInvoiceArrayList(); + if (is_array($arraypropal) && count($arraypropal) > 0) + { + print 'socid.'">'.$langs->trans("ClassifyBilled").''; + } + } + + // Close + if ($object->statut == 1 && $user->rights->propal->cloturer) + { + print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; + print '>'.$langs->trans('Close').''; + } + + // Clone + if ($user->rights->propal->creer) + { + print ''.$langs->trans("ToClone").''; + } + + // Delete + if ($user->rights->propal->supprimer) + { + print ''.$langs->trans('Delete').''; + } + + } + + print '
'; + print "
\n"; +} + +if ($action != 'presend') +{ + print '
'; + print ''; // ancre + + + /* + * Documents generes + */ + $filename=dol_sanitizeFileName($object->ref); + $filedir=$conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed=$user->rights->propal->creer; + $delallowed=$user->rights->propal->supprimer; + + $var=true; + + $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'',0,'',$soc->default_lang,$hookmanager); + + + /* + * Linked object block + */ + $somethingshown=$object->showLinkedObjectBlock(); + + print ''; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions=new FormActions($db); + $somethingshown=$formactions->showactions($object,'propal',$socid); + + print '
'; +} + + +/* + * Action presend + * + */ +if ($action == 'presend') +{ + $ref = dol_sanitizeFileName($object->ref); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref,'/')); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=propale_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref,'/')); + $file=$fileparams['fullname']; + } + + print '
'; + print_titre($langs->trans('SendPropalByMail')); + + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; + $formmail->withtosocid=$soc->id; + $formmail->withtocc=1; + $formmail->withtoccsocid=0; + $formmail->withtoccc=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false); + $formmail->withtocccsocid=0; + $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + + // Tableau des substitutions + $formmail->substit['__PROPREF__']=$object->ref; + $formmail->substit['__SIGNATURE__']=$user->signature; + $formmail->substit['__PERSONALIZED__']=''; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='propal_send'; + $formmail->param['id']=$object->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + + // Init list of files + if (GETPOST("mode")=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); + } + + $formmail->show_form(); + + print '
'; +} + + +// End of page +llxFooter(); +$db->close(); ?> \ No newline at end of file diff --git a/htdocs/core/tpl/freeproductline_create.tpl.php b/htdocs/core/tpl/freeproductline_create.tpl.php index 50acc322952..50d63b5bcbf 100644 --- a/htdocs/core/tpl/freeproductline_create.tpl.php +++ b/htdocs/core/tpl/freeproductline_create.tpl.php @@ -1,155 +1,155 @@ - - * Copyright (C) 2010-2011 Laurent Destailleur - * Copyright (C) 2012 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 - * 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 . - * - * Need to have following variables defined: - * $conf - * $langs - * $dateSelector - * $this (invoice, order, ...) - * $line defined - */ - -$usemargins=0; -if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; - -?> - - - - global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
trans('AddNewLine').' - '.$langs->trans("FreeZone"); ?> - - trans('VAT'); ?> - trans('PriceUHT'); ?> - trans('Qty'); ?> - trans('ReductionShort'); ?> - - - global->MARGIN_TYPE == "1") - echo $langs->trans('BuyingPrice'); - else - echo $langs->trans('CostPrice'); - ?> - - global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - } - ?> -   - - -
"> - - - - - > - global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> - '; - echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1); - echo ''; - - if (is_object($hookmanager)) - { - $parameters=array(); - $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); - } - - if ((! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) echo '
'; - - // Editor wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70); - $doleditor->Create(); - ?> - - - tva_assuj == "0") echo '0'; - else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); - ?> - - "> - - "> - % - - "> - - global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - } - ?> - - - - service->enabled) && $dateSelector) - { - if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; - else $colspan = 9; - - if (! empty($usemargins)) - { - $colspan++; // For the buying price - if($conf->global->DISPLAY_MARGIN_RATES) $colspan++; - if($conf->global->DISPLAY_MARK_RATES) $colspan++; - } - ?> - > - element) && $object->element == 'contrat') - { - print $langs->trans("DateStartPlanned").' '; - $form->select_date('',"date_start_sl",$usehm,$usehm,1,"addline_sl"); - print '   '.$langs->trans("DateEndPlanned").' '; - $form->select_date('',"date_end_sl",$usehm,$usehm,1,"addline_sl"); - } - else - { - echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; - echo $form->select_date('','date_start',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct"); - echo ' '.$langs->trans('to').' '; - echo $form->select_date('','date_end',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct"); - } - ?> - - - - - - + + * Copyright (C) 2010-2011 Laurent Destailleur + * Copyright (C) 2012 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 + * 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 . + * + * Need to have following variables defined: + * $conf + * $langs + * $dateSelector + * $this (invoice, order, ...) + * $line defined + */ + +$usemargins=0; +if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; + +?> + + + + global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
trans('AddNewLine').' - '.$langs->trans("FreeZone"); ?> + + trans('VAT'); ?> + trans('PriceUHT'); ?> + trans('Qty'); ?> + trans('ReductionShort'); ?> + + + global->MARGIN_TYPE == "1") + echo $langs->trans('BuyingPrice'); + else + echo $langs->trans('CostPrice'); + ?> + + global->DISPLAY_MARGIN_RATES)) $colspan++; + if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; + } + ?> +   + + +
"> + + + + + > + global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> + '; + echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1); + echo ''; + + if (is_object($hookmanager)) + { + $parameters=array(); + $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); + } + + if ((! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) echo '
'; + + // Editor wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70); + $doleditor->Create(); + ?> + + + tva_assuj == "0") echo '0'; + else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); + ?> + + "> + + "> + % + + "> + + global->DISPLAY_MARGIN_RATES)) $colspan++; + if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; + } + ?> + + + + service->enabled) && $dateSelector) + { + if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; + else $colspan = 9; + + if (! empty($usemargins)) + { + $colspan++; // For the buying price + if($conf->global->DISPLAY_MARGIN_RATES) $colspan++; + if($conf->global->DISPLAY_MARK_RATES) $colspan++; + } + ?> + > + element) && $object->element == 'contrat') + { + print $langs->trans("DateStartPlanned").' '; + $form->select_date('',"date_start_sl",$usehm,$usehm,1,"addline_sl"); + print '   '.$langs->trans("DateEndPlanned").' '; + $form->select_date('',"date_end_sl",$usehm,$usehm,1,"addline_sl"); + } + else + { + echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; + echo $form->select_date('','date_start',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct"); + echo ' '.$langs->trans('to').' '; + echo $form->select_date('','date_end',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct"); + } + ?> + + + + + + From e2f2ad30ae7877b4c58ad3996a53e06b96f33541 Mon Sep 17 00:00:00 2001 From: simnandez Date: Sat, 18 May 2013 09:15:18 +0200 Subject: [PATCH 16/33] Fix: Remove windows CR/LF --- .../tpl/predefinedproductline_create.tpl.php | 414 +++++++++--------- 1 file changed, 207 insertions(+), 207 deletions(-) diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php index d791a395b93..d77b3f402e1 100644 --- a/htdocs/core/tpl/predefinedproductline_create.tpl.php +++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php @@ -1,207 +1,207 @@ - - * Copyright (C) 2010-2012 Laurent Destailleur - * Copyright (C) 2012 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 - * 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 . - * - * - * Need to have following variables defined: - * $conf - * $langs - * $dateSelector - * $this (invoice, order, ...) - * $line defined - */ - -$usemargins=0; -if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; - -?> - - - - - global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> - trans("AddNewLine").' - '; - if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('RecordedProducts'); - else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('RecordedServices'); - else echo $langs->trans('RecordedProductsAndServices'); - ?> - - trans('Qty'); ?> - trans('ReductionShort'); ?> -global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - ?> - - global->MARGIN_TYPE == "1") - echo $langs->trans('BuyingPrice'); - else - echo $langs->trans('CostPrice'); - ?> - - -   - - -
"> - - - - - - -> - global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> - '; - $filtertype=''; - if (! empty($object->element) && $object->element == 'contrat') $filtertype='1'; - $form->select_produits('','idprod',$filtertype,$conf->product->limit_size,$buyer->price_level); - echo ''; - - if (is_object($hookmanager)) - { - $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int')); - $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); - } - - echo '
'; - - // Editor wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('np_desc',GETPOST('np_desc"'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70); - $doleditor->Create(); - ?> - - - % - global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - ?> - - - "> - - - - " name="addline"> - - - -service->enabled) && $dateSelector) -{ - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; - else $colspan = 9; - if (! empty($usemargins)) - { - $colspan++; // For the buying price - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - } -?> -> - - element) && $object->element == 'contrat') - { - print $langs->trans("DateStartPlanned").' '; - $form->select_date('',"date_start",$usehm,$usehm,1,"addline"); - print '   '.$langs->trans("DateEndPlanned").' '; - $form->select_date('',"date_end",$usehm,$usehm,1,"addline"); - } - else - { - echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; - echo $form->select_date('','date_start_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); - echo ' '.$langs->trans('to').' '; - echo $form->select_date('','date_end_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); - } - ?> - - - - - - - - - - + + * Copyright (C) 2010-2012 Laurent Destailleur + * Copyright (C) 2012 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 + * 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 . + * + * + * Need to have following variables defined: + * $conf + * $langs + * $dateSelector + * $this (invoice, order, ...) + * $line defined + */ + +$usemargins=0; +if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; + +?> + + + + + global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> + trans("AddNewLine").' - '; + if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('RecordedProducts'); + else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('RecordedServices'); + else echo $langs->trans('RecordedProductsAndServices'); + ?> + + trans('Qty'); ?> + trans('ReductionShort'); ?> +global->DISPLAY_MARGIN_RATES)) $colspan++; + if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; + ?> + + global->MARGIN_TYPE == "1") + echo $langs->trans('BuyingPrice'); + else + echo $langs->trans('CostPrice'); + ?> + + +   + + +
"> + + + + + + +> + global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> + '; + $filtertype=''; + if (! empty($object->element) && $object->element == 'contrat') $filtertype='1'; + $form->select_produits('','idprod',$filtertype,$conf->product->limit_size,$buyer->price_level); + echo ''; + + if (is_object($hookmanager)) + { + $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int')); + $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); + } + + echo '
'; + + // Editor wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + $enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $doleditor=new DolEditor('np_desc',GETPOST('np_desc"'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70); + $doleditor->Create(); + ?> + + + % + global->DISPLAY_MARGIN_RATES)) $colspan++; + if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; + ?> + + + "> + + + + " name="addline"> + + + +service->enabled) && $dateSelector) +{ + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; + else $colspan = 9; + if (! empty($usemargins)) + { + $colspan++; // For the buying price + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; + if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; + } +?> +> + + element) && $object->element == 'contrat') + { + print $langs->trans("DateStartPlanned").' '; + $form->select_date('',"date_start",$usehm,$usehm,1,"addline"); + print '   '.$langs->trans("DateEndPlanned").' '; + $form->select_date('',"date_end",$usehm,$usehm,1,"addline"); + } + else + { + echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; + echo $form->select_date('','date_start_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); + echo ' '.$langs->trans('to').' '; + echo $form->select_date('','date_end_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); + } + ?> + + + + + + + + + + From fefb21a56e9c99090a6c6ff98263222a4f33edf3 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sat, 18 May 2013 12:17:43 +0200 Subject: [PATCH 17/33] Fix bug on Extrafield checkbox Fix bug on ActionComm Update [ task #900 ] Review code of ficheinter.class.php --- ChangeLog | 1 + htdocs/comm/action/class/actioncomm.class.php | 4 +- htdocs/comm/propal.php | 4 + htdocs/commande/class/commande.class.php | 2 +- htdocs/commande/fiche.php | 4 + htdocs/compta/facture.php | 6 +- htdocs/core/class/extrafields.class.php | 2 +- htdocs/core/tpl/admin_extrafields_add.tpl.php | 4 +- htdocs/fichinter/class/fichinter.class.php | 1492 ++++++------ htdocs/fichinter/fiche.php | 2135 +++++++++-------- 10 files changed, 1844 insertions(+), 1810 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8d658a1d58..dd34664a02d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,7 @@ For users: - New: [ task #741 ] Add intervention box. - New: [ task #826 ] Optionnal increase stock when deleting an invoice already validated. - New: [ task #823 ] Shipping_validate email notification. +- New: [ task #900 ] Review code of ficheinter.class.php For translators: - Update language files. diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 067b36f989c..bb30efe8ef9 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -188,8 +188,8 @@ class ActionComm extends CommonObject $sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").","; $sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").","; $sql.= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").","; - $sql.= (isset($this->type_id)?$this->type_id:"null"); - $sql.= (isset($this->code)?" '".$this->code."'":"null")."," ; + $sql.= (isset($this->type_id)?$this->type_id:"null").","; + $sql.= (isset($this->code)?" '".$this->code."'":"null").","; $sql.= (isset($this->societe->id) && $this->societe->id > 0?" '".$this->societe->id."'":"null").","; $sql.= (isset($this->fk_project) && $this->fk_project > 0?" '".$this->fk_project."'":"null").","; $sql.= " '".$this->db->escape($this->note)."',"; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 1ad89847ea8..973c37d91af 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1845,7 +1845,11 @@ else foreach($extrafields->attribute_label as $key=>$label) { + if ($action == 'edit_extras') { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + } else { + $value=$object->array_options["options_".$key]; + } if ($extrafields->attribute_type[$key] == 'separate') { print $extrafields->showSeparator($key); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 60522561346..508f9a70fc6 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2834,7 +2834,7 @@ class Commande extends CommonOrder } /** - * Update value of extrafields on the proposal + * Update value of extrafields on order * * @param User $user Object user that modify * @return int <0 if ko, >0 if ok diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 816df65ea85..2926a040298 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2145,7 +2145,11 @@ else foreach($extrafields->attribute_label as $key=>$label) { + if ($action == 'edit_extras') { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + } else { + $value=$object->array_options["options_".$key]; + } if ($extrafields->attribute_type[$key] == 'separate') { print $extrafields->showSeparator($key); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 82205be3e7b..250605f386b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3291,7 +3291,11 @@ else if ($id > 0 || ! empty($ref)) foreach($extrafields->attribute_label as $key=>$label) { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + if ($action == 'edit_extras') { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + } else { + $value=$object->array_options["options_".$key]; + } if ($extrafields->attribute_type[$key] == 'separate') { print $extrafields->showSeparator($key); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 6c6a9de1e99..8c5f485de32 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -445,7 +445,7 @@ class ExtraFields if(is_array($param) && count($param) > 0) { - $param = serialize($param); + $param = $this->db->escape(serialize($param)); } $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 451b85f81e8..3a5b02a9d48 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -49,8 +49,8 @@ else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();} else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();} else if (type == 'sellist') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();} - else if (type == 'checkbox') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();} - else if (type == 'radio') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();} + else if (type == 'checkbox') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();} + else if (type == 'radio') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();} else if (type == 'separate') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); required.val('').attr('disabled','disabled'); default_value.val('').attr('disabled','disabled'); jQuery("#value_choice").hide();} else size.val('').attr('disabled','disabled'); } diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 213b3f4f075..13baa5ac389 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -1,28 +1,28 @@ * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011-2013 Juanjo Menent - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * 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 . - */ +* Copyright (C) 2005-2012 Regis Houssin +* Copyright (C) 2011-2013 Juanjo Menent +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* 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/fichinter/class/fichinter.class.php - * \ingroup ficheinter - * \brief Fichier de la classe des gestion des fiches interventions - */ +* \ingroup ficheinter +* \brief Fichier de la classe des gestion des fiches interventions +*/ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; @@ -61,7 +61,7 @@ class Fichinter extends CommonObject * Constructor * * @param DoliDB $db Database handler - */ + */ function __construct($db) { $this->db = $db; @@ -82,16 +82,20 @@ class Fichinter extends CommonObject /** * Create an intervention into data base * + * @param User $user Objet user that make creation + * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK */ - function create() + function create($user, $notrigger=0) { global $conf, $user, $langs; dol_syslog(get_class($this)."::create ref=".$this->ref); // Check parameters - if (! is_numeric($this->duree)) { $this->duree = 0; } + if (! is_numeric($this->duree)) { + $this->duree = 0; + } if ($this->socid <= 0) { $this->error='ErrorBadParameterForFunc'; @@ -142,7 +146,7 @@ class Fichinter extends CommonObject $sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->ref."'"; $sql.= ", ".$conf->entity; - $sql.= ", ".$this->author; + $sql.= ", ".$user->id; $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null"); $sql.= ", '".$this->modelpdf."'"; $sql.= ", ".($this->fk_project ? $this->fk_project : 0); @@ -156,33 +160,33 @@ class Fichinter extends CommonObject if ($result) { $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); - + if ($this->id) { $this->ref='(PROV'.$this->id.')'; $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->ref."' WHERE rowid=".$this->id; - + dol_syslog(get_class($this)."::create sql=".$sql); $resql=$this->db->query($sql); if (! $resql) $error++; } - // Add linked object - if (! $error && $this->origin && $this->origin_id) - { - $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); - } - - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $tmpuser=new User($this->db); - $tmpuser->fetch($this->author); - $result=$interface->run_triggers('FICHINTER_CREATE',$this,$tmpuser,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; + // Add linked object + if (! $error && $this->origin && $this->origin_id) + { + $ret = $this->add_object_linked(); + if (! $ret) dol_print_error($this->db); + } + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } } - // Fin appel triggers if (! $error) { @@ -210,716 +214,728 @@ class Fichinter extends CommonObject /** * Update an intervention * + * @param User $user Objet user that make creation + * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK */ - function update() - { - if (! is_numeric($this->duree)) { $this->duree = 0; } - if (! dol_strlen($this->fk_project)) { $this->fk_project = 0; } + function update($user, $notrigger=0) + { + if (! is_numeric($this->duree)) { + $this->duree = 0; + } + if (! dol_strlen($this->fk_project)) { + $this->fk_project = 0; + } - $this->db->begin(); + $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; - $sql.= ", description = '".$this->db->escape($this->description)."'"; - $sql.= ", duree = ".$this->duree; - $sql.= ", fk_projet = ".$this->fk_project; - $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); - $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); - $sql.= " WHERE rowid = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; + $sql.= ", description = '".$this->db->escape($this->description)."'"; + $sql.= ", duree = ".$this->duree; + $sql.= ", fk_projet = ".$this->fk_project; + $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); + $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); + $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::update error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::update error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } - /** - * Fetch a intervention - * - * @param int $rowid Id of intervention - * @param string $ref Ref of intervention - * @return int <0 if KO, >0 if OK - */ - function fetch($rowid,$ref='') - { - $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; - $sql.= " f.datec,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.tms as datem,"; - $sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; - if ($ref) $sql.= " WHERE f.ref='".$this->db->escape($ref)."'"; - else $sql.= " WHERE f.rowid=".$rowid; + /** + * Fetch a intervention + * + * @param int $rowid Id of intervention + * @param string $ref Ref of intervention + * @return int <0 if KO, >0 if OK + */ + function fetch($rowid,$ref='') + { + $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; + $sql.= " f.datec,"; + $sql.= " f.date_valid as datev,"; + $sql.= " f.tms as datem,"; + $sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + if ($ref) $sql.= " WHERE f.ref='".$this->db->escape($ref)."'"; + else $sql.= " WHERE f.rowid=".$rowid; - dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->description = $obj->description; - $this->socid = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->duree = $obj->duree; - $this->datec = $this->db->jdate($obj->datec); - $this->datev = $this->db->jdate($obj->datev); - $this->datem = $this->db->jdate($obj->datem); - $this->fk_project = $obj->fk_projet; - $this->note_public = $obj->note_public; - $this->note_private = $obj->note_private; - $this->modelpdf = $obj->model_pdf; + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->description = $obj->description; + $this->socid = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->duree = $obj->duree; + $this->datec = $this->db->jdate($obj->datec); + $this->datev = $this->db->jdate($obj->datev); + $this->datem = $this->db->jdate($obj->datem); + $this->fk_project = $obj->fk_projet; + $this->note_public = $obj->note_public; + $this->note_private = $obj->note_private; + $this->modelpdf = $obj->model_pdf; - $this->extraparams = (array) json_decode($obj->extraparams, true); + $this->extraparams = (array) json_decode($obj->extraparams, true); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == 0) $this->brouillon = 1; - /* - * Lines + /* + * Lines */ - $result=$this->fetch_lines(); - if ($result < 0) - { - return -3; - } - $this->db->free($resql); - return 1; - } - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::fetch ".$this->error,LOG_ERR); - return -1; - } - } - - /** - * Set status to draft - * - * @param User $user User that set draft - * @return int <0 if KO, >0 if OK - */ - function setDraft($user) - { - global $langs, $conf; - - if ($this->statut != 0) - { - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = 0"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - - dol_syslog("Fichinter::setDraft sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog("Fichinter::setDraft ".$this->error,LOG_ERR); - return -1; - } - } - } - - /** - * Validate a intervention - * - * @param User $user User that validate - * @return int <0 if KO, >0 if OK - */ - function setValid($user) - { - global $langs, $conf; - - $error=0; - - if ($this->statut != 1) - { - $this->db->begin(); - - $now=dol_now(); - - // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) - { - $num = $this->getNextNumRef($this->thirdparty); - } - else - { - $num = $this->ref; - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = 1"; - $sql.= ", ref = '".$num."'"; - $sql.= ", date_valid = ".$this->db->idate($now); - $sql.= ", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; - - dol_syslog(get_class($this)."::setValid sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=join(',',$this->errors); - dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); - return -1; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); - return -1; - } - } - } - - /** - * Set intervetnion as billed - * - * @return int <0 si ko, >0 si ok - */ - function setBilled() - { - global $conf; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter SET fk_statut = 2'; - $sql.= ' WHERE rowid = '.$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 1"; - - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dol_print_error($this->db); - return -1; - } - } - - - /** - * Returns the label status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->statut,$mode); - } - - /** - * Returns the label of a statut - * - * @param int $statut id statut - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label - */ - function LibStatut($statut,$mode=0) - { - global $langs; - - if ($mode == 0) - { - return $langs->trans($this->statuts[$statut]); - } - if ($mode == 1) - { - return $langs->trans($this->statuts_short[$statut]); - } - if ($mode == 2) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); - } - if ($mode == 3) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); - } - if ($mode == 4) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); - } - if ($mode == 5) - { - if ($statut==0) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); - if ($statut==1) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); - if ($statut==2) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); - } - } - - /** - * Return clicable name (with picto eventually) - * - * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only - * @return string String with URL - */ - function getNomUrl($withpicto=0) - { - global $langs; - - $result=''; - - $lien = ''; - $lienfin=''; - - $picto='intervention'; - - $label=$langs->trans("Show").': '.$this->ref; - - if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; - return $result; - } - - - /** - * Returns the next non used reference of intervention - * depending on the module numbering assets within FICHEINTER_ADDON - * - * @param Societe $soc Object society - * @return string Free reference for intervention - */ - function getNextNumRef($soc) - { - global $conf, $db, $langs; - $langs->load("interventions"); - - $dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/"; - - if (! empty($conf->global->FICHEINTER_ADDON)) - { - $file = $conf->global->FICHEINTER_ADDON.".php"; - $classname = $conf->global->FICHEINTER_ADDON; - if (! file_exists($dir.$file)) - { - $file='mod_'.$file; - $classname='mod_'.$classname; - } - - // Chargement de la classe de numerotation - require_once $dir.$file; - - $obj = new $classname(); - - $numref = ""; - $numref = $obj->getNumRef($soc,$this); - - if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db,"Fichinter::getNextNumRef ".$obj->error); - return ""; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"); - return ""; - } - } - - /** - * Information sur l'objet fiche intervention - * - * @param int $id Id de la fiche d'intervention - * @return void - */ - function info($id) - { - global $conf; - - $sql = "SELECT f.rowid,"; - $sql.= " datec,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.fk_user_author,"; - $sql.= " f.fk_user_valid"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; - $sql.= " WHERE f.rowid = ".$id; - $sql.= " AND f.entity = ".$conf->entity; - - $result = $this->db->query($sql); - - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_validation = $this->db->jdate($obj->datev); - - $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; - } - } - $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } - - /** - * Delete intervetnion - * - * @param User $user Object user who delete - * @return int <0 if KO, >0 if OK - */ - function delete($user) - { - global $conf; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - $error=0; - - $this->db->begin(); - - // Delete linked object - $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; - - // Delete linked contacts - $res = $this->delete_linked_contact(); - if ($res < 0) - { - $this->error='ErrorFailToDeleteLinkedContact'; - $error++; - } - - if ($error) - { - $this->db->rollback(); - return -1; - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; - $sql.= " WHERE fk_fichinter = ".$this->id; - - dol_syslog("Fichinter::delete sql=".$sql); - if ( $this->db->query($sql) ) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - - dol_syslog("Fichinter::delete sql=".$sql); - if ( $this->db->query($sql) ) - { - - // Remove directory with files - $fichinterref = dol_sanitizeFileName($this->ref); - if ($conf->ficheinter->dir_output) - { - $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ; - $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; - if (file_exists($file)) - { - dol_delete_preview($this); - - if (! dol_delete_file($file,0,0,0,$this)) // For triggers - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (! dol_delete_dir_recursive($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } - - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -2; - } - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - /** - * Defines a delivery date of intervention - * - * @param User $user Object user who define - * @param date $date_delivery date of delivery - * @return int <0 if ko, >0 if ok - */ - function set_date_delivery($user, $date_delivery) - { - global $conf; - - if ($user->rights->ficheinter->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET datei = ".$this->db->idate($date_delivery); - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; - - if ($this->db->query($sql)) - { - $this->date_delivery = $date_delivery; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Fichinter::set_date_delivery Erreur SQL"); - return -1; - } - } - } - - /** - * Define the label of the intervention - * - * @param User $user Object user who modify - * @param string $description description - * @return int <0 if ko, >0 if ok - */ - function set_description($user, $description) - { - global $conf; - - if ($user->rights->ficheinter->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET description = '".$this->db->escape($description)."'"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; - - if ($this->db->query($sql)) - { - $this->description = $description; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Fichinter::set_description Erreur SQL"); - return -1; - } - } - } - - /** - * Adding a line of intervention into data base - * - * @param int $fichinterid Id of intervention - * @param string $desc Line description - * @param date $date_intervention Intervention date - * @param int $duration Intervention duration - * @return int >0 if ok, <0 if ko - */ - function addline($fichinterid, $desc, $date_intervention, $duration) - { - dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); - - if ($this->statut == 0) - { - $this->db->begin(); - - // Insertion ligne - $line=new FichinterLigne($this->db); - - $line->fk_fichinter = $fichinterid; - $line->desc = $desc; - $line->datei = $date_intervention; - $line->duration = $duration; - - $result=$line->insert(); - if ($result > 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Error sql=$sql, error=".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - } - - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - function initAsSpecimen() - { - global $user,$langs,$conf; - - $now=dol_now(); - - // Initialise parametres - $this->id=0; - $this->ref = 'SPECIMEN'; - $this->specimen=1; - $this->socid = 1; - $this->datec = $now; - $this->note_private='Private note'; - $this->note_public='SPECIMEN'; - $this->duree = 0; - $nbp = 20; - $xnbp = 0; - while ($xnbp < $nbp) - { - $line=new FichinterLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->datei=($now-3600*(1+$xnbp)); - $line->duration=600; - $line->fk_fichinter=0; - $this->lines[$xnbp]=$line; - $xnbp++; - - $this->duree+=$line->duration; - } - } - - /** - * Load array lines - * - * @return int <0 if Ko, >0 if OK - */ - function fetch_lines() - { - $sql = 'SELECT rowid, description, duree, date, rang'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; - $sql.= ' WHERE fk_fichinter = '.$this->id; - - dol_syslog(get_class($this)."::fetch_lines sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $objp = $this->db->fetch_object($resql); - - $line = new FichinterLigne($this->db); - $line->id = $objp->rowid; - $line->desc = $objp->description; - //For invoicing we calculing hours - $line->qty = round($objp->duree/3600,2); - $line->date = $this->db->jdate($objp->date); - $line->rang = $objp->rang; - $line->product_type = 1; - - $this->lines[$i] = $line; - - $i++; - } - $this->db->free($resql); - - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } + $this->db->free($resql); + return 1; + } + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::fetch ".$this->error,LOG_ERR); + return -1; + } + } + + /** + * Set status to draft + * + * @param User $user User that set draft + * @return int <0 if KO, >0 if OK + */ + function setDraft($user) + { + global $langs, $conf; + + if ($this->statut != 0) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; + $sql.= " SET fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + + dol_syslog("Fichinter::setDraft sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("Fichinter::setDraft ".$this->error,LOG_ERR); + return -1; + } + } + } + + /** + * Validate a intervention + * + * @param User $user User that validate + * @return int <0 if KO, >0 if OK + */ + function setValid($user) + { + global $langs, $conf; + + $error=0; + + if ($this->statut != 1) + { + $this->db->begin(); + + $now=dol_now(); + + // Define new ref + if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) + { + $num = $this->getNextNumRef($this->thirdparty); + } + else + { + $num = $this->ref; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; + $sql.= " SET fk_statut = 1"; + $sql.= ", ref = '".$num."'"; + $sql.= ", date_valid = ".$this->db->idate($now); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; + + dol_syslog(get_class($this)."::setValid sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=join(',',$this->errors); + dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); + return -1; + } + } + } + + /** + * Set intervetnion as billed + * + * @return int <0 si ko, >0 si ok + */ + function setBilled() + { + global $conf; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter SET fk_statut = 2'; + $sql.= ' WHERE rowid = '.$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 1"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + + /** + * Returns the label status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } + + /** + * Returns the label of a statut + * + * @param int $statut id statut + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function LibStatut($statut,$mode=0) + { + global $langs; + + if ($mode == 0) + { + return $langs->trans($this->statuts[$statut]); + } + if ($mode == 1) + { + return $langs->trans($this->statuts_short[$statut]); + } + if ($mode == 2) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); + } + if ($mode == 3) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); + } + if ($mode == 4) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); + } + if ($mode == 5) + { + if ($statut==0) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); + if ($statut==1) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); + if ($statut==2) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); + } + } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only + * @return string String with URL + */ + function getNomUrl($withpicto=0) + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + $picto='intervention'; + + $label=$langs->trans("Show").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; + } + + + /** + * Returns the next non used reference of intervention + * depending on the module numbering assets within FICHEINTER_ADDON + * + * @param Societe $soc Object society + * @return string Free reference for intervention + */ + function getNextNumRef($soc) + { + global $conf, $db, $langs; + $langs->load("interventions"); + + $dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/"; + + if (! empty($conf->global->FICHEINTER_ADDON)) + { + $file = $conf->global->FICHEINTER_ADDON.".php"; + $classname = $conf->global->FICHEINTER_ADDON; + if (! file_exists($dir.$file)) + { + $file='mod_'.$file; + $classname='mod_'.$classname; + } + + // Chargement de la classe de numerotation + require_once $dir.$file; + + $obj = new $classname(); + + $numref = ""; + $numref = $obj->getNumRef($soc,$this); + + if ( $numref != "") + { + return $numref; + } + else + { + dol_print_error($db,"Fichinter::getNextNumRef ".$obj->error); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"); + return ""; + } + } + + /** + * Information sur l'objet fiche intervention + * + * @param int $id Id de la fiche d'intervention + * @return void + */ + function info($id) + { + global $conf; + + $sql = "SELECT f.rowid,"; + $sql.= " datec,"; + $sql.= " f.date_valid as datev,"; + $sql.= " f.fk_user_author,"; + $sql.= " f.fk_user_valid"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + $sql.= " WHERE f.rowid = ".$id; + $sql.= " AND f.entity = ".$conf->entity; + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_validation = $this->db->jdate($obj->datev); + + $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; + } + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } + + /** + * Delete intervetnion + * + * @param User $user Object user who delete + * @return int <0 if KO, >0 if OK + */ + function delete($user) + { + global $conf; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $error=0; + + $this->db->begin(); + + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; + + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) + { + $this->error='ErrorFailToDeleteLinkedContact'; + $error++; + } + + if ($error) + { + $this->db->rollback(); + return -1; + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; + $sql.= " WHERE fk_fichinter = ".$this->id; + + dol_syslog("Fichinter::delete sql=".$sql); + if ( $this->db->query($sql) ) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + + dol_syslog("Fichinter::delete sql=".$sql); + if ( $this->db->query($sql) ) + { + + // Remove directory with files + $fichinterref = dol_sanitizeFileName($this->ref); + if ($conf->ficheinter->dir_output) + { + $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ; + $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; + if (file_exists($file)) + { + dol_delete_preview($this); + + if (! dol_delete_file($file,0,0,0,$this)) // For triggers + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (! dol_delete_dir_recursive($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } + + /** + * Defines a delivery date of intervention + * + * @param User $user Object user who define + * @param date $date_delivery date of delivery + * @return int <0 if ko, >0 if ok + */ + function set_date_delivery($user, $date_delivery) + { + global $conf; + + if ($user->rights->ficheinter->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; + $sql.= " SET datei = ".$this->db->idate($date_delivery); + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; + + if ($this->db->query($sql)) + { + $this->date_delivery = $date_delivery; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Fichinter::set_date_delivery Erreur SQL"); + return -1; + } + } + } + + /** + * Define the label of the intervention + * + * @param User $user Object user who modify + * @param string $description description + * @return int <0 if ko, >0 if ok + */ + function set_description($user, $description) + { + global $conf; + + if ($user->rights->ficheinter->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; + $sql.= " SET description = '".$this->db->escape($description)."'"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; + + if ($this->db->query($sql)) + { + $this->description = $description; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Fichinter::set_description Erreur SQL"); + return -1; + } + } + } + + /** + * Adding a line of intervention into data base + * + * @param int $fichinterid Id of intervention + * @param string $desc Line description + * @param date $date_intervention Intervention date + * @param int $duration Intervention duration + * @return int >0 if ok, <0 if ko + */ + function addline($fichinterid, $desc, $date_intervention, $duration) + { + dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); + + if ($this->statut == 0) + { + $this->db->begin(); + + // Insertion ligne + $line=new FichinterLigne($this->db); + + $line->fk_fichinter = $fichinterid; + $line->desc = $desc; + $line->datei = $date_intervention; + $line->duration = $duration; + + $result=$line->insert(); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Error sql=$sql, error=".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + global $user,$langs,$conf; + + $now=dol_now(); + + // Initialise parametres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $this->socid = 1; + $this->datec = $now; + $this->note_private='Private note'; + $this->note_public='SPECIMEN'; + $this->duree = 0; + $nbp = 20; + $xnbp = 0; + while ($xnbp < $nbp) + { + $line=new FichinterLigne($this->db); + $line->desc=$langs->trans("Description")." ".$xnbp; + $line->datei=($now-3600*(1+$xnbp)); + $line->duration=600; + $line->fk_fichinter=0; + $this->lines[$xnbp]=$line; + $xnbp++; + + $this->duree+=$line->duration; + } + } + + /** + * Load array lines + * + * @return int <0 if Ko, >0 if OK + */ + function fetch_lines() + { + $sql = 'SELECT rowid, description, duree, date, rang'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; + $sql.= ' WHERE fk_fichinter = '.$this->id; + + dol_syslog(get_class($this)."::fetch_lines sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $objp = $this->db->fetch_object($resql); + + $line = new FichinterLigne($this->db); + $line->id = $objp->rowid; + $line->desc = $objp->description; + //For invoicing we calculing hours + $line->qty = round($objp->duree/3600,2); + $line->date = $this->db->jdate($objp->date); + $line->rang = $objp->rang; + $line->product_type = 1; + + $this->lines[$i] = $line; + + $i++; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } } /** diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 941b5232f54..0ef8ca87f2c 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -1,29 +1,29 @@ * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011-2013 Juanjo Menent - * Copyright (C) 2013 Florian Henry - * - * 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 . - */ +* Copyright (C) 2005-2012 Regis Houssin +* Copyright (C) 2011-2013 Juanjo Menent +* Copyright (C) 2013 Florian Henry +* +* 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/fichinter/fiche.php - * \brief Fichier fiche intervention - * \ingroup ficheinter - */ +* \brief Fichier fiche intervention +* \ingroup ficheinter +*/ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; @@ -33,12 +33,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; if (! empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php")) { - require_once DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php'; + require_once DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php'; } require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -71,127 +71,132 @@ $object = new Fichinter($db); /* * Actions - */ +*/ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); + $object->fetch($id); + $object->fetch_thirdparty(); - $result = $object->setValid($user); - if ($result >= 0) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } + $result = $object->setValid($user); + if ($result >= 0) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } } else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); + $object->fetch($id); + $object->fetch_thirdparty(); - $result = $object->setDraft($user); - if ($result >= 0) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } + $result = $object->setDraft($user); + if ($result >= 0) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } } else if ($action == 'add' && $user->rights->ficheinter->creer) { - $object->socid = $socid; - $object->duree = GETPOST('duree','int'); - $object->fk_project = GETPOST('projectid','int'); - $object->author = $user->id; - $object->description = GETPOST('description'); - $object->ref = $ref; - $object->modelpdf = GETPOST('model','alpha'); - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); + $object->socid = $socid; + $object->duree = GETPOST('duree','int'); + $object->fk_project = GETPOST('projectid','int'); + $object->description = GETPOST('description'); + $object->ref = $ref; + $object->modelpdf = GETPOST('model','alpha'); + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); - if ($object->socid > 0) - { - // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid) ) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = $_POST['origin']; - if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - } + if ($object->socid > 0) + { + // If creation from another object of another module (Example: origin=propal, originid=1) + if (!empty($origin) && !empty($originid) ) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $_POST['origin']; + if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } - // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - if ($element == 'contract') { $element = $subelement = 'contrat'; } + // For compatibility + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } - $object->origin = $origin; - $object->origin_id = $originid; + $object->origin = $origin; + $object->origin_id = $originid; - // Possibility to add external linked objects with hooks - $object->linked_objects[$object->origin] = $object->origin_id; - if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) - { - $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); - } + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } - $id = $object->create($user); + $id = $object->create($user); - if ($id > 0) - { - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + if ($id > 0) + { + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - $srcobject = new $classname($db); + $classname = ucfirst($subelement); + $srcobject = new $classname($db); - dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); - $result=$srcobject->fetch($object->origin_id); - if ($result > 0) - { - $srcobject->fetch_thirdparty(); + dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); + $result=$srcobject->fetch($object->origin_id); + if ($result > 0) + { + $srcobject->fetch_thirdparty(); $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); + if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); - $fk_parent_line=0; - $num=count($lines); + $fk_parent_line=0; + $num=count($lines); - for ($i=0;$i<$num;$i++) - { - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + for ($i=0;$i<$num;$i++) + { + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); if ($product_type == 1) { //only services // service prédéfini @@ -232,107 +237,110 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?'
'.dol_htmlentitiesbr($lines[$i]->desc):''; } else { - $desc = dol_htmlentitiesbr($lines[$i]->desc); - $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; - } + $desc = dol_htmlentitiesbr($lines[$i]->desc); + $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; + } $timearray=dol_getdate(mktime()); - $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); + $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); $duration = 3600; - $result = $object->addline( - $id, - $desc, - $date_intervention, - $duration - ); + $result = $object->addline( + $id, + $desc, + $date_intervention, + $duration + ); - if ($result < 0) - { - $error++; - break; - } + if ($result < 0) + { + $error++; + break; + } } - } + } - } - else - { - $mesg=$srcobject->error; - $error++; - } - } - else - { - $mesg=$object->error; - $error++; - } - } - else - { - $result = $object->create(); - if ($result > 0) - { - $id=$result; // Force raffraichissement sur fiche venant d'etre cree - } - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans($object->error).'
'; - $action = 'create'; - } - } - } - else - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; - $action = 'create'; - } + } + else + { + $mesg=$srcobject->error; + $error++; + } + } + else + { + $mesg=$object->error; + $error++; + } + } + else + { + $result = $object->create($user); + if ($result > 0) + { + $id=$result; // Force raffraichissement sur fiche venant d'etre cree + } + else + { + $langs->load("errors"); + $mesg='
'.$langs->trans($object->error).'
'; + $action = 'create'; + } + } + } + else + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; + $action = 'create'; + } } else if ($action == 'update' && $user->rights->ficheinter->creer) { - $object->fetch($id); + $object->fetch($id); - $object->socid = $socid; - $object->fk_project = GETPOST('projectid','int'); - $object->author = $user->id; - $object->description = GETPOST('description','alpha'); - $object->ref = $ref; + $object->socid = $socid; + $object->fk_project = GETPOST('projectid','int'); + $object->author = $user->id; + $object->description = GETPOST('description','alpha'); + $object->ref = $ref; - $object->update(); + $result=$object->update($user); + if ($result<0) { + setEventMessage($object->error,'errors'); + } } /* * Build doc - */ +*/ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post { - $object->fetch($id); - $object->fetch_thirdparty(); - $object->fetch_lines(); + $object->fetch($id); + $object->fetch_thirdparty(); + $object->fetch_lines(); - if (GETPOST('model','alpha')) - { - $object->setDocModel($user, GETPOST('model','alpha')); - } + if (GETPOST('model','alpha')) + { + $object->setDocModel($user, GETPOST('model','alpha')); + } - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } } // Remove file in doc form @@ -356,9 +364,9 @@ else if ($action == 'remove_file') // Set into a project else if ($action == 'classin' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $result=$object->setProject(GETPOST('projectid','int')); - if ($result < 0) dol_print_error($db,$object->error); + $object->fetch($id); + $result=$object->setProject(GETPOST('projectid','int')); + if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) @@ -367,155 +375,155 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fich $object->fetch_thirdparty(); $object->delete($user); - header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); - exit; + header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); + exit; } else if ($action == 'setdescription' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $result=$object->set_description($user,GETPOST('description')); - if ($result < 0) dol_print_error($db,$object->error); + $object->fetch($id); + $result=$object->set_description($user,GETPOST('description')); + if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'setnote_public' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public'); - if ($result < 0) dol_print_error($db,$object->error); + $object->fetch($id); + $result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public'); + if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'setnote_private' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private'); - if ($result < 0) dol_print_error($db,$object->error); + $object->fetch($id); + $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private'); + if ($result < 0) dol_print_error($db,$object->error); } // Add line else if ($action == "addline" && $user->rights->ficheinter->creer) { - if (!GETPOST('np_desc')) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'
'; - $error++; - } - if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int')) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'
'; - $error++; - } - if (! $error) - { + if (!GETPOST('np_desc')) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'
'; + $error++; + } + if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int')) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'
'; + $error++; + } + if (! $error) + { $db->begin(); - $ret=$object->fetch($id); - $object->fetch_thirdparty(); + $ret=$object->fetch($id); + $object->fetch_thirdparty(); - $desc=GETPOST('np_desc'); - $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); - $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); + $desc=GETPOST('np_desc'); + $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); + $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); - $result=$object->addline( - $id, - $desc, - $date_intervention, - $duration - ); + $result=$object->addline( + $id, + $desc, + $date_intervention, + $duration + ); - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } if ($result >= 0) { $db->commit(); - fichinter_create($db, $object, $object->modelpdf, $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + fichinter_create($db, $object, $object->modelpdf, $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } else { $mesg=$object->error; $db->rollback(); } - } + } } // Classify Billed else if ($action == 'classifybilled' && $user->rights->ficheinter->creer) { - $object->fetch($id); + $object->fetch($id); $result=$object->setBilled(); if ($result > 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } else { - $mesg='
'.$object->error.'
'; + $mesg='
'.$object->error.'
'; } } /* * Mise a jour d'une ligne d'intervention - */ +*/ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save")) { - $objectline = new FichinterLigne($db); - if ($objectline->fetch(GETPOST('line_id','int')) <= 0) - { - dol_print_error($db); - exit; - } + $objectline = new FichinterLigne($db); + if ($objectline->fetch(GETPOST('line_id','int')) <= 0) + { + dol_print_error($db); + exit; + } - if ($object->fetch($objectline->fk_fichinter) <= 0) - { - dol_print_error($db); - exit; - } - $object->fetch_thirdparty(); + if ($object->fetch($objectline->fk_fichinter) <= 0) + { + dol_print_error($db); + exit; + } + $object->fetch_thirdparty(); - $desc = GETPOST('np_desc'); - $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); - $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int')); + $desc = GETPOST('np_desc'); + $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); + $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int')); - $objectline->datei = $date_inter; - $objectline->desc = $desc; - $objectline->duration = $duration; - $result = $objectline->update(); - if ($result < 0) - { - dol_print_error($db); - exit; - } + $objectline->datei = $date_inter; + $objectline->desc = $desc; + $objectline->duration = $duration; + $result = $objectline->update(); + if ($result < 0) + { + dol_print_error($db); + exit; + } - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - fichinter_create($db, $object, $object->modelpdf, $outputlangs); + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + fichinter_create($db, $object, $object->modelpdf, $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } /* * Supprime une ligne d'intervention AVEC confirmation - */ +*/ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer) { $objectline = new FichinterLigne($db); @@ -547,235 +555,226 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> /* * Ordonnancement des lignes - */ +*/ else if ($action == 'up' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); - $object->line_up(GETPOST('line_id','int')); + $object->fetch($id); + $object->fetch_thirdparty(); + $object->line_up(GETPOST('line_id','int')); - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - fichinter_create($db, $object, $object->modelpdf, $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int')); - exit; + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + fichinter_create($db, $object, $object->modelpdf, $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int')); + exit; } else if ($action == 'down' && $user->rights->ficheinter->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); - $object->line_down(GETPOST('line_id','int')); + $object->fetch($id); + $object->fetch_thirdparty(); + $object->line_down(GETPOST('line_id','int')); - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - fichinter_create($db, $object, $object->modelpdf, $outputlangs); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int')); - exit; + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + fichinter_create($db, $object, $object->modelpdf, $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int')); + exit; } /* * Add file in email form - */ +*/ if (GETPOST('addfile','alpha')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - // Set tmp user directory TODO Use a dedicated directory for temp mails files - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; + // Set tmp user directory TODO Use a dedicated directory for temp mails files + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; - dol_add_file_process($upload_dir_tmp,0,0); - $action='presend'; + dol_add_file_process($upload_dir_tmp,0,0); + $action='presend'; } /* * Remove file in email form - */ +*/ if (GETPOST('removedfile','alpha')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; // TODO Delete only files that was uploaded from email form - dol_remove_file_process(GETPOST('removedfile','alpha'),0); - $action='presend'; + dol_remove_file_process(GETPOST('removedfile','alpha'),0); + $action='presend'; } /* * Send mail - */ +*/ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)) { - $langs->load('mails'); + $langs->load('mails'); - if ($object->fetch($id) > 0) - { -// $objectref = dol_sanitizeFileName($object->ref); -// $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; + if ($object->fetch($id) > 0) + { -// if (is_readable($file)) -// { - $object->fetch_thirdparty(); + $object->fetch_thirdparty(); - if (GETPOST('sendto','alpha')) - { - // Le destinataire a ete fourni via le champ libre - $sendto = GETPOST('sendto','alpha'); - $sendtoid = 0; - } - elseif (GETPOST('receiver','alpha') != '-1') - { - // Recipient was provided from combo list - if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party - { - $sendto = $object->client->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email'); - $sendtoid = GETPOST('receiver','alpha'); - } - } + if (GETPOST('sendto','alpha')) + { + // Le destinataire a ete fourni via le champ libre + $sendto = GETPOST('sendto','alpha'); + $sendtoid = 0; + } + elseif (GETPOST('receiver','alpha') != '-1') + { + // Recipient was provided from combo list + if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party + { + $sendto = $object->client->email; + $sendtoid = 0; + } + else // Id du contact + { + $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email'); + $sendtoid = GETPOST('receiver','alpha'); + } + } - if (dol_strlen($sendto)) - { - $langs->load("commercial"); + if (dol_strlen($sendto)) + { + $langs->load("commercial"); - $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>'; - $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>'; - $message = GETPOST('message'); - $sendtocc = GETPOST('sendtocc','alpha'); - $deliveryreceipt = GETPOST('deliveryreceipt','alpha'); + $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>'; + $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>'; + $message = GETPOST('message'); + $sendtocc = GETPOST('sendtocc','alpha'); + $deliveryreceipt = GETPOST('deliveryreceipt','alpha'); - if ($action == 'send') - { - if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha'); - else $subject = $langs->transnoentities('Intervention').' '.$object->ref; - $actiontypecode='AC_OTH_AUTO'; - $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; - if ($message) - { - $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; - $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; - $actionmsg.=$message; - } - $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); - } + if ($action == 'send') + { + if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha'); + else $subject = $langs->transnoentities('Intervention').' '.$object->ref; + $actiontypecode='AC_OTH_AUTO'; + $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; + if ($message) + { + $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; + $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; + $actionmsg.=$message; + } + $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); + } - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); - $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; - // Envoi de la propal - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); - if ($mailfile->error) - { - $mesg='
'.$mailfile->error.'
'; - } - else - { - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); - setEventMessage($mesg); - $error=0; + // Envoi de la propal + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); + if ($mailfile->error) + { + $mesg='
'.$mailfile->error.'
'; + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); + setEventMessage($mesg); + $error=0; - // Initialisation donnees - $object->sendtoid = $sendtoid; - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; - $object->actionmsg2 = $actionmsg2; - $object->fk_element = $object->id; - $object->elementtype = $object->element; + // Initialisation donnees + $object->sendtoid = $sendtoid; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; + $object->actionmsg2 = $actionmsg2; + $object->fk_element = $object->id; + $object->elementtype = $object->element; - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers - if ($error) - { - dol_print_error($db); - } - else - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } - else - { - $langs->load("other"); - $mesg='
'; - if ($mailfile->error) - { - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; - } - else - { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } - $mesg.='
'; - } - } - } - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; - dol_syslog('Recipient email is empty'); - } - /*} - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; - dol_syslog('Failed to read file: '.$file); - }*/ - } - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'
'; - dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.'); - } + if ($error) + { + dol_print_error($db); + } + else + { + // Redirect here + // This avoid sending mail twice if going out and then back to page + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + } + else + { + $langs->load("other"); + $mesg='
'; + if ($mailfile->error) + { + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.='
'; + } + } + } + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; + dol_syslog('Recipient email is empty'); + } + } + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'
'; + dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.'); + } - $action='presend'; + $action='presend'; } if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) @@ -842,7 +841,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheint /* * View - */ +*/ $form = new Form($db); $formfile = new FormFile($db); @@ -851,733 +850,739 @@ llxHeader(); if ($action == 'create') { - /* - * Mode creation - * Creation d'une nouvelle fiche d'intervention - */ + /* + * Mode creation + * Creation d'une nouvelle fiche d'intervention + */ - $soc=new Societe($db); + $soc=new Societe($db); - print_fiche_titre($langs->trans("AddIntervention")); + print_fiche_titre($langs->trans("AddIntervention")); - dol_htmloutput_mesg($mesg); + dol_htmloutput_mesg($mesg); - if ($socid) $res=$soc->fetch($socid); + if ($socid) $res=$soc->fetch($socid); - if (GETPOST('origin') && GETPOST('originid')) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); - if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - } + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); + if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } - if ($element == 'project') - { - $projectid=GETPOST('originid'); - } - else - { - // For compatibility - if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - if ($element == 'contract') { $element = $subelement = 'contrat'; } + if ($element == 'project') + { + $projectid=GETPOST('originid'); + } + else + { + // For compatibility + if ($element == 'order' || $element == 'commande') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - $objectsrc = new $classname($db); - $objectsrc->fetch(GETPOST('originid')); - if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); - $objectsrc->fetch_thirdparty(); + $classname = ucfirst($subelement); + $objectsrc = new $classname($db); + $objectsrc->fetch(GETPOST('originid')); + if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); + $objectsrc->fetch_thirdparty(); - $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); - $soc = $objectsrc->client; + $soc = $objectsrc->client; - $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : '')); - $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); + $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : '')); + $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); - // Object source contacts list - $srccontactslist = $objectsrc->liste_contact(-1,'external',1); - } - } - else { + // Object source contacts list + $srccontactslist = $objectsrc->liste_contact(-1,'external',1); + } + } + else { $projectid = GETPOST('projectid','int'); $note_private = ''; $note_public = ''; } - if (! $conf->global->FICHEINTER_ADDON) - { - dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); - exit; - } + if (! $conf->global->FICHEINTER_ADDON) + { + dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); + exit; + } - $object->date = dol_now(); + $object->date = dol_now(); - $obj = $conf->global->FICHEINTER_ADDON; - $obj = "mod_".$obj; + $obj = $conf->global->FICHEINTER_ADDON; + $obj = "mod_".$obj; - //$modFicheinter = new $obj; - //$numpr = $modFicheinter->getNextValue($soc, $object); + //$modFicheinter = new $obj; + //$numpr = $modFicheinter->getNextValue($soc, $object); - if ($socid > 0) - { - $soc->fetch($socid); + if ($socid > 0) + { + $soc->fetch($socid); - print '
'; - print ''; + print ''; + print ''; - print ''; + print '
'; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; - // Ref + // Ref print ''; - // Description (must be a textarea and not html must be allowed (used in list view) - print ''; - print ''; + // Description (must be a textarea and not html must be allowed (used in list view) + print ''; + print ''; - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("project"); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("project"); - print ''; - } - - // Model - print ''; - print ''; - print '"; - - // Public note - print ''; - print ''; - print ''; - - // Private note - if (!empty($user->societe_id)) - { - print ''; - print ''; - print ''; - } - - // Other attributes - $parameters=array('colspan' => ' colspan="2"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - - - // Show link to origin object - if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) - { - $newclassname=$classname; - if ($newclassname=='Propal') $newclassname='CommercialProposal'; - print ''; - } - - print '
'.$langs->trans("ThirdParty").''.$soc->getNomUrl(1).'
'.$langs->trans("ThirdParty").''.$soc->getNomUrl(1).'
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans("Description").''; - print ''; - print '
'.$langs->trans("Description").''; + print ''; + print '
'.$langs->trans("Project").''; - /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty - if ($societe->fournisseur==1) - $numprojet=select_projects(-1,$_POST["projectid"],'projectid'); - else - $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid'); - */ - $numprojet=select_projects($soc->id,GETPOST('projectid','int'),'projectid'); - if ($numprojet==0) - { - print '   '.$langs->trans("AddProject").''; - } - print '
'.$langs->trans("DefaultModel").''; - $liste=ModelePDFFicheinter::liste_modeles($db); - print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF); - print "
'.$langs->trans('NotePublic').''; - $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); - print $doleditor->Create(1); - //print ''; - print '
'.$langs->trans('NotePrivate').''; - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); - print $doleditor->Create(1); - //print ''; - print '
'.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).'
'; - - if (is_object($objectsrc)) - { - print ''; - print ''; + print ''.$langs->trans("Project").''; + /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty + if ($societe->fournisseur==1) + $numprojet=select_projects(-1,$_POST["projectid"],'projectid'); + else + $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid'); + */ + $numprojet=select_projects($soc->id,GETPOST('projectid','int'),'projectid'); + if ($numprojet==0) + { + print '   '.$langs->trans("AddProject").''; + } + print ''; } - print '

'; - print ''; - print '
'; + // Model + print ''; + print ''.$langs->trans("DefaultModel").''; + print ''; + $liste=ModelePDFFicheinter::liste_modeles($db); + print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF); + print ""; - print '
'; - } - else - { - print '
'; - print ''; - print ''; - print '
'.$langs->trans("ThirdParty").''; - print $form->select_company('','socid','',1,1); - print '
'; + // Public note + print ''; + print ''.$langs->trans('NotePublic').''; + print ''; + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + print $doleditor->Create(1); + //print ''; + print ''; - print '
'; - print ''; - print ''; - print '
'; + // Private note + if (!empty($user->societe_id)) + { + print ''; + print ''.$langs->trans('NotePrivate').''; + print ''; + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + print $doleditor->Create(1); + //print ''; + print ''; + } - print '
'; - } + // Other attributes + $parameters=array('colspan' => ' colspan="2"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + + // Show link to origin object + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) + { + $newclassname=$classname; + if ($newclassname=='Propal') $newclassname='CommercialProposal'; + print ''.$langs->trans($newclassname).''.$objectsrc->getNomUrl(1).''; + } + + print ''; + + if (is_object($objectsrc)) + { + print ''; + print ''; + } + + print '

'; + print ''; + print '
'; + + print ''; + } + else + { + print '
'; + print ''; + print ''; + print '
'.$langs->trans("ThirdParty").''; + print $form->select_company('','socid','',1,1); + print '
'; + + print '
'; + print ''; + print ''; + print '
'; + + print '
'; + } } else if ($id > 0 || ! empty($ref)) { - /* - * Affichage en mode visu - */ + /* + * Affichage en mode visu + */ $object->fetch($id, $ref); - $object->fetch_thirdparty(); + $object->fetch_thirdparty(); - $soc=new Societe($db); - $soc->fetch($object->socid); + $soc=new Societe($db); + $soc->fetch($object->socid); - dol_htmloutput_mesg($mesg); + dol_htmloutput_mesg($mesg); - $head = fichinter_prepare_head($object); + $head = fichinter_prepare_head($object); - dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention'); + dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention'); - // Confirmation de la suppression de la fiche d'intervention - if ($action == 'delete') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1); - if ($ret == 'html') print '
'; - } + // Confirmation de la suppression de la fiche d'intervention + if ($action == 'delete') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1); + if ($ret == 'html') print '
'; + } - // Confirmation validation - if ($action == 'validate') - { - // on verifie si l'objet est en numerotation provisoire - $ref = substr($object->ref, 1, 4); - if ($ref == 'PROV') - { - $numref = $object->getNextNumRef($soc); - if (empty($numref)) - { - $error++; - dol_htmloutput_errors($object->error); - } - } - else - { - $numref = $object->ref; - } - $text=$langs->trans('ConfirmValidateIntervention',$numref); + // Confirmation validation + if ($action == 'validate') + { + // on verifie si l'objet est en numerotation provisoire + $ref = substr($object->ref, 1, 4); + if ($ref == 'PROV') + { + $numref = $object->getNextNumRef($soc); + if (empty($numref)) + { + $error++; + dol_htmloutput_errors($object->error); + } + } + else + { + $numref = $object->ref; + } + $text=$langs->trans('ConfirmValidateIntervention',$numref); - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate','',0,1); - if ($ret == 'html') print '
'; - } + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate','',0,1); + if ($ret == 'html') print '
'; + } - // Confirmation de la validation de la fiche d'intervention - if ($action == 'modify') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1); - if ($ret == 'html') print '
'; - } + // Confirmation de la validation de la fiche d'intervention + if ($action == 'modify') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1); + if ($ret == 'html') print '
'; + } - // Confirmation de la suppression d'une ligne d'intervention - if ($action == 'ask_deleteline') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.GETPOST('line_id','int'), $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1); - if ($ret == 'html') print '
'; - } + // Confirmation de la suppression d'une ligne d'intervention + if ($action == 'ask_deleteline') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.GETPOST('line_id','int'), $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1); + if ($ret == 'html') print '
'; + } - print ''; + print '
'; - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; - // Ref - print ''; + // Ref + print ''; - // Third party - print ""; + // Third party + print ""; - // Duration - print ''; - print ''; - print ''; + // Duration + print ''; + print ''; + print ''; - // Description (must be a textarea and not html must be allowed (used in list view) - print ''; - print ''; + // Description (must be a textarea and not html must be allowed (used in list view) + print ''; + print ''; - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load('projects'); - print ''; - print ''; + print ''; - print ''; - } + print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); + print '
".$langs->trans("Company")."".$object->client->getNomUrl(1)."
".$langs->trans("Company")."".$object->client->getNomUrl(1)."
'.$langs->trans("TotalDuration").''.convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'
'.$langs->trans("TotalDuration").''.convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'
'; - print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea'); - print ''; - print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea:8:80'); - print '
'; + print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea'); + print ''; + print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea:8:80'); + print '
'; + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load('projects'); + print '
'; - print ''; - if ($action != 'classify') - { - print ''; - } - print '
'; - print $langs->trans('Project'); - print 'id.'">'; - print img_edit($langs->trans('SetProject'),1); - print '
'; - print '
'; - if ($action == 'classify') - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); - } - else - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); - } - print '
'; + if ($action != 'classify') + { + print ''; + } + print '
'; + print $langs->trans('Project'); + print 'id.'">'; + print img_edit($langs->trans('SetProject'),1); + print '
'; + print ''; + if ($action == 'classify') + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); + } + else + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); + } + print ''; + print ''; + } - // Statut - print ''.$langs->trans("Status").''.$object->getLibStatut(4).''; + // Statut + print ''.$langs->trans("Status").''.$object->getLibStatut(4).''; - // Other attributes - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + // Other attributes + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print "
"; + print "
"; - if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) - { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) + { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } + { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } - /* - * Lignes d'intervention - */ - $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,'; - $sql.= ' ft.date as date_intervention'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft'; - $sql.= ' WHERE ft.fk_fichinter = '.$object->id; - $sql.= ' ORDER BY ft.rang ASC, ft.rowid'; + /* + * Lignes d'intervention + */ + $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,'; + $sql.= ' ft.date as date_intervention'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft'; + $sql.= ' WHERE ft.fk_fichinter = '.$object->id; + $sql.= ' ORDER BY ft.rang ASC, ft.rowid'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; - if ($num) - { - print ''; + if ($num) + { + print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; - // Ligne en mode visu - if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid) - { - print ''; - print ''; + print ''; + // Date + print ''; - // Duration - print ''; + // Duration + print ''; - print "\n"; + print "\n"; - // Icone d'edition et suppression - if ($object->statut == 0 && $user->rights->ficheinter->creer) - { - print ''; - print ''; - if ($num > 1) - { - print ''; - } - } - else - { - print ''; - } + // Icone d'edition et suppression + if ($object->statut == 0 && $user->rights->ficheinter->creer) + { + print ''; + print ''; + if ($num > 1) + { + print ''; + } + } + else + { + print ''; + } - print ''; - } + print ''; + } - // Ligne en mode update - if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid) - { - print 'rowid.'" method="post">'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + // Editeur wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70); + $doleditor->Create(); + print ''; - // Date d'intervention - print ''; + // Date d'intervention + print ''; - // Duration - print ''; + // Duration + print ''; - print ''; - print '' . "\n"; + print ''; + print '' . "\n"; - print "\n"; - } + print "\n"; + } - $i++; - } + $i++; + } - $db->free($resql); + $db->free($resql); - /* - * Add line - */ - if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline') - { - if (! $num) print '
'.$langs->trans('Description').''.$langs->trans('Date').''.$langs->trans('Duration').' 
'.$langs->trans('Description').''.$langs->trans('Date').''.$langs->trans('Duration').' 
'; - print ''; // ancre pour retourner sur la ligne - print dol_htmlentitiesbr($objp->description); + // Ligne en mode visu + if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid) + { + print '
'; + print ''; // ancre pour retourner sur la ligne + print dol_htmlentitiesbr($objp->description); - // Date - print ''.dol_print_date($db->jdate($objp->date_intervention),'dayhour').''.dol_print_date($db->jdate($objp->date_intervention),'dayhour').''.convertSecondToTime($objp->duree).''.convertSecondToTime($objp->duree).''; - print 'rowid.'#'.$objp->rowid.'">'; - print img_edit(); - print ''; - print ''; - print 'rowid.'">'; - print img_delete(); - print ''; - if ($i > 0) - { - print 'rowid.'">'; - print img_up(); - print ''; - } - if ($i < $num-1) - { - print 'rowid.'">'; - print img_down(); - print ''; - } - print ' '; + print 'rowid.'#'.$objp->rowid.'">'; + print img_edit(); + print ''; + print ''; + print 'rowid.'">'; + print img_delete(); + print ''; + if ($i > 0) + { + print 'rowid.'">'; + print img_up(); + print ''; + } + if ($i < $num-1) + { + print 'rowid.'">'; + print img_down(); + print ''; + } + print ' 
'; - print ''; // ancre pour retourner sur la ligne + // Ligne en mode update + if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid) + { + print 'rowid.'" method="post">'; + print ''; + print ''; + print ''; + print ''; + print '
'; + print ''; // ancre pour retourner sur la ligne - // Editeur wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70); - $doleditor->Create(); - print ''; - $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention"); - print ''; + $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention"); + print ''; - $form->select_duration('duration',$objp->duree); - print ''; + $form->select_duration('duration',$objp->duree); + print ''; - print '
'; + print '
'; + /* + * Add line + */ + if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline') + { + if (! $num) print '
'; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - print ''; - print "\n"; + print ''; + print "\n"; - // Ajout ligne d'intervention - print ''; - print ''; - print ''; - print ''; + // Ajout ligne d'intervention + print ''; + print ''; + print ''; + print ''; - $var=false; + $var=false; - print '\n"; - print ''; + print '\n"; + print ''; - // Date intervention - print ''; + // Date intervention + print ''; - // Duration - print ''; + // Duration + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; - if (! $num) print '
'; - print ''; // ancre - print $langs->trans('Description').''.$langs->trans('Date').''.$langs->trans('Duration').'
'; + print ''; // ancre + print $langs->trans('Description').''.$langs->trans('Date').''.$langs->trans('Duration').' 
 
'; - // editeur wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('np_desc',GETPOST('np_desc','alpha'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70); - $doleditor->Create(); - print '
'; + // editeur wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor=new DolEditor('np_desc',GETPOST('np_desc','alpha'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70); + $doleditor->Create(); + print ''; - $now=dol_now(); - $timearray=dol_getdate($now); - if (!GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); - else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int')); - $form->select_date($timewithnohour,'di',1,1,0,"addinter"); - print ''; + $now=dol_now(); + $timearray=dol_getdate($now); + if (!GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); + else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int')); + $form->select_date($timewithnohour,'di',1,1,0,"addinter"); + print ''; - $form->select_duration('duration',(!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))?3600:(60*60*GETPOST('durationhour','int')+60*GETPOST('durationmin','int'))); - print ''; + $form->select_duration('duration',(!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))?3600:(60*60*GETPOST('durationhour','int')+60*GETPOST('durationmin','int'))); + print '
'; - } + if (! $num) print ''; + } - if ($num) print ''; - } - else - { - dol_print_error($db); - } + if ($num) print ''; + } + else + { + dol_print_error($db); + } - print ''; - print "\n"; + print ''; + print "\n"; - /* - * Barre d'actions - */ - print '
'; + /* + * Barre d'actions + */ + print '
'; - if ($user->societe_id == 0) - { - if ($action != 'editdescription' && ($action != 'presend')) - { - // Validate - if ($object->statut == 0 && $user->rights->ficheinter->creer && count($object->lines) > 0) - { - print ''; - } + if ($user->societe_id == 0) + { + if ($action != 'editdescription' && ($action != 'presend')) + { + // Validate + if ($object->statut == 0 && $user->rights->ficheinter->creer && count($object->lines) > 0) + { + print ''; + } - // Modify - if ($object->statut == 1 && $user->rights->ficheinter->creer) - { - print ''; - } + // Modify + if ($object->statut == 1 && $user->rights->ficheinter->creer) + { + print ''; + } - // Send - if ($object->statut > 0) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) - { - print ''; - } - else print ''; - } + // Send + if ($object->statut > 0) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) + { + print ''; + } + else print ''; + } - // Invoicing + // Invoicing if (! empty($conf->facture->enabled) && $object->statut > 0) - { + { $langs->load("bills"); - if ($object->statut < 2) - { + if ($object->statut < 2) + { if ($user->rights->facture->creer) print ''; else print ''; - } + } - if (! empty($conf->global->FICHINTER_CLASSIFY_BILLED)) - { - if ($object->statut != 2) + if (! empty($conf->global->FICHINTER_CLASSIFY_BILLED)) + { + if ($object->statut != 2) { print ''; } - } - } + } + } - // Delete - if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) - { - print ''; - } + // Delete + if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) + { + print ''; + } - } - } + } + } - print '
'; - print '
'; + print '
'; + print '
'; - if ($action != 'presend') - { + if ($action != 'presend') + { print '
'; - //print '
'; + //print '
'; - /* - * Built documents - */ - $filename=dol_sanitizeFileName($object->ref); - $filedir=$conf->ficheinter->dir_output . "/".$object->ref; - $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed=$user->rights->ficheinter->creer; - $delallowed=$user->rights->ficheinter->supprimer; - $genallowed=1; - $delallowed=1; + /* + * Built documents + */ + $filename=dol_sanitizeFileName($object->ref); + $filedir=$conf->ficheinter->dir_output . "/".$object->ref; + $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed=$user->rights->ficheinter->creer; + $delallowed=$user->rights->ficheinter->supprimer; + $genallowed=1; + $delallowed=1; - $var=true; + $var=true; - //print "
\n"; - $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); + //print "
\n"; + $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); - /* - * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); + /* + * Linked object block + */ + $somethingshown=$object->showLinkedObjectBlock(); - //print '
'; - print '
'; + //print '
'; + print '
'; - // List of actions on element - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - $somethingshown=$formactions->showactions($object,'fichinter',$socid); + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions=new FormActions($db); + $somethingshown=$formactions->showactions($object,'fichinter',$socid); - print '
'; - //print "
\n"; - } + print ''; + //print "
\n"; + } - /* - * Action presend - */ - if ($action == 'presend') - { - $ref = dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); - $file=$fileparams['fullname']; + /* + * Action presend + */ + if ($action == 'presend') + { + $ref = dol_sanitizeFileName($object->ref); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); + $file=$fileparams['fullname']; - // Build document if it not exists - if (! $file || ! is_readable($file)) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } - $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); - $file=$fileparams['fullname']; - } + $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); + $file=$fileparams['fullname']; + } - print '
'; - print_titre($langs->trans('SendInterventionByMail')); + print '
'; + print_titre($langs->trans('SendInterventionByMail')); - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->fromtype = 'user'; - $formmail->fromid = $user->id; - $formmail->fromname = $user->getFullName($langs); - $formmail->frommail = $user->email; - $formmail->withfrom=1; + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + $formmail->withfrom=1; $liste=array(); foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value; $formmail->withto=GETPOST("sendto")?GETOST("sendto"):$liste; $formmail->withtocc=$liste; - $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; - $formmail->withtopic=$langs->trans('SendInterventionRef','__FICHINTERREF__'); - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtopic=$langs->trans('SendInterventionRef','__FICHINTERREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; - // Tableau des substitutions - $formmail->substit['__FICHINTERREF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - $formmail->substit['__CONTACTCIVNAME__']=''; + // Tableau des substitutions + $formmail->substit['__FICHINTERREF__']=$object->ref; + $formmail->substit['__SIGNATURE__']=$user->signature; + $formmail->substit['__PERSONALIZED__']=''; + $formmail->substit['__CONTACTCIVNAME__']=''; - //Find the good contact adress - $custcontact=''; - $contactarr=array(); - $contactarr=$object->liste_contact(-1,'external'); + //Find the good contact adress + $custcontact=''; + $contactarr=array(); + $contactarr=$object->liste_contact(-1,'external'); - if (is_array($contactarr) && count($contactarr)>0) { - foreach($contactarr as $contact) { - if ($contact['libelle']==$langs->trans('TypeContact_fichinter_external_CUSTOMER')) { - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - $contactstatic=new Contact($db); - $contactstatic->fetch($contact['id']); - $custcontact=$contactstatic->getFullName($langs,1); - } - } + if (is_array($contactarr) && count($contactarr)>0) { + foreach($contactarr as $contact) { + if ($contact['libelle']==$langs->trans('TypeContact_fichinter_external_CUSTOMER')) { + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + $contactstatic=new Contact($db); + $contactstatic->fetch($contact['id']); + $custcontact=$contactstatic->getFullName($langs,1); + } + } - if (!empty($custcontact)) { - $formmail->substit['__CONTACTCIVNAME__']=$custcontact; - } - } + if (!empty($custcontact)) { + $formmail->substit['__CONTACTCIVNAME__']=$custcontact; + } + } - // Tableau des parametres complementaires - $formmail->param['action']='send'; - $formmail->param['models']='fichinter_send'; - $formmail->param['fichinter_id']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='fichinter_send'; + $formmail->param['fichinter_id']=$object->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - // Init list of files - if (GETPOST("mode")=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); - } + // Init list of files + if (GETPOST("mode")=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); + } - $formmail->show_form(); + $formmail->show_form(); - print '
'; - } + print '
'; + } } From 181ce5222353cabf9bca897a150c0292196a3b72 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sat, 18 May 2013 22:17:46 +0200 Subject: [PATCH 18/33] Add ficheinter in GetElementURL for action --- htdocs/core/class/commonobject.class.php | 3 +++ htdocs/fichinter/class/fichinter.class.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5678936ea5d..232e2dda9fc 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2517,6 +2517,9 @@ abstract class CommonObject if ($objecttype == 'cabinetmed_cons') { $classpath = 'cabinetmed/class'; $module='cabinetmed'; $subelement='cabinetmedcons'; } + if ($objecttype == 'ficheinter') { + $classpath = 'fichinter/class'; $module='ficheinter'; $subelement='fichinter'; + } //print "objecttype=".$objecttype." module=".$module." subelement=".$subelement; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 13baa5ac389..953198b220b 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -526,7 +526,7 @@ class Fichinter extends CommonObject * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only * @return string String with URL */ - function getNomUrl($withpicto=0) + function getNomUrl($withpicto=0,$option='') { global $langs; From a8e1d111c35e9553f7300a71568ea3c63b51b746 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 10:26:25 +0200 Subject: [PATCH 19/33] Add trigger into ficheinter lines and $user pass trought parameters every where --- htdocs/fichinter/class/fichinter.class.php | 63 +++++++++++++++++++--- htdocs/fichinter/fiche.php | 6 ++- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 953198b220b..7d310c5310b 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -246,7 +246,7 @@ class Fichinter extends CommonObject // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_MODIFY',$this,$user,$langs,$conf); + $result=$interface->run_triggers('FICHINTER_UPDATE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } @@ -652,7 +652,7 @@ class Fichinter extends CommonObject * @param User $user Object user who delete * @return int <0 if KO, >0 if OK */ - function delete($user) + function delete($user, $notrigger=0) { global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -719,6 +719,8 @@ class Fichinter extends CommonObject } } + if (! $notrigger) + { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); @@ -727,7 +729,7 @@ class Fichinter extends CommonObject $error++; $this->errors=$interface->errors; } // Fin appel triggers - + } $this->db->commit(); return 1; } @@ -815,13 +817,14 @@ class Fichinter extends CommonObject /** * Adding a line of intervention into data base * + * @param user $user User that do the action * @param int $fichinterid Id of intervention * @param string $desc Line description * @param date $date_intervention Intervention date * @param int $duration Intervention duration * @return int >0 if ok, <0 if ko */ - function addline($fichinterid, $desc, $date_intervention, $duration) + function addline($user,$fichinterid, $desc, $date_intervention, $duration) { dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); @@ -837,7 +840,7 @@ class Fichinter extends CommonObject $line->datei = $date_intervention; $line->duration = $duration; - $result=$line->insert(); + $result=$line->insert($user); if ($result > 0) { $this->db->commit(); @@ -1006,7 +1009,7 @@ class FichinterLigne * * @return int <0 if ko, >0 if ok */ - function insert() + function insert($user, $notrigger=0) { dol_syslog("FichinterLigne::insert rang=".$this->rang); @@ -1050,6 +1053,19 @@ class FichinterLigne if ($result > 0) { $this->rang=$rangToUse; + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTERDET_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } + $this->db->commit(); return $result; } @@ -1072,9 +1088,11 @@ class FichinterLigne /** * Update intervention into database * + * @param User $user Objet user that make creation + * @param int $notrigger Disable all triggers * @return int <0 if ko, >0 if ok */ - function update() + function update($user,$notrigger=0) { $this->db->begin(); @@ -1093,6 +1111,20 @@ class FichinterLigne $result=$this->update_total(); if ($result > 0) { + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTERDET_UPDATE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } + + $this->db->commit(); return $result; } @@ -1168,9 +1200,11 @@ class FichinterLigne /** * Delete a intervention line * + * @param User $user Objet user that make creation + * @param int $notrigger Disable all triggers * @return int >0 if ok, <0 if ko */ - function deleteline() + function deleteline($user,$notrigger=0) { if ($this->statut == 0) { @@ -1187,6 +1221,19 @@ class FichinterLigne if ($result > 0) { $this->db->commit(); + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTERDET_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } + return $result; } else diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 0ef8ca87f2c..c6201c6d1dc 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -245,6 +245,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $duration = 3600; $result = $object->addline( + $user, $id, $desc, $date_intervention, @@ -423,6 +424,7 @@ else if ($action == "addline" && $user->rights->ficheinter->creer) $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); $result=$object->addline( + $user, $id, $desc, $date_intervention, @@ -498,7 +500,7 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST( $objectline->datei = $date_inter; $objectline->desc = $desc; $objectline->duration = $duration; - $result = $objectline->update(); + $result = $objectline->update($user); if ($result < 0) { dol_print_error($db); @@ -532,7 +534,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> dol_print_error($db); exit; } - $result=$objectline->deleteline(); + $result=$objectline->deleteline($user); if ($object->fetch($objectline->fk_fichinter) <= 0) { From 94e2ea05d2c88f1ac3e41e097530356f50854057 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 11:18:45 +0200 Subject: [PATCH 20/33] Fix trigger ficheinterline --- htdocs/fichinter/class/fichinter.class.php | 1282 ++++++++++---------- 1 file changed, 646 insertions(+), 636 deletions(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 7d310c5310b..ba9da8a12d1 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -160,7 +160,7 @@ class Fichinter extends CommonObject if ($result) { $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); - + if ($this->id) { $this->ref='(PROV'.$this->id.')'; @@ -218,506 +218,506 @@ class Fichinter extends CommonObject * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK */ - function update($user, $notrigger=0) - { - if (! is_numeric($this->duree)) { - $this->duree = 0; - } - if (! dol_strlen($this->fk_project)) { - $this->fk_project = 0; - } + function update($user, $notrigger=0) + { + if (! is_numeric($this->duree)) { + $this->duree = 0; + } + if (! dol_strlen($this->fk_project)) { + $this->fk_project = 0; + } - $this->db->begin(); + $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; - $sql.= ", description = '".$this->db->escape($this->description)."'"; - $sql.= ", duree = ".$this->duree; - $sql.= ", fk_projet = ".$this->fk_project; - $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); - $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); - $sql.= " WHERE rowid = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; + $sql.= ", description = '".$this->db->escape($this->description)."'"; + $sql.= ", duree = ".$this->duree; + $sql.= ", fk_projet = ".$this->fk_project; + $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); + $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); + $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); $result=$interface->run_triggers('FICHINTER_UPDATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - } + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::update error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::update error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } - /** - * Fetch a intervention - * - * @param int $rowid Id of intervention - * @param string $ref Ref of intervention - * @return int <0 if KO, >0 if OK - */ - function fetch($rowid,$ref='') - { - $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; - $sql.= " f.datec,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.tms as datem,"; - $sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; - if ($ref) $sql.= " WHERE f.ref='".$this->db->escape($ref)."'"; - else $sql.= " WHERE f.rowid=".$rowid; + /** + * Fetch a intervention + * + * @param int $rowid Id of intervention + * @param string $ref Ref of intervention + * @return int <0 if KO, >0 if OK + */ + function fetch($rowid,$ref='') + { + $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; + $sql.= " f.datec,"; + $sql.= " f.date_valid as datev,"; + $sql.= " f.tms as datem,"; + $sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + if ($ref) $sql.= " WHERE f.ref='".$this->db->escape($ref)."'"; + else $sql.= " WHERE f.rowid=".$rowid; - dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->description = $obj->description; - $this->socid = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->duree = $obj->duree; - $this->datec = $this->db->jdate($obj->datec); - $this->datev = $this->db->jdate($obj->datev); - $this->datem = $this->db->jdate($obj->datem); - $this->fk_project = $obj->fk_projet; - $this->note_public = $obj->note_public; - $this->note_private = $obj->note_private; - $this->modelpdf = $obj->model_pdf; + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->description = $obj->description; + $this->socid = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->duree = $obj->duree; + $this->datec = $this->db->jdate($obj->datec); + $this->datev = $this->db->jdate($obj->datev); + $this->datem = $this->db->jdate($obj->datem); + $this->fk_project = $obj->fk_projet; + $this->note_public = $obj->note_public; + $this->note_private = $obj->note_private; + $this->modelpdf = $obj->model_pdf; - $this->extraparams = (array) json_decode($obj->extraparams, true); + $this->extraparams = (array) json_decode($obj->extraparams, true); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == 0) $this->brouillon = 1; - /* - * Lines - */ - $result=$this->fetch_lines(); - if ($result < 0) - { - return -3; - } - $this->db->free($resql); - return 1; - } - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::fetch ".$this->error,LOG_ERR); - return -1; - } - } + /* + * Lines + */ + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } + $this->db->free($resql); + return 1; + } + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::fetch ".$this->error,LOG_ERR); + return -1; + } + } - /** - * Set status to draft - * - * @param User $user User that set draft - * @return int <0 if KO, >0 if OK - */ - function setDraft($user) - { - global $langs, $conf; + /** + * Set status to draft + * + * @param User $user User that set draft + * @return int <0 if KO, >0 if OK + */ + function setDraft($user) + { + global $langs, $conf; - if ($this->statut != 0) - { - $this->db->begin(); + if ($this->statut != 0) + { + $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = 0"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; + $sql.= " SET fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; - dol_syslog("Fichinter::setDraft sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog("Fichinter::setDraft ".$this->error,LOG_ERR); - return -1; - } - } - } + dol_syslog("Fichinter::setDraft sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("Fichinter::setDraft ".$this->error,LOG_ERR); + return -1; + } + } + } - /** - * Validate a intervention - * - * @param User $user User that validate - * @return int <0 if KO, >0 if OK - */ - function setValid($user) - { - global $langs, $conf; + /** + * Validate a intervention + * + * @param User $user User that validate + * @return int <0 if KO, >0 if OK + */ + function setValid($user) + { + global $langs, $conf; - $error=0; + $error=0; - if ($this->statut != 1) - { - $this->db->begin(); + if ($this->statut != 1) + { + $this->db->begin(); - $now=dol_now(); - - // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) - { - $num = $this->getNextNumRef($this->thirdparty); - } - else - { - $num = $this->ref; - } + $now=dol_now(); + + // Define new ref + if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) + { + $num = $this->getNextNumRef($this->thirdparty); + } + else + { + $num = $this->ref; + } - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = 1"; - $sql.= ", ref = '".$num."'"; - $sql.= ", date_valid = ".$this->db->idate($now); - $sql.= ", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; + $sql.= " SET fk_statut = 1"; + $sql.= ", ref = '".$num."'"; + $sql.= ", date_valid = ".$this->db->idate($now); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; - dol_syslog(get_class($this)."::setValid sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + dol_syslog(get_class($this)."::setValid sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=join(',',$this->errors); - dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); - return -1; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); - return -1; - } - } - } + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=join(',',$this->errors); + dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR); + return -1; + } + } + } - /** - * Set intervetnion as billed - * - * @return int <0 si ko, >0 si ok - */ - function setBilled() - { - global $conf; + /** + * Set intervetnion as billed + * + * @return int <0 si ko, >0 si ok + */ + function setBilled() + { + global $conf; - $sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter SET fk_statut = 2'; - $sql.= ' WHERE rowid = '.$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 1"; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter SET fk_statut = 2'; + $sql.= ' WHERE rowid = '.$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 1"; - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dol_print_error($this->db); - return -1; - } - } + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } - /** - * Returns the label status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->statut,$mode); - } + /** + * Returns the label status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } - /** - * Returns the label of a statut - * - * @param int $statut id statut - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label - */ - function LibStatut($statut,$mode=0) - { - global $langs; + /** + * Returns the label of a statut + * + * @param int $statut id statut + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function LibStatut($statut,$mode=0) + { + global $langs; - if ($mode == 0) - { - return $langs->trans($this->statuts[$statut]); - } - if ($mode == 1) - { - return $langs->trans($this->statuts_short[$statut]); - } - if ($mode == 2) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); - } - if ($mode == 3) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); - } - if ($mode == 4) - { - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); - if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); - if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); - } - if ($mode == 5) - { - if ($statut==0) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); - if ($statut==1) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); - if ($statut==2) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); - } - } + if ($mode == 0) + { + return $langs->trans($this->statuts[$statut]); + } + if ($mode == 1) + { + return $langs->trans($this->statuts_short[$statut]); + } + if ($mode == 2) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); + } + if ($mode == 3) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); + } + if ($mode == 4) + { + if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); + if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); + if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); + } + if ($mode == 5) + { + if ($statut==0) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); + if ($statut==1) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); + if ($statut==2) return ''.$langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); + } + } - /** - * Return clicable name (with picto eventually) - * - * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only - * @return string String with URL - */ - function getNomUrl($withpicto=0,$option='') - { - global $langs; + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only + * @return string String with URL + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; - $result=''; + $result=''; - $lien = ''; - $lienfin=''; + $lien = ''; + $lienfin=''; - $picto='intervention'; + $picto='intervention'; - $label=$langs->trans("Show").': '.$this->ref; + $label=$langs->trans("Show").': '.$this->ref; - if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; - return $result; - } + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; + } - /** - * Returns the next non used reference of intervention - * depending on the module numbering assets within FICHEINTER_ADDON - * - * @param Societe $soc Object society - * @return string Free reference for intervention - */ - function getNextNumRef($soc) - { - global $conf, $db, $langs; - $langs->load("interventions"); + /** + * Returns the next non used reference of intervention + * depending on the module numbering assets within FICHEINTER_ADDON + * + * @param Societe $soc Object society + * @return string Free reference for intervention + */ + function getNextNumRef($soc) + { + global $conf, $db, $langs; + $langs->load("interventions"); - $dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/"; + $dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/"; - if (! empty($conf->global->FICHEINTER_ADDON)) - { - $file = $conf->global->FICHEINTER_ADDON.".php"; - $classname = $conf->global->FICHEINTER_ADDON; - if (! file_exists($dir.$file)) - { - $file='mod_'.$file; - $classname='mod_'.$classname; - } + if (! empty($conf->global->FICHEINTER_ADDON)) + { + $file = $conf->global->FICHEINTER_ADDON.".php"; + $classname = $conf->global->FICHEINTER_ADDON; + if (! file_exists($dir.$file)) + { + $file='mod_'.$file; + $classname='mod_'.$classname; + } - // Chargement de la classe de numerotation - require_once $dir.$file; + // Chargement de la classe de numerotation + require_once $dir.$file; - $obj = new $classname(); + $obj = new $classname(); - $numref = ""; - $numref = $obj->getNumRef($soc,$this); + $numref = ""; + $numref = $obj->getNumRef($soc,$this); - if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db,"Fichinter::getNextNumRef ".$obj->error); - return ""; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"); - return ""; - } - } + if ( $numref != "") + { + return $numref; + } + else + { + dol_print_error($db,"Fichinter::getNextNumRef ".$obj->error); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"); + return ""; + } + } - /** - * Information sur l'objet fiche intervention - * - * @param int $id Id de la fiche d'intervention - * @return void - */ - function info($id) - { - global $conf; + /** + * Information sur l'objet fiche intervention + * + * @param int $id Id de la fiche d'intervention + * @return void + */ + function info($id) + { + global $conf; - $sql = "SELECT f.rowid,"; - $sql.= " datec,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.fk_user_author,"; - $sql.= " f.fk_user_valid"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; - $sql.= " WHERE f.rowid = ".$id; - $sql.= " AND f.entity = ".$conf->entity; + $sql = "SELECT f.rowid,"; + $sql.= " datec,"; + $sql.= " f.date_valid as datev,"; + $sql.= " f.fk_user_author,"; + $sql.= " f.fk_user_valid"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + $sql.= " WHERE f.rowid = ".$id; + $sql.= " AND f.entity = ".$conf->entity; - $result = $this->db->query($sql); + $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; + $this->id = $obj->rowid; - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_validation = $this->db->jdate($obj->datev); + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_validation = $this->db->jdate($obj->datev); - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; + $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; - } - } - $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } - /** - * Delete intervetnion - * - * @param User $user Object user who delete - * @return int <0 if KO, >0 if OK - */ + /** + * Delete intervetnion + * + * @param User $user Object user who delete + * @return int <0 if KO, >0 if OK + */ function delete($user, $notrigger=0) - { - global $conf; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + { + global $conf; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $error=0; + $error=0; - $this->db->begin(); + $this->db->begin(); - // Delete linked object - $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; - // Delete linked contacts - $res = $this->delete_linked_contact(); - if ($res < 0) - { - $this->error='ErrorFailToDeleteLinkedContact'; - $error++; - } + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) + { + $this->error='ErrorFailToDeleteLinkedContact'; + $error++; + } - if ($error) - { - $this->db->rollback(); - return -1; - } + if ($error) + { + $this->db->rollback(); + return -1; + } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; - $sql.= " WHERE fk_fichinter = ".$this->id; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; + $sql.= " WHERE fk_fichinter = ".$this->id; - dol_syslog("Fichinter::delete sql=".$sql); - if ( $this->db->query($sql) ) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; + dol_syslog("Fichinter::delete sql=".$sql); + if ( $this->db->query($sql) ) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; - dol_syslog("Fichinter::delete sql=".$sql); - if ( $this->db->query($sql) ) - { + dol_syslog("Fichinter::delete sql=".$sql); + if ( $this->db->query($sql) ) + { - // Remove directory with files - $fichinterref = dol_sanitizeFileName($this->ref); - if ($conf->ficheinter->dir_output) - { - $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ; - $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; - if (file_exists($file)) - { - dol_delete_preview($this); + // Remove directory with files + $fichinterref = dol_sanitizeFileName($this->ref); + if ($conf->ficheinter->dir_output) + { + $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ; + $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; + if (file_exists($file)) + { + dol_delete_preview($this); - if (! dol_delete_file($file,0,0,0,$this)) // For triggers - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (! dol_delete_dir_recursive($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } + if (! dol_delete_file($file,0,0,0,$this)) // For triggers + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (! dol_delete_dir_recursive($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } if (! $notrigger) { @@ -730,215 +730,215 @@ class Fichinter extends CommonObject } // Fin appel triggers } - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -2; - } - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } - /** - * Defines a delivery date of intervention - * - * @param User $user Object user who define - * @param date $date_delivery date of delivery - * @return int <0 if ko, >0 if ok - */ - function set_date_delivery($user, $date_delivery) - { - global $conf; + /** + * Defines a delivery date of intervention + * + * @param User $user Object user who define + * @param date $date_delivery date of delivery + * @return int <0 if ko, >0 if ok + */ + function set_date_delivery($user, $date_delivery) + { + global $conf; - if ($user->rights->ficheinter->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET datei = ".$this->db->idate($date_delivery); - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; + if ($user->rights->ficheinter->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; + $sql.= " SET datei = ".$this->db->idate($date_delivery); + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; - if ($this->db->query($sql)) - { - $this->date_delivery = $date_delivery; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Fichinter::set_date_delivery Erreur SQL"); - return -1; - } - } - } + if ($this->db->query($sql)) + { + $this->date_delivery = $date_delivery; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Fichinter::set_date_delivery Erreur SQL"); + return -1; + } + } + } - /** - * Define the label of the intervention - * - * @param User $user Object user who modify - * @param string $description description - * @return int <0 if ko, >0 if ok - */ - function set_description($user, $description) - { - global $conf; + /** + * Define the label of the intervention + * + * @param User $user Object user who modify + * @param string $description description + * @return int <0 if ko, >0 if ok + */ + function set_description($user, $description) + { + global $conf; - if ($user->rights->ficheinter->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET description = '".$this->db->escape($description)."'"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; + if ($user->rights->ficheinter->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; + $sql.= " SET description = '".$this->db->escape($description)."'"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_statut = 0"; - if ($this->db->query($sql)) - { - $this->description = $description; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Fichinter::set_description Erreur SQL"); - return -1; - } - } - } + if ($this->db->query($sql)) + { + $this->description = $description; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Fichinter::set_description Erreur SQL"); + return -1; + } + } + } - /** - * Adding a line of intervention into data base - * + /** + * Adding a line of intervention into data base + * * @param user $user User that do the action - * @param int $fichinterid Id of intervention - * @param string $desc Line description - * @param date $date_intervention Intervention date - * @param int $duration Intervention duration - * @return int >0 if ok, <0 if ko - */ + * @param int $fichinterid Id of intervention + * @param string $desc Line description + * @param date $date_intervention Intervention date + * @param int $duration Intervention duration + * @return int >0 if ok, <0 if ko + */ function addline($user,$fichinterid, $desc, $date_intervention, $duration) - { - dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); + { + dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); - if ($this->statut == 0) - { - $this->db->begin(); + if ($this->statut == 0) + { + $this->db->begin(); - // Insertion ligne - $line=new FichinterLigne($this->db); + // Insertion ligne + $line=new FichinterLigne($this->db); - $line->fk_fichinter = $fichinterid; - $line->desc = $desc; - $line->datei = $date_intervention; - $line->duration = $duration; + $line->fk_fichinter = $fichinterid; + $line->desc = $desc; + $line->datei = $date_intervention; + $line->duration = $duration; $result=$line->insert($user); - if ($result > 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Error sql=$sql, error=".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - } + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Error sql=$sql, error=".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + } - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - function initAsSpecimen() - { - global $user,$langs,$conf; + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + global $user,$langs,$conf; - $now=dol_now(); + $now=dol_now(); - // Initialise parametres - $this->id=0; - $this->ref = 'SPECIMEN'; - $this->specimen=1; - $this->socid = 1; - $this->datec = $now; - $this->note_private='Private note'; - $this->note_public='SPECIMEN'; - $this->duree = 0; - $nbp = 20; - $xnbp = 0; - while ($xnbp < $nbp) - { - $line=new FichinterLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->datei=($now-3600*(1+$xnbp)); - $line->duration=600; - $line->fk_fichinter=0; - $this->lines[$xnbp]=$line; - $xnbp++; + // Initialise parametres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $this->socid = 1; + $this->datec = $now; + $this->note_private='Private note'; + $this->note_public='SPECIMEN'; + $this->duree = 0; + $nbp = 20; + $xnbp = 0; + while ($xnbp < $nbp) + { + $line=new FichinterLigne($this->db); + $line->desc=$langs->trans("Description")." ".$xnbp; + $line->datei=($now-3600*(1+$xnbp)); + $line->duration=600; + $line->fk_fichinter=0; + $this->lines[$xnbp]=$line; + $xnbp++; - $this->duree+=$line->duration; - } - } + $this->duree+=$line->duration; + } + } - /** - * Load array lines - * - * @return int <0 if Ko, >0 if OK - */ - function fetch_lines() - { - $sql = 'SELECT rowid, description, duree, date, rang'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; - $sql.= ' WHERE fk_fichinter = '.$this->id; + /** + * Load array lines + * + * @return int <0 if Ko, >0 if OK + */ + function fetch_lines() + { + $sql = 'SELECT rowid, description, duree, date, rang'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; + $sql.= ' WHERE fk_fichinter = '.$this->id; - dol_syslog(get_class($this)."::fetch_lines sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $objp = $this->db->fetch_object($resql); + dol_syslog(get_class($this)."::fetch_lines sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $objp = $this->db->fetch_object($resql); - $line = new FichinterLigne($this->db); - $line->id = $objp->rowid; - $line->desc = $objp->description; - //For invoicing we calculing hours - $line->qty = round($objp->duree/3600,2); - $line->date = $this->db->jdate($objp->date); - $line->rang = $objp->rang; - $line->product_type = 1; + $line = new FichinterLigne($this->db); + $line->id = $objp->rowid; + $line->desc = $objp->description; + //For invoicing we calculing hours + $line->qty = round($objp->duree/3600,2); + $line->date = $this->db->jdate($objp->date); + $line->rang = $objp->rang; + $line->product_type = 1; - $this->lines[$i] = $line; + $this->lines[$i] = $line; - $i++; - } - $this->db->free($resql); + $i++; + } + $this->db->free($resql); - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } } /** @@ -1007,10 +1007,14 @@ class FichinterLigne /** * Insert the line into database * + * @param User $user Objet user that make creation + * @param int $notrigger Disable all triggers * @return int <0 if ko, >0 if ok */ function insert($user, $notrigger=0) { + global $langs,$conf; + dol_syslog("FichinterLigne::insert rang=".$this->rang); $this->db->begin(); @@ -1053,19 +1057,21 @@ class FichinterLigne if ($result > 0) { $this->rang=$rangToUse; - + if (! $notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTERDET_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { + $resulttrigger=$interface->run_triggers('FICHINTERDET_CREATE',$this,$user,$langs,$conf); + if ($resulttrigger < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } + } + if (!$error) { $this->db->commit(); return $result; } @@ -1089,11 +1095,13 @@ class FichinterLigne * Update intervention into database * * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers + * @param int $notrigger Disable all triggers * @return int <0 if ko, >0 if ok */ function update($user,$notrigger=0) { + global $langs,$conf; + $this->db->begin(); // Mise a jour ligne en base @@ -1111,20 +1119,22 @@ class FichinterLigne $result=$this->update_total(); if ($result > 0) { - + if (! $notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTERDET_UPDATE',$this,$user,$langs,$conf); - if ($result < 0) { + $resulttrigger=$interface->run_triggers('FICHINTERDET_UPDATE',$this,$user,$langs,$conf); + if ($resulttrigger < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } - - + } + + if (!$error) + { $this->db->commit(); return $result; } @@ -1201,7 +1211,7 @@ class FichinterLigne * Delete a intervention line * * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers + * @param int $notrigger Disable all triggers * @return int >0 if ok, <0 if ko */ function deleteline($user,$notrigger=0) @@ -1221,19 +1231,19 @@ class FichinterLigne if ($result > 0) { $this->db->commit(); - + if (! $notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTERDET_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { + $resulttrigger=$interface->run_triggers('FICHINTERDET_DELETE',$this,$user,$langs,$conf); + if ($resulttrigger < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } - + return $result; } else From 6190dddac95fb75b5835a34ada60ea13390469ab Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 11:30:35 +0200 Subject: [PATCH 21/33] GetElmentURL fichinter instead of ficheinter (to be ok with element of fichinter class --- 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 232e2dda9fc..dcbd404a3e0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2517,7 +2517,7 @@ abstract class CommonObject if ($objecttype == 'cabinetmed_cons') { $classpath = 'cabinetmed/class'; $module='cabinetmed'; $subelement='cabinetmedcons'; } - if ($objecttype == 'ficheinter') { + if ($objecttype == 'fichinter') { $classpath = 'fichinter/class'; $module='ficheinter'; $subelement='fichinter'; } From c07d5045d14b3abc39cfba7de14fac2e4ce961f6 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 11:55:03 +0200 Subject: [PATCH 22/33] Error management --- htdocs/fichinter/fiche.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index c6201c6d1dc..e83f3bf00f6 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -374,7 +374,10 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fich { $object->fetch($id); $object->fetch_thirdparty(); - $object->delete($user); + $result=$object->delete($user); + if ($result<0) { + setEventMessage($object->error,'errors'); + } header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); exit; From 08b234ed012db11d4d1b2f871440576fb18fe2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Sun, 19 May 2013 12:08:18 +0200 Subject: [PATCH 23/33] Corrected translation key BuyingPrice from lang files --- htdocs/langs/ar_SA/products.lang | 2 +- htdocs/langs/bg_BG/products.lang | 2 +- htdocs/langs/ca_ES/products.lang | 2 +- htdocs/langs/da_DK/products.lang | 2 +- htdocs/langs/de_AT/products.lang | 2 +- htdocs/langs/de_DE/products.lang | 2 +- htdocs/langs/el_GR/products.lang | 2 +- htdocs/langs/en_US/products.lang | 2 +- htdocs/langs/es_ES/products.lang | 2 +- htdocs/langs/et_EE/products.lang | 2 +- htdocs/langs/fa_IR/products.lang | 2 +- htdocs/langs/fi_FI/products.lang | 2 +- htdocs/langs/fr_FR/products.lang | 2 +- htdocs/langs/he_IL/products.lang | 2 +- htdocs/langs/hu_HU/products.lang | 2 +- htdocs/langs/is_IS/products.lang | 2 +- htdocs/langs/it_IT/products.lang | 2 +- htdocs/langs/ja_JP/products.lang | 2 +- htdocs/langs/nb_NO/products.lang | 2 +- htdocs/langs/nl_BE/products.lang | 2 +- htdocs/langs/nl_NL/products.lang | 2 +- htdocs/langs/pl_PL/products.lang | 2 +- htdocs/langs/pt_BR/products.lang | 2 +- htdocs/langs/pt_PT/products.lang | 2 +- htdocs/langs/ro_RO/products.lang | 2 +- htdocs/langs/ru_RU/products.lang | 2 +- htdocs/langs/sl_SI/products.lang | 2 +- htdocs/langs/sv_SE/products.lang | 2 +- htdocs/langs/tr_TR/products.lang | 2 +- htdocs/langs/zh_CN/products.lang | 2 +- htdocs/langs/zh_TW/products.lang | 2 +- 31 files changed, 31 insertions(+), 31 deletions(-) diff --git a/htdocs/langs/ar_SA/products.lang b/htdocs/langs/ar_SA/products.lang index 4b541540357..18d53bcbb6b 100644 --- a/htdocs/langs/ar_SA/products.lang +++ b/htdocs/langs/ar_SA/products.lang @@ -88,7 +88,7 @@ CorrectStock=تصحيح الأوراق المالية AddPhoto=إضافة الصورة ListOfStockMovements=قائمة الحركات الأسهم NoPhotoYet=لا صور حتى الان -BuiingPrice=سعر الشراء +BuyingPrice=سعر الشراء SupplierCard=بطاقة المورد CommercialCard=بطاقة تجارية AllWays=الطريق إلى إيجاد منتجك في الأسهم diff --git a/htdocs/langs/bg_BG/products.lang b/htdocs/langs/bg_BG/products.lang index 1f006fa349c..55b47c45263 100644 --- a/htdocs/langs/bg_BG/products.lang +++ b/htdocs/langs/bg_BG/products.lang @@ -100,7 +100,7 @@ CorrectStock=Точен състав AddPhoto=Добави снимка ListOfStockMovements=Списък на движението на стоковите наличности NoPhotoYet=Няма достъпни снимки още -BuiingPrice=Покупната цена +BuyingPrice=Покупната цена SupplierCard=Доставчик карта CommercialCard=Търговския карта AllWays=Път да намерите вашия продукт в наличност diff --git a/htdocs/langs/ca_ES/products.lang b/htdocs/langs/ca_ES/products.lang index b4cf11d44de..7211f09d610 100644 --- a/htdocs/langs/ca_ES/products.lang +++ b/htdocs/langs/ca_ES/products.lang @@ -92,7 +92,7 @@ CorrectStock=Corregir stock AddPhoto=Adjuntar una foto ListOfStockMovements=Llistat de moviments de stock NoPhotoYet=No hi ha fotografia disponible per el moment -BuiingPrice=Preu de compra +BuyingPrice=Preu de compra SupplierCard=Fitxa proveïdor CommercialCard=Fitxa comercial AllWays=Ruta per trobar el seu producte en el stock diff --git a/htdocs/langs/da_DK/products.lang b/htdocs/langs/da_DK/products.lang index 18ad7c6317f..2520de34bad 100644 --- a/htdocs/langs/da_DK/products.lang +++ b/htdocs/langs/da_DK/products.lang @@ -88,7 +88,7 @@ CorrectStock=Korrekt lager AddPhoto=Tilføj foto ListOfStockMovements=Liste over lagerbevægelserne NoPhotoYet=Ingen billeder tilgængelige endnu -BuiingPrice=Koebspris +BuyingPrice=Koebspris SupplierCard=Leverandør-kortet CommercialCard=Kommerciel kortet AllWays=Vej til at finde dit produkt på lager diff --git a/htdocs/langs/de_AT/products.lang b/htdocs/langs/de_AT/products.lang index 8ea58dfe159..db756167e8f 100644 --- a/htdocs/langs/de_AT/products.lang +++ b/htdocs/langs/de_AT/products.lang @@ -83,7 +83,7 @@ CorrectStock=Lagerstandsanpassung AddPhoto=Bild hinzufügen ListOfStockMovements=Liste der Lagerbewegungen NoPhotoYet=Es wurde noch kein Bild hochgeladen -BuiingPrice=Einkaufspreis +BuyingPrice=Einkaufspreis SupplierCard=Lieferantenkarte CommercialCard=Vertriebskarte AllWays=Pfad zu Produkt im Lager diff --git a/htdocs/langs/de_DE/products.lang b/htdocs/langs/de_DE/products.lang index 47627f7de91..a8dd0939e0b 100644 --- a/htdocs/langs/de_DE/products.lang +++ b/htdocs/langs/de_DE/products.lang @@ -99,7 +99,7 @@ CorrectStock=Lagerstandsanpassung AddPhoto=Bild hinzufügen ListOfStockMovements=Liste der Lagerbewegungen NoPhotoYet=Es wurde noch kein Bild hochgeladen -BuiingPrice=Einkaufspreis +BuyingPrice=Einkaufspreis SupplierCard=Lieferantenkarte CommercialCard=Vertriebskarte AllWays=Pfad zu Produkt im Lager diff --git a/htdocs/langs/el_GR/products.lang b/htdocs/langs/el_GR/products.lang index 6da5a8d3ed7..b213c2626b3 100644 --- a/htdocs/langs/el_GR/products.lang +++ b/htdocs/langs/el_GR/products.lang @@ -89,7 +89,7 @@ CorrectStock=Σωστό Απόθεμα AddPhoto=Προσθήκη φωτογραφίας ListOfStockMovements=Λίστα κινήσεων αποθέματος NoPhotoYet=Δεν υπάρχει φωτογραφία -BuiingPrice=Τιμή Αγοράς +BuyingPrice=Τιμή Αγοράς SupplierCard=Κάρτα προμηθευτή CommercialCard=Εμπορική Κάρτα NoCat=Το προϊόν σας, δεν ανήκει σε κάποια κατηγορία diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 9b4a0b32e95..f511d309567 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -91,7 +91,7 @@ AddToOtherBills=Add to other bills CorrectStock=Correct stock AddPhoto=Add photo ListOfStockMovements=List of stock movements -BuiingPrice=Buying price +BuyingPrice=Buying price SupplierCard=Supplier card CommercialCard=Commercial card AllWays=Path to find your product in stock diff --git a/htdocs/langs/es_ES/products.lang b/htdocs/langs/es_ES/products.lang index 0870293b79c..66d64d3d4ff 100644 --- a/htdocs/langs/es_ES/products.lang +++ b/htdocs/langs/es_ES/products.lang @@ -92,7 +92,7 @@ CorrectStock=Corregir stock AddPhoto=Adjuntar una foto ListOfStockMovements=Listado de movimientos de stock NoPhotoYet=No hay fotografía disponible por el momento -BuiingPrice=Precio de compra +BuyingPrice=Precio de compra SupplierCard=Ficha proveedor CommercialCard=Ficha comercial AllWays=Ruta para encontrar su producto en el stock diff --git a/htdocs/langs/et_EE/products.lang b/htdocs/langs/et_EE/products.lang index b7e668c3a6b..899d31de333 100644 --- a/htdocs/langs/et_EE/products.lang +++ b/htdocs/langs/et_EE/products.lang @@ -100,7 +100,7 @@ CorrectStock=Õige varude AddPhoto=Lisa foto ListOfStockMovements=List of veeremiliikumiste NoPhotoYet=Pilte ei ole veel -BuiingPrice=Ostes hind +BuyingPrice=Ostes hind SupplierCard=Tarnija kaart CommercialCard=Commercial kaart AllWays=Tee leida oma toote varu diff --git a/htdocs/langs/fa_IR/products.lang b/htdocs/langs/fa_IR/products.lang index fba0fbd0f20..f4179923442 100644 --- a/htdocs/langs/fa_IR/products.lang +++ b/htdocs/langs/fa_IR/products.lang @@ -88,7 +88,7 @@ CorrectStock=تصحيح الأوراق المالية AddPhoto=إضافة الصورة ListOfStockMovements=قائمة الحركات الأسهم NoPhotoYet=لا صور حتى الان -BuiingPrice=سعر الشراء +BuyingPrice=سعر الشراء SupplierCard=بطاقة المورد CommercialCard=بطاقة تجارية AllWays=الطريق إلى إيجاد منتجك في الأسهم diff --git a/htdocs/langs/fi_FI/products.lang b/htdocs/langs/fi_FI/products.lang index 195c03852d4..d2b8fd5782e 100644 --- a/htdocs/langs/fi_FI/products.lang +++ b/htdocs/langs/fi_FI/products.lang @@ -85,7 +85,7 @@ CorrectStock=Oikea varastossa AddPhoto=Lisää kuva ListOfStockMovements=Luettelo varastojen muutokset NoPhotoYet=Ei kuvia saatavilla vielä -BuiingPrice=Osto +BuyingPrice=Osto SupplierCard=Toimittaja-kortti CommercialCard=Kaupalliset kortti AllWays=Polku löydä tuotetta varastossa diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 9aedcc3f820..048b968bbce 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -91,7 +91,7 @@ AddToOtherBills=Ajouter aux autres factures CorrectStock=Corriger stock AddPhoto=Ajouter une photo ListOfStockMovements=Liste des mouvements de stock -BuiingPrice=Prix d'achat +BuyingPrice=Prix d'achat SupplierCard=Fiche fournisseur CommercialCard=Fiche commerciale AllWays=Chemin pour trouver votre produit dans le stock diff --git a/htdocs/langs/he_IL/products.lang b/htdocs/langs/he_IL/products.lang index a66151992b5..e67e8f200e3 100644 --- a/htdocs/langs/he_IL/products.lang +++ b/htdocs/langs/he_IL/products.lang @@ -100,7 +100,7 @@ CorrectStock=נכון במלאי AddPhoto=הוסף תמונה ListOfStockMovements=רשימה של תנועות מלאי NoPhotoYet=אין תמונות זמין עדיין -BuiingPrice=רכישת מחיר +BuyingPrice=רכישת מחיר SupplierCard=הספק לכרטיס CommercialCard=כרטיס מסחרי AllWays=הדרך למצוא את המוצר במלאי diff --git a/htdocs/langs/hu_HU/products.lang b/htdocs/langs/hu_HU/products.lang index a3af722cba2..63abe2cae71 100644 --- a/htdocs/langs/hu_HU/products.lang +++ b/htdocs/langs/hu_HU/products.lang @@ -87,7 +87,7 @@ CorrectStock=Megfelelő készlet AddPhoto=Kép hozzáadása ListOfStockMovements=Készlet mozgások listája NoPhotoYet=Még nincs kép -BuiingPrice=Vásárlási ár +BuyingPrice=Vásárlási ár SupplierCard=Beszállító kártya CommercialCard=Kereskedelmi kártya AllWays=Útvonal a termékhez a készletben diff --git a/htdocs/langs/is_IS/products.lang b/htdocs/langs/is_IS/products.lang index 6f3353cc03d..d03b87e95cd 100644 --- a/htdocs/langs/is_IS/products.lang +++ b/htdocs/langs/is_IS/products.lang @@ -93,7 +93,7 @@ CorrectStock=Rétt lager AddPhoto=Bættu mynd ListOfStockMovements=Listi yfir hreyfingar lager NoPhotoYet=Engar myndir enn í boði -BuiingPrice=Kaupverð +BuyingPrice=Kaupverð SupplierCard=Birgir kort CommercialCard=Auglýsing kort AllWays=Slóð að finna vöruna til á lager diff --git a/htdocs/langs/it_IT/products.lang b/htdocs/langs/it_IT/products.lang index f21fa723771..76cf6197535 100644 --- a/htdocs/langs/it_IT/products.lang +++ b/htdocs/langs/it_IT/products.lang @@ -19,7 +19,7 @@ BarcodeValue =Valore codice a barre Book =Libro BookList =Elenco dei libri Books =Libri -BuiingPrice =Prezzo di acquisto +BuyingPrice =Prezzo di acquisto Buy =Acquisti CantBeLessThanMinPrice =Il prezzo di vendita non può essere inferiore al minimo consentito per questo prodotto ( %s IVA esclusa) CardContract =Scheda contratto diff --git a/htdocs/langs/ja_JP/products.lang b/htdocs/langs/ja_JP/products.lang index 9c3618e81eb..bd23b98f861 100644 --- a/htdocs/langs/ja_JP/products.lang +++ b/htdocs/langs/ja_JP/products.lang @@ -100,7 +100,7 @@ CorrectStock=正しい株式 AddPhoto=写真を追加する ListOfStockMovements=在庫変動のリスト NoPhotoYet=まだまだ写真はありません -BuiingPrice=買価 +BuyingPrice=買価 SupplierCard=サプライヤーカード CommercialCard=コマーシャルカード AllWays=在庫製品を検索するためのパス diff --git a/htdocs/langs/nb_NO/products.lang b/htdocs/langs/nb_NO/products.lang index 79a4698a4c0..8808dfd9b56 100644 --- a/htdocs/langs/nb_NO/products.lang +++ b/htdocs/langs/nb_NO/products.lang @@ -77,7 +77,7 @@ CorrectStock=Korriger beholdning AddPhoto=Legg til bilde ListOfStockMovements=Vis lagerbevegelser NoPhotoYet=Det finnes ikke noe bilde ennå -BuiingPrice=Innkjøpspris +BuyingPrice=Innkjøpspris SupplierCard=Leverandørkort CommercialCard=Handelskort AllWays=Sti til varebeholdning diff --git a/htdocs/langs/nl_BE/products.lang b/htdocs/langs/nl_BE/products.lang index 9f1b1a5d8ea..0b1e6f0be82 100644 --- a/htdocs/langs/nl_BE/products.lang +++ b/htdocs/langs/nl_BE/products.lang @@ -79,7 +79,7 @@ CorrectStock=Aanpassen stock AddPhoto=Foto toevoegen ListOfStockMovements=Lijst van de voorraden NoPhotoYet=Geen foto's beschikbaar -BuiingPrice=Aankoopprijs +BuyingPrice=Aankoopprijs SupplierCard=Leverancierskaart CommercialCard=Commerciële kaart AllWays=Pad naar het vinden van uw product in voorraad diff --git a/htdocs/langs/nl_NL/products.lang b/htdocs/langs/nl_NL/products.lang index be0b5c1d150..731630aa79b 100644 --- a/htdocs/langs/nl_NL/products.lang +++ b/htdocs/langs/nl_NL/products.lang @@ -92,7 +92,7 @@ CorrectStock = Juiste voorraad AddPhoto = Afbeelding toevoegen ListOfStockMovements = Voorradenlijst NoPhotoYet = Geen afbeelding beschikbaar -BuiingPrice = Inkoopprijs +BuyingPrice = Inkoopprijs SupplierCard = Leveranciersdetails CommercialCard = Offertedetails AllWays = Pad om het product in de voorraad te vinden diff --git a/htdocs/langs/pl_PL/products.lang b/htdocs/langs/pl_PL/products.lang index 0055974d4ac..d46af11a04a 100644 --- a/htdocs/langs/pl_PL/products.lang +++ b/htdocs/langs/pl_PL/products.lang @@ -87,7 +87,7 @@ CorrectStock=Poprawny stanie AddPhoto=Dodaj zdjęcia ListOfStockMovements=Wykaz stanu magazynowego NoPhotoYet=Żadne zdjęcia dostępne jeszcze -BuiingPrice=Kupowanie cena +BuyingPrice=Kupowanie cena SupplierCard=Dostawca karty CommercialCard=Commercial karty AllWays=Ścieżka znaleźć swój produkt w stanie diff --git a/htdocs/langs/pt_BR/products.lang b/htdocs/langs/pt_BR/products.lang index 04e9920c5c6..1c1c00df2f3 100644 --- a/htdocs/langs/pt_BR/products.lang +++ b/htdocs/langs/pt_BR/products.lang @@ -82,7 +82,7 @@ CorrectStock=Corrigir estoque AddPhoto=Adicionar uma foto ListOfStockMovements=Lista de movimentos de estoque NoPhotoYet=Não existe fotografía disponível neste momento -BuiingPrice=Preço de compra +BuyingPrice=Preço de compra SupplierCard=Ficha fornecedor CommercialCard=Ficha comercial AllWays=Rota para encontrar o sua produto ao estoque diff --git a/htdocs/langs/pt_PT/products.lang b/htdocs/langs/pt_PT/products.lang index a820d88c00c..6842c4cd186 100644 --- a/htdocs/langs/pt_PT/products.lang +++ b/htdocs/langs/pt_PT/products.lang @@ -77,7 +77,7 @@ CorrectStock=Corrigir stock AddPhoto=Adicionar uma foto ListOfStockMovements=Lista de movimentos de stock NoPhotoYet=Não existe fotografía disponivel neste momento -BuiingPrice=Preço de compra +BuyingPrice=Preço de compra SupplierCard=Ficha fornecedor CommercialCard=Ficha comercial AllWays=Rota para encontrar o sua produto ao stock diff --git a/htdocs/langs/ro_RO/products.lang b/htdocs/langs/ro_RO/products.lang index 4e2365f0ca6..4db301d36ef 100644 --- a/htdocs/langs/ro_RO/products.lang +++ b/htdocs/langs/ro_RO/products.lang @@ -86,7 +86,7 @@ CorrectStock=Corect stoc AddPhoto=Adăugaţi fotografie ListOfStockMovements=Lista de stoc mişcările NoPhotoYet=Nici o fotografie disponibilă încă -BuiingPrice=Cumpararea de preţ +BuyingPrice=Cumpararea de preţ SupplierCard=Furnizor cartela CommercialCard=Comerciale carte AllWays=Cale, pentru a vă găsi produsul în stoc diff --git a/htdocs/langs/ru_RU/products.lang b/htdocs/langs/ru_RU/products.lang index ce83e26a7e9..dcd9b847d49 100644 --- a/htdocs/langs/ru_RU/products.lang +++ b/htdocs/langs/ru_RU/products.lang @@ -85,7 +85,7 @@ CorrectStock=Правильно запас AddPhoto=Добавить фото ListOfStockMovements=Список акций движения NoPhotoYet=Нет фотографии доступны еще -BuiingPrice=Покупка цене +BuyingPrice=Покупка цене SupplierCard=Поставщик карту CommercialCard=Коммерческая карту AllWays=Путь найти свой продукт в запасе diff --git a/htdocs/langs/sl_SI/products.lang b/htdocs/langs/sl_SI/products.lang index f7e076a134e..cc967102d48 100644 --- a/htdocs/langs/sl_SI/products.lang +++ b/htdocs/langs/sl_SI/products.lang @@ -92,7 +92,7 @@ CorrectStock = Popravi zalogo AddPhoto = Dodaj sliko ListOfStockMovements = Seznam gibanja zalog NoPhotoYet = Slik še ni na voljo -BuiingPrice = Nabavna cena +BuyingPrice = Nabavna cena SupplierCard = Kartica dobavitelja CommercialCard = Kartica komerciale AllWays = Pot za iskanje proizvoda v zalogi diff --git a/htdocs/langs/sv_SE/products.lang b/htdocs/langs/sv_SE/products.lang index 7d2e9cf9de9..f29d08645d7 100644 --- a/htdocs/langs/sv_SE/products.lang +++ b/htdocs/langs/sv_SE/products.lang @@ -100,7 +100,7 @@ CorrectStock=Rätt lager AddPhoto=Lägg till foto ListOfStockMovements=Lista över lageromsättningen NoPhotoYet=Finns inga tillgängliga bilder än -BuiingPrice=BETALKURS +BuyingPrice=BETALKURS SupplierCard=Leverantör kort CommercialCard=Kommersiella kort AllWays=Sökväg för att hitta din produkt i lager diff --git a/htdocs/langs/tr_TR/products.lang b/htdocs/langs/tr_TR/products.lang index 7a97a482424..8a469ae4566 100644 --- a/htdocs/langs/tr_TR/products.lang +++ b/htdocs/langs/tr_TR/products.lang @@ -95,7 +95,7 @@ CorrectStock=Doğru stok AddPhoto=Fotoğraf Ekle ListOfStockMovements=Stok hareketleri listesi NoPhotoYet=Henüz resim yok -BuiingPrice=Alış Fiyat +BuyingPrice=Alış Fiyat SupplierCard=Tedarikçi kartı CommercialCard=Ticari Kart AllWays=Stokta ürün bulmak için yol diff --git a/htdocs/langs/zh_CN/products.lang b/htdocs/langs/zh_CN/products.lang index 6f5ddb05eb4..f9bf14ee809 100644 --- a/htdocs/langs/zh_CN/products.lang +++ b/htdocs/langs/zh_CN/products.lang @@ -93,7 +93,7 @@ CorrectStock=正确的股票 AddPhoto=添加照片 ListOfStockMovements=名单的股票走势 NoPhotoYet=没有照片尚未 -BuiingPrice=买价 +BuyingPrice=买价 SupplierCard=供应卡 CommercialCard=商务卡 AllWays=路径找到您的产品库存 diff --git a/htdocs/langs/zh_TW/products.lang b/htdocs/langs/zh_TW/products.lang index 1648f5cfae4..c54e9b1ccc9 100644 --- a/htdocs/langs/zh_TW/products.lang +++ b/htdocs/langs/zh_TW/products.lang @@ -93,7 +93,7 @@ CorrectStock=正確的股票 AddPhoto=添加照片 ListOfStockMovements=庫存轉讓清單 NoPhotoYet=沒有照片尚未 -BuiingPrice=買價 +BuyingPrice=買價 SupplierCard=供應卡 CommercialCard=商務卡 AllWays=路徑找到您的產品庫存 From 5f4433dbffba52f87d0716e1c6692cab1064390e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Sun, 19 May 2013 12:09:34 +0200 Subject: [PATCH 24/33] Missing succes message in margin module config page --- htdocs/margin/admin/margin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/margin/admin/margin.php b/htdocs/margin/admin/margin.php index a8d6d0d4e6e..d3406b849d3 100644 --- a/htdocs/margin/admin/margin.php +++ b/htdocs/margin/admin/margin.php @@ -99,6 +99,7 @@ if ($action == 'contact') if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0) { $conf->global->AGENT_CONTACT_TYPE = $_POST['AGENT_CONTACT_TYPE']; + setEventMessage($langs->trans("RecordModifiedSuccessfully")); } else { From 347fc6d714cdf12b0abdd5b95f09c9fb8a86ee2f Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Sun, 19 May 2013 14:04:21 +0200 Subject: [PATCH 25/33] fix unauthorized access to margins for external user --- htdocs/core/modules/modMargin.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modMargin.class.php b/htdocs/core/modules/modMargin.class.php index 4baa4f51680..34e6ba322db 100644 --- a/htdocs/core/modules/modMargin.class.php +++ b/htdocs/core/modules/modMargin.class.php @@ -80,7 +80,7 @@ class modMargin extends DolibarrModules // New pages on tabs $this->tabs = array( 'product:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/productMargins.php?id=__ID__', - 'thirdparty:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/thirdpartyMargins.php?socid=__ID__' + 'thirdparty:+margin:Margins:margins:$conf->margin->enabled && empty($user->societe_id)s:/margin/tabs/thirdpartyMargins.php?socid=__ID__' ); From fea0e6de54077d46c6ec6e31f788c6dc6551772a Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Sun, 19 May 2013 14:06:51 +0200 Subject: [PATCH 26/33] Fix - external users should not see costprice and margin infos --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9ceddc61d1a..df8af03efea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,7 +32,7 @@ English Dolibarr ChangeLog - Fix: [ bug #865 ] Dolibarr navigation array in project/task do not work - Fix: [ bug #866 ] Standing order from an invoice suggests invoice total amount instead of remaining to pay - Fix: [ bug #788 ] Date of linked interventions are not shown - +- Fix: external users should not see costprice and margin infos ***** ChangeLog for 3.3.1 compared to 3.3 ***** From a6233a738c2f67e557b54b144066a7cb15c728e8 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 14:13:41 +0200 Subject: [PATCH 27/33] Fix trigger in deleteline fiche inter --- htdocs/fichinter/class/fichinter.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index ba9da8a12d1..7f681950b3e 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -1216,6 +1216,8 @@ class FichinterLigne */ function deleteline($user,$notrigger=0) { + global $langs,$conf; + if ($this->statut == 0) { dol_syslog(get_class($this)."::deleteline lineid=".$this->rowid); From 3d409390a57b546ed7a9734dd37d3009651ffd27 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sun, 19 May 2013 18:37:38 +0200 Subject: [PATCH 28/33] Revert Class rewrite and ficheinter line trigger --- htdocs/fichinter/class/fichinter.class.php | 124 +++++---------------- htdocs/fichinter/fiche.php | 13 +-- 2 files changed, 36 insertions(+), 101 deletions(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 7f681950b3e..6e3079c6d7d 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -82,11 +82,9 @@ class Fichinter extends CommonObject /** * Create an intervention into data base * - * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK */ - function create($user, $notrigger=0) + function create() { global $conf, $user, $langs; @@ -146,7 +144,7 @@ class Fichinter extends CommonObject $sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->ref."'"; $sql.= ", ".$conf->entity; - $sql.= ", ".$user->id; + $sql.= ", ".$this->author; $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null"); $sql.= ", '".$this->modelpdf."'"; $sql.= ", ".($this->fk_project ? $this->fk_project : 0); @@ -177,16 +175,17 @@ class Fichinter extends CommonObject if (! $ret) dol_print_error($this->db); } - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $tmpuser=new User($this->db); + $tmpuser->fetch($this->author); + $result=$interface->run_triggers('FICHINTER_CREATE',$this,$tmpuser,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; } + // Fin appel triggers if (! $error) { @@ -214,11 +213,9 @@ class Fichinter extends CommonObject /** * Update an intervention * - * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers * @return int <0 if KO, >0 if OK */ - function update($user, $notrigger=0) + function update() { if (! is_numeric($this->duree)) { $this->duree = 0; @@ -240,18 +237,15 @@ class Fichinter extends CommonObject dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { - - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('FICHINTER_UPDATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('FICHINTER_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; } + // Fin appel triggers + $this->db->commit(); return 1; @@ -526,7 +520,7 @@ class Fichinter extends CommonObject * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only * @return string String with URL */ - function getNomUrl($withpicto=0,$option='') + function getNomUrl($withpicto=0) { global $langs; @@ -652,7 +646,7 @@ class Fichinter extends CommonObject * @param User $user Object user who delete * @return int <0 if KO, >0 if OK */ - function delete($user, $notrigger=0) + function delete($user) { global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -719,8 +713,6 @@ class Fichinter extends CommonObject } } - if (! $notrigger) - { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); @@ -729,7 +721,7 @@ class Fichinter extends CommonObject $error++; $this->errors=$interface->errors; } // Fin appel triggers - } + $this->db->commit(); return 1; } @@ -817,14 +809,13 @@ class Fichinter extends CommonObject /** * Adding a line of intervention into data base * - * @param user $user User that do the action * @param int $fichinterid Id of intervention * @param string $desc Line description * @param date $date_intervention Intervention date * @param int $duration Intervention duration * @return int >0 if ok, <0 if ko */ - function addline($user,$fichinterid, $desc, $date_intervention, $duration) + function addline($fichinterid, $desc, $date_intervention, $duration) { dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); @@ -840,7 +831,7 @@ class Fichinter extends CommonObject $line->datei = $date_intervention; $line->duration = $duration; - $result=$line->insert($user); + $result=$line->insert(); if ($result > 0) { $this->db->commit(); @@ -1007,13 +998,10 @@ class FichinterLigne /** * Insert the line into database * - * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers * @return int <0 if ko, >0 if ok */ - function insert($user, $notrigger=0) + function insert() { - global $langs,$conf; dol_syslog("FichinterLigne::insert rang=".$this->rang); @@ -1057,21 +1045,6 @@ class FichinterLigne if ($result > 0) { $this->rang=$rangToUse; - - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $resulttrigger=$interface->run_triggers('FICHINTERDET_CREATE',$this,$user,$langs,$conf); - if ($resulttrigger < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - } - } - - if (!$error) { $this->db->commit(); return $result; } @@ -1094,14 +1067,10 @@ class FichinterLigne /** * Update intervention into database * - * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers * @return int <0 if ko, >0 if ok */ - function update($user,$notrigger=0) + function update() { - global $langs,$conf; - $this->db->begin(); // Mise a jour ligne en base @@ -1118,22 +1087,6 @@ class FichinterLigne { $result=$this->update_total(); if ($result > 0) - { - - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $resulttrigger=$interface->run_triggers('FICHINTERDET_UPDATE',$this,$user,$langs,$conf); - if ($resulttrigger < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - } - } - - if (!$error) { $this->db->commit(); return $result; @@ -1210,14 +1163,10 @@ class FichinterLigne /** * Delete a intervention line * - * @param User $user Objet user that make creation - * @param int $notrigger Disable all triggers * @return int >0 if ok, <0 if ko */ - function deleteline($user,$notrigger=0) - { - global $langs,$conf; - + function deleteline() + { if ($this->statut == 0) { dol_syslog(get_class($this)."::deleteline lineid=".$this->rowid); @@ -1233,19 +1182,6 @@ class FichinterLigne if ($result > 0) { $this->db->commit(); - - if (! $notrigger) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $resulttrigger=$interface->run_triggers('FICHINTERDET_DELETE',$this,$user,$langs,$conf); - if ($resulttrigger < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - } - return $result; } else diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index e83f3bf00f6..f88e7a87043 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -134,6 +134,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $object->socid = $socid; $object->duree = GETPOST('duree','int'); $object->fk_project = GETPOST('projectid','int'); + $object->author = $user->id; $object->description = GETPOST('description'); $object->ref = $ref; $object->modelpdf = GETPOST('model','alpha'); @@ -174,7 +175,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } - $id = $object->create($user); + $id = $object->create(); if ($id > 0) { @@ -245,7 +246,6 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $duration = 3600; $result = $object->addline( - $user, $id, $desc, $date_intervention, @@ -276,7 +276,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) } else { - $result = $object->create($user); + $result = $object->create(); if ($result > 0) { $id=$result; // Force raffraichissement sur fiche venant d'etre cree @@ -306,7 +306,7 @@ else if ($action == 'update' && $user->rights->ficheinter->creer) $object->description = GETPOST('description','alpha'); $object->ref = $ref; - $result=$object->update($user); + $result=$object->update(); if ($result<0) { setEventMessage($object->error,'errors'); } @@ -427,7 +427,6 @@ else if ($action == "addline" && $user->rights->ficheinter->creer) $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); $result=$object->addline( - $user, $id, $desc, $date_intervention, @@ -503,7 +502,7 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST( $objectline->datei = $date_inter; $objectline->desc = $desc; $objectline->duration = $duration; - $result = $objectline->update($user); + $result = $objectline->update(); if ($result < 0) { dol_print_error($db); @@ -537,7 +536,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> dol_print_error($db); exit; } - $result=$objectline->deleteline($user); + $result=$objectline->deleteline(); if ($object->fetch($objectline->fk_fichinter) <= 0) { From f8ca8426856c341dbcde7add82580bf74864a46d Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Mon, 20 May 2013 10:10:34 +0200 Subject: [PATCH 29/33] fix typo error --- htdocs/core/modules/modMargin.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modMargin.class.php b/htdocs/core/modules/modMargin.class.php index 34e6ba322db..cc5eb01ffa3 100644 --- a/htdocs/core/modules/modMargin.class.php +++ b/htdocs/core/modules/modMargin.class.php @@ -80,7 +80,7 @@ class modMargin extends DolibarrModules // New pages on tabs $this->tabs = array( 'product:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/productMargins.php?id=__ID__', - 'thirdparty:+margin:Margins:margins:$conf->margin->enabled && empty($user->societe_id)s:/margin/tabs/thirdpartyMargins.php?socid=__ID__' + 'thirdparty:+margin:Margins:margins:$conf->margin->enabled && empty($user->societe_id):/margin/tabs/thirdpartyMargins.php?socid=__ID__' ); From 5f714f1403467bc0c2f8fded950e52d9f580f272 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Mon, 20 May 2013 14:39:27 +0200 Subject: [PATCH 30/33] fix: wrong trad --- htdocs/admin/supplier_order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/supplier_order.php b/htdocs/admin/supplier_order.php index 2b4feda1b8d..7195d9ef388 100644 --- a/htdocs/admin/supplier_order.php +++ b/htdocs/admin/supplier_order.php @@ -454,7 +454,7 @@ print '
'; print ''; print ''; print ''; -print $langs->trans("FreeLegalTextOnInvoices").' ('.$langs->trans("AddCRIfTooLong").')
'; +print $langs->trans("FreeLegalTextOnOrders").' ('.$langs->trans("AddCRIfTooLong").')
'; print ''; print ''; print ''; From 250b6d65020fdff5f9cafce516d3c609fa8b7e54 Mon Sep 17 00:00:00 2001 From: fhenry Date: Mon, 20 May 2013 17:58:03 +0200 Subject: [PATCH 31/33] Fix bug on service date strat date end in propal line not recorded --- htdocs/comm/propal.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 973c37d91af..e71d342ea0c 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -638,6 +638,7 @@ else if ($action == "addline" && $user->rights->propal->creer) $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):''))); $price_ht = GETPOST('price_ht'); $tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0); + $predef=((! empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : ''); if (empty($idprod) && GETPOST('type') < 0) { @@ -1968,7 +1969,7 @@ else // Show object lines $result = $object->getLinesArray(); if (! empty($object->lines)) - $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid); + $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1); // Form to add new line if ($object->statut == 0 && $user->rights->propal->creer) From 3f1dabb4e2afb6e93f6a760822db7a0b52bb8448 Mon Sep 17 00:00:00 2001 From: simnandez Date: Mon, 20 May 2013 18:43:21 +0200 Subject: [PATCH 32/33] Trad: Fix Catalan words into Spanish --- htdocs/langs/es_ES/admin.lang | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/langs/es_ES/admin.lang b/htdocs/langs/es_ES/admin.lang index 18f58bd0dae..883c316bdce 100644 --- a/htdocs/langs/es_ES/admin.lang +++ b/htdocs/langs/es_ES/admin.lang @@ -356,14 +356,14 @@ ExtrafieldPhone=Teléfono ExtrafieldPrice=Precio ExtrafieldMail=Correo ExtrafieldSelect=Lista de selección -ExtrafieldSelectList=Llista de selección de table +ExtrafieldSelectList=Lista de selección de tabla ExtrafieldSeparator=Separador ExtrafieldCheckBox=Casilla de verificación ExtrafieldRadio=Botón de selección excluyente -ExtrafieldParamHelpselect=La llista ha de ser en forma clau, valor

per exemple :
1,text1
2,text2
3,text3
... -ExtrafieldParamHelpcheckbox=La llista ha de ser en forma clau, valor

per exemple :
1,text1
2,text2
3,text3
... -ExtrafieldParamHelpradio=La llista ha de ser en forma clau, valor

per exemple :
1,text1
2,text2
3,text3
... -ExtrafieldParamHelpsellist=La llista ha de ser del table

per exemple :
table:label:(code)
+ExtrafieldParamHelpselect=La lista ha de ser en forma llave, valor

por ejemplo :
1,text1
2,text2
3,text3
... +ExtrafieldParamHelpcheckbox=La lista ha de ser en forma llave, valor

por ejemplo :
1,text1
2,text2
3,text3
... +ExtrafieldParamHelpradio=La lista ha de ser en forma llave, valor

por ejemplo :
1,text1
2,text2
3,text3
... +ExtrafieldParamHelpsellist=La lista ha de ser de la tabl

por ejemplo:
table:label:(code)
LibraryToBuildPDF=Librería usada para la creación de archivos PDF WarningUsingFPDF=Atención: Su archivo conf.php contiene la directiva dolibarr_pdf_force_fpdf=1. Esto hace que se use la librería FPDF para generar sus archivos PDF. Esta librería es antigua y no cubre algunas funcionalidades (Unicode, transparencia de imágenes, idiomas cirílicos, árabes o asiáticos, etc.), por lo que puede tener problemas en la generación de los PDF.
Para resolverlo, y disponer de un soporte completo de PDF, puede descargar la librería TCPDF , y a continuación comentar o eliminar la línea $dolibarr_pdf_force_fpdf=1, y añadir en su lugar $dolibarr_lib_TCPDF_PATH='ruta_a_TCPDF' LocalTaxDesc=Algunos países aplican 2 o 3 tasas a cada línea de factura. Si es el caso, escoja el tipo de la segunda y tercera tasa y su valor. Los posibles tipos son:
1 : tasa local aplicable a productos y servicios sin IVA (IVA no se aplica en la tasa local)
2 : tasa local se aplica a productos y servicios antes del IVA (IVA se calcula sobre importe+tasa local)
3 : tasa local se aplica a productos sin IVA (IVA no se aplica en la tasa local)
4 : tasa local se aplica a productos antes del IVA (IVA se calcula sobre el importe+tasa local)
5 : tasa local se aplica a servicios sin IVA (IVA no se aplica a la tasa local)
6 : tasa local se aplica a servicios antes del IVA (IVA se calcula sobre importe + tasa local) From 6db07ac2d8f059205c4e550feb4f71c0903d1282 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 May 2013 19:24:27 +0200 Subject: [PATCH 33/33] Fix: Several bugs into filter on statistics pages. --- .../comm/propal/class/propalestats.class.php | 23 +++--- htdocs/comm/propal/stats/index.php | 9 +-- htdocs/commande/class/commandestats.class.php | 11 +-- htdocs/commande/stats/index.php | 9 +-- .../facture/class/facturestats.class.php | 72 ++++++++++--------- htdocs/compta/facture/stats/index.php | 3 +- 6 files changed, 69 insertions(+), 58 deletions(-) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 5911058cdbc..54ddc846272 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -26,6 +26,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; +include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** @@ -49,14 +50,14 @@ class PropaleStats extends Stats * * @param DoliDB $db Database handler * @param int $socid Id third party - * @param int $userid Id user for filter + * @param int $userid Id user for filter (creation user) */ function __construct($db, $socid=0, $userid=0) { global $user, $conf; $this->db = $db; - $this->socid = $socid; + $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; $object=new Propal($this->db); @@ -66,7 +67,7 @@ class PropaleStats extends Stats $this->field='total_ht'; - $this->where.= " fk_statut > 0"; + $this->where.= " p.fk_statut > 0"; $this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) @@ -79,7 +80,7 @@ class PropaleStats extends Stats /** * Return propals number by month for a year - * + * * @param int $year year for stats * @return array array with number by month */ @@ -90,7 +91,7 @@ class PropaleStats extends Stats $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'"; + $sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -100,7 +101,7 @@ class PropaleStats extends Stats /** * Return propals number by year - * + * * @return array array with number by year * */ @@ -117,7 +118,7 @@ class PropaleStats extends Stats return $this->_getNbByYear($sql); } - + /** * Return the propals amount by month for a year * @@ -131,14 +132,14 @@ class PropaleStats extends Stats $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'"; + $sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); return $this->_getAmountByMonth($year, $sql); } - + /** * Return the propals amount average by month for a year * @@ -152,7 +153,7 @@ class PropaleStats extends Stats $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'"; + $sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -162,7 +163,7 @@ class PropaleStats extends Stats /** * Return nb, total and average - * + * * @return array Array of values */ function getAllByYear() diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index ef979275101..a4b7ad69d24 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -31,8 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $WIDTH=DolGraph::getDefaultGraphSizeForStats('width'); $HEIGHT=DolGraph::getDefaultGraphSizeForStats('height'); -$userid=GETPOST('userid','int'); if ($userid < 0) $userid=0; -$socid=GETPOST('socid','int'); if ($socid < 0) $socid=0; +$userid=GETPOST('userid','int'); +$socid=GETPOST('socid','int'); // Security check if ($user->societe_id > 0) { @@ -63,7 +63,7 @@ $dir=$conf->propal->dir_temp; dol_mkdir($dir); -$stats = new PropaleStats($db, $socid, $userid); +$stats = new PropaleStats($db, $socid, ($userid>0?$userid:0)); // Build graphic number of object $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); @@ -233,12 +233,13 @@ print '
'; print $form->select_company($socid,'socid',$filter,1); print ''; // User - print ''.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").''; + print ''.$langs->trans("CreatedBy").''; print $form->select_users($userid,'userid',1); print ''; // Year print ''.$langs->trans("Year").''; if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year; + if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear; arsort($arrayyears); print $form->selectarray('year',$arrayyears,$year,0); print ''; diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index fba88538145..56c69d84541 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -26,6 +26,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php'; +include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** @@ -49,7 +50,7 @@ class CommandeStats extends Stats * @param DoliDB $db Database handler * @param int $socid Id third party for filter * @param string $mode Option - * @param int $userid Id user for filter + * @param int $userid Id user for filter (creation user) */ function __construct($db, $socid, $mode, $userid=0) { @@ -57,7 +58,7 @@ class CommandeStats extends Stats $this->db = $db; - $this->socid = $socid; + $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; if ($mode == 'customer') @@ -100,7 +101,7 @@ class CommandeStats extends Stats $sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'"; + $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -143,7 +144,7 @@ class CommandeStats extends Stats $sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'"; + $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -165,7 +166,7 @@ class CommandeStats extends Stats $sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE date_format(c.date_commande,'%Y') = '".$year."'"; + $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index cb7e2034275..07dfb674c74 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -36,8 +36,8 @@ $mode=GETPOST("mode")?GETPOST("mode"):'customer'; if ($mode == 'customer' && ! $user->rights->commande->lire) accessforbidden(); if ($mode == 'supplier' && ! $user->rights->fournisseur->commande->lire) accessforbidden(); -$userid=GETPOST('userid','int'); if ($userid < 0) $userid=0; -$socid=GETPOST('socid','int'); if ($socid < 0) $socid=0; +$userid=GETPOST('userid','int'); +$socid=GETPOST('socid','int'); // Security check if ($user->societe_id > 0) { @@ -77,7 +77,7 @@ print_fiche_titre($title); dol_mkdir($dir); -$stats = new CommandeStats($db, $socid, $mode, $userid); +$stats = new CommandeStats($db, $socid, $mode, ($userid>0?$userid:0)); // Build graphic number of object $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); @@ -255,12 +255,13 @@ print '
'; print $form->select_company($socid,'socid',$filter,1); print ''; // User - print ''.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").''; + print ''.$langs->trans("CreatedBy").''; print $form->select_users($userid,'userid',1); print ''; // Year print ''.$langs->trans("Year").''; if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year; + if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear; arsort($arrayyears); print $form->selectarray('year',$arrayyears,$year,0); print ''; diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index f99b8f3bb27..0fe45fc6c66 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -48,12 +48,12 @@ class FactureStats extends Stats * @param DoliDB $db Database handler * @param int $socid Id third party * @param string $mode Option - * @param int $userid Id user for filter + * @param int $userid Id user for filter (creation user) * @return FactureStats */ function __construct($db, $socid, $mode, $userid=0) { - global $conf; + global $user, $conf; $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); @@ -62,41 +62,25 @@ class FactureStats extends Stats if ($mode == 'customer') { $object=new Facture($this->db); - $this->from = MAIN_DB_PREFIX.$object->table_element; + $this->from = MAIN_DB_PREFIX.$object->table_element." as f"; $this->field='total'; } if ($mode == 'supplier') { $object=new FactureFournisseur($this->db); - $this->from = MAIN_DB_PREFIX.$object->table_element; + $this->from = MAIN_DB_PREFIX.$object->table_element." as f"; $this->field='total_ht'; } - $this->where = " fk_statut > 0"; - $this->where.= " AND entity = ".$conf->entity; - if ($mode == 'customer') $this->where.=" AND (fk_statut <> 3 OR close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) + $this->where = " f.fk_statut > 0"; + $this->where.= " AND f.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) if ($this->socid) { - $this->where.=" AND fk_soc = ".$this->socid; + $this->where.=" AND f.fk_soc = ".$this->socid; } - if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid; - } - - - /** - * Renvoie le nombre de facture par annee - * - * @return array Array of values - */ - function getNbByYear() - { - $sql = "SELECT YEAR(datef) as dm, COUNT(*)"; - $sql.= " FROM ".$this->from; - $sql.= " WHERE ".$this->where; - $sql.= " GROUP BY dm"; - $sql.= $this->db->order('dm','DESC'); - - return $this->_getNbByYear($sql); + if ($this->userid > 0) $this->where.=' AND f.fk_user_author = '.$this->userid; } @@ -108,9 +92,10 @@ class FactureStats extends Stats */ function getNbByMonth($year) { - $sql = "SELECT MONTH(datef) as dm, COUNT(*)"; + $sql = "SELECT MONTH(f.datef) as dm, COUNT(*)"; $sql.= " FROM ".$this->from; - $sql.= " WHERE datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -121,6 +106,24 @@ class FactureStats extends Stats } + /** + * Renvoie le nombre de facture par annee + * + * @return array Array of values + */ + function getNbByYear() + { + $sql = "SELECT YEAR(f.datef) as dm, COUNT(*)"; + $sql.= " FROM ".$this->from; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE ".$this->where; + $sql.= " GROUP BY dm"; + $sql.= $this->db->order('dm','DESC'); + + return $this->_getNbByYear($sql); + } + + /** * Renvoie le montant de facture par mois pour une annee donnee * @@ -129,9 +132,10 @@ class FactureStats extends Stats */ function getAmountByMonth($year) { - $sql = "SELECT date_format(datef,'%m') as dm, SUM(".$this->field.")"; + $sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")"; $sql.= " FROM ".$this->from; - $sql.= " WHERE date_format(datef,'%Y') = '".$year."'"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -149,9 +153,10 @@ class FactureStats extends Stats */ function getAverageByMonth($year) { - $sql = "SELECT date_format(datef,'%m') as dm, AVG(".$this->field.")"; + $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; $sql.= " FROM ".$this->from; - $sql.= " WHERE datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -166,8 +171,9 @@ class FactureStats extends Stats */ function getAllByYear() { - $sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg"; + $sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg"; $sql.= " FROM ".$this->from; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " GROUP BY year"; $sql.= $this->db->order('year','DESC'); diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 0b4a341e1c2..4abff5b63be 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -233,12 +233,13 @@ print '
'; print $form->select_company($socid,'socid',$filter,1); print ''; // User - print ''.$langs->trans("User").'/'.$langs->trans("SalesRepresentative").''; + print ''.$langs->trans("CreatedBy").''; print $form->select_users($userid,'userid',1); print ''; // Year print ''.$langs->trans("Year").''; if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year; + if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear; arsort($arrayyears); print $form->selectarray('year',$arrayyears,$year,0); print '';