Test Failed
Push — master ( e0c20c...b8c830 )
by Alxarafe
39:29
created
dolibarr/scripts/company/export-contacts-xls-example.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 $sapi_type = php_sapi_name();
28 28
 $script_file = basename(__FILE__);
29
-$path=dirname(__FILE__).'/';
29
+$path = dirname(__FILE__).'/';
30 30
 
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	exit(-1);
35 35
 }
36 36
 
37
-if (! isset($argv[1]) || ! $argv[1]) {
37
+if (!isset($argv[1]) || !$argv[1]) {
38 38
 	print "Usage: $script_file now\n";
39 39
 	exit(-1);
40 40
 }
41
-$now=$argv[1];
41
+$now = $argv[1];
42 42
 
43 43
 
44 44
 require_once $path."../../htdocs/master.inc.php";
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel5.php";
51 51
 
52 52
 // Global variables
53
-$version=DOL_VERSION;
54
-$error=0;
53
+$version = DOL_VERSION;
54
+$error = 0;
55 55
 
56 56
 
57 57
 /*
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
 @set_time_limit(0);
62 62
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
63
-dol_syslog($script_file." launched with arg ".join(',',$argv));
63
+dol_syslog($script_file." launched with arg ".join(',', $argv));
64 64
 
65 65
 $fname = DOL_DATA_ROOT.'/export-contacts.xls';
66 66
 
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 //$page->set_column(0,4,18); // A
81 81
 
82 82
 $sql = "SELECT distinct c.lastname, c.firstname, c.email, s.nom as name";
83
-$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
84
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = c.fk_soc";
83
+$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
84
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = c.fk_soc";
85 85
 
86
-$resql=$db->query($sql);
86
+$resql = $db->query($sql);
87 87
 if ($resql)
88 88
 {
89 89
 	$num = $db->num_rows($resql);
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 	{
103 103
 		$obj = $db->fetch_object($resql);
104 104
 
105
-    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
-    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
-    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
-    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
105
+    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i + 2), $obj->firstname);
106
+    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i + 2), $obj->lastname);
107
+    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i + 2), $obj->email);
108
+    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i + 2), $obj->name);
109 109
 
110 110
 		$j++;
111 111
 		$i++;
Please login to merge, or discard this patch.
dolibarr/scripts/modulebuilder/builddoc.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
 $sapi_type = php_sapi_name();
33 33
 $script_file = basename(__FILE__);
34
-$path=dirname(__FILE__).'/';
34
+$path = dirname(__FILE__).'/';
35 35
 
36 36
 // Test if batch mode
37 37
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	exit(-1);
40 40
 }
41 41
 
42
-if (! isset($argv[1]) || ! $argv[1]) {
42
+if (!isset($argv[1]) || !$argv[1]) {
43 43
 	print "Usage: ".$script_file." ModuleName\n";
44 44
 	exit(-1);
45 45
 }
46
-$modulename=$argv[1];
46
+$modulename = $argv[1];
47 47
 
48 48
 require_once $path."../../htdocs/master.inc.php";
49 49
 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -57,31 +57,31 @@  discard block
 block discarded – undo
57 57
 
58 58
 
59 59
 // Global variables
60
-$version=DOL_VERSION;
61
-$error=0;
60
+$version = DOL_VERSION;
61
+$error = 0;
62 62
 
63 63
 // Dir for custom dirs
64
-$tmp=explode(',', $dolibarr_main_document_root_alt);
64
+$tmp = explode(',', $dolibarr_main_document_root_alt);
65 65
 $dirins = $tmp[0];
66 66
 $dirread = $dirins;
67 67
 $forceddirread = 0;
68 68
 
69 69
 $tmpdir = explode('@', $module);
70
-if (! empty($tmpdir[1]))
70
+if (!empty($tmpdir[1]))
71 71
 {
72
-	$module=$tmpdir[0];
73
-	$dirread=$tmpdir[1];
74
-	$forceddirread=1;
72
+	$module = $tmpdir[0];
73
+	$dirread = $tmpdir[1];
74
+	$forceddirread = 1;
75 75
 }
76 76
 
77
-$FILEFLAG='modulebuilder.txt';
77
+$FILEFLAG = 'modulebuilder.txt';
78 78
 
79
-$now=dol_now();
79
+$now = dol_now();
80 80
 $newmask = 0;
81
-if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
81
+if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
82 82
 if (empty($newmask))	// This should no happen
83 83
 {
84
-	$newmask='0664';
84
+	$newmask = '0664';
85 85
 }
86 86
 
87 87
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 print "modulename=".$modulename."\n";
95 95
 print "dirins=".$dirins."\n";
96 96
 
97
-$FILENAMEDOC=strtolower($module).'.html';			// TODO Use/text PDF
97
+$FILENAMEDOC = strtolower($module).'.html'; // TODO Use/text PDF
98 98
 $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc';
99 99
 $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
100 100
 
Please login to merge, or discard this patch.
dolibarr/scripts/modulebuilder/initmodule.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test if batch mode
33 33
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	exit(-1);
36 36
 }
37 37
 
38
-if (! isset($argv[1]) || ! $argv[1]) {
38
+if (!isset($argv[1]) || !$argv[1]) {
39 39
 	print "Usage: ".$script_file." ModuleName\n";
40 40
 	exit(-1);
41 41
 }
42
-$modulename=$argv[1];
42
+$modulename = $argv[1];
43 43
 
44 44
 require_once $path."../../htdocs/master.inc.php";
45 45
 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -52,31 +52,31 @@  discard block
 block discarded – undo
52 52
 
53 53
 
54 54
 // Global variables
55
-$version=DOL_VERSION;
56
-$error=0;
55
+$version = DOL_VERSION;
56
+$error = 0;
57 57
 
58 58
 // Dir for custom dirs
59
-$tmp=explode(',', $dolibarr_main_document_root_alt);
59
+$tmp = explode(',', $dolibarr_main_document_root_alt);
60 60
 $dirins = $tmp[0];
61 61
 $dirread = $dirins;
62 62
 $forceddirread = 0;
63 63
 
64 64
 $tmpdir = explode('@', $module);
65
-if (! empty($tmpdir[1]))
65
+if (!empty($tmpdir[1]))
66 66
 {
67
-	$module=$tmpdir[0];
68
-	$dirread=$tmpdir[1];
69
-	$forceddirread=1;
67
+	$module = $tmpdir[0];
68
+	$dirread = $tmpdir[1];
69
+	$forceddirread = 1;
70 70
 }
71 71
 
72
-$FILEFLAG='modulebuilder.txt';
72
+$FILEFLAG = 'modulebuilder.txt';
73 73
 
74
-$now=dol_now();
74
+$now = dol_now();
75 75
 $newmask = 0;
76
-if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
76
+if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
77 77
 if (empty($newmask))	// This should no happen
78 78
 {
79
-	$newmask='0664';
79
+	$newmask = '0664';
80 80
 }
81 81
 
82 82
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	exit(1);
97 97
 }
98 98
 
99
-if (! $error)
99
+if (!$error)
100 100
 {
101 101
 	$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102 102
 	$destdir = $dirins.'/'.strtolower($modulename);
103 103
 
104
-	$arrayreplacement=array(
104
+	$arrayreplacement = array(
105 105
 	'mymodule'=>strtolower($modulename),
106 106
 	'MyModule'=>$modulename
107 107
 	);
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 }
142 142
 
143 143
 // Edit PHP files
144
-if (! $error)
144
+if (!$error)
145 145
 {
146 146
 	$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
-	foreach($listofphpfilestoedit as $phpfileval)
147
+	foreach ($listofphpfilestoedit as $phpfileval)
148 148
 	{
149 149
 		//var_dump($phpfileval['fullname']);
150
-		$arrayreplacement=array(
150
+		$arrayreplacement = array(
151 151
 		'mymodule'=>strtolower($modulename),
152 152
 		'MyModule'=>$modulename,
153 153
 		'MYMODULE'=>strtoupper($modulename),
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 		'Mon module'=>$modulename,
157 157
 		'mon module'=>$modulename,
158 158
 		'htdocs/modulebuilder/template'=>strtolower($modulename),
159
-		'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
159
+		'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
160 160
 		);
161 161
 
162 162
 
163
-		$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
163
+		$result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164 164
 		//var_dump($result);
165 165
 		if ($result < 0)
166 166
 		{
Please login to merge, or discard this patch.
dolibarr/scripts/bank/export-bank-receipts.php 1 patch
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 $sapi_type = php_sapi_name();
27 27
 $script_file = basename(__FILE__);
28
-$path=dirname(__FILE__).'/';
28
+$path = dirname(__FILE__).'/';
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
50 50
 
51 51
 // Global variables
52
-$version=DOL_VERSION;
53
-$error=0;
52
+$version = DOL_VERSION;
53
+$error = 0;
54 54
 
55 55
 
56 56
 
@@ -60,51 +60,51 @@  discard block
 block discarded – undo
60 60
 
61 61
 @set_time_limit(0);
62 62
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
63
-dol_syslog($script_file." launched with arg ".join(',',$argv));
63
+dol_syslog($script_file." launched with arg ".join(',', $argv));
64 64
 
65
-if (! isset($argv[3]) || ! $argv[3]) {
65
+if (!isset($argv[3]) || !$argv[3]) {
66 66
 	print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67 67
 	exit(-1);
68 68
 }
69
-$bankref=$argv[1];
70
-$num=$argv[2];
71
-$model=$argv[3];
72
-$newlangid='en_EN';	// To force a new lang id
69
+$bankref = $argv[1];
70
+$num = $argv[2];
71
+$model = $argv[3];
72
+$newlangid = 'en_EN'; // To force a new lang id
73 73
 
74 74
 
75
-$invoicestatic=new Facture($db);
76
-$invoicesupplierstatic=new FactureFournisseur($db);
77
-$societestatic=new Societe($db);
78
-$chargestatic=new ChargeSociales($db);
79
-$memberstatic=new Adherent($db);
80
-$paymentstatic=new Paiement($db);
81
-$paymentsupplierstatic=new PaiementFourn($db);
82
-$paymentsocialcontributionstatic=new PaymentSocialContribution($db);
83
-$paymentvatstatic=new Tva($db);
84
-$bankstatic=new Account($db);
85
-$banklinestatic=new AccountLine($db);
75
+$invoicestatic = new Facture($db);
76
+$invoicesupplierstatic = new FactureFournisseur($db);
77
+$societestatic = new Societe($db);
78
+$chargestatic = new ChargeSociales($db);
79
+$memberstatic = new Adherent($db);
80
+$paymentstatic = new Paiement($db);
81
+$paymentsupplierstatic = new PaiementFourn($db);
82
+$paymentsocialcontributionstatic = new PaymentSocialContribution($db);
83
+$paymentvatstatic = new Tva($db);
84
+$bankstatic = new Account($db);
85
+$banklinestatic = new AccountLine($db);
86 86
 
87 87
 
88 88
 // Parse parameters
89 89
 foreach ($argv as $key => $value)
90 90
 {
91
-	$found=false;
91
+	$found = false;
92 92
 
93 93
 	// Define options
94
-	if (preg_match('/^lang=/i',$value))
94
+	if (preg_match('/^lang=/i', $value))
95 95
 	{
96
-		$found=true;
97
-		$valarray=explode('=',$value);
98
-		$newlangid=$valarray[1];
96
+		$found = true;
97
+		$valarray = explode('=', $value);
98
+		$newlangid = $valarray[1];
99 99
 		print 'Use language '.$newlangid.".\n";
100 100
 	}
101 101
 }
102 102
 $outputlangs = $langs;
103
-if (! empty($newlangid))
103
+if (!empty($newlangid))
104 104
 {
105 105
 	if ($outputlangs->defaultlang != $newlangid)
106 106
 	{
107
-		$outputlangs = new Translate("",$conf);
107
+		$outputlangs = new Translate("", $conf);
108 108
 		$outputlangs->setDefaultLang($newlangid);
109 109
 	}
110 110
 }
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 // Load translation files required by the page
113 113
 $outputlangs->loadLangs(array("main", "companies", "bills", "banks", "members", "compta"));
114 114
 
115
-$acct=new Account($db);
116
-$result=$acct->fetch('',$bankref);
115
+$acct = new Account($db);
116
+$result = $acct->fetch('', $bankref);
117 117
 if ($result <= 0)
118 118
 {
119 119
 	print "Failed to find bank account with ref ".$bankref.".\n";
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 
127 127
 
128 128
 // Creation de la classe d'export du model ExportXXX
129
-$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
129
+$dir = DOL_DOCUMENT_ROOT."/core/modules/export/";
130 130
 $file = "export_".$model.".modules.php";
131 131
 $classname = "Export".$model;
132
-if (! dol_is_file($dir.$file))
132
+if (!dol_is_file($dir.$file))
133 133
 {
134 134
 	print "No driver to export with format ".$model."\n";
135 135
 	exit(-1);
@@ -143,61 +143,61 @@  discard block
 block discarded – undo
143 143
 $filename = 'export-bank-receipts-'.$bankref.'-'.$num.'.'.$objmodel->extension;
144 144
 
145 145
 
146
-$array_fields=array(
146
+$array_fields = array(
147 147
 'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"),
148
-'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"),
148
+'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"), 'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"), 'type'=>$outputlangs->transnoentitiesnoconv("Type"),
149 149
 'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"),
150 150
 'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"),
151 151
 'soldbefore'=>$outputlangs->transnoentitiesnoconv("BankBalanceBefore"), 'soldafter'=>$outputlangs->transnoentitiesnoconv("BankBalanceAfter"),
152 152
 'comment'=>$outputlangs->transnoentitiesnoconv("Comment")
153 153
 );
154
-$array_selected=array(
154
+$array_selected = array(
155 155
 'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount',
156
-'dateop'=>'dateop','dateval'=>'dateval','type'=>'type',
156
+'dateop'=>'dateop', 'dateval'=>'dateval', 'type'=>'type',
157 157
 'description'=>'description', 'thirdparty'=>'thirdparty', 'accountelem'=>'accountelem',
158 158
 'debit'=>'debit', 'credit'=>'credit',
159
-'soldbefore'=>'soldbefore','soldafter'=>'soldafter',
159
+'soldbefore'=>'soldbefore', 'soldafter'=>'soldafter',
160 160
 'comment'=>'comment'
161 161
 );
162
-$array_export_TypeFields=array(
162
+$array_export_TypeFields = array(
163 163
 'bankreceipt'=>'Text', 'bankaccount'=>'Text',
164
-'dateop'=>'Date','dateval'=>'Date','type'=>'Text',
164
+'dateop'=>'Date', 'dateval'=>'Date', 'type'=>'Text',
165 165
 'description'=>'Text', 'thirdparty'=>'Text', 'accountelem'=>'Text',
166 166
 'debit'=>'Number', 'credit'=>'Number',
167
-'soldbefore'=>'Number','soldafter'=>'Number',
167
+'soldbefore'=>'Number', 'soldafter'=>'Number',
168 168
 'comment'=>'Text'
169 169
 );
170 170
 
171 171
 
172 172
 // Build request to find records for a bank account/receipt
173
-$listofnum="";
174
-if (! empty($num) && $num != "all")
173
+$listofnum = "";
174
+if (!empty($num) && $num != "all")
175 175
 {
176
-	$listofnum.="'";
177
-	$arraynum=explode(',',$num);
178
-	foreach($arraynum as $val)
176
+	$listofnum .= "'";
177
+	$arraynum = explode(',', $num);
178
+	foreach ($arraynum as $val)
179 179
 	{
180
-		if ($listofnum != "'") $listofnum.="','";
181
-		$listofnum.=$val;
180
+		if ($listofnum != "'") $listofnum .= "','";
181
+		$listofnum .= $val;
182 182
 	}
183
-	$listofnum.="'";
183
+	$listofnum .= "'";
184 184
 }
185 185
 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
186
-$sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
187
-$sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
188
-$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
189
-$sql.= ", ".MAIN_DB_PREFIX."bank as b";
190
-$sql.= " WHERE b.fk_account = ".$acct->id;
191
-if ($listofnum) $sql.= " AND b.num_releve IN (".$listofnum.")";
192
-if (!isset($num)) $sql.= " OR b.num_releve is null";
193
-$sql.= " AND b.fk_account = ba.rowid";
194
-$sql.= $db->order("b.num_releve, b.datev, b.datec", "ASC");  // We add date of creation to have correct order when everything is done the same day
186
+$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
187
+$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
188
+$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
189
+$sql .= ", ".MAIN_DB_PREFIX."bank as b";
190
+$sql .= " WHERE b.fk_account = ".$acct->id;
191
+if ($listofnum) $sql .= " AND b.num_releve IN (".$listofnum.")";
192
+if (!isset($num)) $sql .= " OR b.num_releve is null";
193
+$sql .= " AND b.fk_account = ba.rowid";
194
+$sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
195 195
 //print $sql;
196 196
 
197
-$resql=$db->query($sql);
197
+$resql = $db->query($sql);
198 198
 if ($resql)
199 199
 {
200
-	$balancebefore=array();
200
+	$balancebefore = array();
201 201
 
202 202
 	$numrows = $db->num_rows($resql);
203 203
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		// Open file
207 207
 		print 'Open file '.$filename.' into directory '.$dirname."\n";
208 208
 		dol_mkdir($dirname);
209
-		$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
209
+		$result = $objmodel->open_file($dirname."/".$filename, $outputlangs);
210 210
 
211 211
 		if ($result < 0)
212 212
 		{
@@ -218,32 +218,32 @@  discard block
 block discarded – undo
218 218
 		$objmodel->write_header($outputlangs);
219 219
 
220 220
 		// Genere ligne de titre
221
-		$objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
221
+		$objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
222 222
 	}
223 223
 
224
-	$i=0;
224
+	$i = 0;
225 225
 	while ($i < $numrows)
226 226
 	{
227
-		$thirdparty='';
228
-		$accountelem='';
229
-		$comment='';
227
+		$thirdparty = '';
228
+		$accountelem = '';
229
+		$comment = '';
230 230
 
231 231
 		$objp = $db->fetch_object($resql);
232 232
 
233 233
 		// Calculate start balance
234
-		if (! isset($balancebefore[$objp->num_releve]))
234
+		if (!isset($balancebefore[$objp->num_releve]))
235 235
 		{
236 236
 			print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237 237
 
238 238
 			$sql2 = "SELECT sum(b.amount) as amount";
239
-			$sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
-			$sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
-			$sql2.= " AND b.fk_account = ".$objp->bankid;
242
-			$resql2=$db->query($sql2);
239
+			$sql2 .= " FROM ".MAIN_DB_PREFIX."bank as b";
240
+			$sql2 .= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
+			$sql2 .= " AND b.fk_account = ".$objp->bankid;
242
+			$resql2 = $db->query($sql2);
243 243
 			if ($resql2)
244 244
 			{
245
-				$obj2=$db->fetch_object($resql2);
246
-				$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
245
+				$obj2 = $db->fetch_object($resql2);
246
+				$balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
247 247
 				$db->free($resql2);
248 248
 			}
249 249
 			else
@@ -261,109 +261,109 @@  discard block
 block discarded – undo
261 261
 
262 262
 
263 263
 		// Date operation
264
-		$dateop=$db->jdate($objp->do);
264
+		$dateop = $db->jdate($objp->do);
265 265
 
266 266
 		// Date de valeur
267
-		$datevalue=$db->jdate($objp->dv);
267
+		$datevalue = $db->jdate($objp->dv);
268 268
 
269 269
 		// Num cheque
270
-		$numchq=($objp->num_chq?$objp->num_chq:'');
270
+		$numchq = ($objp->num_chq ? $objp->num_chq : '');
271 271
 
272 272
 		// Libelle
273
-		$reg=array();
274
-		preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
-		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
-		else $description=$objp->label;
273
+		$reg = array();
274
+		preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
275
+		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) $description = $langs->transnoentitiesnoconv($reg[1]);
276
+		else $description = $objp->label;
277 277
 
278 278
 		/*
279 279
 		 * Ajout les liens (societe, company...)
280 280
 		 */
281 281
 		$links = $acct->get_url($objp->rowid);
282
-		foreach($links as $key=>$val)
282
+		foreach ($links as $key=>$val)
283 283
 		{
284
-			if ($links[$key]['type']=='payment')
284
+			if ($links[$key]['type'] == 'payment')
285 285
 			{
286 286
 				$paymentstatic->fetch($links[$key]['url_id']);
287
-				$tmparray=$paymentstatic->getBillsArray('');
287
+				$tmparray = $paymentstatic->getBillsArray('');
288 288
 				if (is_array($tmparray))
289 289
 				{
290
-					foreach($tmparray as $key => $val)
290
+					foreach ($tmparray as $key => $val)
291 291
 					{
292 292
 						$invoicestatic->fetch($val);
293
-						if ($accountelem) $accountelem.= ', ';
294
-						$accountelem.=$invoicestatic->ref;
293
+						if ($accountelem) $accountelem .= ', ';
294
+						$accountelem .= $invoicestatic->ref;
295 295
 					}
296 296
 				}
297 297
 			}
298
-			elseif ($links[$key]['type']=='payment_supplier')
298
+			elseif ($links[$key]['type'] == 'payment_supplier')
299 299
 			{
300 300
 				$paymentsupplierstatic->fetch($links[$key]['url_id']);
301
-				$tmparray=$paymentsupplierstatic->getBillsArray('');
301
+				$tmparray = $paymentsupplierstatic->getBillsArray('');
302 302
 				if (is_array($tmparray))
303 303
 				{
304
-					foreach($tmparray as $key => $val)
304
+					foreach ($tmparray as $key => $val)
305 305
 					{
306 306
 						$invoicesupplierstatic->fetch($val);
307
-						if ($accountelem) $accountelem.= ', ';
308
-						$accountelem.=$invoicesupplierstatic->ref;
307
+						if ($accountelem) $accountelem .= ', ';
308
+						$accountelem .= $invoicesupplierstatic->ref;
309 309
 					}
310 310
 				}
311 311
 			}
312
-			elseif ($links[$key]['type']=='payment_sc')
312
+			elseif ($links[$key]['type'] == 'payment_sc')
313 313
 			{
314 314
 				$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
-				if ($accountelem) $accountelem.= ', ';
316
-				$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
315
+				if ($accountelem) $accountelem .= ', ';
316
+				$accountelem .= $langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317 317
 			}
318
-			elseif ($links[$key]['type']=='payment_vat')
318
+			elseif ($links[$key]['type'] == 'payment_vat')
319 319
 			{
320 320
 				$paymentvatstatic->fetch($links[$key]['url_id']);
321
-				if ($accountelem) $accountelem.= ', ';
322
-				$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
321
+				if ($accountelem) $accountelem .= ', ';
322
+				$accountelem .= $langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323 323
 			}
324
-			elseif ($links[$key]['type']=='banktransfert')
324
+			elseif ($links[$key]['type'] == 'banktransfert')
325 325
 			{
326
-				$comment=$outputlangs->transnoentitiesnoconv("Transfer");
326
+				$comment = $outputlangs->transnoentitiesnoconv("Transfer");
327 327
 				if ($objp->amount > 0)
328 328
 				{
329
-					if ($comment) $comment.= ' ';
329
+					if ($comment) $comment .= ' ';
330 330
 					$banklinestatic->fetch($links[$key]['url_id']);
331
-					$bankstatic->id=$banklinestatic->fk_account;
332
-					$bankstatic->label=$banklinestatic->bank_account_label;
333
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
335
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
-					$bankstatic->id=$objp->bankid;
337
-					$bankstatic->label=$objp->bankref;
338
-					$comment.= $bankstatic->getNomUrl(1,'');
339
-					$comment.= ')';
331
+					$bankstatic->id = $banklinestatic->fk_account;
332
+					$bankstatic->label = $banklinestatic->bank_account_label;
333
+					$comment .= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
+					$comment .= $bankstatic->getNomUrl(1, 'transactions');
335
+					$comment .= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
+					$bankstatic->id = $objp->bankid;
337
+					$bankstatic->label = $objp->bankref;
338
+					$comment .= $bankstatic->getNomUrl(1, '');
339
+					$comment .= ')';
340 340
 				}
341 341
 				else
342 342
 				{
343
-					if ($comment) $comment.= ' ';
344
-					$bankstatic->id=$objp->bankid;
345
-					$bankstatic->label=$objp->bankref;
346
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
-					$comment.= $bankstatic->getNomUrl(1,'');
348
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
343
+					if ($comment) $comment .= ' ';
344
+					$bankstatic->id = $objp->bankid;
345
+					$bankstatic->label = $objp->bankref;
346
+					$comment .= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
+					$comment .= $bankstatic->getNomUrl(1, '');
348
+					$comment .= ' '.$langs->transnoentitiesnoconv("toward").' ';
349 349
 					$banklinestatic->fetch($links[$key]['url_id']);
350
-					$bankstatic->id=$banklinestatic->fk_account;
351
-					$bankstatic->label=$banklinestatic->bank_account_label;
352
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
353
-					$comment.= ')';
350
+					$bankstatic->id = $banklinestatic->fk_account;
351
+					$bankstatic->label = $banklinestatic->bank_account_label;
352
+					$comment .= $bankstatic->getNomUrl(1, 'transactions');
353
+					$comment .= ')';
354 354
 				}
355 355
 			}
356
-			elseif ($links[$key]['type']=='company')
356
+			elseif ($links[$key]['type'] == 'company')
357 357
 			{
358
-				if ($thirdparty) $thirdparty.= ', ';
359
-				$thirdparty.= dol_trunc($links[$key]['label'],24);
360
-				$newline=0;
358
+				if ($thirdparty) $thirdparty .= ', ';
359
+				$thirdparty .= dol_trunc($links[$key]['label'], 24);
360
+				$newline = 0;
361 361
 			}
362
-			elseif ($links[$key]['type']=='member')
362
+			elseif ($links[$key]['type'] == 'member')
363 363
 			{
364
-				if ($thirdparty) $accountelem.= ', ';
365
-				$thirdparty.= $links[$key]['label'];
366
-				$newline=0;
364
+				if ($thirdparty) $accountelem .= ', ';
365
+				$thirdparty .= $links[$key]['label'];
366
+				$newline = 0;
367 367
 			}
368 368
 			/*elseif ($links[$key]['type']=='sc')
369 369
 				{
@@ -384,37 +384,37 @@  discard block
 block discarded – undo
384 384
 			}*/
385 385
 		}
386 386
 
387
-		$debit=$credit='';
387
+		$debit = $credit = '';
388 388
 		if ($objp->amount < 0)
389 389
 		{
390 390
 			$totald = $totald + abs($objp->amount);
391
-			$debit=price2num($objp->amount * -1);
391
+			$debit = price2num($objp->amount * -1);
392 392
 		}
393 393
 		else
394 394
 		{
395 395
 			$totalc = $totalc + abs($objp->amount);
396
-			$credit=price2num($objp->amount);
396
+			$credit = price2num($objp->amount);
397 397
 		}
398 398
 
399 399
 		$i++;
400 400
 
401
-		$rec=new stdClass();
402
-		$rec->bankreceipt=$objp->num_releve;
403
-		$rec->bankaccount=$objp->banklabel;
404
-		$rec->dateop=dol_print_date($dateop,'dayrfc');
405
-		$rec->dateval=dol_print_date($datevalue,'dayrfc');
406
-		$rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
-		$rec->description=$description;
408
-		$rec->thirdparty=$thirdparty;
409
-		$rec->accountelem=$accountelem;
410
-		$rec->debit=$debit;
411
-		$rec->credit=$credit;
412
-		$rec->comment=$comment;
413
-		$rec->soldbefore=price2num($totalbefore);
414
-		$rec->soldafter=price2num($total);
401
+		$rec = new stdClass();
402
+		$rec->bankreceipt = $objp->num_releve;
403
+		$rec->bankaccount = $objp->banklabel;
404
+		$rec->dateop = dol_print_date($dateop, 'dayrfc');
405
+		$rec->dateval = dol_print_date($datevalue, 'dayrfc');
406
+		$rec->type = $objp->fk_type.' '.($objp->num_chq ? $objp->num_chq : '');
407
+		$rec->description = $description;
408
+		$rec->thirdparty = $thirdparty;
409
+		$rec->accountelem = $accountelem;
410
+		$rec->debit = $debit;
411
+		$rec->credit = $credit;
412
+		$rec->comment = $comment;
413
+		$rec->soldbefore = price2num($totalbefore);
414
+		$rec->soldafter = price2num($total);
415 415
 
416 416
 		// end of special operation processing
417
-		$objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
417
+		$objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
418 418
 	}
419 419
 
420 420
 	if ($numrows > 0)
@@ -429,19 +429,19 @@  discard block
 block discarded – undo
429 429
 
430 430
 		print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431 431
 
432
-		$ret=0;
432
+		$ret = 0;
433 433
 	}
434 434
 	else
435 435
 	{
436 436
 		print "No records found for receipt ".$num."\n";
437 437
 
438
-		$ret=0;
438
+		$ret = 0;
439 439
 	}
440 440
 }
441 441
 else
442 442
 {
443 443
 	dol_print_error($db);
444
-	$ret=-1;
444
+	$ret = -1;
445 445
 }
446 446
 
447 447
 $db->close();
Please login to merge, or discard this patch.
dolibarr/scripts/contracts/email_expire_services_to_customers.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')) || !in_array($argv[2], array('thirdparties', 'contacts')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42 42
 	print "\n";
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n";
47 47
 	exit(-1);
48 48
 }
49
-$mode=$argv[1];
50
-$targettype=$argv[2];
49
+$mode = $argv[1];
50
+$targettype = $argv[2];
51 51
 
52 52
 
53 53
 require $path."../../htdocs/master.inc.php";
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 $langs->loadLangs(array('main', 'contracts'));
57 57
 
58 58
 // Global variables
59
-$version=DOL_VERSION;
60
-$error=0;
59
+$version = DOL_VERSION;
60
+$error = 0;
61 61
 
62 62
 
63 63
 /*
@@ -66,46 +66,46 @@  discard block
 block discarded – undo
66 66
 
67 67
 @set_time_limit(0);
68 68
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
69
-dol_syslog($script_file." launched with arg ".join(',',$argv));
69
+dol_syslog($script_file." launched with arg ".join(',', $argv));
70 70
 
71
-$now=dol_now('tzserver');
72
-$duration_value=isset($argv[3])?$argv[3]:'none';
73
-$duration_value2=isset($argv[4])?$argv[4]:'none';
71
+$now = dol_now('tzserver');
72
+$duration_value = isset($argv[3]) ? $argv[3] : 'none';
73
+$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
74 74
 
75 75
 $error = 0;
76
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
76
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n";
77 77
 
78
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
78
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
79 79
 
80 80
 $sql  = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,";
81
-$sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
82
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
81
+$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
82
+if ($targettype == 'contacts') $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
83 83
 $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
84
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
84
+if ($targettype == 'contacts') $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
85 85
 $sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
86 86
 $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
87 87
 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
88 88
 $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5";
89
-if (is_numeric($duration_value2)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
90
-if (is_numeric($duration_value)) $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
91
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
92
-$sql.= " ORDER BY";
93
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
94
-$sql.= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC";	// Order by email to allow one message per email
89
+if (is_numeric($duration_value2)) $sql .= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
90
+if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
91
+if ($targettype == 'contacts') $sql .= " AND s.rowid = sp.fk_soc";
92
+$sql .= " ORDER BY";
93
+if ($targettype == 'contacts') $sql .= " sp.email, sp.rowid,";
94
+$sql .= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email
95 95
 
96 96
 //print $sql;
97
-$resql=$db->query($sql);
97
+$resql = $db->query($sql);
98 98
 if ($resql)
99 99
 {
100 100
     $num = $db->num_rows($resql);
101 101
     $i = 0;
102
-    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
102
+    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang = '';
103 103
     $total = 0; $foundtoprocess = 0;
104 104
     $trackthirdpartiessent = array();
105 105
 
106 106
     print "We found ".$num." couples (services to expire-".$targettype.") qualified\n";
107 107
     dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified");
108
-	$message='';
108
+	$message = '';
109 109
 
110 110
     if ($num)
111 111
     {
@@ -113,21 +113,21 @@  discard block
 block discarded – undo
113 113
         {
114 114
             $obj = $db->fetch_object($resql);
115 115
 
116
-            $newemail=empty($obj->cemail)?$obj->email:$obj->cemail;
116
+            $newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
117 117
 
118 118
             // Check if this record is a break after previous one
119
-            $startbreak=false;
120
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
121
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
122
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
119
+            $startbreak = false;
120
+			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak = true;
121
+			if ($obj->sid && $obj->sid <> $oldsid) $startbreak = true;
122
+			if ($obj->cid && $obj->cid <> $oldcid) $startbreak = true;
123 123
 
124 124
             if ($startbreak)
125 125
             {
126 126
                 // Break onto sales representative (new email or cid)
127 127
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
128 128
                 {
129
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
130
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
129
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
130
+                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
131 131
                 }
132 132
                 else
133 133
 				{
@@ -141,28 +141,28 @@  discard block
 block discarded – undo
141 141
                 $oldsid  = $obj->sid;
142 142
                 $oldcid  = $obj->cid;
143 143
                 $oldlang = $obj->lang;
144
-                $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
144
+                $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
145 145
                 $message = '';
146 146
                 $total   = 0;
147 147
                 $foundtoprocess = 0;
148
-                $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
148
+                $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
149 149
                 //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
150 150
             }
151 151
 
152 152
             // Define line content
153
-            $outputlangs=new Translate('',$conf);
154
-            $outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang);	// By default language of customer
153
+            $outputlangs = new Translate('', $conf);
154
+            $outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
155 155
 
156 156
             // Load translation files required by the page
157 157
             $outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
158 158
 
159 159
             if (dol_strlen($newemail))
160 160
             {
161
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
161
+            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel, $obj->description)." (".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')."\n\n";
162 162
             	dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
163 163
             	$foundtoprocess++;
164 164
             }
165
-            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165
+            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
166 166
             if (dol_strlen($newemail)) print "qualified.";
167 167
             else print "disqualified (no email).";
168 168
 			print "\n";
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
         {
180 180
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
181 181
             {
182
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
183
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
182
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
183
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
184 184
             }
185 185
             else
186 186
 			{
@@ -220,26 +220,26 @@  discard block
 block discarded – undo
220 220
  *  @param  int		$duration_value	duration value
221 221
  * 	@return	int						<0 if KO, >0 if OK
222 222
  */
223
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget,$duration_value)
223
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
224 224
 {
225
-    global $conf,$langs;
225
+    global $conf, $langs;
226 226
 
227
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
227
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
228 228
 
229
-    $newlangs=new Translate('',$conf);
230
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
229
+    $newlangs = new Translate('', $conf);
230
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
231 231
     $newlangs->load("main");
232 232
     $newlangs->load("contracts");
233 233
 
234 234
     if ($duration_value)
235 235
     {
236
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
237
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
236
+    	if ($duration_value > 0) $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
237
+    	else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
238 238
     }
239 239
     else
240
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
240
+    	$title = $newlangs->transnoentities("ListOfServicesToExpire");
241 241
 
242
-    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
242
+    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
243 243
     $sendto = $oldemail;
244 244
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
245 245
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -248,26 +248,26 @@  discard block
 block discarded – undo
248 248
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
249 249
     dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
250 250
 
251
-    $usehtml=0;
252
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
253
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml+=1;
251
+    $usehtml = 0;
252
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml += 1;
253
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml += 1;
254 254
 
255
-    $allmessage='';
256
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
255
+    $allmessage = '';
256
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
257 257
     {
258
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
258
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
259 259
     }
260 260
     else
261 261
 	{
262
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
263
-    	$allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
262
+    	$allmessage .= "Dear customer".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
263
+    	$allmessage .= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
264 264
     }
265
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
265
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
266 266
     //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
267
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
267
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
268 268
     {
269
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
269
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml += 1;
271 271
     }
272 272
 
273 273
     $mail = new CMailFile(
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
     // Send or not email
290 290
     if ($mode == 'confirm')
291 291
     {
292
-    	$result=$mail->sendfile();
293
-    	if (! $result)
292
+    	$result = $mail->sendfile();
293
+    	if (!$result)
294 294
     	{
295 295
     		print "Error sending email ".$mail->error."\n";
296 296
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
     	print "No email sent (test mode)\n";
302 302
     	dol_syslog("No email sent (test mode)");
303 303
     	$mail->dump_mail();
304
-    	$result=1;
304
+    	$result = 1;
305 305
     }
306 306
 
307 307
     unset($newlangs);
Please login to merge, or discard this patch.
dolibarr/scripts/contracts/email_expire_services_to_representatives.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) [delay]\n";
42 42
 	print "\n";
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46 46
 	exit(-1);
47 47
 }
48
-$mode=$argv[1];
48
+$mode = $argv[1];
49 49
 
50 50
 
51 51
 require $path."../../htdocs/master.inc.php";
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 $langs->loadLangs(array('main', 'contracts'));
55 55
 
56 56
 // Global variables
57
-$version=DOL_VERSION;
58
-$error=0;
57
+$version = DOL_VERSION;
58
+$error = 0;
59 59
 
60 60
 
61 61
 /*
@@ -64,35 +64,35 @@  discard block
 block discarded – undo
64 64
 
65 65
 @set_time_limit(0);
66 66
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
67
-dol_syslog($script_file." launched with arg ".join(',',$argv));
67
+dol_syslog($script_file." launched with arg ".join(',', $argv));
68 68
 
69
-$now=dol_now('tzserver');
70
-$duration_value=isset($argv[2])?$argv[2]:'none';
69
+$now = dol_now('tzserver');
70
+$duration_value = isset($argv[2]) ? $argv[2] : 'none';
71 71
 
72
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
72
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n";
73 73
 
74
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
74
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
75 75
 
76
-$sql  = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,";
77
-$sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
78
-$sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
79
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
80
-$sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
76
+$sql = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,";
77
+$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
78
+$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
79
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
80
+$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
81 81
 if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
82
-$sql.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
83
-$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC";	// Order by email to allow one message per email
82
+$sql .= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
83
+$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email
84 84
 
85 85
 //print $sql;
86
-$resql=$db->query($sql);
86
+$resql = $db->query($sql);
87 87
 if ($resql)
88 88
 {
89 89
     $num = $db->num_rows($resql);
90 90
     $i = 0;
91
-    $oldemail = 'none'; $olduid = 0; $oldlang='';
91
+    $oldemail = 'none'; $olduid = 0; $oldlang = '';
92 92
     $total = 0; $foundtoprocess = 0;
93 93
 	print "We found ".$num." couples (services to expire - sale representative) qualified\n";
94 94
     dol_syslog("We found ".$num." couples (services to expire - sale representative) qualified");
95
-	$message='';
95
+	$message = '';
96 96
 
97 97
     if ($num)
98 98
     {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                 // Break onto sales representative (new email or uid)
106 106
                 if (dol_strlen($oldemail) && $oldemail != 'none')
107 107
                 {
108
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
108
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
109 109
                 }
110 110
                 else
111 111
 				{
@@ -114,28 +114,28 @@  discard block
 block discarded – undo
114 114
                 $oldemail = $obj->email;
115 115
                 $olduid = $obj->uid;
116 116
                 $oldlang = $obj->lang;
117
-                $oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
117
+                $oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
118 118
                 $message = '';
119 119
                 $total = 0;
120 120
                 $foundtoprocess = 0;
121
-                $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
121
+                $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
122 122
                 if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
123 123
             }
124 124
 
125 125
             // Define line content
126
-            $outputlangs=new Translate('',$conf);
127
-            $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang);	// By default language of sale representative
126
+            $outputlangs = new Translate('', $conf);
127
+            $outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
128 128
 
129 129
             // Load translation files required by the page
130 130
             $outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
131 131
 
132 132
             if (dol_strlen($obj->email))
133 133
             {
134
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
134
+            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel, $obj->description)." (".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')."\n\n";
135 135
             	dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136 136
             	$foundtoprocess++;
137 137
             }
138
-            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
138
+            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
139 139
             if (dol_strlen($obj->email)) print "qualified.";
140 140
             else print "disqualified (no email).";
141 141
 			print "\n";
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         {
152 152
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
153 153
             {
154
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
154
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
155 155
             }
156 156
             else
157 157
 			{
@@ -187,26 +187,26 @@  discard block
 block discarded – undo
187 187
  *  @param  int		$duration_value			duration value
188 188
  * 	@return	int						<0 if KO, >0 if OK
189 189
  */
190
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresentative,$duration_value)
190
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative, $duration_value)
191 191
 {
192
-    global $conf,$langs;
192
+    global $conf, $langs;
193 193
 
194
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
194
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
195 195
 
196
-    $newlangs=new Translate('',$conf);
197
-	$newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
196
+    $newlangs = new Translate('', $conf);
197
+	$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
198 198
     $newlangs->load("main");
199 199
     $newlangs->load("contracts");
200 200
 
201 201
     if ($duration_value)
202 202
     {
203
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
203
+    	if ($duration_value > 0) $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
204
+    	else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
205 205
     }
206 206
     else
207
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
207
+    	$title = $newlangs->transnoentities("ListOfServicesToExpire");
208 208
 
209
-    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
209
+    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
210 210
     $sendto = $oldemail;
211 211
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
212 212
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -215,26 +215,26 @@  discard block
 block discarded – undo
215 215
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
216 216
     dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
217 217
 
218
-    $usehtml=0;
219
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
220
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
218
+    $usehtml = 0;
219
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
220
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml += 1;
221 221
 
222
-    $allmessage='';
223
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
222
+    $allmessage = '';
223
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
224 224
     {
225
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
225
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
226 226
     }
227 227
     else
228 228
     {
229
-    	$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
229
+    	$allmessage .= $title.($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
230
+    	$allmessage .= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
231 231
     }
232
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
233
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
234
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
232
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
233
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
234
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
235 235
     {
236
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
236
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
238 238
     }
239 239
 
240 240
     $mail = new CMailFile(
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
     // Send or not email
257 257
     if ($mode == 'confirm')
258 258
     {
259
-    	$result=$mail->sendfile();
260
-    	if (! $result)
259
+    	$result = $mail->sendfile();
260
+    	if (!$result)
261 261
     	{
262 262
     		print "Error sending email ".$mail->error."\n";
263 263
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     	print "No email sent (test mode)\n";
269 269
     	dol_syslog("No email sent (test mode)");
270 270
     	$mail->dump_mail();
271
-    	$result=1;
271
+    	$result = 1;
272 272
     }
273 273
 
274 274
     if ($result)
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/rebuild_merge_pdf.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 $sapi_type = php_sapi_name();
27 27
 $script_file = basename(__FILE__);
28
-$path=dirname(__FILE__).'/';
28
+$path = dirname(__FILE__).'/';
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 $langs->load("main");
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$error=0;
49
+$version = DOL_VERSION;
50
+$error = 0;
51 51
 
52 52
 
53 53
 
@@ -57,162 +57,162 @@  discard block
 block discarded – undo
57 57
 
58 58
 @set_time_limit(0);
59 59
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
60
-dol_syslog($script_file." launched with arg ".join(',',$argv));
60
+dol_syslog($script_file." launched with arg ".join(',', $argv));
61 61
 
62 62
 // Check parameters
63
-if (! isset($argv[1]))
63
+if (!isset($argv[1]))
64 64
 {
65 65
 	usage();
66 66
 	exit(-1);
67 67
 }
68 68
 
69
-$diroutputpdf=$conf->facture->dir_output . '/temp';
70
-$newlangid='en_EN';	// To force a new lang id
71
-$filter=array();
72
-$regenerate='';		// Ask regenerate (contains name of model to use)
73
-$option='';
74
-$fileprefix='mergedpdf';
69
+$diroutputpdf = $conf->facture->dir_output.'/temp';
70
+$newlangid = 'en_EN'; // To force a new lang id
71
+$filter = array();
72
+$regenerate = ''; // Ask regenerate (contains name of model to use)
73
+$option = '';
74
+$fileprefix = 'mergedpdf';
75 75
 
76 76
 foreach ($argv as $key => $value)
77 77
 {
78
-	$found=false;
78
+	$found = false;
79 79
 
80 80
 	// Define options
81
-	if (preg_match('/^lang=/i',$value))
81
+	if (preg_match('/^lang=/i', $value))
82 82
 	{
83
-		$found=true;
84
-		$valarray=explode('=',$value);
85
-		$newlangid=$valarray[1];
83
+		$found = true;
84
+		$valarray = explode('=', $value);
85
+		$newlangid = $valarray[1];
86 86
 		print 'Use language '.$newlangid.".\n";
87 87
 	}
88
-	if (preg_match('/^prefix=/i',$value))
88
+	if (preg_match('/^prefix=/i', $value))
89 89
 	{
90
-		$found=true;
91
-		$valarray=explode('=',$value);
92
-		$fileprefix=$valarray[1];
90
+		$found = true;
91
+		$valarray = explode('=', $value);
92
+		$fileprefix = $valarray[1];
93 93
 		print 'Use prefix for filename '.$fileprefix.".\n";
94 94
 	}
95 95
 
96
-	if (preg_match('/^regenerate=(.*)/i',$value,$reg))
96
+	if (preg_match('/^regenerate=(.*)/i', $value, $reg))
97 97
 	{
98
-	    if (! in_array($reg[1],array('','0','no')))
98
+	    if (!in_array($reg[1], array('', '0', 'no')))
99 99
 	    {
100
-		    $found=true;
101
-		    $regenerate=$reg[1];
100
+		    $found = true;
101
+		    $regenerate = $reg[1];
102 102
 		    print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103 103
 	    }
104 104
 	}
105 105
 
106 106
 	if ($value == 'filter=all')
107 107
 	{
108
-		$found=true;
109
-		$option.=(empty($option)?'':'_').'all';
110
-		$filter[]='all';
108
+		$found = true;
109
+		$option .= (empty($option) ? '' : '_').'all';
110
+		$filter[] = 'all';
111 111
 
112 112
 		print 'Rebuild PDF for all invoices'."\n";
113 113
 	}
114 114
 
115 115
 	if ($value == 'filter=date')
116 116
 	{
117
-		$found=true;
118
-		$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
-		$filter[]='date';
117
+		$found = true;
118
+		$option .= (empty($option) ? '' : '_').'date_'.$argv[$key + 1].'_'.$argv[$key + 2];
119
+		$filter[] = 'date';
120 120
 
121
-		$dateafterdate=dol_stringtotime($argv[$key+1]);
122
-		$datebeforedate=dol_stringtotime($argv[$key+2]);
123
-		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
121
+		$dateafterdate = dol_stringtotime($argv[$key + 1]);
122
+		$datebeforedate = dol_stringtotime($argv[$key + 2]);
123
+		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate, 'day', 'gmt')." and ".dol_print_date($datebeforedate, 'day', 'gmt').".\n";
124 124
 	}
125 125
 
126 126
 	if ($value == 'filter=payments')
127 127
 	{
128
-		$found=true;
129
-		$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
-		$filter[]='payments';
128
+		$found = true;
129
+		$option .= (empty($option) ? '' : '_').'payments_'.$argv[$key + 1].'_'.$argv[$key + 2];
130
+		$filter[] = 'payments';
131 131
 
132
-		$paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
-		$paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
132
+		$paymentdateafter = dol_stringtotime($argv[$key + 1].'000000');
133
+		$paymentdatebefore = dol_stringtotime($argv[$key + 2].'235959');
134 134
 		if (empty($paymentdateafter) || empty($paymentdatebefore))
135 135
 		{
136 136
 			print 'Error: Bad date format or value'."\n";
137 137
 			exit(-1);
138 138
 		}
139
-		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
139
+		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter, 'day', 'gmt')." and ".dol_print_date($paymentdatebefore, 'day', 'gmt').".\n";
140 140
 	}
141 141
 
142 142
 	if ($value == 'filter=nopayment')
143 143
 	{
144
-		$found=true;
145
-		$option.=(empty($option)?'':'_').'nopayment';
146
-		$filter[]='nopayment';
144
+		$found = true;
145
+		$option .= (empty($option) ? '' : '_').'nopayment';
146
+		$filter[] = 'nopayment';
147 147
 
148 148
 		print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149 149
 	}
150 150
 
151 151
 	if ($value == 'filter=bank')
152 152
 	{
153
-		$found=true;
154
-		$option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
-		$filter[]='bank';
153
+		$found = true;
154
+		$option .= (empty($option) ? '' : '_').'bank_'.$argv[$key + 1];
155
+		$filter[] = 'bank';
156 156
 
157
-		$paymentonbankref=$argv[$key+1];
158
-		$bankaccount=new Account($db);
159
-		$result=$bankaccount->fetch(0,$paymentonbankref);
157
+		$paymentonbankref = $argv[$key + 1];
158
+		$bankaccount = new Account($db);
159
+		$result = $bankaccount->fetch(0, $paymentonbankref);
160 160
 		if ($result <= 0)
161 161
 		{
162 162
 			print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163 163
 			exit(-1);
164 164
 		}
165
-		$paymentonbankid=$bankaccount->id;
165
+		$paymentonbankid = $bankaccount->id;
166 166
 		print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167 167
 	}
168 168
 
169 169
 	if ($value == 'filter=nodeposit')
170 170
     {
171
-        $found=true;
172
-        $option.=(empty($option)?'':'_').'nodeposit';
173
-        $filter[]='nodeposit';
171
+        $found = true;
172
+        $option .= (empty($option) ? '' : '_').'nodeposit';
173
+        $filter[] = 'nodeposit';
174 174
 
175 175
         print 'Exclude deposit invoices'."\n";
176 176
     }
177 177
     if ($value == 'filter=noreplacement')
178 178
     {
179
-        $found=true;
180
-        $option.=(empty($option)?'':'_').'noreplacement';
181
-        $filter[]='noreplacement';
179
+        $found = true;
180
+        $option .= (empty($option) ? '' : '_').'noreplacement';
181
+        $filter[] = 'noreplacement';
182 182
 
183 183
         print 'Exclude replacement invoices'."\n";
184 184
     }
185 185
     if ($value == 'filter=nocreditnote')
186 186
     {
187
-        $found=true;
188
-        $option.=(empty($option)?'':'_').'nocreditnote';
189
-        $filter[]='nocreditnote';
187
+        $found = true;
188
+        $option .= (empty($option) ? '' : '_').'nocreditnote';
189
+        $filter[] = 'nocreditnote';
190 190
 
191 191
         print 'Exclude credit note invoices'."\n";
192 192
     }
193 193
 
194 194
     if ($value == 'filter=excludethirdparties')
195 195
     {
196
-    	$found=true;
197
-    	$filter[]='excludethirdparties';
196
+    	$found = true;
197
+    	$filter[] = 'excludethirdparties';
198 198
 
199
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
200
-    	print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
199
+    	$thirdpartiesid = explode(',', $argv[$key + 1]);
200
+    	print 'Exclude thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
201 201
 
202
-    	$option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
202
+    	$option .= (empty($option) ? '' : '_').'excludethirdparties'.join('-', $thirdpartiesid);
203 203
     }
204 204
     if ($value == 'filter=onlythirdparties')
205 205
     {
206
-    	$found=true;
207
-    	$filter[]='onlythirdparties';
206
+    	$found = true;
207
+    	$filter[] = 'onlythirdparties';
208 208
 
209
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
210
-    	print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
209
+    	$thirdpartiesid = explode(',', $argv[$key + 1]);
210
+    	print 'Only thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
211 211
 
212
-    	$option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
212
+    	$option .= (empty($option) ? '' : '_').'onlythirdparty'.join('-', $thirdpartiesid);
213 213
     }
214 214
 
215
-	if (! $found && preg_match('/filter=/i',$value))
215
+	if (!$found && preg_match('/filter=/i', $value))
216 216
 	{
217 217
 		usage();
218 218
 		exit(-1);
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 	exit(-1);
227 227
 }
228 228
 // Check if there is no uncompatible choice
229
-if (in_array('payments',$filter) && in_array('nopayment',$filter))
229
+if (in_array('payments', $filter) && in_array('nopayment', $filter))
230 230
 {
231 231
 	usage();
232 232
 	exit(-1);
233 233
 }
234
-if (in_array('bank',$filter) && in_array('nopayment',$filter))
234
+if (in_array('bank', $filter) && in_array('nopayment', $filter))
235 235
 {
236 236
 	usage();
237 237
 	exit(-1);
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
 // Define SQL and SQL request to select invoices
242 242
 // Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore
243
-$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
243
+$result = rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
244 244
 
245 245
 
246 246
 
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
 
249 249
 if ($result >= 0)
250 250
 {
251
-	$error=0;
251
+	$error = 0;
252 252
 	print '--- end ok'."\n";
253 253
 }
254 254
 else
255 255
 {
256
-	$error=$result;
256
+	$error = $result;
257 257
 	print '--- end error code='.$error."\n";
258 258
 }
259 259
 
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_representatives.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) [delay]\n";
42 42
 	print "\n";
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46 46
 	exit(-1);
47 47
 }
48
-$mode=$argv[1];
48
+$mode = $argv[1];
49 49
 
50 50
 
51 51
 require $path."../../htdocs/master.inc.php";
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 
56 56
 
57 57
 // Global variables
58
-$version=DOL_VERSION;
59
-$error=0;
58
+$version = DOL_VERSION;
59
+$error = 0;
60 60
 
61 61
 
62 62
 
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 
67 67
 @set_time_limit(0);
68 68
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
69
-dol_syslog($script_file." launched with arg ".join(',',$argv));
69
+dol_syslog($script_file." launched with arg ".join(',', $argv));
70 70
 
71
-$now=dol_now('tzserver');
72
-$duration_value=isset($argv[2])?$argv[2]:'none';
71
+$now = dol_now('tzserver');
72
+$duration_value = isset($argv[2]) ? $argv[2] : 'none';
73 73
 
74
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
74
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n";
75 75
 
76
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
76
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
77 77
 
78 78
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang,";
79
-$sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
79
+$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
80 80
 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
81 81
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
82 82
 $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 if (is_numeric($duration_value)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
87 87
 $sql .= " AND sc.fk_soc = s.rowid";
88 88
 $sql .= " AND sc.fk_user = u.rowid";
89
-$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
89
+$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
90 90
 
91 91
 //print $sql;
92
-$resql=$db->query($sql);
92
+$resql = $db->query($sql);
93 93
 if ($resql)
94 94
 {
95 95
     $num = $db->num_rows($resql);
96 96
     $i = 0;
97
-    $oldemail = 'none'; $olduid = 0; $oldlang='';
97
+    $oldemail = 'none'; $olduid = 0; $oldlang = '';
98 98
     $total = 0; $foundtoprocess = 0;
99 99
 	print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
100 100
     dol_syslog("We found ".$num." couples (unpayed validated invoice - sale representative) qualified");
101
-	$message='';
101
+	$message = '';
102 102
 
103 103
     if ($num)
104 104
     {
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                 // Break onto sales representative (new email or uid)
112 112
                 if (dol_strlen($oldemail) && $oldemail != 'none')
113 113
                 {
114
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
114
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
115 115
                 }
116 116
                 else
117 117
 				{
@@ -120,28 +120,28 @@  discard block
 block discarded – undo
120 120
                 $oldemail = $obj->email;
121 121
                 $olduid = $obj->uid;
122 122
                 $oldlang = $obj->lang;
123
-                $oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
123
+                $oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
124 124
                 $message = '';
125 125
                 $total = 0;
126 126
                 $foundtoprocess = 0;
127
-                $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
127
+                $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
128 128
                 if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
129 129
             }
130 130
 
131 131
             // Define line content
132
-            $outputlangs=new Translate('',$conf);
133
-            $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang);	// By default language of sale representative
132
+            $outputlangs = new Translate('', $conf);
133
+            $outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
134 134
 
135 135
             // Load translation files required by the page
136 136
             $outputlangs->loadLangs(array("main", "bills"));
137 137
 
138 138
             if (dol_strlen($obj->email))
139 139
             {
140
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
140
+            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)." : ".$obj->name."\n";
141 141
             	dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142 142
             	$foundtoprocess++;
143 143
             }
144
-            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
144
+            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
145 145
             if (dol_strlen($obj->email)) print "qualified.";
146 146
             else print "disqualified (no email).";
147 147
 			print "\n";
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         {
158 158
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
159 159
             {
160
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
160
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
161 161
             }
162 162
             else
163 163
 			{
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
  *  @param	string	$oldsalerepresentative	Old sale representative
193 193
  * 	@return	int								<0 if KO, >0 if OK
194 194
  */
195
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresentative)
195
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
196 196
 {
197
-    global $conf,$langs;
197
+    global $conf, $langs;
198 198
 
199
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
199
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
200 200
 
201
-    $newlangs=new Translate('',$conf);
202
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
201
+    $newlangs = new Translate('', $conf);
202
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
203 203
     $newlangs->load("main");
204 204
     $newlangs->load("bills");
205 205
 
206
-    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
206
+    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
207 207
     $sendto = $oldemail;
208 208
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
209 209
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -212,26 +212,26 @@  discard block
 block discarded – undo
212 212
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
213 213
     dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
214 214
 
215
-    $usehtml=0;
216
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
217
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
215
+    $usehtml = 0;
216
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
217
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml += 1;
218 218
 
219
-    $allmessage='';
220
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
219
+    $allmessage = '';
220
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
221 221
     {
222
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
222
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
223 223
     }
224 224
     else
225 225
     {
226
-    	$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
226
+    	$allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
227
+    	$allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml ? "<br>\n" : "\n");
228 228
     }
229
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
230
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$newlangs,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
231
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
229
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
230
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $newlangs, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
231
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
232 232
     {
233
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
233
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
235 235
     }
236 236
 
237 237
     $mail = new CMailFile(
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
     // Send or not email
254 254
     if ($mode == 'confirm')
255 255
     {
256
-    	$result=$mail->sendfile();
257
-    	if (! $result)
256
+    	$result = $mail->sendfile();
257
+    	if (!$result)
258 258
     	{
259 259
     		print "Error sending email ".$mail->error."\n";
260 260
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     	print "No email sent (test mode)\n";
266 266
     	dol_syslog("No email sent (test mode)");
267 267
     	$mail->dump_mail();
268
-    	$result=1;
268
+    	$result = 1;
269 269
     }
270 270
 
271 271
     if ($result)
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_customers.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
39
+if (!isset($argv[2]) || !$argv[2] || !in_array($argv[1], array('test', 'confirm')) || !in_array($argv[2], array('thirdparties', 'contacts')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42 42
 	print "\n";
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47 47
 	exit(-1);
48 48
 }
49
-$mode=$argv[1];
50
-$targettype=$argv[2];
49
+$mode = $argv[1];
50
+$targettype = $argv[2];
51 51
 
52 52
 
53 53
 require $path."../../htdocs/master.inc.php";
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 $langs->load('main');
57 57
 
58 58
 // Global variables
59
-$version=DOL_VERSION;
60
-$error=0;
59
+$version = DOL_VERSION;
60
+$error = 0;
61 61
 
62 62
 
63 63
 
@@ -67,44 +67,44 @@  discard block
 block discarded – undo
67 67
 
68 68
 @set_time_limit(0);
69 69
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
70
-dol_syslog($script_file." launched with arg ".join(',',$argv));
70
+dol_syslog($script_file." launched with arg ".join(',', $argv));
71 71
 
72
-$now=dol_now('tzserver');
73
-$duration_value=isset($argv[3])?$argv[3]:'none';
74
-$duration_value2=isset($argv[4])?$argv[4]:'none';
72
+$now = dol_now('tzserver');
73
+$duration_value = isset($argv[3]) ? $argv[3] : 'none';
74
+$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
75 75
 
76 76
 $error = 0;
77
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
77
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n";
78 78
 
79
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
79
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
80 80
 
81 81
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,";
82
-$sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
83
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
84
-$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
85
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
86
-$sql.= " WHERE f.fk_statut = 1 AND f.paye = 0";
87
-$sql.= " AND f.fk_soc = s.rowid";
88
-if (is_numeric($duration_value2)) $sql.= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
89
-if (is_numeric($duration_value)) $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
91
-$sql.= " ORDER BY";
92
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
93
-$sql.= " s.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
82
+$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
83
+if ($targettype == 'contacts') $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
84
+$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
85
+if ($targettype == 'contacts') $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
86
+$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
87
+$sql .= " AND f.fk_soc = s.rowid";
88
+if (is_numeric($duration_value2)) $sql .= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
89
+if (is_numeric($duration_value)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
+if ($targettype == 'contacts') $sql .= " AND s.rowid = sp.fk_soc";
91
+$sql .= " ORDER BY";
92
+if ($targettype == 'contacts') $sql .= " sp.email, sp.rowid,";
93
+$sql .= " s.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
94 94
 
95 95
 //print $sql;
96
-$resql=$db->query($sql);
96
+$resql = $db->query($sql);
97 97
 if ($resql)
98 98
 {
99 99
     $num = $db->num_rows($resql);
100 100
     $i = 0;
101
-    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
101
+    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang = '';
102 102
     $total = 0; $foundtoprocess = 0;
103 103
     $trackthirdpartiessent = array();
104 104
 
105 105
 	print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
106 106
     dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified");
107
-	$message='';
107
+	$message = '';
108 108
 
109 109
     if ($num)
110 110
     {
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
         {
113 113
             $obj = $db->fetch_object($resql);
114 114
 
115
-            $newemail=empty($obj->cemail)?$obj->email:$obj->cemail;
115
+            $newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
116 116
 
117 117
             // Check if this record is a break after previous one
118
-            $startbreak=false;
119
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
118
+            $startbreak = false;
119
+			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak = true;
120
+			if ($obj->sid && $obj->sid <> $oldsid) $startbreak = true;
121
+			if ($obj->cid && $obj->cid <> $oldcid) $startbreak = true;
122 122
 
123 123
             if ($startbreak)
124 124
             {
125 125
                 // Break onto sales representative (new email or cid)
126 126
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
127 127
                 {
128
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
128
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
129
+                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
130 130
                 }
131 131
                 else
132 132
 				{
@@ -140,28 +140,28 @@  discard block
 block discarded – undo
140 140
                 $oldsid  = $obj->sid;
141 141
                 $oldcid  = $obj->cid;
142 142
                 $oldlang = $obj->lang;
143
-                $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
143
+                $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
144 144
                 $message = '';
145 145
                 $total   = 0;
146 146
                 $foundtoprocess = 0;
147
-                $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
147
+                $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
148 148
                 //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
149 149
             }
150 150
 
151 151
             // Define line content
152
-            $outputlangs=new Translate('',$conf);
153
-            $outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang);	// By default language of customer
152
+            $outputlangs = new Translate('', $conf);
153
+            $outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
154 154
 
155 155
             // Load translation files required by the page
156 156
             $outputlangs->loadLangs(array("main", "bills"));
157 157
 
158 158
             if (dol_strlen($newemail))
159 159
             {
160
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
160
+            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)."\n";
161 161
             	dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162 162
             	$foundtoprocess++;
163 163
             }
164
-            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
164
+            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165 165
             if (dol_strlen($newemail)) print "qualified.";
166 166
             else print "disqualified (no email).";
167 167
             print "\n";
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
180 180
             {
181
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
181
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
182
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
183 183
             }
184 184
             else
185 185
 			{
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
  *  @param	string	$oldtarget		Target name
219 219
  * 	@return	int						<0 if KO, >0 if OK
220 220
  */
221
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget)
221
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
222 222
 {
223
-    global $conf,$langs;
223
+    global $conf, $langs;
224 224
 
225
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
225
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
226 226
 
227
-    $newlangs=new Translate('',$conf);
228
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
227
+    $newlangs = new Translate('', $conf);
228
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
229 229
     $newlangs->load("main");
230 230
     $newlangs->load("bills");
231 231
 
232
-    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
232
+    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
233 233
     $sendto = $oldemail;
234 234
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
235 235
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -238,27 +238,27 @@  discard block
 block discarded – undo
238 238
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
239 239
     dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
240 240
 
241
-    $usehtml=0;
242
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
243
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml+=1;
241
+    $usehtml = 0;
242
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml += 1;
243
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml += 1;
244 244
 
245
-    $allmessage='';
246
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
245
+    $allmessage = '';
246
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
247 247
     {
248
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
248
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
249 249
     }
250 250
     else
251 251
     {
252
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
-    	$allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
-    	$allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
252
+    	$allmessage .= "Dear customer".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
253
+    	$allmessage .= "Please, find a summary of the bills with pending payments from you.".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
254
+    	$allmessage .= "Note: This list contains only unpaid invoices.".($usehtml ? "<br>\n" : "\n");
255 255
     }
256
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
257
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
258
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
256
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
257
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
258
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
259 259
     {
260
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
260
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml += 1;
262 262
     }
263 263
 
264 264
     $mail = new CMailFile(
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
     // Send or not email
281 281
     if ($mode == 'confirm')
282 282
     {
283
-    	$result=$mail->sendfile();
284
-    	if (! $result)
283
+    	$result = $mail->sendfile();
284
+    	if (!$result)
285 285
     	{
286 286
     		print "Error sending email ".$mail->error."\n";
287 287
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     	print "No email sent (test mode)\n";
293 293
     	dol_syslog("No email sent (test mode)");
294 294
     	$mail->dump_mail();
295
-    	$result=1;
295
+    	$result = 1;
296 296
     }
297 297
 
298 298
     unset($newlangs);
Please login to merge, or discard this patch.