Passed
Push — master ( 222e44...208bd5 )
by Alxarafe
31:22
created
dolibarr/htdocs/contrat/index.php 3 patches
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
     // Search contract
78 78
     if (! empty($conf->contrat->enabled))
79 79
     {
80
-    	print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
81
-    	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
82
-    	print '<table class="noborder nohover" width="100%">';
83
-    	print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
84
-    	print '<tr class="oddeven">';
85
-    	print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
86
-    	print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
87
-    	print "</table></form>\n";
88
-    	print "<br>";
80
+        print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
81
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
82
+        print '<table class="noborder nohover" width="100%">';
83
+        print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
84
+        print '<tr class="oddeven">';
85
+        print '<td class="nowrap">'.$langs->trans("Contract").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
86
+        print '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
87
+        print "</table></form>\n";
88
+        print "<br>";
89 89
     }
90 90
 }
91 91
 
@@ -114,28 +114,28 @@  discard block
 block discarded – undo
114 114
 $resql = $db->query($sql);
115 115
 if ($resql)
116 116
 {
117
-	$num = $db->num_rows($resql);
118
-	$i = 0;
119
-	while ($i < $num)
120
-	{
121
-		$row = $db->fetch_row($resql);
122
-		if ($row)
123
-		{
124
-    		$nb[$row[1]]=$row[0];
117
+    $num = $db->num_rows($resql);
118
+    $i = 0;
119
+    while ($i < $num)
120
+    {
121
+        $row = $db->fetch_row($resql);
122
+        if ($row)
123
+        {
124
+            $nb[$row[1]]=$row[0];
125 125
             if ($row[1]!=5)
126 126
             {
127 127
                 $vals[$row[1]]=$row[0];
128 128
                 $totalinprocess+=$row[0];
129 129
             }
130 130
             $total+=$row[0];
131
-		}
132
-		$i++;
133
-	}
134
-	$db->free($resql);
131
+        }
132
+        $i++;
133
+    }
134
+    $db->free($resql);
135 135
 }
136 136
 else
137 137
 {
138
-	dol_print_error($db);
138
+    dol_print_error($db);
139 139
 }
140 140
 // Search by status (only expired)
141 141
 $sql = "SELECT count(cd.rowid), cd.statut";
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 $resql = $db->query($sql);
152 152
 if ($resql)
153 153
 {
154
-	$num = $db->num_rows($resql);
154
+    $num = $db->num_rows($resql);
155 155
 
156 156
     // 0 inactive, 4 active, 5 closed
157 157
     $i = 0;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 }
175 175
 else
176 176
 {
177
-	dol_print_error($db);
177
+    dol_print_error($db);
178 178
 }
179 179
 
180 180
 
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 {
217 217
     if (empty($conf->use_javascript_ajax))
218 218
     {
219
-    	print '<tr class="oddeven">';
220
-    	print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
221
-    	print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
222
-    	if ($status==4 && ! $bool) $bool=true;
223
-    	else $bool=false;
219
+        print '<tr class="oddeven">';
220
+        print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
221
+        print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
222
+        if ($status==4 && ! $bool) $bool=true;
223
+        else $bool=false;
224 224
         print "</tr>\n";
225 225
     }
226 226
 }
@@ -234,64 +234,64 @@  discard block
 block discarded – undo
234 234
 
235 235
 if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
236 236
 {
237
-	$sql  = "SELECT c.rowid, c.ref,";
238
-	$sql.= " s.nom as name, s.rowid as socid";
239
-	$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
240
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
241
-	$sql.= " WHERE s.rowid = c.fk_soc";
242
-	$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
243
-	$sql.= " AND c.statut = 0";
244
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
245
-	if ($socid) $sql.= " AND c.fk_soc = ".$socid;
246
-
247
-	$resql = $db->query($sql);
248
-
249
-	if ( $resql )
250
-	{
251
-		$num = $db->num_rows($resql);
252
-
253
-		print '<table class="noborder" width="100%">';
254
-		print '<tr class="liste_titre">';
255
-		print '<th colspan="3">'.$langs->trans("DraftContracts").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
256
-		if ($num)
257
-		{
258
-			$companystatic=new Societe($db);
259
-
260
-			$i = 0;
261
-			//$tot_ttc = 0;
262
-			while ($i < $num)
263
-			{
264
-				$obj = $db->fetch_object($resql);
265
-
266
-				$staticcontrat->ref=$obj->ref;
267
-				$staticcontrat->id=$obj->rowid;
268
-
269
-				$companystatic->id=$obj->socid;
270
-				$companystatic->name=$obj->name;
271
-				$companystatic->client=1;
272
-
273
-				print '<tr class="oddeven"><td class="nowrap">';
274
-				print $staticcontrat->getNomUrl(1,'');
275
-				print '</td>';
276
-				print '<td>';
277
-				print $companystatic->getNomUrl(1,'',16);
278
-				print '</td>';
279
-				print '</tr>';
280
-				//$tot_ttc+=$obj->total_ttc;
281
-				$i++;
282
-			}
283
-		}
284
-		else
285
-		{
286
-			print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
287
-		}
288
-		print "</table><br>";
289
-		$db->free($resql);
290
-	}
291
-	else
292
-	{
293
-		dol_print_error($db);
294
-	}
237
+    $sql  = "SELECT c.rowid, c.ref,";
238
+    $sql.= " s.nom as name, s.rowid as socid";
239
+    $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
240
+    if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
241
+    $sql.= " WHERE s.rowid = c.fk_soc";
242
+    $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
243
+    $sql.= " AND c.statut = 0";
244
+    if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
245
+    if ($socid) $sql.= " AND c.fk_soc = ".$socid;
246
+
247
+    $resql = $db->query($sql);
248
+
249
+    if ( $resql )
250
+    {
251
+        $num = $db->num_rows($resql);
252
+
253
+        print '<table class="noborder" width="100%">';
254
+        print '<tr class="liste_titre">';
255
+        print '<th colspan="3">'.$langs->trans("DraftContracts").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
256
+        if ($num)
257
+        {
258
+            $companystatic=new Societe($db);
259
+
260
+            $i = 0;
261
+            //$tot_ttc = 0;
262
+            while ($i < $num)
263
+            {
264
+                $obj = $db->fetch_object($resql);
265
+
266
+                $staticcontrat->ref=$obj->ref;
267
+                $staticcontrat->id=$obj->rowid;
268
+
269
+                $companystatic->id=$obj->socid;
270
+                $companystatic->name=$obj->name;
271
+                $companystatic->client=1;
272
+
273
+                print '<tr class="oddeven"><td class="nowrap">';
274
+                print $staticcontrat->getNomUrl(1,'');
275
+                print '</td>';
276
+                print '<td>';
277
+                print $companystatic->getNomUrl(1,'',16);
278
+                print '</td>';
279
+                print '</tr>';
280
+                //$tot_ttc+=$obj->total_ttc;
281
+                $i++;
282
+            }
283
+        }
284
+        else
285
+        {
286
+            print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
287
+        }
288
+        print "</table><br>";
289
+        $db->free($resql);
290
+    }
291
+    else
292
+    {
293
+        dol_print_error($db);
294
+    }
295 295
 }
296 296
 
297 297
 
@@ -325,49 +325,49 @@  discard block
 block discarded – undo
325 325
 $result=$db->query($sql);
326 326
 if ($result)
327 327
 {
328
-	$num = $db->num_rows($result);
329
-	$i = 0;
330
-
331
-	print '<table class="noborder" width="100%">';
332
-
333
-	print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts",5).'</th>';
334
-	print '<th align="center">'.$langs->trans("DateModification").'</th>';
335
-	//print '<th align="left">'.$langs->trans("Status").'</th>';
336
-	print '<th align="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
337
-	print "</tr>\n";
338
-
339
-	while ($i < $num)
340
-	{
341
-		$obj = $db->fetch_object($result);
342
-
343
-		print '<tr class="oddeven">';
344
-		print '<td width="110" class="nowrap">';
345
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
346
-		$staticcontrat->id=$obj->cid;
347
-		print $staticcontrat->getNomUrl(1,16);
348
-		if ($obj->nb_late) print img_warning($langs->trans("Late"));
349
-		print '</td>';
350
-		print '<td>';
351
-		$staticcompany->id=$obj->socid;
352
-		$staticcompany->name=$obj->name;
353
-		print $staticcompany->getNomUrl(1,'',20);
354
-		print '</td>';
355
-		print '<td align="center">'.dol_print_date($db->jdate($obj->tms),'dayhour').'</td>';
356
-		//print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
357
-		print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
358
-		print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
359
-		print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
360
-		print '<td align="right" width="32">'.($obj->nb_closed>0  ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
361
-		print "</tr>\n";
362
-		$i++;
363
-	}
364
-	$db->free($result);
365
-
366
-	print "</table>";
328
+    $num = $db->num_rows($result);
329
+    $i = 0;
330
+
331
+    print '<table class="noborder" width="100%">';
332
+
333
+    print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts",5).'</th>';
334
+    print '<th align="center">'.$langs->trans("DateModification").'</th>';
335
+    //print '<th align="left">'.$langs->trans("Status").'</th>';
336
+    print '<th align="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
337
+    print "</tr>\n";
338
+
339
+    while ($i < $num)
340
+    {
341
+        $obj = $db->fetch_object($result);
342
+
343
+        print '<tr class="oddeven">';
344
+        print '<td width="110" class="nowrap">';
345
+        $staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
346
+        $staticcontrat->id=$obj->cid;
347
+        print $staticcontrat->getNomUrl(1,16);
348
+        if ($obj->nb_late) print img_warning($langs->trans("Late"));
349
+        print '</td>';
350
+        print '<td>';
351
+        $staticcompany->id=$obj->socid;
352
+        $staticcompany->name=$obj->name;
353
+        print $staticcompany->getNomUrl(1,'',20);
354
+        print '</td>';
355
+        print '<td align="center">'.dol_print_date($db->jdate($obj->tms),'dayhour').'</td>';
356
+        //print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
357
+        print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
358
+        print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
359
+        print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
360
+        print '<td align="right" width="32">'.($obj->nb_closed>0  ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
361
+        print "</tr>\n";
362
+        $i++;
363
+    }
364
+    $db->free($result);
365
+
366
+    print "</table>";
367 367
 }
368 368
 else
369 369
 {
370
-	dol_print_error($db);
370
+    dol_print_error($db);
371 371
 }
372 372
 
373 373
 print '<br>';
@@ -392,60 +392,60 @@  discard block
 block discarded – undo
392 392
 $resql=$db->query($sql);
393 393
 if ($resql)
394 394
 {
395
-	$num = $db->num_rows($resql);
396
-	$i = 0;
397
-
398
-	print '<table class="noborder" width="100%">';
399
-
400
-	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices",$max).'</th>';
401
-	print "</tr>\n";
402
-
403
-	while ($i < min($num,$max))
404
-	{
405
-		$obj = $db->fetch_object($resql);
406
-
407
-		print '<tr class="oddeven">';
408
-		print '<td width="110" class="nowrap">';
409
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
410
-		$staticcontrat->id=$obj->fk_contrat;
411
-		print $staticcontrat->getNomUrl(1,16);
412
-		//if (1 == 1) print img_warning($langs->trans("Late"));
413
-		print '</td>';
414
-		print '<td>';
415
-		if ($obj->fk_product > 0)
416
-		{
417
-    		$productstatic->id=$obj->fk_product;
395
+    $num = $db->num_rows($resql);
396
+    $i = 0;
397
+
398
+    print '<table class="noborder" width="100%">';
399
+
400
+    print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices",$max).'</th>';
401
+    print "</tr>\n";
402
+
403
+    while ($i < min($num,$max))
404
+    {
405
+        $obj = $db->fetch_object($resql);
406
+
407
+        print '<tr class="oddeven">';
408
+        print '<td width="110" class="nowrap">';
409
+        $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
410
+        $staticcontrat->id=$obj->fk_contrat;
411
+        print $staticcontrat->getNomUrl(1,16);
412
+        //if (1 == 1) print img_warning($langs->trans("Late"));
413
+        print '</td>';
414
+        print '<td>';
415
+        if ($obj->fk_product > 0)
416
+        {
417
+            $productstatic->id=$obj->fk_product;
418 418
             $productstatic->type=$obj->ptype;
419 419
             $productstatic->ref=$obj->pref;
420
-			$productstatic->entity=$obj->pentity;
420
+            $productstatic->entity=$obj->pentity;
421 421
             print $productstatic->getNomUrl(1,'',20);
422
-		}
423
-		else
424
-		{
425
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
422
+        }
423
+        else
424
+        {
425
+            print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
426 426
             if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
427 427
             else print '</a> '.dol_trunc($obj->note,20);
428
-		}
429
-		print '</td>';
430
-		print '<td>';
431
-		$staticcompany->id=$obj->fk_soc;
432
-		$staticcompany->name=$obj->name;
433
-		print $staticcompany->getNomUrl(1,'',20);
434
-		print '</td>';
435
-		print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
436
-		$dateend=$db->jdate($obj->date_fin_validite);
437
-		print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
438
-		print '</a></td>';
439
-		print "</tr>\n";
440
-		$i++;
441
-	}
442
-	$db->free();
443
-
444
-	print "</table>";
428
+        }
429
+        print '</td>';
430
+        print '<td>';
431
+        $staticcompany->id=$obj->fk_soc;
432
+        $staticcompany->name=$obj->name;
433
+        print $staticcompany->getNomUrl(1,'',20);
434
+        print '</td>';
435
+        print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
436
+        $dateend=$db->jdate($obj->date_fin_validite);
437
+        print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
438
+        print '</a></td>';
439
+        print "</tr>\n";
440
+        $i++;
441
+    }
442
+    $db->free();
443
+
444
+    print "</table>";
445 445
 }
446 446
 else
447 447
 {
448
-	dol_print_error($db);
448
+    dol_print_error($db);
449 449
 }
450 450
 
451 451
 print '<br>';
@@ -471,59 +471,59 @@  discard block
 block discarded – undo
471 471
 $resql=$db->query($sql);
472 472
 if ($resql)
473 473
 {
474
-	$num = $db->num_rows($resql);
475
-	$i = 0;
474
+    $num = $db->num_rows($resql);
475
+    $i = 0;
476 476
 
477
-	print '<table class="noborder" width="100%">';
477
+    print '<table class="noborder" width="100%">';
478 478
 
479
-	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("NotActivatedServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=0"><span class="badge">'.$num.'</span></a></th>';
480
-	print "</tr>\n";
479
+    print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("NotActivatedServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=0"><span class="badge">'.$num.'</span></a></th>';
480
+    print "</tr>\n";
481 481
 
482
-	while ($i < $num)
483
-	{
484
-		$obj = $db->fetch_object($resql);
482
+    while ($i < $num)
483
+    {
484
+        $obj = $db->fetch_object($resql);
485 485
 
486
-		print '<tr class="oddeven">';
486
+        print '<tr class="oddeven">';
487 487
 
488
-		print '<td width="110" class="nowrap">';
489
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
490
-		$staticcontrat->id=$obj->fk_contrat;
491
-		print $staticcontrat->getNomUrl(1,16);
492
-		print '</td>';
493
-		print '<td class="nowrap">';
494
-		if ($obj->fk_product > 0)
495
-		{
496
-    		$productstatic->id=$obj->fk_product;
488
+        print '<td width="110" class="nowrap">';
489
+        $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
490
+        $staticcontrat->id=$obj->fk_contrat;
491
+        print $staticcontrat->getNomUrl(1,16);
492
+        print '</td>';
493
+        print '<td class="nowrap">';
494
+        if ($obj->fk_product > 0)
495
+        {
496
+            $productstatic->id=$obj->fk_product;
497 497
             $productstatic->type=$obj->ptype;
498 498
             $productstatic->ref=$obj->pref;
499
-			$productstatic->entity=$obj->pentity;
499
+            $productstatic->entity=$obj->pentity;
500 500
             print $productstatic->getNomUrl(1,'',20);
501
-		}
502
-		else
503
-		{
504
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
501
+        }
502
+        else
503
+        {
504
+            print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
505 505
             if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
506 506
             else print '</a> '.dol_trunc($obj->note,20);
507
-		}
507
+        }
508
+        print '</td>';
509
+        print '<td>';
510
+        $staticcompany->id=$obj->fk_soc;
511
+        $staticcompany->name=$obj->name;
512
+        print $staticcompany->getNomUrl(1,'',20);
508 513
         print '</td>';
509
-		print '<td>';
510
-		$staticcompany->id=$obj->fk_soc;
511
-		$staticcompany->name=$obj->name;
512
-		print $staticcompany->getNomUrl(1,'',20);
513
-		print '</td>';
514
-		print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
515
-		print $staticcontratligne->LibStatut($obj->statut,3);
516
-		print '</a></td>';
517
-		print "</tr>\n";
518
-		$i++;
519
-	}
520
-	$db->free();
521
-
522
-	print "</table>";
514
+        print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
515
+        print $staticcontratligne->LibStatut($obj->statut,3);
516
+        print '</a></td>';
517
+        print "</tr>\n";
518
+        $i++;
519
+    }
520
+    $db->free();
521
+
522
+    print "</table>";
523 523
 }
524 524
 else
525 525
 {
526
-	dol_print_error($db);
526
+    dol_print_error($db);
527 527
 }
528 528
 
529 529
 print '<br>';
@@ -550,59 +550,59 @@  discard block
 block discarded – undo
550 550
 $resql=$db->query($sql);
551 551
 if ($resql)
552 552
 {
553
-	$num = $db->num_rows($resql);
554
-	$i = 0;
553
+    $num = $db->num_rows($resql);
554
+    $i = 0;
555 555
 
556
-	print '<table class="noborder" width="100%">';
556
+    print '<table class="noborder" width="100%">';
557 557
 
558
-	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';
559
-	print "</tr>\n";
558
+    print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("ListOfExpiredServices").' <a href="'.DOL_URL_ROOT.'/contrat/services_list.php?mode=4&amp;filter=expired"><span class="badge">'.$num.'</span></a></th>';
559
+    print "</tr>\n";
560 560
 
561
-	while ($i < $num)
562
-	{
563
-		$obj = $db->fetch_object($resql);
561
+    while ($i < $num)
562
+    {
563
+        $obj = $db->fetch_object($resql);
564 564
 
565
-		print '<tr class="oddeven">';
565
+        print '<tr class="oddeven">';
566 566
 
567
-		print '<td width="110" class="nowrap">';
568
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
569
-		$staticcontrat->id=$obj->fk_contrat;
570
-		print $staticcontrat->getNomUrl(1,16);
571
-		print '</td>';
572
-		print '<td class="nowrap">';
573
-		if ($obj->fk_product > 0)
574
-		{
575
-    		$productstatic->id=$obj->fk_product;
567
+        print '<td width="110" class="nowrap">';
568
+        $staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
569
+        $staticcontrat->id=$obj->fk_contrat;
570
+        print $staticcontrat->getNomUrl(1,16);
571
+        print '</td>';
572
+        print '<td class="nowrap">';
573
+        if ($obj->fk_product > 0)
574
+        {
575
+            $productstatic->id=$obj->fk_product;
576 576
             $productstatic->type=$obj->ptype;
577 577
             $productstatic->ref=$obj->pref;
578
-			$productstatic->entity=$obj->pentity;
578
+            $productstatic->entity=$obj->pentity;
579 579
             print $productstatic->getNomUrl(1,'',20);
580
-		}
581
-		else
582
-		{
583
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
580
+        }
581
+        else
582
+        {
583
+            print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
584 584
             if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
585 585
             else print '</a> '.dol_trunc($obj->note,20);
586
-		}
587
-		print '</td>';
588
-		print '<td>';
589
-		$staticcompany->id=$obj->fk_soc;
590
-		$staticcompany->name=$obj->name;
591
-		print $staticcompany->getNomUrl(1,'',20);
592
-		print '</td>';
593
-		print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
594
-		print $staticcontratligne->LibStatut($obj->statut,3,1);
595
-		print '</a></td>';
596
-		print "</tr>\n";
597
-		$i++;
598
-	}
599
-	$db->free();
600
-
601
-	print "</table>";
586
+        }
587
+        print '</td>';
588
+        print '<td>';
589
+        $staticcompany->id=$obj->fk_soc;
590
+        $staticcompany->name=$obj->name;
591
+        print $staticcompany->getNomUrl(1,'',20);
592
+        print '</td>';
593
+        print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
594
+        print $staticcontratligne->LibStatut($obj->statut,3,1);
595
+        print '</a></td>';
596
+        print "</tr>\n";
597
+        $i++;
598
+    }
599
+    $db->free();
600
+
601
+    print "</table>";
602 602
 }
603 603
 else
604 604
 {
605
-	dol_print_error($db);
605
+    dol_print_error($db);
606 606
 }
607 607
 
608 608
 
Please login to merge, or discard this patch.
Spacing   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -31,22 +31,22 @@  discard block
 block discarded – undo
31 31
 // Load translation files required by the page
32 32
 $langs->loadLangs(array('products', 'companies', 'contracts'));
33 33
 
34
-$sortfield=GETPOST('sortfield','alpha');
35
-$sortorder=GETPOST('sortorder','alpha');
36
-$page=GETPOST('page','int');
34
+$sortfield = GETPOST('sortfield', 'alpha');
35
+$sortorder = GETPOST('sortorder', 'alpha');
36
+$page = GETPOST('page', 'int');
37 37
 
38
-$statut=GETPOST('statut')?GETPOST('statut'):1;
38
+$statut = GETPOST('statut') ?GETPOST('statut') : 1;
39 39
 
40 40
 // Security check
41
-$socid=0;
42
-$id = GETPOST('id','int');
43
-if (! empty($user->societe_id)) $socid=$user->societe_id;
41
+$socid = 0;
42
+$id = GETPOST('id', 'int');
43
+if (!empty($user->societe_id)) $socid = $user->societe_id;
44 44
 $result = restrictedArea($user, 'contrat', $id);
45 45
 
46
-$staticcompany=new Societe($db);
47
-$staticcontrat=new Contrat($db);
48
-$staticcontratligne=new ContratLigne($db);
49
-$productstatic=new Product($db);
46
+$staticcompany = new Societe($db);
47
+$staticcontrat = new Contrat($db);
48
+$staticcontratligne = new ContratLigne($db);
49
+$productstatic = new Product($db);
50 50
 
51 51
 
52 52
 /*
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
 llxHeader();
66 66
 
67
-print load_fiche_titre($langs->trans("ContractsArea"),'','title_commercial.png');
67
+print load_fiche_titre($langs->trans("ContractsArea"), '', 'title_commercial.png');
68 68
 
69 69
 
70 70
 //print '<table border="0" width="100%" class="notopnoleftnoright">';
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 print '<div class="fichecenter"><div class="fichethirdleft">';
73 73
 
74 74
 
75
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
75
+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
76 76
 {
77 77
     // Search contract
78
-    if (! empty($conf->contrat->enabled))
78
+    if (!empty($conf->contrat->enabled))
79 79
     {
80 80
     	print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
81 81
     	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -94,23 +94,23 @@  discard block
 block discarded – undo
94 94
  * Statistics
95 95
  */
96 96
 
97
-$nb=array();
98
-$total=0;
99
-$totalinprocess=0;
100
-$dataseries=array();
101
-$vals=array();
97
+$nb = array();
98
+$total = 0;
99
+$totalinprocess = 0;
100
+$dataseries = array();
101
+$vals = array();
102 102
 
103 103
 // Search by status (except expired)
104 104
 $sql = "SELECT count(cd.rowid), cd.statut";
105
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
106
-$sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
107
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
108
-$sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
109
-$sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
110
-$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
111
-if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
112
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
113
-$sql.= " GROUP BY cd.statut";
105
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
106
+$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
107
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
108
+$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
109
+$sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
110
+$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
111
+if ($user->societe_id) $sql .= ' AND c.fk_soc = '.$user->societe_id;
112
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
113
+$sql .= " GROUP BY cd.statut";
114 114
 $resql = $db->query($sql);
115 115
 if ($resql)
116 116
 {
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 		$row = $db->fetch_row($resql);
122 122
 		if ($row)
123 123
 		{
124
-    		$nb[$row[1]]=$row[0];
125
-            if ($row[1]!=5)
124
+    		$nb[$row[1]] = $row[0];
125
+            if ($row[1] != 5)
126 126
             {
127
-                $vals[$row[1]]=$row[0];
128
-                $totalinprocess+=$row[0];
127
+                $vals[$row[1]] = $row[0];
128
+                $totalinprocess += $row[0];
129 129
             }
130
-            $total+=$row[0];
130
+            $total += $row[0];
131 131
 		}
132 132
 		$i++;
133 133
 	}
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 }
140 140
 // Search by status (only expired)
141 141
 $sql = "SELECT count(cd.rowid), cd.statut";
142
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
143
-$sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
144
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
145
-$sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
146
-$sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
147
-$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
148
-if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
149
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
150
-$sql.= " GROUP BY cd.statut";
142
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
143
+$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
144
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
145
+$sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
146
+$sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
147
+$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
148
+if ($user->societe_id) $sql .= ' AND c.fk_soc = '.$user->societe_id;
149
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
150
+$sql .= " GROUP BY cd.statut";
151 151
 $resql = $db->query($sql);
152 152
 if ($resql)
153 153
 {
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
         $row = $db->fetch_row($resql);
161 161
         if ($row)
162 162
         {
163
-            $nb[$row[1].true]=$row[0];
164
-            if ($row[1]!=5)
163
+            $nb[$row[1].true] = $row[0];
164
+            if ($row[1] != 5)
165 165
             {
166
-                $vals[$row[1]]=$row[0];
167
-                $totalinprocess+=$row[0];
166
+                $vals[$row[1]] = $row[0];
167
+                $totalinprocess += $row[0];
168 168
             }
169
-            $total+=$row[0];
169
+            $total += $row[0];
170 170
         }
171 171
         $i++;
172 172
     }
@@ -180,22 +180,22 @@  discard block
 block discarded – undo
180 180
 
181 181
 print '<table class="noborder nohover" width="100%">';
182 182
 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Services").'</th></tr>'."\n";
183
-$listofstatus=array(0,4,4,5); $bool=false;
184
-foreach($listofstatus as $status)
183
+$listofstatus = array(0, 4, 4, 5); $bool = false;
184
+foreach ($listofstatus as $status)
185 185
 {
186
-    $dataseries[]=array($staticcontratligne->LibStatut($status,1,($bool?1:0)),(isset($nb[$status.$bool])?(int) $nb[$status.$bool]:0));
186
+    $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (int) $nb[$status.$bool] : 0));
187 187
     if (empty($conf->use_javascript_ajax))
188 188
     {
189 189
 
190 190
         print '<tr class="oddeven">';
191
-        print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
192
-        print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
191
+        print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
192
+        print '<td align="right"><a href="services_list.php?mode='.$status.($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';
193 193
         print "</tr>\n";
194 194
     }
195
-    if ($status==4 && ! $bool) $bool=true;
196
-    else $bool=false;
195
+    if ($status == 4 && !$bool) $bool = true;
196
+    else $bool = false;
197 197
 }
198
-if (! empty($conf->use_javascript_ajax))
198
+if (!empty($conf->use_javascript_ajax))
199 199
 {
200 200
     print '<tr class="impair"><td align="center" colspan="2">';
201 201
 
@@ -207,20 +207,20 @@  discard block
 block discarded – undo
207 207
     $dolgraph->SetType(array('pie'));
208 208
     $dolgraph->setWidth('100%');
209 209
     $dolgraph->draw('idgraphstatus');
210
-    print $dolgraph->show($total?0:1);
210
+    print $dolgraph->show($total ? 0 : 1);
211 211
 
212 212
     print '</td></tr>';
213 213
 }
214
-$listofstatus=array(0,4,4,5); $bool=false;
215
-foreach($listofstatus as $status)
214
+$listofstatus = array(0, 4, 4, 5); $bool = false;
215
+foreach ($listofstatus as $status)
216 216
 {
217 217
     if (empty($conf->use_javascript_ajax))
218 218
     {
219 219
     	print '<tr class="oddeven">';
220
-    	print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
221
-    	print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
222
-    	if ($status==4 && ! $bool) $bool=true;
223
-    	else $bool=false;
220
+    	print '<td>'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).'</td>';
221
+    	print '<td align="right"><a href="services_list.php?mode='.$status.($bool ? '&filter=expired' : '').'">'.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'</a></td>';
222
+    	if ($status == 4 && !$bool) $bool = true;
223
+    	else $bool = false;
224 224
         print "</tr>\n";
225 225
     }
226 226
 }
@@ -232,30 +232,30 @@  discard block
 block discarded – undo
232 232
 
233 233
 // Draft contracts
234 234
 
235
-if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
235
+if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire)
236 236
 {
237
-	$sql  = "SELECT c.rowid, c.ref,";
238
-	$sql.= " s.nom as name, s.rowid as socid";
239
-	$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
240
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
241
-	$sql.= " WHERE s.rowid = c.fk_soc";
242
-	$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
243
-	$sql.= " AND c.statut = 0";
244
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
245
-	if ($socid) $sql.= " AND c.fk_soc = ".$socid;
237
+	$sql = "SELECT c.rowid, c.ref,";
238
+	$sql .= " s.nom as name, s.rowid as socid";
239
+	$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
240
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
241
+	$sql .= " WHERE s.rowid = c.fk_soc";
242
+	$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
243
+	$sql .= " AND c.statut = 0";
244
+	if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
245
+	if ($socid) $sql .= " AND c.fk_soc = ".$socid;
246 246
 
247 247
 	$resql = $db->query($sql);
248 248
 
249
-	if ( $resql )
249
+	if ($resql)
250 250
 	{
251 251
 		$num = $db->num_rows($resql);
252 252
 
253 253
 		print '<table class="noborder" width="100%">';
254 254
 		print '<tr class="liste_titre">';
255
-		print '<th colspan="3">'.$langs->trans("DraftContracts").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
255
+		print '<th colspan="3">'.$langs->trans("DraftContracts").($num ? ' <span class="badge">'.$num.'</span>' : '').'</th></tr>';
256 256
 		if ($num)
257 257
 		{
258
-			$companystatic=new Societe($db);
258
+			$companystatic = new Societe($db);
259 259
 
260 260
 			$i = 0;
261 261
 			//$tot_ttc = 0;
@@ -263,18 +263,18 @@  discard block
 block discarded – undo
263 263
 			{
264 264
 				$obj = $db->fetch_object($resql);
265 265
 
266
-				$staticcontrat->ref=$obj->ref;
267
-				$staticcontrat->id=$obj->rowid;
266
+				$staticcontrat->ref = $obj->ref;
267
+				$staticcontrat->id = $obj->rowid;
268 268
 
269
-				$companystatic->id=$obj->socid;
270
-				$companystatic->name=$obj->name;
271
-				$companystatic->client=1;
269
+				$companystatic->id = $obj->socid;
270
+				$companystatic->name = $obj->name;
271
+				$companystatic->client = 1;
272 272
 
273 273
 				print '<tr class="oddeven"><td class="nowrap">';
274
-				print $staticcontrat->getNomUrl(1,'');
274
+				print $staticcontrat->getNomUrl(1, '');
275 275
 				print '</td>';
276 276
 				print '<td>';
277
-				print $companystatic->getNomUrl(1,'',16);
277
+				print $companystatic->getNomUrl(1, '', 16);
278 278
 				print '</td>';
279 279
 				print '</tr>';
280 280
 				//$tot_ttc+=$obj->total_ttc;
@@ -300,29 +300,29 @@  discard block
 block discarded – undo
300 300
 
301 301
 
302 302
 // Last modified contracts
303
-$max=5;
303
+$max = 5;
304 304
 $sql = 'SELECT ';
305
-$sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
306
-$sql.= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')",1,0).') as nb_running,';
307
-$sql.= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')",1,0).') as nb_expired,';
308
-$sql.= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')",1,0).') as nb_late,';
309
-$sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
310
-$sql.= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
311
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
312
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
313
-$sql.= " ".MAIN_DB_PREFIX."contrat as c";
314
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
315
-$sql.= " WHERE c.fk_soc = s.rowid";
316
-$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
317
-$sql.= " AND c.statut > 0";
318
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
319
-if ($socid) $sql.= " AND s.rowid = ".$socid;
320
-$sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
321
-$sql.= " ORDER BY c.tms DESC";
322
-$sql.= " LIMIT ".$max;
305
+$sql .= ' sum('.$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
306
+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';
307
+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';
308
+$sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
309
+$sql .= ' sum('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
310
+$sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
311
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
312
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
313
+$sql .= " ".MAIN_DB_PREFIX."contrat as c";
314
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
315
+$sql .= " WHERE c.fk_soc = s.rowid";
316
+$sql .= " AND c.entity IN (".getEntity('contract', 0).")";
317
+$sql .= " AND c.statut > 0";
318
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
319
+if ($socid) $sql .= " AND s.rowid = ".$socid;
320
+$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
321
+$sql .= " ORDER BY c.tms DESC";
322
+$sql .= " LIMIT ".$max;
323 323
 
324 324
 dol_syslog("contrat/index.php", LOG_DEBUG);
325
-$result=$db->query($sql);
325
+$result = $db->query($sql);
326 326
 if ($result)
327 327
 {
328 328
 	$num = $db->num_rows($result);
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 
331 331
 	print '<table class="noborder" width="100%">';
332 332
 
333
-	print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts",5).'</th>';
333
+	print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("LastContracts", 5).'</th>';
334 334
 	print '<th align="center">'.$langs->trans("DateModification").'</th>';
335 335
 	//print '<th align="left">'.$langs->trans("Status").'</th>';
336 336
 	print '<th align="center" width="80" colspan="4">'.$langs->trans("Services").'</th>';
@@ -342,22 +342,22 @@  discard block
 block discarded – undo
342 342
 
343 343
 		print '<tr class="oddeven">';
344 344
 		print '<td width="110" class="nowrap">';
345
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
346
-		$staticcontrat->id=$obj->cid;
347
-		print $staticcontrat->getNomUrl(1,16);
345
+		$staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid);
346
+		$staticcontrat->id = $obj->cid;
347
+		print $staticcontrat->getNomUrl(1, 16);
348 348
 		if ($obj->nb_late) print img_warning($langs->trans("Late"));
349 349
 		print '</td>';
350 350
 		print '<td>';
351
-		$staticcompany->id=$obj->socid;
352
-		$staticcompany->name=$obj->name;
353
-		print $staticcompany->getNomUrl(1,'',20);
351
+		$staticcompany->id = $obj->socid;
352
+		$staticcompany->name = $obj->name;
353
+		print $staticcompany->getNomUrl(1, '', 20);
354 354
 		print '</td>';
355
-		print '<td align="center">'.dol_print_date($db->jdate($obj->tms),'dayhour').'</td>';
355
+		print '<td align="center">'.dol_print_date($db->jdate($obj->tms), 'dayhour').'</td>';
356 356
 		//print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
357
-		print '<td align="right" width="32">'.($obj->nb_initial>0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0,3):'').'</td>';
358
-		print '<td align="right" width="32">'.($obj->nb_running>0 ? $obj->nb_running.$staticcontratligne->LibStatut(4,3,0):'').'</td>';
359
-		print '<td align="right" width="32">'.($obj->nb_expired>0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4,3,1):'').'</td>';
360
-		print '<td align="right" width="32">'.($obj->nb_closed>0  ? $obj->nb_closed.$staticcontratligne->LibStatut(5,3):'').'</td>';
357
+		print '<td align="right" width="32">'.($obj->nb_initial > 0 ? $obj->nb_initial.$staticcontratligne->LibStatut(0, 3) : '').'</td>';
358
+		print '<td align="right" width="32">'.($obj->nb_running > 0 ? $obj->nb_running.$staticcontratligne->LibStatut(4, 3, 0) : '').'</td>';
359
+		print '<td align="right" width="32">'.($obj->nb_expired > 0 ? $obj->nb_expired.$staticcontratligne->LibStatut(4, 3, 1) : '').'</td>';
360
+		print '<td align="right" width="32">'.($obj->nb_closed > 0 ? $obj->nb_closed.$staticcontratligne->LibStatut(5, 3) : '').'</td>';
361 361
 		print "</tr>\n";
362 362
 		$i++;
363 363
 	}
@@ -374,22 +374,22 @@  discard block
 block discarded – undo
374 374
 
375 375
 // Last modified services
376 376
 $sql = "SELECT c.ref, c.fk_soc, ";
377
-$sql.= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
378
-$sql.= " s.nom as name,";
379
-$sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
380
-$sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
381
-$sql.= ", ".MAIN_DB_PREFIX."societe as s";
382
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
383
-$sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
384
-$sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
385
-$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
386
-$sql.= " AND cd.fk_contrat = c.rowid";
387
-$sql.= " AND c.fk_soc = s.rowid";
388
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
389
-if ($socid) $sql.= " AND s.rowid = ".$socid;
390
-$sql.= " ORDER BY cd.tms DESC";
391
-
392
-$resql=$db->query($sql);
377
+$sql .= " cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat, cd.date_fin_validite,";
378
+$sql .= " s.nom as name,";
379
+$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
380
+$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
381
+$sql .= ", ".MAIN_DB_PREFIX."societe as s";
382
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
383
+$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
384
+$sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
385
+$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
386
+$sql .= " AND cd.fk_contrat = c.rowid";
387
+$sql .= " AND c.fk_soc = s.rowid";
388
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
389
+if ($socid) $sql .= " AND s.rowid = ".$socid;
390
+$sql .= " ORDER BY cd.tms DESC";
391
+
392
+$resql = $db->query($sql);
393 393
 if ($resql)
394 394
 {
395 395
 	$num = $db->num_rows($resql);
@@ -397,44 +397,44 @@  discard block
 block discarded – undo
397 397
 
398 398
 	print '<table class="noborder" width="100%">';
399 399
 
400
-	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices",$max).'</th>';
400
+	print '<tr class="liste_titre"><th colspan="4">'.$langs->trans("LastModifiedServices", $max).'</th>';
401 401
 	print "</tr>\n";
402 402
 
403
-	while ($i < min($num,$max))
403
+	while ($i < min($num, $max))
404 404
 	{
405 405
 		$obj = $db->fetch_object($resql);
406 406
 
407 407
 		print '<tr class="oddeven">';
408 408
 		print '<td width="110" class="nowrap">';
409
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
410
-		$staticcontrat->id=$obj->fk_contrat;
411
-		print $staticcontrat->getNomUrl(1,16);
409
+		$staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
410
+		$staticcontrat->id = $obj->fk_contrat;
411
+		print $staticcontrat->getNomUrl(1, 16);
412 412
 		//if (1 == 1) print img_warning($langs->trans("Late"));
413 413
 		print '</td>';
414 414
 		print '<td>';
415 415
 		if ($obj->fk_product > 0)
416 416
 		{
417
-    		$productstatic->id=$obj->fk_product;
418
-            $productstatic->type=$obj->ptype;
419
-            $productstatic->ref=$obj->pref;
420
-			$productstatic->entity=$obj->pentity;
421
-            print $productstatic->getNomUrl(1,'',20);
417
+    		$productstatic->id = $obj->fk_product;
418
+            $productstatic->type = $obj->ptype;
419
+            $productstatic->ref = $obj->pref;
420
+			$productstatic->entity = $obj->pentity;
421
+            print $productstatic->getNomUrl(1, '', 20);
422 422
 		}
423 423
 		else
424 424
 		{
425
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
426
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
427
-            else print '</a> '.dol_trunc($obj->note,20);
425
+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
426
+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';
427
+            else print '</a> '.dol_trunc($obj->note, 20);
428 428
 		}
429 429
 		print '</td>';
430 430
 		print '<td>';
431
-		$staticcompany->id=$obj->fk_soc;
432
-		$staticcompany->name=$obj->name;
433
-		print $staticcompany->getNomUrl(1,'',20);
431
+		$staticcompany->id = $obj->fk_soc;
432
+		$staticcompany->name = $obj->name;
433
+		print $staticcompany->getNomUrl(1, '', 20);
434 434
 		print '</td>';
435 435
 		print '<td class="nowrap" align="right"><a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
436
-		$dateend=$db->jdate($obj->date_fin_validite);
437
-		print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now)?1:0);
436
+		$dateend = $db->jdate($obj->date_fin_validite);
437
+		print $staticcontratligne->LibStatut($obj->statut, 3, ($dateend && $dateend < $now) ? 1 : 0);
438 438
 		print '</a></td>';
439 439
 		print "</tr>\n";
440 440
 		$i++;
@@ -452,23 +452,23 @@  discard block
 block discarded – undo
452 452
 
453 453
 // Not activated services
454 454
 $sql = "SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
455
-$sql.= " s.nom as name,";
456
-$sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
457
-$sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
458
-$sql.= ", ".MAIN_DB_PREFIX."societe as s";
459
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
460
-$sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
461
-$sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
462
-$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
463
-$sql.= " AND c.statut = 1";
464
-$sql.= " AND cd.statut = 0";
465
-$sql.= " AND cd.fk_contrat = c.rowid";
466
-$sql.= " AND c.fk_soc = s.rowid";
467
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
468
-if ($socid) $sql.= " AND s.rowid = ".$socid;
469
-$sql.= " ORDER BY cd.tms DESC";
470
-
471
-$resql=$db->query($sql);
455
+$sql .= " s.nom as name,";
456
+$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
457
+$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
458
+$sql .= ", ".MAIN_DB_PREFIX."societe as s";
459
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
460
+$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
461
+$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
462
+$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
463
+$sql .= " AND c.statut = 1";
464
+$sql .= " AND cd.statut = 0";
465
+$sql .= " AND cd.fk_contrat = c.rowid";
466
+$sql .= " AND c.fk_soc = s.rowid";
467
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
468
+if ($socid) $sql .= " AND s.rowid = ".$socid;
469
+$sql .= " ORDER BY cd.tms DESC";
470
+
471
+$resql = $db->query($sql);
472 472
 if ($resql)
473 473
 {
474 474
 	$num = $db->num_rows($resql);
@@ -486,33 +486,33 @@  discard block
 block discarded – undo
486 486
 		print '<tr class="oddeven">';
487 487
 
488 488
 		print '<td width="110" class="nowrap">';
489
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
490
-		$staticcontrat->id=$obj->fk_contrat;
491
-		print $staticcontrat->getNomUrl(1,16);
489
+		$staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
490
+		$staticcontrat->id = $obj->fk_contrat;
491
+		print $staticcontrat->getNomUrl(1, 16);
492 492
 		print '</td>';
493 493
 		print '<td class="nowrap">';
494 494
 		if ($obj->fk_product > 0)
495 495
 		{
496
-    		$productstatic->id=$obj->fk_product;
497
-            $productstatic->type=$obj->ptype;
498
-            $productstatic->ref=$obj->pref;
499
-			$productstatic->entity=$obj->pentity;
500
-            print $productstatic->getNomUrl(1,'',20);
496
+    		$productstatic->id = $obj->fk_product;
497
+            $productstatic->type = $obj->ptype;
498
+            $productstatic->ref = $obj->pref;
499
+			$productstatic->entity = $obj->pentity;
500
+            print $productstatic->getNomUrl(1, '', 20);
501 501
 		}
502 502
 		else
503 503
 		{
504
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
505
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
506
-            else print '</a> '.dol_trunc($obj->note,20);
504
+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
505
+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';
506
+            else print '</a> '.dol_trunc($obj->note, 20);
507 507
 		}
508 508
         print '</td>';
509 509
 		print '<td>';
510
-		$staticcompany->id=$obj->fk_soc;
511
-		$staticcompany->name=$obj->name;
512
-		print $staticcompany->getNomUrl(1,'',20);
510
+		$staticcompany->id = $obj->fk_soc;
511
+		$staticcompany->name = $obj->name;
512
+		print $staticcompany->getNomUrl(1, '', 20);
513 513
 		print '</td>';
514 514
 		print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
515
-		print $staticcontratligne->LibStatut($obj->statut,3);
515
+		print $staticcontratligne->LibStatut($obj->statut, 3);
516 516
 		print '</a></td>';
517 517
 		print "</tr>\n";
518 518
 		$i++;
@@ -530,24 +530,24 @@  discard block
 block discarded – undo
530 530
 
531 531
 // Expired services
532 532
 $sql = "SELECT c.ref, c.fk_soc, cd.rowid as cid, cd.statut, cd.label, cd.fk_product, cd.description as note, cd.fk_contrat,";
533
-$sql.= " s.nom as name,";
534
-$sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
535
-$sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
536
-$sql.= ", ".MAIN_DB_PREFIX."societe as s";
537
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
538
-$sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
539
-$sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
540
-$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
541
-$sql.= " AND c.statut = 1";
542
-$sql.= " AND cd.statut = 4";
543
-$sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
544
-$sql.= " AND cd.fk_contrat = c.rowid";
545
-$sql.= " AND c.fk_soc = s.rowid";
546
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
547
-if ($socid) $sql.= " AND s.rowid = ".$socid;
548
-$sql.= " ORDER BY cd.tms DESC";
549
-
550
-$resql=$db->query($sql);
533
+$sql .= " s.nom as name,";
534
+$sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
535
+$sql .= " FROM (".MAIN_DB_PREFIX."contrat as c";
536
+$sql .= ", ".MAIN_DB_PREFIX."societe as s";
537
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
538
+$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
539
+$sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
540
+$sql .= " WHERE c.entity IN (".getEntity('contract', 0).")";
541
+$sql .= " AND c.statut = 1";
542
+$sql .= " AND cd.statut = 4";
543
+$sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
544
+$sql .= " AND cd.fk_contrat = c.rowid";
545
+$sql .= " AND c.fk_soc = s.rowid";
546
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
547
+if ($socid) $sql .= " AND s.rowid = ".$socid;
548
+$sql .= " ORDER BY cd.tms DESC";
549
+
550
+$resql = $db->query($sql);
551 551
 if ($resql)
552 552
 {
553 553
 	$num = $db->num_rows($resql);
@@ -565,33 +565,33 @@  discard block
 block discarded – undo
565 565
 		print '<tr class="oddeven">';
566 566
 
567 567
 		print '<td width="110" class="nowrap">';
568
-		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->fk_contrat);
569
-		$staticcontrat->id=$obj->fk_contrat;
570
-		print $staticcontrat->getNomUrl(1,16);
568
+		$staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->fk_contrat);
569
+		$staticcontrat->id = $obj->fk_contrat;
570
+		print $staticcontrat->getNomUrl(1, 16);
571 571
 		print '</td>';
572 572
 		print '<td class="nowrap">';
573 573
 		if ($obj->fk_product > 0)
574 574
 		{
575
-    		$productstatic->id=$obj->fk_product;
576
-            $productstatic->type=$obj->ptype;
577
-            $productstatic->ref=$obj->pref;
578
-			$productstatic->entity=$obj->pentity;
579
-            print $productstatic->getNomUrl(1,'',20);
575
+    		$productstatic->id = $obj->fk_product;
576
+            $productstatic->type = $obj->ptype;
577
+            $productstatic->ref = $obj->pref;
578
+			$productstatic->entity = $obj->pentity;
579
+            print $productstatic->getNomUrl(1, '', 20);
580 580
 		}
581 581
 		else
582 582
 		{
583
-		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
584
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
585
-            else print '</a> '.dol_trunc($obj->note,20);
583
+		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"), "service");
584
+            if ($obj->label) print ' '.dol_trunc($obj->label, 20).'</a>';
585
+            else print '</a> '.dol_trunc($obj->note, 20);
586 586
 		}
587 587
 		print '</td>';
588 588
 		print '<td>';
589
-		$staticcompany->id=$obj->fk_soc;
590
-		$staticcompany->name=$obj->name;
591
-		print $staticcompany->getNomUrl(1,'',20);
589
+		$staticcompany->id = $obj->fk_soc;
590
+		$staticcompany->name = $obj->name;
591
+		print $staticcompany->getNomUrl(1, '', 20);
592 592
 		print '</td>';
593 593
 		print '<td width="16" align="right"><a href="ligne.php?id='.$obj->fk_contrat.'&ligne='.$obj->cid.'">';
594
-		print $staticcontratligne->LibStatut($obj->statut,3,1);
594
+		print $staticcontratligne->LibStatut($obj->statut, 3, 1);
595 595
 		print '</a></td>';
596 596
 		print "</tr>\n";
597 597
 		$i++;
Please login to merge, or discard this patch.
Braces   +109 added lines, -57 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 // Security check
41 41
 $socid=0;
42 42
 $id = GETPOST('id','int');
43
-if (! empty($user->societe_id)) $socid=$user->societe_id;
43
+if (! empty($user->societe_id)) {
44
+    $socid=$user->societe_id;
45
+}
44 46
 $result = restrictedArea($user, 'contrat', $id);
45 47
 
46 48
 $staticcompany=new Societe($db);
@@ -72,12 +74,14 @@  discard block
 block discarded – undo
72 74
 print '<div class="fichecenter"><div class="fichethirdleft">';
73 75
 
74 76
 
75
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
77
+if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
78
+    // This is useless due to the global search combo
76 79
 {
77 80
     // Search contract
78 81
     if (! empty($conf->contrat->enabled))
79 82
     {
80 83
     	print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/list.php">';
84
+}
81 85
     	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
82 86
     	print '<table class="noborder nohover" width="100%">';
83 87
     	print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
@@ -104,12 +108,18 @@  discard block
 block discarded – undo
104 108
 $sql = "SELECT count(cd.rowid), cd.statut";
105 109
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
106 110
 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
107
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
111
+if (!$user->rights->societe->client->voir && !$socid) {
112
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
113
+}
108 114
 $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
109 115
 $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))";
110 116
 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
111
-if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
112
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
117
+if ($user->societe_id) {
118
+    $sql.=' AND c.fk_soc = '.$user->societe_id;
119
+}
120
+if (!$user->rights->societe->client->voir && !$socid) {
121
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
122
+}
113 123
 $sql.= " GROUP BY cd.statut";
114 124
 $resql = $db->query($sql);
115 125
 if ($resql)
@@ -132,8 +142,7 @@  discard block
 block discarded – undo
132 142
 		$i++;
133 143
 	}
134 144
 	$db->free($resql);
135
-}
136
-else
145
+} else
137 146
 {
138 147
 	dol_print_error($db);
139 148
 }
@@ -141,12 +150,18 @@  discard block
 block discarded – undo
141 150
 $sql = "SELECT count(cd.rowid), cd.statut";
142 151
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
143 152
 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
144
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
153
+if (!$user->rights->societe->client->voir && !$socid) {
154
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
155
+}
145 156
 $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
146 157
 $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')";
147 158
 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
148
-if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
149
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
159
+if ($user->societe_id) {
160
+    $sql.=' AND c.fk_soc = '.$user->societe_id;
161
+}
162
+if (!$user->rights->societe->client->voir && !$socid) {
163
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
164
+}
150 165
 $sql.= " GROUP BY cd.statut";
151 166
 $resql = $db->query($sql);
152 167
 if ($resql)
@@ -171,8 +186,7 @@  discard block
 block discarded – undo
171 186
         $i++;
172 187
     }
173 188
     $db->free($resql);
174
-}
175
-else
189
+} else
176 190
 {
177 191
 	dol_print_error($db);
178 192
 }
@@ -192,9 +206,12 @@  discard block
 block discarded – undo
192 206
         print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
193 207
         print "</tr>\n";
194 208
     }
195
-    if ($status==4 && ! $bool) $bool=true;
196
-    else $bool=false;
197
-}
209
+    if ($status==4 && ! $bool) {
210
+        $bool=true;
211
+    } else {
212
+        $bool=false;
213
+    }
214
+    }
198 215
 if (! empty($conf->use_javascript_ajax))
199 216
 {
200 217
     print '<tr class="impair"><td align="center" colspan="2">';
@@ -219,8 +236,11 @@  discard block
 block discarded – undo
219 236
     	print '<tr class="oddeven">';
220 237
     	print '<td>'.$staticcontratligne->LibStatut($status,0,($bool?1:0)).'</td>';
221 238
     	print '<td align="right"><a href="services_list.php?mode='.$status.($bool?'&filter=expired':'').'">'.($nb[$status.$bool]?$nb[$status.$bool]:0).' '.$staticcontratligne->LibStatut($status,3,($bool?1:0)).'</a></td>';
222
-    	if ($status==4 && ! $bool) $bool=true;
223
-    	else $bool=false;
239
+    	if ($status==4 && ! $bool) {
240
+    	    $bool=true;
241
+    	} else {
242
+    	    $bool=false;
243
+    	}
224 244
         print "</tr>\n";
225 245
     }
226 246
 }
@@ -237,12 +257,18 @@  discard block
 block discarded – undo
237 257
 	$sql  = "SELECT c.rowid, c.ref,";
238 258
 	$sql.= " s.nom as name, s.rowid as socid";
239 259
 	$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
240
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
260
+	if (!$user->rights->societe->client->voir && !$socid) {
261
+	    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
262
+	}
241 263
 	$sql.= " WHERE s.rowid = c.fk_soc";
242 264
 	$sql.= " AND c.entity IN (".getEntity('contract', 0).")";
243 265
 	$sql.= " AND c.statut = 0";
244
-	if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
245
-	if ($socid) $sql.= " AND c.fk_soc = ".$socid;
266
+	if (!$user->rights->societe->client->voir && !$socid) {
267
+	    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
268
+	}
269
+	if ($socid) {
270
+	    $sql.= " AND c.fk_soc = ".$socid;
271
+	}
246 272
 
247 273
 	$resql = $db->query($sql);
248 274
 
@@ -280,15 +306,13 @@  discard block
 block discarded – undo
280 306
 				//$tot_ttc+=$obj->total_ttc;
281 307
 				$i++;
282 308
 			}
283
-		}
284
-		else
309
+		} else
285 310
 		{
286 311
 			print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoContracts").'</td></tr>';
287 312
 		}
288 313
 		print "</table><br>";
289 314
 		$db->free($resql);
290
-	}
291
-	else
315
+	} else
292 316
 	{
293 317
 		dol_print_error($db);
294 318
 	}
@@ -309,14 +333,20 @@  discard block
 block discarded – undo
309 333
 $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
310 334
 $sql.= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid";
311 335
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
312
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
336
+if (!$user->rights->societe->client->voir && !$socid) {
337
+    $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
338
+}
313 339
 $sql.= " ".MAIN_DB_PREFIX."contrat as c";
314 340
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
315 341
 $sql.= " WHERE c.fk_soc = s.rowid";
316 342
 $sql.= " AND c.entity IN (".getEntity('contract', 0).")";
317 343
 $sql.= " AND c.statut > 0";
318
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
319
-if ($socid) $sql.= " AND s.rowid = ".$socid;
344
+if (!$user->rights->societe->client->voir && !$socid) {
345
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
346
+}
347
+if ($socid) {
348
+    $sql.= " AND s.rowid = ".$socid;
349
+}
320 350
 $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid";
321 351
 $sql.= " ORDER BY c.tms DESC";
322 352
 $sql.= " LIMIT ".$max;
@@ -345,7 +375,9 @@  discard block
 block discarded – undo
345 375
 		$staticcontrat->ref=($obj->ref?$obj->ref:$obj->cid);
346 376
 		$staticcontrat->id=$obj->cid;
347 377
 		print $staticcontrat->getNomUrl(1,16);
348
-		if ($obj->nb_late) print img_warning($langs->trans("Late"));
378
+		if ($obj->nb_late) {
379
+		    print img_warning($langs->trans("Late"));
380
+		}
349 381
 		print '</td>';
350 382
 		print '<td>';
351 383
 		$staticcompany->id=$obj->socid;
@@ -364,8 +396,7 @@  discard block
 block discarded – undo
364 396
 	$db->free($result);
365 397
 
366 398
 	print "</table>";
367
-}
368
-else
399
+} else
369 400
 {
370 401
 	dol_print_error($db);
371 402
 }
@@ -379,14 +410,20 @@  discard block
 block discarded – undo
379 410
 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
380 411
 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
381 412
 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
382
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
413
+if (!$user->rights->societe->client->voir && !$socid) {
414
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
415
+}
383 416
 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
384 417
 $sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
385 418
 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
386 419
 $sql.= " AND cd.fk_contrat = c.rowid";
387 420
 $sql.= " AND c.fk_soc = s.rowid";
388
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
389
-if ($socid) $sql.= " AND s.rowid = ".$socid;
421
+if (!$user->rights->societe->client->voir && !$socid) {
422
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
423
+}
424
+if ($socid) {
425
+    $sql.= " AND s.rowid = ".$socid;
426
+}
390 427
 $sql.= " ORDER BY cd.tms DESC";
391 428
 
392 429
 $resql=$db->query($sql);
@@ -419,12 +456,14 @@  discard block
 block discarded – undo
419 456
             $productstatic->ref=$obj->pref;
420 457
 			$productstatic->entity=$obj->pentity;
421 458
             print $productstatic->getNomUrl(1,'',20);
422
-		}
423
-		else
459
+		} else
424 460
 		{
425 461
 		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
426
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
427
-            else print '</a> '.dol_trunc($obj->note,20);
462
+            if ($obj->label) {
463
+                print ' '.dol_trunc($obj->label,20).'</a>';
464
+            } else {
465
+                print '</a> '.dol_trunc($obj->note,20);
466
+            }
428 467
 		}
429 468
 		print '</td>';
430 469
 		print '<td>';
@@ -442,8 +481,7 @@  discard block
 block discarded – undo
442 481
 	$db->free();
443 482
 
444 483
 	print "</table>";
445
-}
446
-else
484
+} else
447 485
 {
448 486
 	dol_print_error($db);
449 487
 }
@@ -456,7 +494,9 @@  discard block
 block discarded – undo
456 494
 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
457 495
 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
458 496
 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
459
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
497
+if (!$user->rights->societe->client->voir && !$socid) {
498
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
499
+}
460 500
 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
461 501
 $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
462 502
 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
@@ -464,8 +504,12 @@  discard block
 block discarded – undo
464 504
 $sql.= " AND cd.statut = 0";
465 505
 $sql.= " AND cd.fk_contrat = c.rowid";
466 506
 $sql.= " AND c.fk_soc = s.rowid";
467
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
468
-if ($socid) $sql.= " AND s.rowid = ".$socid;
507
+if (!$user->rights->societe->client->voir && !$socid) {
508
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
509
+}
510
+if ($socid) {
511
+    $sql.= " AND s.rowid = ".$socid;
512
+}
469 513
 $sql.= " ORDER BY cd.tms DESC";
470 514
 
471 515
 $resql=$db->query($sql);
@@ -498,12 +542,14 @@  discard block
 block discarded – undo
498 542
             $productstatic->ref=$obj->pref;
499 543
 			$productstatic->entity=$obj->pentity;
500 544
             print $productstatic->getNomUrl(1,'',20);
501
-		}
502
-		else
545
+		} else
503 546
 		{
504 547
 		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
505
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
506
-            else print '</a> '.dol_trunc($obj->note,20);
548
+            if ($obj->label) {
549
+                print ' '.dol_trunc($obj->label,20).'</a>';
550
+            } else {
551
+                print '</a> '.dol_trunc($obj->note,20);
552
+            }
507 553
 		}
508 554
         print '</td>';
509 555
 		print '<td>';
@@ -520,8 +566,7 @@  discard block
 block discarded – undo
520 566
 	$db->free();
521 567
 
522 568
 	print "</table>";
523
-}
524
-else
569
+} else
525 570
 {
526 571
 	dol_print_error($db);
527 572
 }
@@ -534,7 +579,9 @@  discard block
 block discarded – undo
534 579
 $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity";
535 580
 $sql.= " FROM (".MAIN_DB_PREFIX."contrat as c";
536 581
 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
537
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
582
+if (!$user->rights->societe->client->voir && !$socid) {
583
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
584
+}
538 585
 $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
539 586
 $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
540 587
 $sql.= " WHERE c.entity IN (".getEntity('contract', 0).")";
@@ -543,8 +590,12 @@  discard block
 block discarded – undo
543 590
 $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
544 591
 $sql.= " AND cd.fk_contrat = c.rowid";
545 592
 $sql.= " AND c.fk_soc = s.rowid";
546
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
547
-if ($socid) $sql.= " AND s.rowid = ".$socid;
593
+if (!$user->rights->societe->client->voir && !$socid) {
594
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
595
+}
596
+if ($socid) {
597
+    $sql.= " AND s.rowid = ".$socid;
598
+}
548 599
 $sql.= " ORDER BY cd.tms DESC";
549 600
 
550 601
 $resql=$db->query($sql);
@@ -577,12 +628,14 @@  discard block
 block discarded – undo
577 628
             $productstatic->ref=$obj->pref;
578 629
 			$productstatic->entity=$obj->pentity;
579 630
             print $productstatic->getNomUrl(1,'',20);
580
-		}
581
-		else
631
+		} else
582 632
 		{
583 633
 		    print '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$obj->fk_contrat.'">'.img_object($langs->trans("ShowService"),"service");
584
-            if ($obj->label) print ' '.dol_trunc($obj->label,20).'</a>';
585
-            else print '</a> '.dol_trunc($obj->note,20);
634
+            if ($obj->label) {
635
+                print ' '.dol_trunc($obj->label,20).'</a>';
636
+            } else {
637
+                print '</a> '.dol_trunc($obj->note,20);
638
+            }
586 639
 		}
587 640
 		print '</td>';
588 641
 		print '<td>';
@@ -599,8 +652,7 @@  discard block
 block discarded – undo
599 652
 	$db->free();
600 653
 
601 654
 	print "</table>";
602
-}
603
-else
655
+} else
604 656
 {
605 657
 	dol_print_error($db);
606 658
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/contrat/contact.php 3 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 32
 if (! empty($conf->projet->enabled)) {
33
-	require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
33
+    require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
34 34
 }
35 35
 
36 36
 // Load translation files required by the page
@@ -58,56 +58,56 @@  discard block
 block discarded – undo
58 58
 
59 59
 if ($action == 'addcontact' && $user->rights->contrat->creer)
60 60
 {
61
-	$result = $object->fetch($id);
61
+    $result = $object->fetch($id);
62 62
 
63 63
     if ($result > 0 && $id > 0)
64 64
     {
65
-    	$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
66
-  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
65
+        $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
66
+            $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
67 67
     }
68 68
 
69
-	if ($result >= 0)
70
-	{
71
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72
-		exit;
73
-	}
74
-	else
75
-	{
76
-		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
77
-			$langs->load("errors");
78
-			$msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
79
-		} else {
80
-			$mesg = $object->error;
81
-		}
82
-
83
-		setEventMessages($mesg, null, 'errors');
84
-	}
69
+    if ($result >= 0)
70
+    {
71
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72
+        exit;
73
+    }
74
+    else
75
+    {
76
+        if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
77
+            $langs->load("errors");
78
+            $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
79
+        } else {
80
+            $mesg = $object->error;
81
+        }
82
+
83
+        setEventMessages($mesg, null, 'errors');
84
+    }
85 85
 }
86 86
 
87 87
 // bascule du statut d'un contact
88 88
 if ($action == 'swapstatut' && $user->rights->contrat->creer)
89 89
 {
90
-	if ($object->fetch($id))
91
-	{
92
-	    $result=$object->swapContactStatus(GETPOST('ligne'));
93
-	}
94
-	else
95
-	{
96
-		dol_print_error($db,$object->error);
97
-	}
90
+    if ($object->fetch($id))
91
+    {
92
+        $result=$object->swapContactStatus(GETPOST('ligne'));
93
+    }
94
+    else
95
+    {
96
+        dol_print_error($db,$object->error);
97
+    }
98 98
 }
99 99
 
100 100
 // Delete contact
101 101
 if ($action == 'deletecontact' && $user->rights->contrat->creer)
102 102
 {
103
-	$object->fetch($id);
104
-	$result = $object->delete_contact($_GET["lineid"]);
105
-
106
-	if ($result >= 0)
107
-	{
108
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
109
-		exit;
110
-	}
103
+    $object->fetch($id);
104
+    $result = $object->delete_contact($_GET["lineid"]);
105
+
106
+    if ($result >= 0)
107
+    {
108
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
109
+        exit;
110
+    }
111 111
 }
112 112
 
113 113
 
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
 
131 131
 if ($id > 0 || ! empty($ref))
132 132
 {
133
-	if ($object->fetch($id, $ref) > 0)
134
-	{
135
-		$object->fetch_thirdparty();
133
+    if ($object->fetch($id, $ref) > 0)
134
+    {
135
+        $object->fetch_thirdparty();
136 136
 
137
-	    $head = contract_prepare_head($object);
137
+        $head = contract_prepare_head($object);
138 138
 
139
-		$hselected=1;
139
+        $hselected=1;
140 140
 
141
-		dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
141
+        dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
142 142
 
143
-		// Contract card
143
+        // Contract card
144 144
 
145 145
         $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
146 146
 
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
             $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
154 154
         }*/
155 155
 
156
-		$morehtmlref.='<div class="refidno">';
157
-		// Ref customer
158
-		$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
159
-		$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
160
-		// Ref supplier
161
-		$morehtmlref.='<br>';
162
-		$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
163
-		$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
164
-		// Thirdparty
165
-	    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
156
+        $morehtmlref.='<div class="refidno">';
157
+        // Ref customer
158
+        $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
159
+        $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
160
+        // Ref supplier
161
+        $morehtmlref.='<br>';
162
+        $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
163
+        $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
164
+        // Thirdparty
165
+        $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
166 166
         // Project
167 167
         if (! empty($conf->projet->enabled)) {
168 168
             $langs->load("projects");
@@ -173,38 +173,38 @@  discard block
 block discarded – undo
173 173
                     $morehtmlref.=' : ';
174 174
                 }
175 175
                 if ($action == 'classify') {
176
-	                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
177
-	                $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
178
-	                $morehtmlref.='<input type="hidden" name="action" value="classin">';
179
-	                $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
180
-	                $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
181
-	                $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
182
-	                $morehtmlref.='</form>';
183
-	            } else {
184
-	                $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
185
-	            }
186
-	        } else {
187
-	            if (! empty($object->fk_project)) {
188
-	                $proj = new Project($db);
189
-	                $proj->fetch($object->fk_project);
190
-	                $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
191
-	                $morehtmlref.=$proj->ref;
192
-	                $morehtmlref.='</a>';
193
-	            } else {
194
-	                $morehtmlref.='';
195
-	            }
196
-	        }
197
-	    }
198
-	    $morehtmlref.='</div>';
199
-
200
-
201
-	    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
202
-
203
-
204
-	    print '<div class="fichecenter">';
205
-	    print '<div class="underbanner clearboth"></div>';
206
-
207
-		print '<table class="border" width="100%">';
176
+                    //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
177
+                    $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
178
+                    $morehtmlref.='<input type="hidden" name="action" value="classin">';
179
+                    $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
180
+                    $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
181
+                    $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
182
+                    $morehtmlref.='</form>';
183
+                } else {
184
+                    $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
185
+                }
186
+            } else {
187
+                if (! empty($object->fk_project)) {
188
+                    $proj = new Project($db);
189
+                    $proj->fetch($object->fk_project);
190
+                    $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
191
+                    $morehtmlref.=$proj->ref;
192
+                    $morehtmlref.='</a>';
193
+                } else {
194
+                    $morehtmlref.='';
195
+                }
196
+            }
197
+        }
198
+        $morehtmlref.='</div>';
199
+
200
+
201
+        dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
202
+
203
+
204
+        print '<div class="fichecenter">';
205
+        print '<div class="underbanner clearboth"></div>';
206
+
207
+        print '<table class="border" width="100%">';
208 208
 
209 209
 
210 210
         // Ligne info remises tiers
@@ -223,26 +223,26 @@  discard block
 block discarded – undo
223 223
 
224 224
         // Date
225 225
         print '<tr>';
226
-		print '<td class="titlefield">';
227
-		print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0);
228
-		print '</td><td>';
229
-		print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker');
230
-		print '</td>';
231
-		print '</tr>';
226
+        print '<td class="titlefield">';
227
+        print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0);
228
+        print '</td><td>';
229
+        print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker');
230
+        print '</td>';
231
+        print '</tr>';
232 232
 
233
-		print "</table>";
233
+        print "</table>";
234 234
 
235
-		print '</div>';
235
+        print '</div>';
236 236
 
237
-		dol_fiche_end();
237
+        dol_fiche_end();
238 238
 
239
-		print '<br>';
239
+        print '<br>';
240 240
 
241
-		// Contacts lines
242
-		include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
243
-	} else {
244
-		print "ErrorRecordNotFound";
245
-	}
241
+        // Contacts lines
242
+        include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
243
+    } else {
244
+        print "ErrorRecordNotFound";
245
+    }
246 246
 }
247 247
 
248 248
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -7 removed lines patch added patch discarded remove patch
@@ -43,7 +43,9 @@  discard block
 block discarded – undo
43 43
 $ref=GETPOST('ref','alpha');
44 44
 
45 45
 // Security check
46
-if ($user->societe_id) $socid=$user->societe_id;
46
+if ($user->societe_id) {
47
+    $socid=$user->societe_id;
48
+}
47 49
 $result=restrictedArea($user,'contrat',$id);
48 50
 
49 51
 $object = new Contrat($db);
@@ -70,8 +72,7 @@  discard block
 block discarded – undo
70 72
 	{
71 73
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72 74
 		exit;
73
-	}
74
-	else
75
+	} else
75 76
 	{
76 77
 		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
77 78
 			$langs->load("errors");
@@ -90,8 +91,7 @@  discard block
 block discarded – undo
90 91
 	if ($object->fetch($id))
91 92
 	{
92 93
 	    $result=$object->swapContactStatus(GETPOST('ligne'));
93
-	}
94
-	else
94
+	} else
95 95
 	{
96 96
 		dol_print_error($db,$object->error);
97 97
 	}
@@ -216,8 +216,11 @@  discard block
 block discarded – undo
216 216
         }
217 217
         $absolute_discount = $object->thirdparty->getAvailableDiscounts();
218 218
         print '. ';
219
-        if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
220
-        else print $langs->trans("CompanyHasNoAbsoluteDiscount");
219
+        if ($absolute_discount) {
220
+            print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
221
+        } else {
222
+            print $langs->trans("CompanyHasNoAbsoluteDiscount");
223
+        }
221 224
         print '.';
222 225
         print '</td></tr>';
223 226
 
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36
-if (! empty($conf->projet->enabled)) {
37
-	require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
36
+if (!empty($conf->projet->enabled)) {
37
+	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38 38
 }
39 39
 
40 40
 // Load translation files required by the page
41 41
 $langs->loadLangs(array('contracts', 'companies'));
42 42
 
43
-$action=GETPOST('action','alpha');
44
-$confirm=GETPOST('confirm','alpha');
45
-$socid = GETPOST('socid','int');
46
-$id = GETPOST('id','int');
47
-$ref=GETPOST('ref','alpha');
43
+$action = GETPOST('action', 'alpha');
44
+$confirm = GETPOST('confirm', 'alpha');
45
+$socid = GETPOST('socid', 'int');
46
+$id = GETPOST('id', 'int');
47
+$ref = GETPOST('ref', 'alpha');
48 48
 
49 49
 // Security check
50
-if ($user->societe_id) $socid=$user->societe_id;
51
-$result=restrictedArea($user,'contrat',$id);
50
+if ($user->societe_id) $socid = $user->societe_id;
51
+$result = restrictedArea($user, 'contrat', $id);
52 52
 
53 53
 $object = new Contrat($db);
54 54
 
55 55
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
56
-$hookmanager->initHooks(array('contractcard','globalcard'));
56
+$hookmanager->initHooks(array('contractcard', 'globalcard'));
57 57
 
58 58
 
59 59
 /*
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 {
94 94
 	if ($object->fetch($id))
95 95
 	{
96
-	    $result=$object->swapContactStatus(GETPOST('ligne'));
96
+	    $result = $object->swapContactStatus(GETPOST('ligne'));
97 97
 	}
98 98
 	else
99 99
 	{
100
-		dol_print_error($db,$object->error);
100
+		dol_print_error($db, $object->error);
101 101
 	}
102 102
 }
103 103
 
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
  * View
120 120
  */
121 121
 
122
-llxHeader('',$langs->trans("Contract"),"");
122
+llxHeader('', $langs->trans("Contract"), "");
123 123
 
124 124
 $form = new Form($db);
125
-$formcompany= new FormCompany($db);
126
-$contactstatic=new Contact($db);
127
-$userstatic=new User($db);
125
+$formcompany = new FormCompany($db);
126
+$contactstatic = new Contact($db);
127
+$userstatic = new User($db);
128 128
 
129 129
 /* *************************************************************************** */
130 130
 /*                                                                             */
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 /*                                                                             */
133 133
 /* *************************************************************************** */
134 134
 
135
-if ($id > 0 || ! empty($ref))
135
+if ($id > 0 || !empty($ref))
136 136
 {
137 137
 	if ($object->fetch($id, $ref) > 0)
138 138
 	{
@@ -140,66 +140,66 @@  discard block
 block discarded – undo
140 140
 
141 141
 	    $head = contract_prepare_head($object);
142 142
 
143
-		$hselected=1;
143
+		$hselected = 1;
144 144
 
145 145
 		dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
146 146
 
147 147
 		// Contract card
148 148
 
149
-        $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
149
+        $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
150 150
 
151 151
 
152
-        $morehtmlref='';
152
+        $morehtmlref = '';
153 153
         //if (! empty($modCodeContract->code_auto)) {
154
-            $morehtmlref.=$object->ref;
154
+            $morehtmlref .= $object->ref;
155 155
         /*} else {
156 156
             $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
157 157
             $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
158 158
         }*/
159 159
 
160
-		$morehtmlref.='<div class="refidno">';
160
+		$morehtmlref .= '<div class="refidno">';
161 161
 		// Ref customer
162
-		$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
163
-		$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
162
+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
163
+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
164 164
 		// Ref supplier
165
-		$morehtmlref.='<br>';
166
-		$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
167
-		$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
165
+		$morehtmlref .= '<br>';
166
+		$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
167
+		$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
168 168
 		// Thirdparty
169
-	    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
169
+	    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
170 170
         // Project
171
-        if (! empty($conf->projet->enabled)) {
171
+        if (!empty($conf->projet->enabled)) {
172 172
             $langs->load("projects");
173
-            $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
173
+            $morehtmlref .= '<br>'.$langs->trans('Project').' ';
174 174
             if ($user->rights->contrat->creer) {
175 175
                 if ($action != 'classify') {
176 176
                     //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
177
-                    $morehtmlref.=' : ';
177
+                    $morehtmlref .= ' : ';
178 178
                 }
179 179
                 if ($action == 'classify') {
180 180
 	                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
181
-	                $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
182
-	                $morehtmlref.='<input type="hidden" name="action" value="classin">';
183
-	                $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
184
-	                $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
185
-	                $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186
-	                $morehtmlref.='</form>';
181
+	                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
182
+	                $morehtmlref .= '<input type="hidden" name="action" value="classin">';
183
+	                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
184
+	                $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
185
+	                $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186
+	                $morehtmlref .= '</form>';
187 187
 	            } else {
188
-	                $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
188
+	                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
189 189
 	            }
190 190
 	        } else {
191
-	            if (! empty($object->fk_project)) {
191
+	            if (!empty($object->fk_project)) {
192 192
 	                $proj = new Project($db);
193 193
 	                $proj->fetch($object->fk_project);
194
-	                $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
195
-	                $morehtmlref.=$proj->ref;
196
-	                $morehtmlref.='</a>';
194
+	                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
195
+	                $morehtmlref .= $proj->ref;
196
+	                $morehtmlref .= '</a>';
197 197
 	            } else {
198
-	                $morehtmlref.='';
198
+	                $morehtmlref .= '';
199 199
 	            }
200 200
 	        }
201 201
 	    }
202
-	    $morehtmlref.='</div>';
202
+	    $morehtmlref .= '</div>';
203 203
 
204 204
 
205 205
 	    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
         // Ligne info remises tiers
215 215
         print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
216 216
         if ($object->thirdparty->remise_percent) {
217
-            print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent);
217
+            print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
218 218
         } else {
219 219
             print $langs->trans("CompanyHasNoRelativeDiscount");
220 220
         }
221 221
         $absolute_discount = $object->thirdparty->getAvailableDiscounts();
222 222
         print '. ';
223
-        if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
223
+        if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
224 224
         else print $langs->trans("CompanyHasNoAbsoluteDiscount");
225 225
         print '.';
226 226
         print '</td></tr>';
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
         // Date
229 229
         print '<tr>';
230 230
 		print '<td class="titlefield">';
231
-		print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0);
231
+		print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
232 232
 		print '</td><td>';
233
-		print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker');
233
+		print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
234 234
 		print '</td>';
235 235
 		print '</tr>';
236 236
 
Please login to merge, or discard this patch.
dolibarr/htdocs/contrat/list.php 3 patches
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -103,38 +103,38 @@  discard block
 block discarded – undo
103 103
 $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
104 104
 // List of fields to search into when doing a "search in all"
105 105
 $fieldstosearchall = array(
106
-	'c.ref'=>'Ref',
107
-	'c.ref_customer'=>'RefCustomer',
108
-	'c.ref_supplier'=>'RefSupplier',
109
-	's.nom'=>"ThirdParty",
110
-	'c.note_public'=>'NotePublic',
106
+    'c.ref'=>'Ref',
107
+    'c.ref_customer'=>'RefCustomer',
108
+    'c.ref_supplier'=>'RefSupplier',
109
+    's.nom'=>"ThirdParty",
110
+    'c.note_public'=>'NotePublic',
111 111
 );
112 112
 if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
113 113
 
114 114
 $arrayfields=array(
115
-	'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
116
-	'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
117
-	'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
118
-	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
119
-	's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0),
120
-	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
121
-	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
122
-	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
123
-	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
124
-	'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),
125
-	'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),
126
-	'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
127
-	'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
128
-	'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
129
-	'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
115
+    'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
116
+    'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
117
+    'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
118
+    's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
119
+    's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0),
120
+    's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
121
+    's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
122
+    'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
123
+    'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
124
+    'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),
125
+    'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),
126
+    'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
127
+    'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
128
+    'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
129
+    'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
130 130
 );
131 131
 // Extra fields
132 132
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
133 133
 {
134
-	foreach($extrafields->attribute_label as $key => $val)
135
-	{
136
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
137
-	}
134
+    foreach($extrafields->attribute_label as $key => $val)
135
+    {
136
+        if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
137
+    }
138 138
 }
139 139
 
140 140
 
@@ -154,39 +154,39 @@  discard block
 block discarded – undo
154 154
 // Purge search criteria
155 155
 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
156 156
 {
157
-	$day='';
158
-	$month='';
159
-	$year='';
160
-	$search_dfmonth='';
161
-	$search_dfyear='';
162
-	$search_op2df='';
163
-	$search_name="";
164
-	$search_email="";
165
-	$search_town='';
166
-	$search_zip="";
167
-	$search_state="";
168
-	$search_type='';
169
-	$search_country='';
170
-	$search_contract="";
171
-	$search_ref_customer="";
172
-	$search_ref_supplier="";
173
-	$search_user='';
174
-	$search_sale='';
175
-	$search_product_category='';
176
-	$sall="";
177
-	$search_status="";
178
-	$toselect='';
179
-	$search_array_options=array();
157
+    $day='';
158
+    $month='';
159
+    $year='';
160
+    $search_dfmonth='';
161
+    $search_dfyear='';
162
+    $search_op2df='';
163
+    $search_name="";
164
+    $search_email="";
165
+    $search_town='';
166
+    $search_zip="";
167
+    $search_state="";
168
+    $search_type='';
169
+    $search_country='';
170
+    $search_contract="";
171
+    $search_ref_customer="";
172
+    $search_ref_supplier="";
173
+    $search_user='';
174
+    $search_sale='';
175
+    $search_product_category='';
176
+    $sall="";
177
+    $search_status="";
178
+    $toselect='';
179
+    $search_array_options=array();
180 180
 }
181 181
 
182 182
 if (empty($reshook))
183 183
 {
184
-	$objectclass='Contrat';
185
-	$objectlabel='Contracts';
186
-	$permtoread = $user->rights->contrat->lire;
187
-	$permtodelete = $user->rights->contrat->supprimer;
188
-	$uploaddir = $conf->contrat->dir_output;
189
-	include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
184
+    $objectclass='Contrat';
185
+    $objectlabel='Contracts';
186
+    $permtoread = $user->rights->contrat->lire;
187
+    $permtodelete = $user->rights->contrat->supprimer;
188
+    $uploaddir = $conf->contrat->dir_output;
189
+    include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
190 190
 }
191 191
 
192 192
 
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
230 230
 if ($search_user > 0)
231 231
 {
232
-	$sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
233
-	$sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
232
+    $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
233
+    $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
234 234
 }
235 235
 $sql.= " WHERE c.fk_soc = s.rowid ";
236 236
 $sql.= ' AND c.entity IN ('.getEntity('contract').')';
@@ -239,16 +239,16 @@  discard block
 block discarded – undo
239 239
 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
240 240
 if ($month > 0)
241 241
 {
242
-	if ($year > 0 && empty($day))
243
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
244
-	else if ($year > 0 && ! empty($day))
245
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
246
-	else
247
-	$sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
242
+    if ($year > 0 && empty($day))
243
+    $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
244
+    else if ($year > 0 && ! empty($day))
245
+    $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
246
+    else
247
+    $sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
248 248
 }
249 249
 else if ($year > 0)
250 250
 {
251
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
251
+    $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
252 252
 }
253 253
 if ($search_name) $sql .= natural_search('s.nom', $search_name);
254 254
 if ($search_email) $sql .= natural_search('s.email', $search_email);
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
258 258
 if ($search_sale > 0)
259 259
 {
260
-	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
260
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
261 261
 }
262 262
 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
263 263
 if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 $sql.=$hookmanager->resPrint;
280 280
 if ($search_dfyear > 0 && $search_op2df)
281 281
 {
282
-	if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
283
-	elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
284
-	else $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
282
+    if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
283
+    elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
284
+    else $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
285 285
 }
286 286
 $sql.= $db->order($sortfield,$sortorder);
287 287
 //print $sql;
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
 $result=$db->query($sql);
291 291
 if ($result)
292 292
 {
293
-	$totalnboflines = $db->num_rows($result);
293
+    $totalnboflines = $db->num_rows($result);
294 294
 }
295 295
 
296 296
 $nbtotalofrecords = '';
297 297
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
298 298
 {
299
-	$result = $db->query($sql);
300
-	$nbtotalofrecords = $db->num_rows($result);
301
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
302
-	{
303
-		$page = 0;
304
-		$offset = 0;
305
-	}
299
+    $result = $db->query($sql);
300
+    $nbtotalofrecords = $db->num_rows($result);
301
+    if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
302
+    {
303
+        $page = 0;
304
+        $offset = 0;
305
+    }
306 306
 }
307 307
 
308 308
 $sql.= $db->plimit($limit + 1, $offset);
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
 $resql=$db->query($sql);
311 311
 if (! $resql)
312 312
 {
313
-	dol_print_error($db);
314
-	exit;
313
+    dol_print_error($db);
314
+    exit;
315 315
 }
316 316
 
317 317
 $num = $db->num_rows($resql);
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
 // Direct jump if only one record found
320 320
 if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
321 321
 {
322
-	$obj = $db->fetch_object($resql);
323
-	$id = $obj->rowid;
324
-	header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
325
-	exit;
322
+    $obj = $db->fetch_object($resql);
323
+    $id = $obj->rowid;
324
+    header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
325
+    exit;
326 326
 }
327 327
 
328 328
 
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
 
338 338
 if ($socid > 0)
339 339
 {
340
-	$soc = new Societe($db);
341
-	$soc->fetch($socid);
342
-	if (empty($search_name)) $search_name = $soc->name;
340
+    $soc = new Societe($db);
341
+    $soc->fetch($socid);
342
+    if (empty($search_name)) $search_name = $soc->name;
343 343
 }
344 344
 
345 345
 $param='';
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 
365 365
 // List of mass actions available
366 366
 $arrayofmassactions =  array(
367
-	'generate_doc'=>$langs->trans("Generate"),
368
-	'presend'=>$langs->trans("SendByMail"),
369
-	'builddoc'=>$langs->trans("PDFMerge"),
367
+    'generate_doc'=>$langs->trans("Generate"),
368
+    'presend'=>$langs->trans("SendByMail"),
369
+    'builddoc'=>$langs->trans("PDFMerge"),
370 370
 );
371 371
 if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
372 372
 if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 $newcardbutton='';
376 376
 if ($user->rights->contrat->creer)
377 377
 {
378
-	$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewContractSubscription').'</span>';
379
-	$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
380
-	$newcardbutton.= '</a>';
378
+    $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewContractSubscription').'</span>';
379
+    $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
380
+    $newcardbutton.= '</a>';
381 381
 }
382 382
 
383 383
 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
 
401 401
 if ($sall)
402 402
 {
403
-	foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
404
-	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
403
+    foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
404
+    print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
405 405
 }
406 406
 
407 407
 $moreforfilter='';
@@ -409,29 +409,29 @@  discard block
 block discarded – undo
409 409
 // If the user can view prospects other than his'
410 410
 if ($user->rights->societe->client->voir || $socid)
411 411
 {
412
-	$langs->load("commercial");
413
-	$moreforfilter.='<div class="divsearchfield">';
414
-	$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
415
-	$moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200');
416
-	$moreforfilter.='</div>';
412
+    $langs->load("commercial");
413
+    $moreforfilter.='<div class="divsearchfield">';
414
+    $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
415
+    $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200');
416
+    $moreforfilter.='</div>';
417 417
 }
418 418
 // If the user can view other users
419 419
 if ($user->rights->user->user->lire)
420 420
 {
421
-	$moreforfilter.='<div class="divsearchfield">';
422
-	$moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
423
-	$moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
424
- 	$moreforfilter.='</div>';
421
+    $moreforfilter.='<div class="divsearchfield">';
422
+    $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
423
+    $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
424
+        $moreforfilter.='</div>';
425 425
 }
426 426
 // If the user can view categories of products
427 427
 if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
428 428
 {
429
-	include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
430
-	$moreforfilter.='<div class="divsearchfield">';
431
-	$moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
432
-	$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
433
-	$moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
434
-	$moreforfilter.='</div>';
429
+    include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
430
+    $moreforfilter.='<div class="divsearchfield">';
431
+    $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
432
+    $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
433
+    $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
434
+    $moreforfilter.='</div>';
435 435
 }
436 436
 
437 437
 $parameters=array();
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
 
442 442
 if (! empty($moreforfilter))
443 443
 {
444
-	print '<div class="liste_titre liste_titre_bydiv centpercent">';
445
-	print $moreforfilter;
446
-	print '</div>';
444
+    print '<div class="liste_titre liste_titre_bydiv centpercent">';
445
+    print $moreforfilter;
446
+    print '</div>';
447 447
 }
448 448
 
449 449
 $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
@@ -456,33 +456,33 @@  discard block
 block discarded – undo
456 456
 print '<tr class="liste_titre_filter">';
457 457
 if (! empty($arrayfields['c.ref']['checked']))
458 458
 {
459
-	print '<td class="liste_titre">';
460
-	print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
461
-	print '</td>';
459
+    print '<td class="liste_titre">';
460
+    print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
461
+    print '</td>';
462 462
 }
463 463
 if (! empty($arrayfields['c.ref_customer']['checked']))
464 464
 {
465
-	print '<td class="liste_titre">';
466
-	print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
467
-	print '</td>';
465
+    print '<td class="liste_titre">';
466
+    print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
467
+    print '</td>';
468 468
 }
469 469
 if (! empty($arrayfields['c.ref_supplier']['checked']))
470 470
 {
471
-	print '<td class="liste_titre">';
472
-	print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
473
-	print '</td>';
471
+    print '<td class="liste_titre">';
472
+    print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
473
+    print '</td>';
474 474
 }
475 475
 if (! empty($arrayfields['s.nom']['checked']))
476 476
 {
477
-	print '<td class="liste_titre">';
478
-	print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
479
-	print '</td>';
477
+    print '<td class="liste_titre">';
478
+    print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
479
+    print '</td>';
480 480
 }
481 481
 if (! empty($arrayfields['s.email']['checked']))
482 482
 {
483
-	print '<td class="liste_titre">';
484
-	print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
485
-	print '</td>';
483
+    print '<td class="liste_titre">';
484
+    print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
485
+    print '</td>';
486 486
 }
487 487
 // Town
488 488
 if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
@@ -491,39 +491,39 @@  discard block
 block discarded – undo
491 491
 // State
492 492
 if (! empty($arrayfields['state.nom']['checked']))
493 493
 {
494
-	print '<td class="liste_titre">';
495
-	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
496
-	print '</td>';
494
+    print '<td class="liste_titre">';
495
+    print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
496
+    print '</td>';
497 497
 }
498 498
 // Country
499 499
 if (! empty($arrayfields['country.code_iso']['checked']))
500 500
 {
501
-	print '<td class="liste_titre" align="center">';
502
-	print $form->select_country($search_country,'search_country','',0,'maxwidth100');
503
-	print '</td>';
501
+    print '<td class="liste_titre" align="center">';
502
+    print $form->select_country($search_country,'search_country','',0,'maxwidth100');
503
+    print '</td>';
504 504
 }
505 505
 // Company type
506 506
 if (! empty($arrayfields['typent.code']['checked']))
507 507
 {
508
-	print '<td class="liste_titre maxwidthonsmartphone" align="center">';
509
-	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
510
-	print '</td>';
508
+    print '<td class="liste_titre maxwidthonsmartphone" align="center">';
509
+    print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
510
+    print '</td>';
511 511
 }
512 512
 if (! empty($arrayfields['sale_representative']['checked']))
513 513
 {
514
-	print '<td class="liste_titre"></td>';
514
+    print '<td class="liste_titre"></td>';
515 515
 }
516 516
 if (! empty($arrayfields['c.date_contrat']['checked']))
517 517
 {
518
-	// Date contract
519
-	print '<td class="liste_titre center nowraponall">';
520
-	//print $langs->trans('Month').': ';
521
-	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
522
-	print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';
523
-	//print '&nbsp;'.$langs->trans('Year').': ';
524
-	$syear = $year;
525
-	print $formother->selectyear($syear,'year',1, 20, 5);
526
-	print '</td>';
518
+    // Date contract
519
+    print '<td class="liste_titre center nowraponall">';
520
+    //print $langs->trans('Month').': ';
521
+    if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
522
+    print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';
523
+    //print '&nbsp;'.$langs->trans('Year').': ';
524
+    $syear = $year;
525
+    print $formother->selectyear($syear,'year',1, 20, 5);
526
+    print '</td>';
527 527
 }
528 528
 // Extra fields
529 529
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
@@ -535,31 +535,31 @@  discard block
 block discarded – undo
535 535
 // Date creation
536 536
 if (! empty($arrayfields['c.datec']['checked']))
537 537
 {
538
-	print '<td class="liste_titre">';
539
-	print '</td>';
538
+    print '<td class="liste_titre">';
539
+    print '</td>';
540 540
 }
541 541
 // Date modification
542 542
 if (! empty($arrayfields['c.tms']['checked']))
543 543
 {
544
-	print '<td class="liste_titre">';
545
-	print '</td>';
544
+    print '<td class="liste_titre">';
545
+    print '</td>';
546 546
 }
547 547
 // First end date
548 548
 if (! empty($arrayfields['lower_planned_end_date']['checked']))
549 549
 {
550
-		print '<td class="liste_titre nowraponall" align="center">';
551
-		$arrayofoperators=array('0'=>'','='=>'=','<='=>'<=','>='=>'>=');
552
-		print $form->selectarray('search_op2df',$arrayofoperators,$search_op2df,0);
553
-		print '</br>';
554
-		print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0, 'valignmiddle');
555
-		print ' ';
556
-		$formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '', 'valignmiddle');
557
-		print '</td>';
550
+        print '<td class="liste_titre nowraponall" align="center">';
551
+        $arrayofoperators=array('0'=>'','='=>'=','<='=>'<=','>='=>'>=');
552
+        print $form->selectarray('search_op2df',$arrayofoperators,$search_op2df,0);
553
+        print '</br>';
554
+        print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0, 'valignmiddle');
555
+        print ' ';
556
+        $formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '', 'valignmiddle');
557
+        print '</td>';
558 558
 }
559 559
 // Status
560 560
 if (! empty($arrayfields['status']['checked']))
561 561
 {
562
-	print '<td class="liste_titre" colspan="4" align="right"></td>';
562
+    print '<td class="liste_titre" colspan="4" align="right"></td>';
563 563
 }
564 564
 print '<td class="liste_titre" align="middle">';
565 565
 $searchpicto=$form->showFilterButtons();
@@ -591,211 +591,211 @@  discard block
 block discarded – undo
591 591
 if (! empty($arrayfields['lower_planned_end_date']['checked']))       print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
592 592
 if (! empty($arrayfields['status']['checked']))
593 593
 {
594
-	print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
595
-	print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
596
-	print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
597
-	print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
594
+    print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
595
+    print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
596
+    print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
597
+    print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
598 598
 }
599 599
 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
600 600
 print "</tr>\n";
601 601
 
602 602
 while ($i < min($num,$limit))
603 603
 {
604
-	$obj = $db->fetch_object($resql);
605
-
606
-	$contracttmp->ref=$obj->ref;
607
-	$contracttmp->id=$obj->rowid;
608
-	$contracttmp->ref_customer=$obj->ref_customer;
609
-	$contracttmp->ref_supplier=$obj->ref_supplier;
610
-
611
-	if ($obj->socid > 0)
612
-	{
613
-		$result=$socstatic->fetch($obj->socid);
614
-	}
615
-
616
-	print '<tr class="oddeven">';
617
-	if (! empty($arrayfields['c.ref']['checked']))
618
-	{
619
-		print '<td class="nowrap">';
620
-		print $contracttmp->getNomUrl(1);
621
-		if ($obj->nb_late) print img_warning($langs->trans("Late"));
622
-		if (!empty($obj->note_private) || !empty($obj->note_public))
623
-		{
624
-			print ' <span class="note">';
625
-			print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"),'note').'</a>';
626
-			print '</span>';
627
-		}
628
-
629
-		$filename=dol_sanitizeFileName($obj->ref);
630
-		$filedir=$conf->contrat->dir_output . '/' . dol_sanitizeFileName($obj->ref);
631
-		$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
632
-		print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
633
-		print '</td>';
634
-
635
-		print '</td>';
636
-	}
637
-	if (! empty($arrayfields['c.ref_customer']['checked']))
638
-	{
639
-		print '<td>'.$obj->ref_customer.'</td>';
640
-	}
641
-	if (! empty($arrayfields['c.ref_supplier']['checked']))
642
-	{
643
-		print '<td>'.$obj->ref_supplier.'</td>';
644
-	}
645
-	if (! empty($arrayfields['s.nom']['checked']))
646
-	{
647
-		print '<td>';
648
-		//print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';
649
-		if ($obj->socid > 0)
650
-		{
651
-			print $socstatic->getNomUrl(1, '');
652
-		}
653
-		print '</td>';
654
-	}
655
-	if (! empty($arrayfields['s.email']['checked']))
656
-	{
657
-		print '<td>'.$obj->email.'</td>';
658
-	}
659
-	// Town
660
-	if (! empty($arrayfields['s.town']['checked']))
661
-	{
662
-		print '<td class="nocellnopadd">';
663
-		print $obj->town;
664
-		print '</td>';
665
-		if (! $i) $totalarray['nbfield']++;
666
-	}
667
-	// Zip
668
-	if (! empty($arrayfields['s.zip']['checked']))
669
-	{
670
-		print '<td class="nocellnopadd">';
671
-		print $obj->zip;
672
-		print '</td>';
673
-		if (! $i) $totalarray['nbfield']++;
674
-	}
675
-	// State
676
-	if (! empty($arrayfields['state.nom']['checked']))
677
-	{
678
-		print "<td>".$obj->state_name."</td>\n";
679
-		if (! $i) $totalarray['nbfield']++;
680
-	}
681
-	// Country
682
-	if (! empty($arrayfields['country.code_iso']['checked']))
683
-	{
684
-		print '<td align="center">';
685
-		$tmparray=getCountry($obj->fk_pays,'all');
686
-		print $tmparray['label'];
687
-		print '</td>';
688
-		if (! $i) $totalarray['nbfield']++;
689
-	}
690
-	// Type ent
691
-	if (! empty($arrayfields['typent.code']['checked']))
692
-	{
693
-		print '<td align="center">';
694
-		if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
695
-		print $typenArray[$obj->typent_code];
696
-		print '</td>';
697
-		if (! $i) $totalarray['nbfield']++;
698
-	}
699
-	if (! empty($arrayfields['sale_representative']['checked']))
700
-	{
701
-		// Sales representatives
702
-		print '<td>';
703
-		if ($obj->socid > 0)
704
-		{
705
-			$listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
706
-			if ($listsalesrepresentatives < 0) dol_print_error($db);
707
-			$nbofsalesrepresentative=count($listsalesrepresentatives);
708
-			if ($nbofsalesrepresentative > 3)   // We print only number
709
-			{
710
-				print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
711
-				print $nbofsalesrepresentative;
712
-				print '</a>';
713
-			}
714
-			else if ($nbofsalesrepresentative > 0)
715
-			{
716
-				$userstatic=new User($db);
717
-				$j=0;
718
-				foreach($listsalesrepresentatives as $val)
719
-				{
720
-					$userstatic->id=$val['id'];
721
-					$userstatic->lastname=$val['lastname'];
722
-					$userstatic->firstname=$val['firstname'];
723
-					$userstatic->email=$val['email'];
724
-					$userstatic->statut=$val['statut'];
725
-					$userstatic->entity=$val['entity'];
726
-					$userstatic->photo=$val['photo'];
727
-
728
-					//print '<div class="float">':
729
-					print $userstatic->getNomUrl(-2);
730
-					$j++;
731
-					if ($j < $nbofsalesrepresentative) print ' ';
732
-					//print '</div>';
733
-				}
734
-			}
735
-			//else print $langs->trans("NoSalesRepresentativeAffected");
736
-		}
737
-		else
738
-		{
739
-			print '&nbsp';
740
-		}
741
-		print '</td>';
742
-	}
743
-	// Date
744
-	if (! empty($arrayfields['c.date_contrat']['checked']))
745
-	{
746
-		print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzuser').'</td>';
747
-	}
748
-	// Extra fields
749
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
750
-	// Fields from hook
751
-	$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
752
-	$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
753
-	print $hookmanager->resPrint;
754
-	// Date creation
755
-	if (! empty($arrayfields['c.datec']['checked']))
756
-	{
757
-		print '<td align="center" class="nowrap">';
758
-		print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
759
-		print '</td>';
760
-		if (! $i) $totalarray['nbfield']++;
761
-	}
762
-	// Date modification
763
-	if (! empty($arrayfields['c.tms']['checked']))
764
-	{
765
-		print '<td align="center" class="nowrap">';
766
-		print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
767
-		print '</td>';
768
-		if (! $i) $totalarray['nbfield']++;
769
-	}
770
-	// Date lower end date
771
-	if (! empty($arrayfields['lower_planned_end_date']['checked']))
772
-	{
773
-		print '<td align="center" class="nowrapforall">';
774
-		print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
775
-		print '</td>';
776
-		if (! $i) $totalarray['nbfield']++;
777
-	}
778
-	// Status
779
-	if (! empty($arrayfields['status']['checked']))
780
-	{
781
-		print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
782
-		print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
783
-		print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
784
-		print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
785
-	}
786
-	// Action column
787
-	print '<td class="nowrap" align="center">';
788
-	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
789
-	{
790
-		$selected=0;
791
-		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
792
-		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
793
-	}
794
-	print '</td>';
795
-	if (! $i) $totalarray['nbfield']++;
796
-
797
-	print "</tr>\n";
798
-	$i++;
604
+    $obj = $db->fetch_object($resql);
605
+
606
+    $contracttmp->ref=$obj->ref;
607
+    $contracttmp->id=$obj->rowid;
608
+    $contracttmp->ref_customer=$obj->ref_customer;
609
+    $contracttmp->ref_supplier=$obj->ref_supplier;
610
+
611
+    if ($obj->socid > 0)
612
+    {
613
+        $result=$socstatic->fetch($obj->socid);
614
+    }
615
+
616
+    print '<tr class="oddeven">';
617
+    if (! empty($arrayfields['c.ref']['checked']))
618
+    {
619
+        print '<td class="nowrap">';
620
+        print $contracttmp->getNomUrl(1);
621
+        if ($obj->nb_late) print img_warning($langs->trans("Late"));
622
+        if (!empty($obj->note_private) || !empty($obj->note_public))
623
+        {
624
+            print ' <span class="note">';
625
+            print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"),'note').'</a>';
626
+            print '</span>';
627
+        }
628
+
629
+        $filename=dol_sanitizeFileName($obj->ref);
630
+        $filedir=$conf->contrat->dir_output . '/' . dol_sanitizeFileName($obj->ref);
631
+        $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
632
+        print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
633
+        print '</td>';
634
+
635
+        print '</td>';
636
+    }
637
+    if (! empty($arrayfields['c.ref_customer']['checked']))
638
+    {
639
+        print '<td>'.$obj->ref_customer.'</td>';
640
+    }
641
+    if (! empty($arrayfields['c.ref_supplier']['checked']))
642
+    {
643
+        print '<td>'.$obj->ref_supplier.'</td>';
644
+    }
645
+    if (! empty($arrayfields['s.nom']['checked']))
646
+    {
647
+        print '<td>';
648
+        //print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';
649
+        if ($obj->socid > 0)
650
+        {
651
+            print $socstatic->getNomUrl(1, '');
652
+        }
653
+        print '</td>';
654
+    }
655
+    if (! empty($arrayfields['s.email']['checked']))
656
+    {
657
+        print '<td>'.$obj->email.'</td>';
658
+    }
659
+    // Town
660
+    if (! empty($arrayfields['s.town']['checked']))
661
+    {
662
+        print '<td class="nocellnopadd">';
663
+        print $obj->town;
664
+        print '</td>';
665
+        if (! $i) $totalarray['nbfield']++;
666
+    }
667
+    // Zip
668
+    if (! empty($arrayfields['s.zip']['checked']))
669
+    {
670
+        print '<td class="nocellnopadd">';
671
+        print $obj->zip;
672
+        print '</td>';
673
+        if (! $i) $totalarray['nbfield']++;
674
+    }
675
+    // State
676
+    if (! empty($arrayfields['state.nom']['checked']))
677
+    {
678
+        print "<td>".$obj->state_name."</td>\n";
679
+        if (! $i) $totalarray['nbfield']++;
680
+    }
681
+    // Country
682
+    if (! empty($arrayfields['country.code_iso']['checked']))
683
+    {
684
+        print '<td align="center">';
685
+        $tmparray=getCountry($obj->fk_pays,'all');
686
+        print $tmparray['label'];
687
+        print '</td>';
688
+        if (! $i) $totalarray['nbfield']++;
689
+    }
690
+    // Type ent
691
+    if (! empty($arrayfields['typent.code']['checked']))
692
+    {
693
+        print '<td align="center">';
694
+        if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
695
+        print $typenArray[$obj->typent_code];
696
+        print '</td>';
697
+        if (! $i) $totalarray['nbfield']++;
698
+    }
699
+    if (! empty($arrayfields['sale_representative']['checked']))
700
+    {
701
+        // Sales representatives
702
+        print '<td>';
703
+        if ($obj->socid > 0)
704
+        {
705
+            $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
706
+            if ($listsalesrepresentatives < 0) dol_print_error($db);
707
+            $nbofsalesrepresentative=count($listsalesrepresentatives);
708
+            if ($nbofsalesrepresentative > 3)   // We print only number
709
+            {
710
+                print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
711
+                print $nbofsalesrepresentative;
712
+                print '</a>';
713
+            }
714
+            else if ($nbofsalesrepresentative > 0)
715
+            {
716
+                $userstatic=new User($db);
717
+                $j=0;
718
+                foreach($listsalesrepresentatives as $val)
719
+                {
720
+                    $userstatic->id=$val['id'];
721
+                    $userstatic->lastname=$val['lastname'];
722
+                    $userstatic->firstname=$val['firstname'];
723
+                    $userstatic->email=$val['email'];
724
+                    $userstatic->statut=$val['statut'];
725
+                    $userstatic->entity=$val['entity'];
726
+                    $userstatic->photo=$val['photo'];
727
+
728
+                    //print '<div class="float">':
729
+                    print $userstatic->getNomUrl(-2);
730
+                    $j++;
731
+                    if ($j < $nbofsalesrepresentative) print ' ';
732
+                    //print '</div>';
733
+                }
734
+            }
735
+            //else print $langs->trans("NoSalesRepresentativeAffected");
736
+        }
737
+        else
738
+        {
739
+            print '&nbsp';
740
+        }
741
+        print '</td>';
742
+    }
743
+    // Date
744
+    if (! empty($arrayfields['c.date_contrat']['checked']))
745
+    {
746
+        print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzuser').'</td>';
747
+    }
748
+    // Extra fields
749
+    include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
750
+    // Fields from hook
751
+    $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
752
+    $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
753
+    print $hookmanager->resPrint;
754
+    // Date creation
755
+    if (! empty($arrayfields['c.datec']['checked']))
756
+    {
757
+        print '<td align="center" class="nowrap">';
758
+        print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
759
+        print '</td>';
760
+        if (! $i) $totalarray['nbfield']++;
761
+    }
762
+    // Date modification
763
+    if (! empty($arrayfields['c.tms']['checked']))
764
+    {
765
+        print '<td align="center" class="nowrap">';
766
+        print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
767
+        print '</td>';
768
+        if (! $i) $totalarray['nbfield']++;
769
+    }
770
+    // Date lower end date
771
+    if (! empty($arrayfields['lower_planned_end_date']['checked']))
772
+    {
773
+        print '<td align="center" class="nowrapforall">';
774
+        print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
775
+        print '</td>';
776
+        if (! $i) $totalarray['nbfield']++;
777
+    }
778
+    // Status
779
+    if (! empty($arrayfields['status']['checked']))
780
+    {
781
+        print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
782
+        print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
783
+        print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
784
+        print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
785
+    }
786
+    // Action column
787
+    print '<td class="nowrap" align="center">';
788
+    if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
789
+    {
790
+        $selected=0;
791
+        if (in_array($obj->rowid, $arrayofselected)) $selected=1;
792
+        print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
793
+    }
794
+    print '</td>';
795
+    if (! $i) $totalarray['nbfield']++;
796
+
797
+    print "</tr>\n";
798
+    $i++;
799 799
 }
800 800
 $db->free($resql);
801 801
 
Please login to merge, or discard this patch.
Braces   +267 added lines, -100 removed lines patch added patch discarded remove patch
@@ -78,12 +78,18 @@  discard block
 block discarded – undo
78 78
 $offset = $limit * $page;
79 79
 $pageprev = $page - 1;
80 80
 $pagenext = $page + 1;
81
-if (! $sortfield) $sortfield='c.ref';
82
-if (! $sortorder) $sortorder='DESC';
81
+if (! $sortfield) {
82
+    $sortfield='c.ref';
83
+}
84
+if (! $sortorder) {
85
+    $sortorder='DESC';
86
+}
83 87
 
84 88
 // Security check
85 89
 $id=GETPOST('id','int');
86
-if ($user->societe_id) $socid=$user->societe_id;
90
+if ($user->societe_id) {
91
+    $socid=$user->societe_id;
92
+}
87 93
 $result = restrictedArea($user, 'contrat', $id);
88 94
 
89 95
 $diroutputmassaction=$conf->contrat->dir_output . '/temp/massgeneration/'.$user->id;
@@ -91,7 +97,9 @@  discard block
 block discarded – undo
91 97
 $staticcontrat=new Contrat($db);
92 98
 $staticcontratligne=new ContratLigne($db);
93 99
 
94
-if ($search_status == '') $search_status=1;
100
+if ($search_status == '') {
101
+    $search_status=1;
102
+}
95 103
 
96 104
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
97 105
 $object = new Contrat($db);
@@ -109,7 +117,9 @@  discard block
 block discarded – undo
109 117
 	's.nom'=>"ThirdParty",
110 118
 	'c.note_public'=>'NotePublic',
111 119
 );
112
-if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
120
+if (empty($user->socid)) {
121
+    $fieldstosearchall["c.note_private"]="NotePrivate";
122
+}
113 123
 
114 124
 $arrayfields=array(
115 125
 	'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
@@ -133,7 +143,9 @@  discard block
 block discarded – undo
133 143
 {
134 144
 	foreach($extrafields->attribute_label as $key => $val)
135 145
 	{
136
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
146
+		if (! empty($extrafields->attribute_list[$key])) {
147
+		    $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
148
+		}
137 149
 	}
138 150
 }
139 151
 
@@ -147,14 +159,18 @@  discard block
 block discarded – undo
147 159
 
148 160
 $parameters=array('socid'=>$socid);
149 161
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
150
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
162
+if ($reshook < 0) {
163
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
164
+}
151 165
 
152 166
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
153 167
 
154 168
 // Purge search criteria
155
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
169
+if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) {
170
+    // All test are required to be compatible with all browsers
156 171
 {
157 172
 	$day='';
173
+}
158 174
 	$month='';
159 175
 	$year='';
160 176
 	$search_dfmonth='';
@@ -213,7 +229,9 @@  discard block
 block discarded – undo
213 229
 $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')",1,0).') as nb_late,';
214 230
 $sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed';
215 231
 // Add fields from extrafields
216
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
232
+foreach ($extrafields->attribute_label as $key => $val) {
233
+    $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
234
+}
217 235
 // Add fields from hooks
218 236
 $parameters=array();
219 237
 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
@@ -222,11 +240,17 @@  discard block
 block discarded – undo
222 240
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
223 241
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
224 242
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
225
-if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
243
+if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) {
244
+    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
245
+}
226 246
 $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
227
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
247
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
248
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
249
+}
228 250
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
229
-if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
251
+if ($search_product_category > 0) {
252
+    $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
253
+}
230 254
 if ($search_user > 0)
231 255
 {
232 256
 	$sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
@@ -234,33 +258,53 @@  discard block
 block discarded – undo
234 258
 }
235 259
 $sql.= " WHERE c.fk_soc = s.rowid ";
236 260
 $sql.= ' AND c.entity IN ('.getEntity('contract').')';
237
-if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
238
-if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid);
239
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
261
+if ($search_product_category > 0) {
262
+    $sql.=" AND cp.fk_categorie = ".$search_product_category;
263
+}
264
+if ($socid) {
265
+    $sql.= " AND s.rowid = ".$db->escape($socid);
266
+}
267
+if (!$user->rights->societe->client->voir && !$socid) {
268
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
269
+}
240 270
 if ($month > 0)
241 271
 {
242
-	if ($year > 0 && empty($day))
243
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
244
-	else if ($year > 0 && ! empty($day))
245
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
246
-	else
247
-	$sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
248
-}
249
-else if ($year > 0)
272
+	if ($year > 0 && empty($day)) {
273
+		$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
274
+	} else if ($year > 0 && ! empty($day)) {
275
+		$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
276
+	} else {
277
+		$sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
278
+	}
279
+	} else if ($year > 0)
250 280
 {
251 281
 	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
252 282
 }
253
-if ($search_name) $sql .= natural_search('s.nom', $search_name);
254
-if ($search_email) $sql .= natural_search('s.email', $search_email);
255
-if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
256
-if (!empty($search_ref_customer)) $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
257
-if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
283
+if ($search_name) {
284
+    $sql .= natural_search('s.nom', $search_name);
285
+}
286
+if ($search_email) {
287
+    $sql .= natural_search('s.email', $search_email);
288
+}
289
+if ($search_contract) {
290
+    $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
291
+}
292
+if (!empty($search_ref_customer)) {
293
+    $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
294
+}
295
+if (!empty($search_ref_supplier)) {
296
+    $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
297
+}
258 298
 if ($search_sale > 0)
259 299
 {
260 300
 	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
261 301
 }
262
-if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
263
-if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
302
+if ($sall) {
303
+    $sql .= natural_search(array_keys($fieldstosearchall), $sall);
304
+}
305
+if ($search_user > 0) {
306
+    $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
307
+}
264 308
 // Add where from extra fields
265 309
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
266 310
 // Add where from hooks
@@ -272,17 +316,23 @@  discard block
 block discarded – undo
272 316
 $sql.= " typent.code,";
273 317
 $sql.= " state.code_departement, state.nom";
274 318
 // Add fields from extrafields
275
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
319
+foreach ($extrafields->attribute_label as $key => $val) {
320
+    $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
321
+}
276 322
 // Add where from hooks
277 323
 $parameters=array();
278 324
 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters);    // Note that $action and $object may have been modified by hook
279 325
 $sql.=$hookmanager->resPrint;
280 326
 if ($search_dfyear > 0 && $search_op2df)
281 327
 {
282
-	if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
283
-	elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
284
-	else $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
285
-}
328
+	if ($search_op2df == '<=') {
329
+	    $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
330
+	} elseif ($search_op2df == '>=') {
331
+	    $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
332
+	} else {
333
+	    $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
334
+	}
335
+	}
286 336
 $sql.= $db->order($sortfield,$sortorder);
287 337
 //print $sql;
288 338
 
@@ -298,9 +348,11 @@  discard block
 block discarded – undo
298 348
 {
299 349
 	$result = $db->query($sql);
300 350
 	$nbtotalofrecords = $db->num_rows($result);
301
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
351
+	if (($page * $limit) > $nbtotalofrecords) {
352
+	    // if total resultset is smaller then paging size (filtering), goto and load page 0
302 353
 	{
303 354
 		$page = 0;
355
+	}
304 356
 		$offset = 0;
305 357
 	}
306 358
 }
@@ -339,26 +391,60 @@  discard block
 block discarded – undo
339 391
 {
340 392
 	$soc = new Societe($db);
341 393
 	$soc->fetch($socid);
342
-	if (empty($search_name)) $search_name = $soc->name;
343
-}
394
+	if (empty($search_name)) {
395
+	    $search_name = $soc->name;
396
+	}
397
+	}
344 398
 
345 399
 $param='';
346
-if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
347
-if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
348
-if ($sall != '')                $param.='&sall='.urlencode($sall);
349
-if ($search_contract != '')     $param.='&search_contract='.urlencode($search_contract);
350
-if ($search_name != '')         $param.='&search_name='.urlencode($search_name);
351
-if ($search_email != '')        $param.='&search_email='.urlencode($search_email);
352
-if ($search_ref_customer != '') $param.='&search_ref_customer='.urlencode($search_ref_customer);
353
-if ($search_ref_supplier != '') $param.='&search_ref_supplier='.urlencode($search_ref_supplier);
354
-if ($search_op2df != '') 		$param.='&search_op2df='.urlencode($search_op2df);
355
-if ($search_dfyear != '')       $param.='&search_dfyear='.urlencode($search_dfyear);
356
-if ($search_dfmonth != '')      $param.='&search_dfmonth='.urlencode($search_dfmonth);
357
-if ($search_sale != '')         $param.='&search_sale=' .urlencode($search_sale);
358
-if ($search_user != '')			$param.='&search_user=' .urlencode($search_user);
359
-if ($search_product_category != '')	$param.='&search_product_category=' .urlencode($search_product_category);
360
-if ($show_files)                $param.='&show_files=' .urlencode($show_files);
361
-if ($optioncss != '')           $param.='&optioncss='.urlencode($optioncss);
400
+if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
401
+    $param.='&contextpage='.urlencode($contextpage);
402
+}
403
+if ($limit > 0 && $limit != $conf->liste_limit) {
404
+    $param.='&limit='.$limit;
405
+}
406
+if ($sall != '') {
407
+    $param.='&sall='.urlencode($sall);
408
+}
409
+if ($search_contract != '') {
410
+    $param.='&search_contract='.urlencode($search_contract);
411
+}
412
+if ($search_name != '') {
413
+    $param.='&search_name='.urlencode($search_name);
414
+}
415
+if ($search_email != '') {
416
+    $param.='&search_email='.urlencode($search_email);
417
+}
418
+if ($search_ref_customer != '') {
419
+    $param.='&search_ref_customer='.urlencode($search_ref_customer);
420
+}
421
+if ($search_ref_supplier != '') {
422
+    $param.='&search_ref_supplier='.urlencode($search_ref_supplier);
423
+}
424
+if ($search_op2df != '') {
425
+    $param.='&search_op2df='.urlencode($search_op2df);
426
+}
427
+if ($search_dfyear != '') {
428
+    $param.='&search_dfyear='.urlencode($search_dfyear);
429
+}
430
+if ($search_dfmonth != '') {
431
+    $param.='&search_dfmonth='.urlencode($search_dfmonth);
432
+}
433
+if ($search_sale != '') {
434
+    $param.='&search_sale=' .urlencode($search_sale);
435
+}
436
+if ($search_user != '') {
437
+    $param.='&search_user=' .urlencode($search_user);
438
+}
439
+if ($search_product_category != '') {
440
+    $param.='&search_product_category=' .urlencode($search_product_category);
441
+}
442
+if ($show_files) {
443
+    $param.='&show_files=' .urlencode($show_files);
444
+}
445
+if ($optioncss != '') {
446
+    $param.='&optioncss='.urlencode($optioncss);
447
+}
362 448
 // Add $param from extra fields
363 449
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
364 450
 
@@ -368,8 +454,12 @@  discard block
 block discarded – undo
368 454
 	'presend'=>$langs->trans("SendByMail"),
369 455
 	'builddoc'=>$langs->trans("PDFMerge"),
370 456
 );
371
-if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
372
-if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
457
+if ($user->rights->contrat->supprimer) {
458
+    $arrayofmassactions['predelete']=$langs->trans("Delete");
459
+}
460
+if (in_array($massaction, array('presend','predelete'))) {
461
+    $arrayofmassactions=array();
462
+}
373 463
 $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
374 464
 
375 465
 $newcardbutton='';
@@ -381,7 +471,9 @@  discard block
 block discarded – undo
381 471
 }
382 472
 
383 473
 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
384
-if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
474
+if ($optioncss != '') {
475
+    print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
476
+}
385 477
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
386 478
 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
387 479
 print '<input type="hidden" name="action" value="list">';
@@ -400,7 +492,9 @@  discard block
 block discarded – undo
400 492
 
401 493
 if ($sall)
402 494
 {
403
-	foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
495
+	foreach($fieldstosearchall as $key => $val) {
496
+	    $fieldstosearchall[$key]=$langs->trans($val);
497
+	}
404 498
 	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
405 499
 }
406 500
 
@@ -436,8 +530,11 @@  discard block
 block discarded – undo
436 530
 
437 531
 $parameters=array();
438 532
 $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
439
-if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
440
-else $moreforfilter = $hookmanager->resPrint;
533
+if (empty($reshook)) {
534
+    $moreforfilter .= $hookmanager->resPrint;
535
+} else {
536
+    $moreforfilter = $hookmanager->resPrint;
537
+}
441 538
 
442 539
 if (! empty($moreforfilter))
443 540
 {
@@ -448,7 +545,9 @@  discard block
 block discarded – undo
448 545
 
449 546
 $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
450 547
 $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
451
-if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
548
+if ($massactionbutton) {
549
+    $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
550
+}
452 551
 
453 552
 print '<div class="div-table-responsive">';
454 553
 print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
@@ -485,9 +584,13 @@  discard block
 block discarded – undo
485 584
 	print '</td>';
486 585
 }
487 586
 // Town
488
-if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
587
+if (! empty($arrayfields['s.town']['checked'])) {
588
+    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
589
+}
489 590
 // Zip
490
-if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
591
+if (! empty($arrayfields['s.zip']['checked'])) {
592
+    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
593
+}
491 594
 // State
492 595
 if (! empty($arrayfields['state.nom']['checked']))
493 596
 {
@@ -518,7 +621,9 @@  discard block
 block discarded – undo
518 621
 	// Date contract
519 622
 	print '<td class="liste_titre center nowraponall">';
520 623
 	//print $langs->trans('Month').': ';
521
-	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
624
+	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
625
+	    print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
626
+	}
522 627
 	print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';
523 628
 	//print '&nbsp;'.$langs->trans('Year').': ';
524 629
 	$syear = $year;
@@ -568,27 +673,57 @@  discard block
 block discarded – undo
568 673
 print "</tr>\n";
569 674
 
570 675
 print '<tr class="liste_titre">';
571
-if (! empty($arrayfields['c.ref']['checked']))               print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
572
-if (! empty($arrayfields['c.ref_customer']['checked']))      print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
573
-if (! empty($arrayfields['c.ref_supplier']['checked']))      print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
574
-if (! empty($arrayfields['s.nom']['checked']))               print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
575
-if (! empty($arrayfields['s.email']['checked']))             print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email","","$param",'',$sortfield,$sortorder);
576
-if (! empty($arrayfields['s.town']['checked']))              print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
577
-if (! empty($arrayfields['s.zip']['checked']))               print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
578
-if (! empty($arrayfields['state.nom']['checked']))           print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
579
-if (! empty($arrayfields['country.code_iso']['checked']))    print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
580
-if (! empty($arrayfields['typent.code']['checked']))         print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
581
-if (! empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
582
-if (! empty($arrayfields['c.date_contrat']['checked']))      print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
676
+if (! empty($arrayfields['c.ref']['checked'])) {
677
+    print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
678
+}
679
+if (! empty($arrayfields['c.ref_customer']['checked'])) {
680
+    print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
681
+}
682
+if (! empty($arrayfields['c.ref_supplier']['checked'])) {
683
+    print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
684
+}
685
+if (! empty($arrayfields['s.nom']['checked'])) {
686
+    print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
687
+}
688
+if (! empty($arrayfields['s.email']['checked'])) {
689
+    print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email","","$param",'',$sortfield,$sortorder);
690
+}
691
+if (! empty($arrayfields['s.town']['checked'])) {
692
+    print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
693
+}
694
+if (! empty($arrayfields['s.zip']['checked'])) {
695
+    print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
696
+}
697
+if (! empty($arrayfields['state.nom']['checked'])) {
698
+    print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
699
+}
700
+if (! empty($arrayfields['country.code_iso']['checked'])) {
701
+    print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
702
+}
703
+if (! empty($arrayfields['typent.code']['checked'])) {
704
+    print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
705
+}
706
+if (! empty($arrayfields['sale_representative']['checked'])) {
707
+    print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
708
+}
709
+if (! empty($arrayfields['c.date_contrat']['checked'])) {
710
+    print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
711
+}
583 712
 // Extra fields
584 713
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
585 714
 // Hook fields
586 715
 $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
587 716
 $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
588 717
 print $hookmanager->resPrint;
589
-if (! empty($arrayfields['c.datec']['checked']))     print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
590
-if (! empty($arrayfields['c.tms']['checked']))       print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
591
-if (! empty($arrayfields['lower_planned_end_date']['checked']))       print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
718
+if (! empty($arrayfields['c.datec']['checked'])) {
719
+    print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
720
+}
721
+if (! empty($arrayfields['c.tms']['checked'])) {
722
+    print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
723
+}
724
+if (! empty($arrayfields['lower_planned_end_date']['checked'])) {
725
+    print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
726
+}
592 727
 if (! empty($arrayfields['status']['checked']))
593 728
 {
594 729
 	print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
@@ -618,7 +753,9 @@  discard block
 block discarded – undo
618 753
 	{
619 754
 		print '<td class="nowrap">';
620 755
 		print $contracttmp->getNomUrl(1);
621
-		if ($obj->nb_late) print img_warning($langs->trans("Late"));
756
+		if ($obj->nb_late) {
757
+		    print img_warning($langs->trans("Late"));
758
+		}
622 759
 		if (!empty($obj->note_private) || !empty($obj->note_public))
623 760
 		{
624 761
 			print ' <span class="note">';
@@ -662,7 +799,9 @@  discard block
 block discarded – undo
662 799
 		print '<td class="nocellnopadd">';
663 800
 		print $obj->town;
664 801
 		print '</td>';
665
-		if (! $i) $totalarray['nbfield']++;
802
+		if (! $i) {
803
+		    $totalarray['nbfield']++;
804
+		}
666 805
 	}
667 806
 	// Zip
668 807
 	if (! empty($arrayfields['s.zip']['checked']))
@@ -670,13 +809,17 @@  discard block
 block discarded – undo
670 809
 		print '<td class="nocellnopadd">';
671 810
 		print $obj->zip;
672 811
 		print '</td>';
673
-		if (! $i) $totalarray['nbfield']++;
812
+		if (! $i) {
813
+		    $totalarray['nbfield']++;
814
+		}
674 815
 	}
675 816
 	// State
676 817
 	if (! empty($arrayfields['state.nom']['checked']))
677 818
 	{
678 819
 		print "<td>".$obj->state_name."</td>\n";
679
-		if (! $i) $totalarray['nbfield']++;
820
+		if (! $i) {
821
+		    $totalarray['nbfield']++;
822
+		}
680 823
 	}
681 824
 	// Country
682 825
 	if (! empty($arrayfields['country.code_iso']['checked']))
@@ -685,16 +828,22 @@  discard block
 block discarded – undo
685 828
 		$tmparray=getCountry($obj->fk_pays,'all');
686 829
 		print $tmparray['label'];
687 830
 		print '</td>';
688
-		if (! $i) $totalarray['nbfield']++;
831
+		if (! $i) {
832
+		    $totalarray['nbfield']++;
833
+		}
689 834
 	}
690 835
 	// Type ent
691 836
 	if (! empty($arrayfields['typent.code']['checked']))
692 837
 	{
693 838
 		print '<td align="center">';
694
-		if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
839
+		if (count($typenArray)==0) {
840
+		    $typenArray = $formcompany->typent_array(1);
841
+		}
695 842
 		print $typenArray[$obj->typent_code];
696 843
 		print '</td>';
697
-		if (! $i) $totalarray['nbfield']++;
844
+		if (! $i) {
845
+		    $totalarray['nbfield']++;
846
+		}
698 847
 	}
699 848
 	if (! empty($arrayfields['sale_representative']['checked']))
700 849
 	{
@@ -703,15 +852,18 @@  discard block
 block discarded – undo
703 852
 		if ($obj->socid > 0)
704 853
 		{
705 854
 			$listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
706
-			if ($listsalesrepresentatives < 0) dol_print_error($db);
855
+			if ($listsalesrepresentatives < 0) {
856
+			    dol_print_error($db);
857
+			}
707 858
 			$nbofsalesrepresentative=count($listsalesrepresentatives);
708
-			if ($nbofsalesrepresentative > 3)   // We print only number
859
+			if ($nbofsalesrepresentative > 3) {
860
+			    // We print only number
709 861
 			{
710 862
 				print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
863
+			}
711 864
 				print $nbofsalesrepresentative;
712 865
 				print '</a>';
713
-			}
714
-			else if ($nbofsalesrepresentative > 0)
866
+			} else if ($nbofsalesrepresentative > 0)
715 867
 			{
716 868
 				$userstatic=new User($db);
717 869
 				$j=0;
@@ -728,13 +880,14 @@  discard block
 block discarded – undo
728 880
 					//print '<div class="float">':
729 881
 					print $userstatic->getNomUrl(-2);
730 882
 					$j++;
731
-					if ($j < $nbofsalesrepresentative) print ' ';
883
+					if ($j < $nbofsalesrepresentative) {
884
+					    print ' ';
885
+					}
732 886
 					//print '</div>';
733 887
 				}
734 888
 			}
735 889
 			//else print $langs->trans("NoSalesRepresentativeAffected");
736
-		}
737
-		else
890
+		} else
738 891
 		{
739 892
 			print '&nbsp';
740 893
 		}
@@ -757,7 +910,9 @@  discard block
 block discarded – undo
757 910
 		print '<td align="center" class="nowrap">';
758 911
 		print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
759 912
 		print '</td>';
760
-		if (! $i) $totalarray['nbfield']++;
913
+		if (! $i) {
914
+		    $totalarray['nbfield']++;
915
+		}
761 916
 	}
762 917
 	// Date modification
763 918
 	if (! empty($arrayfields['c.tms']['checked']))
@@ -765,7 +920,9 @@  discard block
 block discarded – undo
765 920
 		print '<td align="center" class="nowrap">';
766 921
 		print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
767 922
 		print '</td>';
768
-		if (! $i) $totalarray['nbfield']++;
923
+		if (! $i) {
924
+		    $totalarray['nbfield']++;
925
+		}
769 926
 	}
770 927
 	// Date lower end date
771 928
 	if (! empty($arrayfields['lower_planned_end_date']['checked']))
@@ -773,7 +930,9 @@  discard block
 block discarded – undo
773 930
 		print '<td align="center" class="nowrapforall">';
774 931
 		print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
775 932
 		print '</td>';
776
-		if (! $i) $totalarray['nbfield']++;
933
+		if (! $i) {
934
+		    $totalarray['nbfield']++;
935
+		}
777 936
 	}
778 937
 	// Status
779 938
 	if (! empty($arrayfields['status']['checked']))
@@ -785,14 +944,20 @@  discard block
 block discarded – undo
785 944
 	}
786 945
 	// Action column
787 946
 	print '<td class="nowrap" align="center">';
788
-	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
947
+	if ($massactionbutton || $massaction) {
948
+	    // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
789 949
 	{
790 950
 		$selected=0;
791
-		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
951
+	}
952
+		if (in_array($obj->rowid, $arrayofselected)) {
953
+		    $selected=1;
954
+		}
792 955
 		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
793 956
 	}
794 957
 	print '</td>';
795
-	if (! $i) $totalarray['nbfield']++;
958
+	if (! $i) {
959
+	    $totalarray['nbfield']++;
960
+	}
796 961
 
797 962
 	print "</tr>\n";
798 963
 	$i++;
@@ -805,7 +970,9 @@  discard block
 block discarded – undo
805 970
 print '</form>';
806 971
 
807 972
 $hidegeneratedfilelistifempty=1;
808
-if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
973
+if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
974
+    $hidegeneratedfilelistifempty=0;
975
+}
809 976
 
810 977
 // Show list of available documents
811 978
 $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
Please login to merge, or discard this patch.
Spacing   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
33 33
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
34
-require DOL_BASE_PATH . '/main.inc.php';
34
+require DOL_BASE_PATH.'/main.inc.php';
35 35
 
36 36
 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
37 37
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
@@ -42,60 +42,60 @@  discard block
 block discarded – undo
42 42
 // Load translation files required by the page
43 43
 $langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
44 44
 
45
-$action=GETPOST('action','alpha');
46
-$massaction=GETPOST('massaction','alpha');
47
-$show_files=GETPOST('show_files','int');
48
-$confirm=GETPOST('confirm','alpha');
45
+$action = GETPOST('action', 'alpha');
46
+$massaction = GETPOST('massaction', 'alpha');
47
+$show_files = GETPOST('show_files', 'int');
48
+$confirm = GETPOST('confirm', 'alpha');
49 49
 $toselect = GETPOST('toselect', 'array');
50
-$contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'contractlist';   // To manage different context of search
51
-
52
-$search_name=GETPOST('search_name');
53
-$search_email=GETPOST('search_email');
54
-$search_town=GETPOST('search_town','alpha');
55
-$search_zip=GETPOST('search_zip','alpha');
56
-$search_state=trim(GETPOST("search_state"));
57
-$search_country=GETPOST("search_country",'int');
58
-$search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
59
-$search_contract=GETPOST('search_contract');
60
-$search_ref_customer=GETPOST('search_ref_customer','alpha');
61
-$search_ref_supplier=GETPOST('search_ref_supplier','alpha');
62
-$sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
63
-$search_status=GETPOST('search_status');
64
-$socid=GETPOST('socid');
65
-$search_user=GETPOST('search_user','int');
66
-$search_sale=GETPOST('search_sale','int');
67
-$search_product_category=GETPOST('search_product_category','int');
68
-$search_dfmonth=GETPOST('search_dfmonth','int');
69
-$search_dfyear=GETPOST('search_dfyear','int');
70
-$search_op2df=GETPOST('search_op2df','alpha');
71
-$day=GETPOST("day","int");
72
-$year=GETPOST("year","int");
73
-$month=GETPOST("month","int");
74
-
75
-$optioncss = GETPOST('optioncss','alpha');
76
-
77
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
78
-$sortfield = GETPOST("sortfield",'alpha');
79
-$sortorder = GETPOST("sortorder",'alpha');
80
-$page = GETPOST("page",'int');
50
+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
51
+
52
+$search_name = GETPOST('search_name');
53
+$search_email = GETPOST('search_email');
54
+$search_town = GETPOST('search_town', 'alpha');
55
+$search_zip = GETPOST('search_zip', 'alpha');
56
+$search_state = trim(GETPOST("search_state"));
57
+$search_country = GETPOST("search_country", 'int');
58
+$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
59
+$search_contract = GETPOST('search_contract');
60
+$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
61
+$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
62
+$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
63
+$search_status = GETPOST('search_status');
64
+$socid = GETPOST('socid');
65
+$search_user = GETPOST('search_user', 'int');
66
+$search_sale = GETPOST('search_sale', 'int');
67
+$search_product_category = GETPOST('search_product_category', 'int');
68
+$search_dfmonth = GETPOST('search_dfmonth', 'int');
69
+$search_dfyear = GETPOST('search_dfyear', 'int');
70
+$search_op2df = GETPOST('search_op2df', 'alpha');
71
+$day = GETPOST("day", "int");
72
+$year = GETPOST("year", "int");
73
+$month = GETPOST("month", "int");
74
+
75
+$optioncss = GETPOST('optioncss', 'alpha');
76
+
77
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
78
+$sortfield = GETPOST("sortfield", 'alpha');
79
+$sortorder = GETPOST("sortorder", 'alpha');
80
+$page = GETPOST("page", 'int');
81 81
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
82 82
 $offset = $limit * $page;
83 83
 $pageprev = $page - 1;
84 84
 $pagenext = $page + 1;
85
-if (! $sortfield) $sortfield='c.ref';
86
-if (! $sortorder) $sortorder='DESC';
85
+if (!$sortfield) $sortfield = 'c.ref';
86
+if (!$sortorder) $sortorder = 'DESC';
87 87
 
88 88
 // Security check
89
-$id=GETPOST('id','int');
90
-if ($user->societe_id) $socid=$user->societe_id;
89
+$id = GETPOST('id', 'int');
90
+if ($user->societe_id) $socid = $user->societe_id;
91 91
 $result = restrictedArea($user, 'contrat', $id);
92 92
 
93
-$diroutputmassaction=$conf->contrat->dir_output . '/temp/massgeneration/'.$user->id;
93
+$diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id;
94 94
 
95
-$staticcontrat=new Contrat($db);
96
-$staticcontratligne=new ContratLigne($db);
95
+$staticcontrat = new Contrat($db);
96
+$staticcontratligne = new ContratLigne($db);
97 97
 
98
-if ($search_status == '') $search_status=1;
98
+if ($search_status == '') $search_status = 1;
99 99
 
100 100
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
101 101
 $object = new Contrat($db);
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 
105 105
 // fetch optionals attributes and labels
106 106
 $extralabels = $extrafields->fetch_name_optionals_label('contrat');
107
-$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
107
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
108 108
 // List of fields to search into when doing a "search in all"
109 109
 $fieldstosearchall = array(
110 110
 	'c.ref'=>'Ref',
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 	's.nom'=>"ThirdParty",
114 114
 	'c.note_public'=>'NotePublic',
115 115
 );
116
-if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
116
+if (empty($user->socid)) $fieldstosearchall["c.note_private"] = "NotePrivate";
117 117
 
118
-$arrayfields=array(
118
+$arrayfields = array(
119 119
 	'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
120 120
 	'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
121 121
 	'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 // Extra fields
136 136
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
137 137
 {
138
-	foreach($extrafields->attribute_label as $key => $val)
138
+	foreach ($extrafields->attribute_label as $key => $val)
139 139
 	{
140
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
140
+		if (!empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key] = array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key] < 0) ? 0 : 1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key]) != 3 && $extrafields->attribute_perms[$key]));
141 141
 	}
142 142
 }
143 143
 
@@ -146,47 +146,47 @@  discard block
 block discarded – undo
146 146
  * Action
147 147
  */
148 148
 
149
-if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
150
-if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
149
+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
150
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
151 151
 
152
-$parameters=array('socid'=>$socid);
153
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
152
+$parameters = array('socid'=>$socid);
153
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
154 154
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
155 155
 
156 156
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
157 157
 
158 158
 // Purge search criteria
159
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
160
-{
161
-	$day='';
162
-	$month='';
163
-	$year='';
164
-	$search_dfmonth='';
165
-	$search_dfyear='';
166
-	$search_op2df='';
167
-	$search_name="";
168
-	$search_email="";
169
-	$search_town='';
170
-	$search_zip="";
171
-	$search_state="";
172
-	$search_type='';
173
-	$search_country='';
174
-	$search_contract="";
175
-	$search_ref_customer="";
176
-	$search_ref_supplier="";
177
-	$search_user='';
178
-	$search_sale='';
179
-	$search_product_category='';
180
-	$sall="";
181
-	$search_status="";
182
-	$toselect='';
183
-	$search_array_options=array();
159
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
160
+{
161
+	$day = '';
162
+	$month = '';
163
+	$year = '';
164
+	$search_dfmonth = '';
165
+	$search_dfyear = '';
166
+	$search_op2df = '';
167
+	$search_name = "";
168
+	$search_email = "";
169
+	$search_town = '';
170
+	$search_zip = "";
171
+	$search_state = "";
172
+	$search_type = '';
173
+	$search_country = '';
174
+	$search_contract = "";
175
+	$search_ref_customer = "";
176
+	$search_ref_supplier = "";
177
+	$search_user = '';
178
+	$search_sale = '';
179
+	$search_product_category = '';
180
+	$sall = "";
181
+	$search_status = "";
182
+	$toselect = '';
183
+	$search_array_options = array();
184 184
 }
185 185
 
186 186
 if (empty($reshook))
187 187
 {
188
-	$objectclass='Contrat';
189
-	$objectlabel='Contracts';
188
+	$objectclass = 'Contrat';
189
+	$objectlabel = 'Contracts';
190 190
 	$permtoread = $user->rights->contrat->lire;
191 191
 	$permtodelete = $user->rights->contrat->supprimer;
192 192
 	$uploaddir = $conf->contrat->dir_output;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
  * View
199 199
  */
200 200
 
201
-$now=dol_now();
201
+$now = dol_now();
202 202
 $form = new Form($db);
203 203
 $formfile = new FormFile($db);
204 204
 $formother = new FormOther($db);
@@ -206,53 +206,53 @@  discard block
 block discarded – undo
206 206
 $contracttmp = new Contrat($db);
207 207
 
208 208
 $sql = 'SELECT';
209
-$sql.= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
210
-$sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
211
-$sql.= " typent.code as typent_code,";
212
-$sql.= " state.code_departement as state_code, state.nom as state_name,";
213
-$sql.= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
214
-$sql.= ' SUM('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
215
-$sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')",1,0).') as nb_running,';
216
-$sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')",1,0).') as nb_expired,';
217
-$sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')",1,0).') as nb_late,';
218
-$sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed';
209
+$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
210
+$sql .= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
211
+$sql .= " typent.code as typent_code,";
212
+$sql .= " state.code_departement as state_code, state.nom as state_name,";
213
+$sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
214
+$sql .= ' SUM('.$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
215
+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';
216
+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';
217
+$sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
218
+$sql .= ' SUM('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';
219 219
 // Add fields from extrafields
220
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
220
+foreach ($extrafields->attribute_label as $key => $val) $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
221 221
 // Add fields from hooks
222
-$parameters=array();
223
-$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
224
-$sql.=$hookmanager->resPrint;
225
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
226
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
227
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
228
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
229
-if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
230
-$sql.= ", ".MAIN_DB_PREFIX."contrat as c";
231
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
232
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
233
-if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
222
+$parameters = array();
223
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
224
+$sql .= $hookmanager->resPrint;
225
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
226
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
227
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
228
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
229
+if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
230
+$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
231
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
232
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
233
+if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
234 234
 if ($search_user > 0)
235 235
 {
236
-	$sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
237
-	$sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
236
+	$sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
237
+	$sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
238 238
 }
239
-$sql.= " WHERE c.fk_soc = s.rowid ";
240
-$sql.= ' AND c.entity IN ('.getEntity('contract').')';
241
-if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
242
-if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid);
243
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
239
+$sql .= " WHERE c.fk_soc = s.rowid ";
240
+$sql .= ' AND c.entity IN ('.getEntity('contract').')';
241
+if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;
242
+if ($socid) $sql .= " AND s.rowid = ".$db->escape($socid);
243
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
244 244
 if ($month > 0)
245 245
 {
246 246
 	if ($year > 0 && empty($day))
247
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
248
-	else if ($year > 0 && ! empty($day))
249
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
247
+	$sql .= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year, $month, false))."' AND '".$db->idate(dol_get_last_day($year, $month, false))."'";
248
+	else if ($year > 0 && !empty($day))
249
+	$sql .= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
250 250
 	else
251
-	$sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
251
+	$sql .= " AND date_format(c.date_contrat, '%m') = '".$month."'";
252 252
 }
253 253
 else if ($year > 0)
254 254
 {
255
-	$sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
255
+	$sql .= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
256 256
 }
257 257
 if ($search_name) $sql .= natural_search('s.nom', $search_name);
258 258
 if ($search_email) $sql .= natural_search('s.email', $search_email);
@@ -261,37 +261,37 @@  discard block
 block discarded – undo
261 261
 if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
262 262
 if ($search_sale > 0)
263 263
 {
264
-	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
264
+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale;
265 265
 }
266 266
 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
267
-if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
267
+if ($search_user > 0) $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
268 268
 // Add where from extra fields
269 269
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
270 270
 // Add where from hooks
271
-$parameters=array();
272
-$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
273
-$sql.=$hookmanager->resPrint;
274
-$sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
275
-$sql.= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
276
-$sql.= " typent.code,";
277
-$sql.= " state.code_departement, state.nom";
271
+$parameters = array();
272
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
273
+$sql .= $hookmanager->resPrint;
274
+$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
275
+$sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
276
+$sql .= " typent.code,";
277
+$sql .= " state.code_departement, state.nom";
278 278
 // Add fields from extrafields
279
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
279
+foreach ($extrafields->attribute_label as $key => $val) $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
280 280
 // Add where from hooks
281
-$parameters=array();
282
-$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters);    // Note that $action and $object may have been modified by hook
283
-$sql.=$hookmanager->resPrint;
281
+$parameters = array();
282
+$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters); // Note that $action and $object may have been modified by hook
283
+$sql .= $hookmanager->resPrint;
284 284
 if ($search_dfyear > 0 && $search_op2df)
285 285
 {
286
-	if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
287
-	elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
288
-	else $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
286
+	if ($search_op2df == '<=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
287
+	elseif ($search_op2df == '>=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
288
+	else $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
289 289
 }
290
-$sql.= $db->order($sortfield,$sortorder);
290
+$sql .= $db->order($sortfield, $sortorder);
291 291
 //print $sql;
292 292
 
293
-$totalnboflines=0;
294
-$result=$db->query($sql);
293
+$totalnboflines = 0;
294
+$result = $db->query($sql);
295 295
 if ($result)
296 296
 {
297 297
 	$totalnboflines = $db->num_rows($result);
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 	}
310 310
 }
311 311
 
312
-$sql.= $db->plimit($limit + 1, $offset);
312
+$sql .= $db->plimit($limit + 1, $offset);
313 313
 
314
-$resql=$db->query($sql);
315
-if (! $resql)
314
+$resql = $db->query($sql);
315
+if (!$resql)
316 316
 {
317 317
 	dol_print_error($db);
318 318
 	exit;
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 $num = $db->num_rows($resql);
322 322
 
323 323
 // Direct jump if only one record found
324
-if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
324
+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
325 325
 {
326 326
 	$obj = $db->fetch_object($resql);
327 327
 	$id = $obj->rowid;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 $i = 0;
339 339
 
340
-$arrayofselected=is_array($toselect)?$toselect:array();
340
+$arrayofselected = is_array($toselect) ? $toselect : array();
341 341
 
342 342
 if ($socid > 0)
343 343
 {
@@ -346,42 +346,42 @@  discard block
 block discarded – undo
346 346
 	if (empty($search_name)) $search_name = $soc->name;
347 347
 }
348 348
 
349
-$param='';
350
-if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
351
-if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
352
-if ($sall != '')                $param.='&sall='.urlencode($sall);
353
-if ($search_contract != '')     $param.='&search_contract='.urlencode($search_contract);
354
-if ($search_name != '')         $param.='&search_name='.urlencode($search_name);
355
-if ($search_email != '')        $param.='&search_email='.urlencode($search_email);
356
-if ($search_ref_customer != '') $param.='&search_ref_customer='.urlencode($search_ref_customer);
357
-if ($search_ref_supplier != '') $param.='&search_ref_supplier='.urlencode($search_ref_supplier);
358
-if ($search_op2df != '') 		$param.='&search_op2df='.urlencode($search_op2df);
359
-if ($search_dfyear != '')       $param.='&search_dfyear='.urlencode($search_dfyear);
360
-if ($search_dfmonth != '')      $param.='&search_dfmonth='.urlencode($search_dfmonth);
361
-if ($search_sale != '')         $param.='&search_sale=' .urlencode($search_sale);
362
-if ($search_user != '')			$param.='&search_user=' .urlencode($search_user);
363
-if ($search_product_category != '')	$param.='&search_product_category=' .urlencode($search_product_category);
364
-if ($show_files)                $param.='&show_files=' .urlencode($show_files);
365
-if ($optioncss != '')           $param.='&optioncss='.urlencode($optioncss);
349
+$param = '';
350
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
351
+if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
352
+if ($sall != '')                $param .= '&sall='.urlencode($sall);
353
+if ($search_contract != '')     $param .= '&search_contract='.urlencode($search_contract);
354
+if ($search_name != '')         $param .= '&search_name='.urlencode($search_name);
355
+if ($search_email != '')        $param .= '&search_email='.urlencode($search_email);
356
+if ($search_ref_customer != '') $param .= '&search_ref_customer='.urlencode($search_ref_customer);
357
+if ($search_ref_supplier != '') $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
358
+if ($search_op2df != '') 		$param .= '&search_op2df='.urlencode($search_op2df);
359
+if ($search_dfyear != '')       $param .= '&search_dfyear='.urlencode($search_dfyear);
360
+if ($search_dfmonth != '')      $param .= '&search_dfmonth='.urlencode($search_dfmonth);
361
+if ($search_sale != '')         $param .= '&search_sale='.urlencode($search_sale);
362
+if ($search_user != '')			$param .= '&search_user='.urlencode($search_user);
363
+if ($search_product_category != '')	$param .= '&search_product_category='.urlencode($search_product_category);
364
+if ($show_files)                $param .= '&show_files='.urlencode($show_files);
365
+if ($optioncss != '')           $param .= '&optioncss='.urlencode($optioncss);
366 366
 // Add $param from extra fields
367 367
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
368 368
 
369 369
 // List of mass actions available
370
-$arrayofmassactions =  array(
370
+$arrayofmassactions = array(
371 371
 	'generate_doc'=>$langs->trans("Generate"),
372 372
 	'presend'=>$langs->trans("SendByMail"),
373 373
 	'builddoc'=>$langs->trans("PDFMerge"),
374 374
 );
375
-if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
376
-if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
377
-$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
375
+if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete'] = $langs->trans("Delete");
376
+if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
377
+$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
378 378
 
379
-$newcardbutton='';
379
+$newcardbutton = '';
380 380
 if ($user->rights->contrat->creer)
381 381
 {
382
-	$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewContractSubscription').'</span>';
383
-	$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
384
-	$newcardbutton.= '</a>';
382
+	$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewContractSubscription').'</span>';
383
+	$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>';
384
+	$newcardbutton .= '</a>';
385 385
 }
386 386
 
387 387
 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
@@ -396,164 +396,164 @@  discard block
 block discarded – undo
396 396
 
397 397
 print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'title_commercial.png', 0, $newcardbutton, '', $limit);
398 398
 
399
-$topicmail="SendContractRef";
400
-$modelmail="contract";
401
-$objecttmp=new Contrat($db);
402
-$trackid='con'.$object->id;
399
+$topicmail = "SendContractRef";
400
+$modelmail = "contract";
401
+$objecttmp = new Contrat($db);
402
+$trackid = 'con'.$object->id;
403 403
 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
404 404
 
405 405
 if ($sall)
406 406
 {
407
-	foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
408
-	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
407
+	foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
408
+	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
409 409
 }
410 410
 
411
-$moreforfilter='';
411
+$moreforfilter = '';
412 412
 
413 413
 // If the user can view prospects other than his'
414 414
 if ($user->rights->societe->client->voir || $socid)
415 415
 {
416 416
 	$langs->load("commercial");
417
-	$moreforfilter.='<div class="divsearchfield">';
418
-	$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
419
-	$moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200');
420
-	$moreforfilter.='</div>';
417
+	$moreforfilter .= '<div class="divsearchfield">';
418
+	$moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';
419
+	$moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
420
+	$moreforfilter .= '</div>';
421 421
 }
422 422
 // If the user can view other users
423 423
 if ($user->rights->user->user->lire)
424 424
 {
425
-	$moreforfilter.='<div class="divsearchfield">';
426
-	$moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
427
-	$moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
428
- 	$moreforfilter.='</div>';
425
+	$moreforfilter .= '<div class="divsearchfield">';
426
+	$moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';
427
+	$moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
428
+ 	$moreforfilter .= '</div>';
429 429
 }
430 430
 // If the user can view categories of products
431 431
 if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
432 432
 {
433 433
 	include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
434
-	$moreforfilter.='<div class="divsearchfield">';
435
-	$moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
434
+	$moreforfilter .= '<div class="divsearchfield">';
435
+	$moreforfilter .= $langs->trans('IncludingProductWithTag').': ';
436 436
 	$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
437
-	$moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
438
-	$moreforfilter.='</div>';
437
+	$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
438
+	$moreforfilter .= '</div>';
439 439
 }
440 440
 
441
-$parameters=array();
442
-$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
441
+$parameters = array();
442
+$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
443 443
 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
444 444
 else $moreforfilter = $hookmanager->resPrint;
445 445
 
446
-if (! empty($moreforfilter))
446
+if (!empty($moreforfilter))
447 447
 {
448 448
 	print '<div class="liste_titre liste_titre_bydiv centpercent">';
449 449
 	print $moreforfilter;
450 450
 	print '</div>';
451 451
 }
452 452
 
453
-$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
454
-$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
455
-if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
453
+$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
454
+$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
455
+if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
456 456
 
457 457
 print '<div class="div-table-responsive">';
458
-print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
458
+print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
459 459
 
460 460
 print '<tr class="liste_titre_filter">';
461
-if (! empty($arrayfields['c.ref']['checked']))
461
+if (!empty($arrayfields['c.ref']['checked']))
462 462
 {
463 463
 	print '<td class="liste_titre">';
464 464
 	print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
465 465
 	print '</td>';
466 466
 }
467
-if (! empty($arrayfields['c.ref_customer']['checked']))
467
+if (!empty($arrayfields['c.ref_customer']['checked']))
468 468
 {
469 469
 	print '<td class="liste_titre">';
470 470
 	print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
471 471
 	print '</td>';
472 472
 }
473
-if (! empty($arrayfields['c.ref_supplier']['checked']))
473
+if (!empty($arrayfields['c.ref_supplier']['checked']))
474 474
 {
475 475
 	print '<td class="liste_titre">';
476 476
 	print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
477 477
 	print '</td>';
478 478
 }
479
-if (! empty($arrayfields['s.nom']['checked']))
479
+if (!empty($arrayfields['s.nom']['checked']))
480 480
 {
481 481
 	print '<td class="liste_titre">';
482 482
 	print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
483 483
 	print '</td>';
484 484
 }
485
-if (! empty($arrayfields['s.email']['checked']))
485
+if (!empty($arrayfields['s.email']['checked']))
486 486
 {
487 487
 	print '<td class="liste_titre">';
488 488
 	print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
489 489
 	print '</td>';
490 490
 }
491 491
 // Town
492
-if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
492
+if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
493 493
 // Zip
494
-if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
494
+if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
495 495
 // State
496
-if (! empty($arrayfields['state.nom']['checked']))
496
+if (!empty($arrayfields['state.nom']['checked']))
497 497
 {
498 498
 	print '<td class="liste_titre">';
499 499
 	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
500 500
 	print '</td>';
501 501
 }
502 502
 // Country
503
-if (! empty($arrayfields['country.code_iso']['checked']))
503
+if (!empty($arrayfields['country.code_iso']['checked']))
504 504
 {
505 505
 	print '<td class="liste_titre" align="center">';
506
-	print $form->select_country($search_country,'search_country','',0,'maxwidth100');
506
+	print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth100');
507 507
 	print '</td>';
508 508
 }
509 509
 // Company type
510
-if (! empty($arrayfields['typent.code']['checked']))
510
+if (!empty($arrayfields['typent.code']['checked']))
511 511
 {
512 512
 	print '<td class="liste_titre maxwidthonsmartphone" align="center">';
513
-	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
513
+	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
514 514
 	print '</td>';
515 515
 }
516
-if (! empty($arrayfields['sale_representative']['checked']))
516
+if (!empty($arrayfields['sale_representative']['checked']))
517 517
 {
518 518
 	print '<td class="liste_titre"></td>';
519 519
 }
520
-if (! empty($arrayfields['c.date_contrat']['checked']))
520
+if (!empty($arrayfields['c.date_contrat']['checked']))
521 521
 {
522 522
 	// Date contract
523 523
 	print '<td class="liste_titre center nowraponall">';
524 524
 	//print $langs->trans('Month').': ';
525
-	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
525
+	if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
526 526
 	print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';
527 527
 	//print '&nbsp;'.$langs->trans('Year').': ';
528 528
 	$syear = $year;
529
-	print $formother->selectyear($syear,'year',1, 20, 5);
529
+	print $formother->selectyear($syear, 'year', 1, 20, 5);
530 530
 	print '</td>';
531 531
 }
532 532
 // Extra fields
533 533
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
534 534
 
535 535
 // Fields from hook
536
-$parameters=array('arrayfields'=>$arrayfields);
537
-$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
536
+$parameters = array('arrayfields'=>$arrayfields);
537
+$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
538 538
 print $hookmanager->resPrint;
539 539
 // Date creation
540
-if (! empty($arrayfields['c.datec']['checked']))
540
+if (!empty($arrayfields['c.datec']['checked']))
541 541
 {
542 542
 	print '<td class="liste_titre">';
543 543
 	print '</td>';
544 544
 }
545 545
 // Date modification
546
-if (! empty($arrayfields['c.tms']['checked']))
546
+if (!empty($arrayfields['c.tms']['checked']))
547 547
 {
548 548
 	print '<td class="liste_titre">';
549 549
 	print '</td>';
550 550
 }
551 551
 // First end date
552
-if (! empty($arrayfields['lower_planned_end_date']['checked']))
552
+if (!empty($arrayfields['lower_planned_end_date']['checked']))
553 553
 {
554 554
 		print '<td class="liste_titre nowraponall" align="center">';
555
-		$arrayofoperators=array('0'=>'','='=>'=','<='=>'<=','>='=>'>=');
556
-		print $form->selectarray('search_op2df',$arrayofoperators,$search_op2df,0);
555
+		$arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');
556
+		print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0);
557 557
 		print '</br>';
558 558
 		print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0, 'valignmiddle');
559 559
 		print ' ';
@@ -561,64 +561,64 @@  discard block
 block discarded – undo
561 561
 		print '</td>';
562 562
 }
563 563
 // Status
564
-if (! empty($arrayfields['status']['checked']))
564
+if (!empty($arrayfields['status']['checked']))
565 565
 {
566 566
 	print '<td class="liste_titre" colspan="4" align="right"></td>';
567 567
 }
568 568
 print '<td class="liste_titre" align="middle">';
569
-$searchpicto=$form->showFilterButtons();
569
+$searchpicto = $form->showFilterButtons();
570 570
 print $searchpicto;
571 571
 print '</td>';
572 572
 print "</tr>\n";
573 573
 
574 574
 print '<tr class="liste_titre">';
575
-if (! empty($arrayfields['c.ref']['checked']))               print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
576
-if (! empty($arrayfields['c.ref_customer']['checked']))      print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
577
-if (! empty($arrayfields['c.ref_supplier']['checked']))      print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
578
-if (! empty($arrayfields['s.nom']['checked']))               print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
579
-if (! empty($arrayfields['s.email']['checked']))             print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email","","$param",'',$sortfield,$sortorder);
580
-if (! empty($arrayfields['s.town']['checked']))              print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
581
-if (! empty($arrayfields['s.zip']['checked']))               print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
582
-if (! empty($arrayfields['state.nom']['checked']))           print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
583
-if (! empty($arrayfields['country.code_iso']['checked']))    print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
584
-if (! empty($arrayfields['typent.code']['checked']))         print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
585
-if (! empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
586
-if (! empty($arrayfields['c.date_contrat']['checked']))      print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
575
+if (!empty($arrayfields['c.ref']['checked']))               print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", "$param", '', $sortfield, $sortorder);
576
+if (!empty($arrayfields['c.ref_customer']['checked']))      print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", "$param", '', $sortfield, $sortorder);
577
+if (!empty($arrayfields['c.ref_supplier']['checked']))      print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", "$param", '', $sortfield, $sortorder);
578
+if (!empty($arrayfields['s.nom']['checked']))               print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", "$param", '', $sortfield, $sortorder);
579
+if (!empty($arrayfields['s.email']['checked']))             print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", "$param", '', $sortfield, $sortorder);
580
+if (!empty($arrayfields['s.town']['checked']))              print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
581
+if (!empty($arrayfields['s.zip']['checked']))               print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
582
+if (!empty($arrayfields['state.nom']['checked']))           print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
583
+if (!empty($arrayfields['country.code_iso']['checked']))    print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
584
+if (!empty($arrayfields['typent.code']['checked']))         print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
585
+if (!empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
586
+if (!empty($arrayfields['c.date_contrat']['checked']))      print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", "$param", 'align="center"', $sortfield, $sortorder);
587 587
 // Extra fields
588 588
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
589 589
 // Hook fields
590
-$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
591
-$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
590
+$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
591
+$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
592 592
 print $hookmanager->resPrint;
593
-if (! empty($arrayfields['c.datec']['checked']))     print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
594
-if (! empty($arrayfields['c.tms']['checked']))       print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
595
-if (! empty($arrayfields['lower_planned_end_date']['checked']))       print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
596
-if (! empty($arrayfields['status']['checked']))
593
+if (!empty($arrayfields['c.datec']['checked']))     print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
594
+if (!empty($arrayfields['c.tms']['checked']))       print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
595
+if (!empty($arrayfields['lower_planned_end_date']['checked']))       print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
596
+if (!empty($arrayfields['status']['checked']))
597 597
 {
598
-	print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
599
-	print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
600
-	print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
601
-	print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
598
+	print_liste_field_titre($staticcontratligne->LibStatut(0, 3), '', '', '', '', 'width="16"');
599
+	print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0), '', '', '', '', 'width="16"');
600
+	print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1), '', '', '', '', 'width="16"');
601
+	print_liste_field_titre($staticcontratligne->LibStatut(5, 3), '', '', '', '', 'width="16"');
602 602
 }
603
-print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
603
+print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
604 604
 print "</tr>\n";
605 605
 
606
-while ($i < min($num,$limit))
606
+while ($i < min($num, $limit))
607 607
 {
608 608
 	$obj = $db->fetch_object($resql);
609 609
 
610
-	$contracttmp->ref=$obj->ref;
611
-	$contracttmp->id=$obj->rowid;
612
-	$contracttmp->ref_customer=$obj->ref_customer;
613
-	$contracttmp->ref_supplier=$obj->ref_supplier;
610
+	$contracttmp->ref = $obj->ref;
611
+	$contracttmp->id = $obj->rowid;
612
+	$contracttmp->ref_customer = $obj->ref_customer;
613
+	$contracttmp->ref_supplier = $obj->ref_supplier;
614 614
 
615 615
 	if ($obj->socid > 0)
616 616
 	{
617
-		$result=$socstatic->fetch($obj->socid);
617
+		$result = $socstatic->fetch($obj->socid);
618 618
 	}
619 619
 
620 620
 	print '<tr class="oddeven">';
621
-	if (! empty($arrayfields['c.ref']['checked']))
621
+	if (!empty($arrayfields['c.ref']['checked']))
622 622
 	{
623 623
 		print '<td class="nowrap">';
624 624
 		print $contracttmp->getNomUrl(1);
@@ -626,27 +626,27 @@  discard block
 block discarded – undo
626 626
 		if (!empty($obj->note_private) || !empty($obj->note_public))
627 627
 		{
628 628
 			print ' <span class="note">';
629
-			print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"),'note').'</a>';
629
+			print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
630 630
 			print '</span>';
631 631
 		}
632 632
 
633
-		$filename=dol_sanitizeFileName($obj->ref);
634
-		$filedir=$conf->contrat->dir_output . '/' . dol_sanitizeFileName($obj->ref);
635
-		$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
633
+		$filename = dol_sanitizeFileName($obj->ref);
634
+		$filedir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($obj->ref);
635
+		$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
636 636
 		print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
637 637
 		print '</td>';
638 638
 
639 639
 		print '</td>';
640 640
 	}
641
-	if (! empty($arrayfields['c.ref_customer']['checked']))
641
+	if (!empty($arrayfields['c.ref_customer']['checked']))
642 642
 	{
643 643
 		print '<td>'.$obj->ref_customer.'</td>';
644 644
 	}
645
-	if (! empty($arrayfields['c.ref_supplier']['checked']))
645
+	if (!empty($arrayfields['c.ref_supplier']['checked']))
646 646
 	{
647 647
 		print '<td>'.$obj->ref_supplier.'</td>';
648 648
 	}
649
-	if (! empty($arrayfields['s.nom']['checked']))
649
+	if (!empty($arrayfields['s.nom']['checked']))
650 650
 	{
651 651
 		print '<td>';
652 652
 		//print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';
@@ -656,59 +656,59 @@  discard block
 block discarded – undo
656 656
 		}
657 657
 		print '</td>';
658 658
 	}
659
-	if (! empty($arrayfields['s.email']['checked']))
659
+	if (!empty($arrayfields['s.email']['checked']))
660 660
 	{
661 661
 		print '<td>'.$obj->email.'</td>';
662 662
 	}
663 663
 	// Town
664
-	if (! empty($arrayfields['s.town']['checked']))
664
+	if (!empty($arrayfields['s.town']['checked']))
665 665
 	{
666 666
 		print '<td class="nocellnopadd">';
667 667
 		print $obj->town;
668 668
 		print '</td>';
669
-		if (! $i) $totalarray['nbfield']++;
669
+		if (!$i) $totalarray['nbfield']++;
670 670
 	}
671 671
 	// Zip
672
-	if (! empty($arrayfields['s.zip']['checked']))
672
+	if (!empty($arrayfields['s.zip']['checked']))
673 673
 	{
674 674
 		print '<td class="nocellnopadd">';
675 675
 		print $obj->zip;
676 676
 		print '</td>';
677
-		if (! $i) $totalarray['nbfield']++;
677
+		if (!$i) $totalarray['nbfield']++;
678 678
 	}
679 679
 	// State
680
-	if (! empty($arrayfields['state.nom']['checked']))
680
+	if (!empty($arrayfields['state.nom']['checked']))
681 681
 	{
682 682
 		print "<td>".$obj->state_name."</td>\n";
683
-		if (! $i) $totalarray['nbfield']++;
683
+		if (!$i) $totalarray['nbfield']++;
684 684
 	}
685 685
 	// Country
686
-	if (! empty($arrayfields['country.code_iso']['checked']))
686
+	if (!empty($arrayfields['country.code_iso']['checked']))
687 687
 	{
688 688
 		print '<td align="center">';
689
-		$tmparray=getCountry($obj->fk_pays,'all');
689
+		$tmparray = getCountry($obj->fk_pays, 'all');
690 690
 		print $tmparray['label'];
691 691
 		print '</td>';
692
-		if (! $i) $totalarray['nbfield']++;
692
+		if (!$i) $totalarray['nbfield']++;
693 693
 	}
694 694
 	// Type ent
695
-	if (! empty($arrayfields['typent.code']['checked']))
695
+	if (!empty($arrayfields['typent.code']['checked']))
696 696
 	{
697 697
 		print '<td align="center">';
698
-		if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
698
+		if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
699 699
 		print $typenArray[$obj->typent_code];
700 700
 		print '</td>';
701
-		if (! $i) $totalarray['nbfield']++;
701
+		if (!$i) $totalarray['nbfield']++;
702 702
 	}
703
-	if (! empty($arrayfields['sale_representative']['checked']))
703
+	if (!empty($arrayfields['sale_representative']['checked']))
704 704
 	{
705 705
 		// Sales representatives
706 706
 		print '<td>';
707 707
 		if ($obj->socid > 0)
708 708
 		{
709
-			$listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
709
+			$listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
710 710
 			if ($listsalesrepresentatives < 0) dol_print_error($db);
711
-			$nbofsalesrepresentative=count($listsalesrepresentatives);
711
+			$nbofsalesrepresentative = count($listsalesrepresentatives);
712 712
 			if ($nbofsalesrepresentative > 3)   // We print only number
713 713
 			{
714 714
 				print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
@@ -717,17 +717,17 @@  discard block
 block discarded – undo
717 717
 			}
718 718
 			else if ($nbofsalesrepresentative > 0)
719 719
 			{
720
-				$userstatic=new User($db);
721
-				$j=0;
722
-				foreach($listsalesrepresentatives as $val)
720
+				$userstatic = new User($db);
721
+				$j = 0;
722
+				foreach ($listsalesrepresentatives as $val)
723 723
 				{
724
-					$userstatic->id=$val['id'];
725
-					$userstatic->lastname=$val['lastname'];
726
-					$userstatic->firstname=$val['firstname'];
727
-					$userstatic->email=$val['email'];
728
-					$userstatic->statut=$val['statut'];
729
-					$userstatic->entity=$val['entity'];
730
-					$userstatic->photo=$val['photo'];
724
+					$userstatic->id = $val['id'];
725
+					$userstatic->lastname = $val['lastname'];
726
+					$userstatic->firstname = $val['firstname'];
727
+					$userstatic->email = $val['email'];
728
+					$userstatic->statut = $val['statut'];
729
+					$userstatic->entity = $val['entity'];
730
+					$userstatic->photo = $val['photo'];
731 731
 
732 732
 					//print '<div class="float">':
733 733
 					print $userstatic->getNomUrl(-2);
@@ -745,58 +745,58 @@  discard block
 block discarded – undo
745 745
 		print '</td>';
746 746
 	}
747 747
 	// Date
748
-	if (! empty($arrayfields['c.date_contrat']['checked']))
748
+	if (!empty($arrayfields['c.date_contrat']['checked']))
749 749
 	{
750 750
 		print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzuser').'</td>';
751 751
 	}
752 752
 	// Extra fields
753 753
 	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
754 754
 	// Fields from hook
755
-	$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
756
-	$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
755
+	$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
756
+	$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
757 757
 	print $hookmanager->resPrint;
758 758
 	// Date creation
759
-	if (! empty($arrayfields['c.datec']['checked']))
759
+	if (!empty($arrayfields['c.datec']['checked']))
760 760
 	{
761 761
 		print '<td align="center" class="nowrap">';
762 762
 		print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
763 763
 		print '</td>';
764
-		if (! $i) $totalarray['nbfield']++;
764
+		if (!$i) $totalarray['nbfield']++;
765 765
 	}
766 766
 	// Date modification
767
-	if (! empty($arrayfields['c.tms']['checked']))
767
+	if (!empty($arrayfields['c.tms']['checked']))
768 768
 	{
769 769
 		print '<td align="center" class="nowrap">';
770 770
 		print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
771 771
 		print '</td>';
772
-		if (! $i) $totalarray['nbfield']++;
772
+		if (!$i) $totalarray['nbfield']++;
773 773
 	}
774 774
 	// Date lower end date
775
-	if (! empty($arrayfields['lower_planned_end_date']['checked']))
775
+	if (!empty($arrayfields['lower_planned_end_date']['checked']))
776 776
 	{
777 777
 		print '<td align="center" class="nowrapforall">';
778 778
 		print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
779 779
 		print '</td>';
780
-		if (! $i) $totalarray['nbfield']++;
780
+		if (!$i) $totalarray['nbfield']++;
781 781
 	}
782 782
 	// Status
783
-	if (! empty($arrayfields['status']['checked']))
783
+	if (!empty($arrayfields['status']['checked']))
784 784
 	{
785
-		print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
786
-		print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
787
-		print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
788
-		print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
785
+		print '<td align="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
786
+		print '<td align="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
787
+		print '<td align="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
788
+		print '<td align="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
789 789
 	}
790 790
 	// Action column
791 791
 	print '<td class="nowrap" align="center">';
792 792
 	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
793 793
 	{
794
-		$selected=0;
795
-		if (in_array($obj->rowid, $arrayofselected)) $selected=1;
796
-		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
794
+		$selected = 0;
795
+		if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
796
+		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
797 797
 	}
798 798
 	print '</td>';
799
-	if (! $i) $totalarray['nbfield']++;
799
+	if (!$i) $totalarray['nbfield']++;
800 800
 
801 801
 	print "</tr>\n";
802 802
 	$i++;
@@ -808,18 +808,18 @@  discard block
 block discarded – undo
808 808
 
809 809
 print '</form>';
810 810
 
811
-$hidegeneratedfilelistifempty=1;
812
-if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
811
+$hidegeneratedfilelistifempty = 1;
812
+if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
813 813
 
814 814
 // Show list of available documents
815
-$urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
816
-$urlsource.=str_replace('&amp;','&',$param);
815
+$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
816
+$urlsource .= str_replace('&amp;', '&', $param);
817 817
 
818
-$filedir=$diroutputmassaction;
819
-$genallowed=$user->rights->contrat->lire;
820
-$delallowed=$user->rights->contrat->lire;
818
+$filedir = $diroutputmassaction;
819
+$genallowed = $user->rights->contrat->lire;
820
+$delallowed = $user->rights->contrat->lire;
821 821
 
822
-print $formfile->showdocuments('massfilesarea_contract','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
822
+print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
823 823
 
824 824
 
825 825
 llxFooter();
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/class/stripe.class.php 3 patches
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -28,520 +28,520 @@
 block discarded – undo
28 28
  */
29 29
 class Stripe extends CommonObject
30 30
 {
31
-	/**
32
-	 * @var int ID
33
-	 */
34
-	public $rowid;
35
-
36
-	/**
37
-	 * @var int Thirdparty ID
38
-	 */
31
+    /**
32
+     * @var int ID
33
+     */
34
+    public $rowid;
35
+
36
+    /**
37
+     * @var int Thirdparty ID
38
+     */
39 39
     public $fk_soc;
40 40
 
41 41
     /**
42 42
      * @var int ID
43 43
      */
44
-	public $fk_key;
45
-
46
-	/**
47
-	 * @var int ID
48
-	 */
49
-	public $id;
50
-
51
-	public $mode;
52
-
53
-	/**
54
-	 * @var int Entity
55
-	 */
56
-	public $entity;
57
-
58
-	public $statut;
59
-
60
-	public $type;
61
-
62
-	public $code;
63
-
64
-	public $message;
65
-
66
-	/**
67
-	 * 	Constructor
68
-	 *
69
-	 * 	@param	DoliDB		$db			Database handler
70
-	 */
71
-	public function __construct($db)
72
-	{
73
-		$this->db = $db;
74
-	}
75
-
76
-
77
-	/**
78
-	 * Return main company OAuth Connect stripe account
79
-	 *
80
-	 * @param 	string	$mode		'StripeTest' or 'StripeLive'
81
-	 * @return 	string				Stripe account 'acc_....' or '' if no OAuth token found
82
-	 */
83
-	public function getStripeAccount($mode='StripeTest')
84
-	{
85
-		global $conf;
86
-
87
-		$sql = "SELECT tokenstring";
88
-		$sql.= " FROM ".MAIN_DB_PREFIX."oauth_token";
89
-		$sql.= " WHERE entity = ".$conf->entity;
90
-		$sql.= " AND service = '".$mode."'";
91
-
92
-		dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
93
-		$result = $this->db->query($sql);
94
-    	if ($result)
95
-		{
96
-			if ($this->db->num_rows($result))
97
-			{
98
-				$obj = $this->db->fetch_object($result);
99
-    			$tokenstring=$obj->tokenstring;
100
-
101
-    			$tmparray = dol_json_decode($tokenstring);
102
-    			$key = $tmparray->stripe_user_id;
103
-    		}
104
-    		else {
105
-    			$tokenstring='';
106
-    		}
107
-    	}
108
-    	else {
109
-    		dol_print_error($this->db);
110
-    	}
111
-
112
-    	dol_syslog("No dedicated Stripe Connect account available for entity ".$conf->entity);
113
-		return $key;
114
-	}
115
-
116
-	/**
117
-	 * getStripeCustomerAccount
118
-	 *
119
-	 * @param	int		$id		Id of third party
120
-	 * @param	int		$status		Status
121
-	 * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
122
-	 */
123
-	public function getStripeCustomerAccount($id, $status=0)
124
-	{
125
-		include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
126
-		$societeaccount = new SocieteAccount($this->db);
127
-		return $societeaccount->getCustomerAccount($id, 'stripe', $status);		// Get thirdparty cus_...
128
-	}
129
-
130
-
131
-	/**
132
-	 * Get the Stripe customer of a thirdparty (with option to create it if not linked yet)
133
-	 *
134
-	 * @param	Societe	$object							Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity)
135
-	 * @param	string	$key							''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
136
-	 * @param	int		$status							Status (0=test, 1=live)
137
-	 * @param	int		$createifnotlinkedtostripe		1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer
138
-	 * @return 	\Stripe\StripeCustomer|null 			Stripe Customer or null if not found
139
-	 */
140
-	public function customerStripe(Societe $object, $key='', $status=0, $createifnotlinkedtostripe=0)
141
-	{
142
-		global $conf, $user;
143
-
144
-		if (empty($object->id))
145
-		{
146
-			dol_syslog("customerStripe is called with param object not loaded");
147
-			return null;
148
-		}
149
-
150
-		$customer = null;
151
-
152
-		$sql = "SELECT sa.key_account as key_account, sa.entity";			// key_account is cus_....
153
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
154
-		$sql.= " WHERE sa.fk_soc = " . $object->id;
155
-		$sql.= " AND sa.entity IN (".getEntity('societe').")";
156
-		$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
157
-		$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
158
-
159
-		dol_syslog(get_class($this) . "::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
160
-		$resql = $this->db->query($sql);
161
-		if ($resql) {
162
-			$num = $this->db->num_rows($resql);
163
-			if ($num)
164
-			{
165
-				$obj = $this->db->fetch_object($resql);
166
-				$tiers = $obj->key_account;
167
-
168
-				dol_syslog(get_class($this) . "::customerStripe found stripe customer key_account = ".$tiers);
169
-
170
-				// Force to use the correct API key
171
-				global $stripearrayofkeysbyenv;
172
-				\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
173
-
174
-				try {
175
-					if (empty($key)) {				// If the Stripe connect account not set, we use common API usage
176
-						$customer = \Stripe\Customer::retrieve("$tiers");
177
-					} else {
178
-						$customer = \Stripe\Customer::retrieve("$tiers", array("stripe_account" => $key));
179
-					}
180
-				}
181
-				catch(Exception $e)
182
-				{
183
-					$this->error = $e->getMessage();
184
-				}
185
-			}
186
-			elseif ($createifnotlinkedtostripe)
187
-			{
188
-				$dataforcustomer = array(
189
-					"email" => $object->email,
190
-					"description" => $object->name,
191
-					"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
192
-				);
193
-
194
-				$vatcleaned = $object->tva_intra ? $object->tva_intra : null;
195
-
196
-				$taxinfo = array('type'=>'vat');
197
-				if ($vatcleaned)
198
-				{
199
-					$taxinfo["tax_id"] = $vatcleaned;
200
-				}
201
-				// We force data to "null" if not defined as expected by Stripe
202
-				if (empty($vatcleaned)) $taxinfo=null;
203
-
204
-				$dataforcustomer["tax_info"] = $taxinfo;
205
-
206
-				//$a = \Stripe\Stripe::getApiKey();
207
-				//var_dump($a);var_dump($key);exit;
208
-				try {
209
-					// Force to use the correct API key
210
-					global $stripearrayofkeysbyenv;
211
-					\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
212
-
213
-					if (empty($key)) {				// If the Stripe connect account not set, we use common API usage
214
-						$customer = \Stripe\Customer::create($dataforcustomer);
215
-					} else {
216
-						$customer = \Stripe\Customer::create($dataforcustomer, array("stripe_account" => $key));
217
-					}
218
-
219
-					$sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)";
220
-					$sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer->id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")";
221
-					$resql = $this->db->query($sql);
222
-					if (! $resql)
223
-					{
224
-						$this->error = $this->db->lasterror();
225
-					}
226
-				}
227
-				catch(Exception $e)
228
-				{
229
-					$this->error = $e->getMessage();
230
-				}
231
-			}
232
-		}
233
-		else
234
-		{
235
-			dol_print_error($this->db);
236
-		}
237
-
238
-		return $customer;
239
-	}
240
-
241
-	/**
242
-	 * Get the Stripe card of a company payment mode (with option to create it on Stripe if not linked yet)
243
-	 *
244
-	 * @param	\Stripe\StripeCustomer	$cu								Object stripe customer
245
-	 * @param	CompanyPaymentMode		$object							Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity)
246
-	 * @param	string					$stripeacc						''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
247
-	 * @param	int						$status							Status (0=test, 1=live)
248
-	 * @param	int						$createifnotlinkedtostripe		1=Create the stripe card and the link if the card is not yet linked to a stripe card
249
-	 * @return 	\Stripe\StripeCard|null 								Stripe Card or null if not found
250
-	 */
251
-	public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $status=0, $createifnotlinkedtostripe=0)
252
-	{
253
-		global $conf, $user;
254
-
255
-		$card = null;
256
-
257
-		$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";			// stripe_card_ref is card_....
258
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa";
259
-		$sql.= " WHERE sa.rowid = " . $object->id;
260
-		//$sql.= " AND sa.entity IN (".getEntity('societe').")";
261
-		$sql.= " AND sa.type = 'card'";
262
-
263
-		dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id.", stripeacc=".$stripeacc.", status=".$status.", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
264
-		$resql = $this->db->query($sql);
265
-		if ($resql) {
266
-			$num = $this->db->num_rows($resql);
267
-			if ($num)
268
-			{
269
-				$obj = $this->db->fetch_object($resql);
270
-				$cardref = $obj->stripe_card_ref;
271
-				dol_syslog("************* cardref=".$cardref);
272
-				if ($cardref)
273
-				{
274
-					try {
275
-						if (empty($stripeacc)) {				// If the Stripe connect account not set, we use common API usage
276
-							$card = $cu->sources->retrieve($cardref);
277
-						} else {
278
-							//$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc));		// this API fails when array stripe_account is provided
279
-							$card = $cu->sources->retrieve($cardref);
280
-						}
281
-					}
282
-					catch(Exception $e)
283
-					{
284
-						$this->error = $e->getMessage();
285
-						dol_syslog($this->error, LOG_WARNING);
286
-					}
287
-				}
288
-				elseif ($createifnotlinkedtostripe)
289
-				{
290
-					$exp_date_month=$obj->exp_date_month;
291
-					$exp_date_year=$obj->exp_date_year;
292
-					$number=$obj->number;
293
-					$cvc=$obj->cvn;								// cvn in database, cvc for stripe
294
-					$cardholdername=$obj->proprio;
295
-
296
-					$dataforcard = array(
297
-						"source" => array('object'=>'card', 'exp_month'=>$exp_date_month, 'exp_year'=>$exp_date_year, 'number'=>$number, 'cvc'=>$cvc, 'name'=>$cardholdername),
298
-						"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
299
-					);
300
-
301
-					//$a = \Stripe\Stripe::getApiKey();
302
-					//var_dump($a);var_dump($stripeacc);exit;
303
-					dol_syslog("Try to create card dataforcard = ".dol_json_encode($dataforcard));
304
-					try {
305
-						if (empty($stripeacc)) {				// If the Stripe connect account not set, we use common API usage
306
-							$card = $cu->sources->create($dataforcard);
307
-						} else {
308
-							$card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc));
309
-						}
310
-
311
-						if ($card)
312
-						{
313
-							$sql = "UPDATE " . MAIN_DB_PREFIX . "societe_rib";
314
-							$sql.= " SET stripe_card_ref = '".$this->db->escape($card->id)."', card_type = '".$this->db->escape($card->brand)."',";
315
-							$sql.= " country_code = '".$this->db->escape($card->country)."',";
316
-							$sql.= " approved = ".($card->cvc_check == 'pass' ? 1 : 0);
317
-							$sql.= " WHERE rowid = " . $object->id;
318
-							$sql.= " AND type = 'card'";
319
-							$resql = $this->db->query($sql);
320
-							if (! $resql)
321
-							{
322
-								$this->error = $this->db->lasterror();
323
-							}
324
-						}
325
-						else
326
-						{
327
-							$this->error = 'Call to cu->source->create return empty card';
328
-						}
329
-					}
330
-					catch(Exception $e)
331
-					{
332
-						$this->error = $e->getMessage();
333
-						dol_syslog($this->error, LOG_WARNING);
334
-					}
335
-				}
336
-			}
337
-		}
338
-		else
339
-		{
340
-			dol_print_error($this->db);
341
-		}
342
-
343
-		return $card;
344
-	}
345
-
346
-	/**
347
-	 * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
348
-	 *
349
-	 * @param	int 	$amount									Amount to pay
350
-	 * @param	string 	$currency								EUR, GPB...
351
-	 * @param	string 	$origin									Object type to pay (order, invoice, contract...)
352
-	 * @param	int 	$item									Object id to pay
353
-	 * @param	string 	$source									src_xxxxx or card_xxxxx
354
-	 * @param	string 	$customer								Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
355
-	 * @param	string 	$account								Stripe account ref 'acc_xxxxxxxxxxxxx' via  getStripeAccount()
356
-	 * @param	int		$status									Status (0=test, 1=live)
357
-	 * @param	int		$usethirdpartyemailforreceiptemail		Use thirdparty email as receipt email
358
-	 * @param	boolean	$capture								Set capture flag to true (take payment) or false (wait)
359
-	 * @return Stripe
360
-	 */
361
-	public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
362
-	{
363
-		global $conf;
364
-
365
-		$error = 0;
366
-
367
-		if (empty($status)) $service = 'StripeTest';
368
-		else $service = 'StripeLive';
369
-
370
-		$sql = "SELECT sa.key_account as key_account, sa.fk_soc, sa.entity";
371
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
372
-		$sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'";
373
-		//$sql.= " AND sa.entity IN (".getEntity('societe').")";
374
-		$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
375
-
376
-		dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
377
-		$result = $this->db->query($sql);
378
-		if ($result) {
379
-			if ($this->db->num_rows($result)) {
380
-				$obj = $this->db->fetch_object($result);
381
-				$key = $obj->fk_soc;
382
-			} else {
383
-				$key = null;
384
-			}
385
-		} else {
386
-			$key = null;
387
-		}
388
-
389
-		$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
390
-		if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100;
391
-		else $stripeamount = $amount;
392
-
393
-		$societe = new Societe($this->db);
394
-		if ($key > 0) $societe->fetch($key);
395
-
396
-		$description = "";
397
-		$ref = "";
398
-		if ($origin == order) {
399
-			$order = new Commande($this->db);
400
-			$order->fetch($item);
401
-			$ref = $order->ref;
402
-			$description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
403
-		} elseif ($origin == invoice) {
404
-			$invoice = new Facture($this->db);
405
-			$invoice->fetch($item);
406
-			$ref = $invoice->ref;
407
-			$description = "INV=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
408
-		}
409
-
410
-		$metadata = array(
411
-			"dol_id" => "" . $item . "",
412
-			"dol_type" => "" . $origin . "",
413
-			"dol_thirdparty_id" => "" . $societe->id . "",
414
-			'dol_thirdparty_name' => $societe->name,
415
-			'dol_version'=>DOL_VERSION,
416
-			'dol_entity'=>$conf->entity,
417
-			'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])
418
-		);
419
-		$return = new Stripe($this->db);
420
-		try {
421
-			// Force to use the correct API key
422
-			global $stripearrayofkeysbyenv;
423
-			\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
424
-
425
-			if (empty($conf->stripeconnect->enabled))
426
-			{
427
-				if (preg_match('/acct_/i', $source))
428
-				{
429
-					$charge = \Stripe\Charge::create(array(
430
-						"amount" => "$stripeamount",
431
-						"currency" => "$currency",
432
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
433
-						"description" => "Stripe payment: ".$description,
434
-						"capture"  => $capture,
435
-						"metadata" => $metadata,
436
-						"source" => "$source"
437
-					));
438
-				} else {
439
-					$paymentarray = array(
440
-						"amount" => "$stripeamount",
441
-						"currency" => "$currency",
442
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
443
-						"description" => "Stripe payment: ".$description,
444
-						"capture"  => $capture,
445
-						"metadata" => $metadata,
446
-						"source" => "$source",
447
-						"customer" => "$customer"
448
-					);
449
-
450
-					if ($societe->email && $usethirdpartyemailforreceiptemail)
451
-					{
452
-						$paymentarray["receipt_email"] = $societe->email;
453
-					}
454
-
455
-					$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref"));
456
-				}
457
-			} else {
458
-
459
-				$fee = round(($amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE) * 100);
460
-				if ($fee < ($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100)) {
461
-					$fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100);
462
-				}
463
-
464
-        		$paymentarray = array(
465
-						"amount" => "$stripeamount",
466
-						"currency" => "$currency",
467
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
468
-						"description" => "Stripe payment: ".$description,
469
-						"capture"  => $capture,
470
-						"metadata" => $metadata,
471
-						"source" => "$source",
472
-						"customer" => "$customer"
473
-					);
474
-					if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
475
-					{
476
-						$paymentarray["application_fee"] = $fee;
477
-					}
478
-					if ($societe->email && $usethirdpartyemailforreceiptemail)
479
-					{
480
-						$paymentarray["receipt_email"] = $societe->email;
481
-					}
482
-
483
-					$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref","stripe_account" => "$account"));
484
-			}
485
-			if (isset($charge->id)) {}
486
-
487
-			$return->statut = 'success';
488
-			$return->id = $charge->id;
489
-			if ($charge->source->type == 'card') {
490
-				$return->message = $charge->source->card->brand . " ...." . $charge->source->card->last4;
491
-			} elseif ($charge->source->type == 'three_d_secure') {
492
-				$stripe = new Stripe($this->db);
493
-				$src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
494
-				"stripe_account" => $stripe->getStripeAccount($service)
495
-				));
496
-				$return->message = $src->card->brand . " ...." . $src->card->last4;
497
-			} else {
498
-				$return->message = $charge->id;
499
-			}
500
-		} catch (\Stripe\Error\Card $e) {
501
-			include DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
502
-			// Since it's a decline, \Stripe\Error\Card will be caught
503
-			$body = $e->getJsonBody();
504
-			$err = $body['error'];
505
-
506
-			$return->statut = 'error';
507
-			$return->id = $err['charge'];
508
-			$return->type = $err['type'];
509
-			$return->code = $err['code'];
510
-			$return->message = $err['message'];
511
-			$body = "Error: <br>" . $return->id . " " . $return->message . " ";
512
-			$subject = '[Alert] Payment error using Stripe';
513
-			$cmailfile = new CMailFile($subject, $conf->global->ONLINE_PAYMENT_SENDEMAIL, $conf->global->MAIN_INFO_SOCIETE_MAIL, $body);
514
-			$cmailfile->sendfile();
515
-
516
-			$error++;
517
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
518
-		} catch (\Stripe\Error\RateLimit $e) {
519
-			// Too many requests made to the API too quickly
520
-			$error++;
521
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
522
-		} catch (\Stripe\Error\InvalidRequest $e) {
523
-			// Invalid parameters were supplied to Stripe's API
524
-			$error++;
525
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
526
-		} catch (\Stripe\Error\Authentication $e) {
527
-			// Authentication with Stripe's API failed
528
-			// (maybe you changed API keys recently)
529
-			$error++;
530
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
531
-		} catch (\Stripe\Error\ApiConnection $e) {
532
-			// Network communication with Stripe failed
533
-			$error++;
534
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
535
-		} catch (\Stripe\Error\Base $e) {
536
-			// Display a very generic error to the user, and maybe send
537
-			// yourself an email
538
-			$error++;
539
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
540
-		} catch (Exception $e) {
541
-			// Something else happened, completely unrelated to Stripe
542
-			$error++;
543
-			dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
544
-		}
545
-		return $return;
546
-	}
44
+    public $fk_key;
45
+
46
+    /**
47
+     * @var int ID
48
+     */
49
+    public $id;
50
+
51
+    public $mode;
52
+
53
+    /**
54
+     * @var int Entity
55
+     */
56
+    public $entity;
57
+
58
+    public $statut;
59
+
60
+    public $type;
61
+
62
+    public $code;
63
+
64
+    public $message;
65
+
66
+    /**
67
+     * 	Constructor
68
+     *
69
+     * 	@param	DoliDB		$db			Database handler
70
+     */
71
+    public function __construct($db)
72
+    {
73
+        $this->db = $db;
74
+    }
75
+
76
+
77
+    /**
78
+     * Return main company OAuth Connect stripe account
79
+     *
80
+     * @param 	string	$mode		'StripeTest' or 'StripeLive'
81
+     * @return 	string				Stripe account 'acc_....' or '' if no OAuth token found
82
+     */
83
+    public function getStripeAccount($mode='StripeTest')
84
+    {
85
+        global $conf;
86
+
87
+        $sql = "SELECT tokenstring";
88
+        $sql.= " FROM ".MAIN_DB_PREFIX."oauth_token";
89
+        $sql.= " WHERE entity = ".$conf->entity;
90
+        $sql.= " AND service = '".$mode."'";
91
+
92
+        dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
93
+        $result = $this->db->query($sql);
94
+        if ($result)
95
+        {
96
+            if ($this->db->num_rows($result))
97
+            {
98
+                $obj = $this->db->fetch_object($result);
99
+                $tokenstring=$obj->tokenstring;
100
+
101
+                $tmparray = dol_json_decode($tokenstring);
102
+                $key = $tmparray->stripe_user_id;
103
+            }
104
+            else {
105
+                $tokenstring='';
106
+            }
107
+        }
108
+        else {
109
+            dol_print_error($this->db);
110
+        }
111
+
112
+        dol_syslog("No dedicated Stripe Connect account available for entity ".$conf->entity);
113
+        return $key;
114
+    }
115
+
116
+    /**
117
+     * getStripeCustomerAccount
118
+     *
119
+     * @param	int		$id		Id of third party
120
+     * @param	int		$status		Status
121
+     * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
122
+     */
123
+    public function getStripeCustomerAccount($id, $status=0)
124
+    {
125
+        include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
126
+        $societeaccount = new SocieteAccount($this->db);
127
+        return $societeaccount->getCustomerAccount($id, 'stripe', $status);		// Get thirdparty cus_...
128
+    }
129
+
130
+
131
+    /**
132
+     * Get the Stripe customer of a thirdparty (with option to create it if not linked yet)
133
+     *
134
+     * @param	Societe	$object							Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity)
135
+     * @param	string	$key							''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
136
+     * @param	int		$status							Status (0=test, 1=live)
137
+     * @param	int		$createifnotlinkedtostripe		1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer
138
+     * @return 	\Stripe\StripeCustomer|null 			Stripe Customer or null if not found
139
+     */
140
+    public function customerStripe(Societe $object, $key='', $status=0, $createifnotlinkedtostripe=0)
141
+    {
142
+        global $conf, $user;
143
+
144
+        if (empty($object->id))
145
+        {
146
+            dol_syslog("customerStripe is called with param object not loaded");
147
+            return null;
148
+        }
149
+
150
+        $customer = null;
151
+
152
+        $sql = "SELECT sa.key_account as key_account, sa.entity";			// key_account is cus_....
153
+        $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
154
+        $sql.= " WHERE sa.fk_soc = " . $object->id;
155
+        $sql.= " AND sa.entity IN (".getEntity('societe').")";
156
+        $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
157
+        $sql.= " AND key_account IS NOT NULL AND key_account <> ''";
158
+
159
+        dol_syslog(get_class($this) . "::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
160
+        $resql = $this->db->query($sql);
161
+        if ($resql) {
162
+            $num = $this->db->num_rows($resql);
163
+            if ($num)
164
+            {
165
+                $obj = $this->db->fetch_object($resql);
166
+                $tiers = $obj->key_account;
167
+
168
+                dol_syslog(get_class($this) . "::customerStripe found stripe customer key_account = ".$tiers);
169
+
170
+                // Force to use the correct API key
171
+                global $stripearrayofkeysbyenv;
172
+                \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
173
+
174
+                try {
175
+                    if (empty($key)) {				// If the Stripe connect account not set, we use common API usage
176
+                        $customer = \Stripe\Customer::retrieve("$tiers");
177
+                    } else {
178
+                        $customer = \Stripe\Customer::retrieve("$tiers", array("stripe_account" => $key));
179
+                    }
180
+                }
181
+                catch(Exception $e)
182
+                {
183
+                    $this->error = $e->getMessage();
184
+                }
185
+            }
186
+            elseif ($createifnotlinkedtostripe)
187
+            {
188
+                $dataforcustomer = array(
189
+                    "email" => $object->email,
190
+                    "description" => $object->name,
191
+                    "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
192
+                );
193
+
194
+                $vatcleaned = $object->tva_intra ? $object->tva_intra : null;
195
+
196
+                $taxinfo = array('type'=>'vat');
197
+                if ($vatcleaned)
198
+                {
199
+                    $taxinfo["tax_id"] = $vatcleaned;
200
+                }
201
+                // We force data to "null" if not defined as expected by Stripe
202
+                if (empty($vatcleaned)) $taxinfo=null;
203
+
204
+                $dataforcustomer["tax_info"] = $taxinfo;
205
+
206
+                //$a = \Stripe\Stripe::getApiKey();
207
+                //var_dump($a);var_dump($key);exit;
208
+                try {
209
+                    // Force to use the correct API key
210
+                    global $stripearrayofkeysbyenv;
211
+                    \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
212
+
213
+                    if (empty($key)) {				// If the Stripe connect account not set, we use common API usage
214
+                        $customer = \Stripe\Customer::create($dataforcustomer);
215
+                    } else {
216
+                        $customer = \Stripe\Customer::create($dataforcustomer, array("stripe_account" => $key));
217
+                    }
218
+
219
+                    $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)";
220
+                    $sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer->id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")";
221
+                    $resql = $this->db->query($sql);
222
+                    if (! $resql)
223
+                    {
224
+                        $this->error = $this->db->lasterror();
225
+                    }
226
+                }
227
+                catch(Exception $e)
228
+                {
229
+                    $this->error = $e->getMessage();
230
+                }
231
+            }
232
+        }
233
+        else
234
+        {
235
+            dol_print_error($this->db);
236
+        }
237
+
238
+        return $customer;
239
+    }
240
+
241
+    /**
242
+     * Get the Stripe card of a company payment mode (with option to create it on Stripe if not linked yet)
243
+     *
244
+     * @param	\Stripe\StripeCustomer	$cu								Object stripe customer
245
+     * @param	CompanyPaymentMode		$object							Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity)
246
+     * @param	string					$stripeacc						''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
247
+     * @param	int						$status							Status (0=test, 1=live)
248
+     * @param	int						$createifnotlinkedtostripe		1=Create the stripe card and the link if the card is not yet linked to a stripe card
249
+     * @return 	\Stripe\StripeCard|null 								Stripe Card or null if not found
250
+     */
251
+    public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $status=0, $createifnotlinkedtostripe=0)
252
+    {
253
+        global $conf, $user;
254
+
255
+        $card = null;
256
+
257
+        $sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";			// stripe_card_ref is card_....
258
+        $sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa";
259
+        $sql.= " WHERE sa.rowid = " . $object->id;
260
+        //$sql.= " AND sa.entity IN (".getEntity('societe').")";
261
+        $sql.= " AND sa.type = 'card'";
262
+
263
+        dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id.", stripeacc=".$stripeacc.", status=".$status.", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
264
+        $resql = $this->db->query($sql);
265
+        if ($resql) {
266
+            $num = $this->db->num_rows($resql);
267
+            if ($num)
268
+            {
269
+                $obj = $this->db->fetch_object($resql);
270
+                $cardref = $obj->stripe_card_ref;
271
+                dol_syslog("************* cardref=".$cardref);
272
+                if ($cardref)
273
+                {
274
+                    try {
275
+                        if (empty($stripeacc)) {				// If the Stripe connect account not set, we use common API usage
276
+                            $card = $cu->sources->retrieve($cardref);
277
+                        } else {
278
+                            //$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc));		// this API fails when array stripe_account is provided
279
+                            $card = $cu->sources->retrieve($cardref);
280
+                        }
281
+                    }
282
+                    catch(Exception $e)
283
+                    {
284
+                        $this->error = $e->getMessage();
285
+                        dol_syslog($this->error, LOG_WARNING);
286
+                    }
287
+                }
288
+                elseif ($createifnotlinkedtostripe)
289
+                {
290
+                    $exp_date_month=$obj->exp_date_month;
291
+                    $exp_date_year=$obj->exp_date_year;
292
+                    $number=$obj->number;
293
+                    $cvc=$obj->cvn;								// cvn in database, cvc for stripe
294
+                    $cardholdername=$obj->proprio;
295
+
296
+                    $dataforcard = array(
297
+                        "source" => array('object'=>'card', 'exp_month'=>$exp_date_month, 'exp_year'=>$exp_date_year, 'number'=>$number, 'cvc'=>$cvc, 'name'=>$cardholdername),
298
+                        "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
299
+                    );
300
+
301
+                    //$a = \Stripe\Stripe::getApiKey();
302
+                    //var_dump($a);var_dump($stripeacc);exit;
303
+                    dol_syslog("Try to create card dataforcard = ".dol_json_encode($dataforcard));
304
+                    try {
305
+                        if (empty($stripeacc)) {				// If the Stripe connect account not set, we use common API usage
306
+                            $card = $cu->sources->create($dataforcard);
307
+                        } else {
308
+                            $card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc));
309
+                        }
310
+
311
+                        if ($card)
312
+                        {
313
+                            $sql = "UPDATE " . MAIN_DB_PREFIX . "societe_rib";
314
+                            $sql.= " SET stripe_card_ref = '".$this->db->escape($card->id)."', card_type = '".$this->db->escape($card->brand)."',";
315
+                            $sql.= " country_code = '".$this->db->escape($card->country)."',";
316
+                            $sql.= " approved = ".($card->cvc_check == 'pass' ? 1 : 0);
317
+                            $sql.= " WHERE rowid = " . $object->id;
318
+                            $sql.= " AND type = 'card'";
319
+                            $resql = $this->db->query($sql);
320
+                            if (! $resql)
321
+                            {
322
+                                $this->error = $this->db->lasterror();
323
+                            }
324
+                        }
325
+                        else
326
+                        {
327
+                            $this->error = 'Call to cu->source->create return empty card';
328
+                        }
329
+                    }
330
+                    catch(Exception $e)
331
+                    {
332
+                        $this->error = $e->getMessage();
333
+                        dol_syslog($this->error, LOG_WARNING);
334
+                    }
335
+                }
336
+            }
337
+        }
338
+        else
339
+        {
340
+            dol_print_error($this->db);
341
+        }
342
+
343
+        return $card;
344
+    }
345
+
346
+    /**
347
+     * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
348
+     *
349
+     * @param	int 	$amount									Amount to pay
350
+     * @param	string 	$currency								EUR, GPB...
351
+     * @param	string 	$origin									Object type to pay (order, invoice, contract...)
352
+     * @param	int 	$item									Object id to pay
353
+     * @param	string 	$source									src_xxxxx or card_xxxxx
354
+     * @param	string 	$customer								Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
355
+     * @param	string 	$account								Stripe account ref 'acc_xxxxxxxxxxxxx' via  getStripeAccount()
356
+     * @param	int		$status									Status (0=test, 1=live)
357
+     * @param	int		$usethirdpartyemailforreceiptemail		Use thirdparty email as receipt email
358
+     * @param	boolean	$capture								Set capture flag to true (take payment) or false (wait)
359
+     * @return Stripe
360
+     */
361
+    public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
362
+    {
363
+        global $conf;
364
+
365
+        $error = 0;
366
+
367
+        if (empty($status)) $service = 'StripeTest';
368
+        else $service = 'StripeLive';
369
+
370
+        $sql = "SELECT sa.key_account as key_account, sa.fk_soc, sa.entity";
371
+        $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
372
+        $sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'";
373
+        //$sql.= " AND sa.entity IN (".getEntity('societe').")";
374
+        $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
375
+
376
+        dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
377
+        $result = $this->db->query($sql);
378
+        if ($result) {
379
+            if ($this->db->num_rows($result)) {
380
+                $obj = $this->db->fetch_object($result);
381
+                $key = $obj->fk_soc;
382
+            } else {
383
+                $key = null;
384
+            }
385
+        } else {
386
+            $key = null;
387
+        }
388
+
389
+        $arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
390
+        if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100;
391
+        else $stripeamount = $amount;
392
+
393
+        $societe = new Societe($this->db);
394
+        if ($key > 0) $societe->fetch($key);
395
+
396
+        $description = "";
397
+        $ref = "";
398
+        if ($origin == order) {
399
+            $order = new Commande($this->db);
400
+            $order->fetch($item);
401
+            $ref = $order->ref;
402
+            $description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
403
+        } elseif ($origin == invoice) {
404
+            $invoice = new Facture($this->db);
405
+            $invoice->fetch($item);
406
+            $ref = $invoice->ref;
407
+            $description = "INV=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
408
+        }
409
+
410
+        $metadata = array(
411
+            "dol_id" => "" . $item . "",
412
+            "dol_type" => "" . $origin . "",
413
+            "dol_thirdparty_id" => "" . $societe->id . "",
414
+            'dol_thirdparty_name' => $societe->name,
415
+            'dol_version'=>DOL_VERSION,
416
+            'dol_entity'=>$conf->entity,
417
+            'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])
418
+        );
419
+        $return = new Stripe($this->db);
420
+        try {
421
+            // Force to use the correct API key
422
+            global $stripearrayofkeysbyenv;
423
+            \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
424
+
425
+            if (empty($conf->stripeconnect->enabled))
426
+            {
427
+                if (preg_match('/acct_/i', $source))
428
+                {
429
+                    $charge = \Stripe\Charge::create(array(
430
+                        "amount" => "$stripeamount",
431
+                        "currency" => "$currency",
432
+                        "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
433
+                        "description" => "Stripe payment: ".$description,
434
+                        "capture"  => $capture,
435
+                        "metadata" => $metadata,
436
+                        "source" => "$source"
437
+                    ));
438
+                } else {
439
+                    $paymentarray = array(
440
+                        "amount" => "$stripeamount",
441
+                        "currency" => "$currency",
442
+                        "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
443
+                        "description" => "Stripe payment: ".$description,
444
+                        "capture"  => $capture,
445
+                        "metadata" => $metadata,
446
+                        "source" => "$source",
447
+                        "customer" => "$customer"
448
+                    );
449
+
450
+                    if ($societe->email && $usethirdpartyemailforreceiptemail)
451
+                    {
452
+                        $paymentarray["receipt_email"] = $societe->email;
453
+                    }
454
+
455
+                    $charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref"));
456
+                }
457
+            } else {
458
+
459
+                $fee = round(($amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE) * 100);
460
+                if ($fee < ($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100)) {
461
+                    $fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100);
462
+                }
463
+
464
+                $paymentarray = array(
465
+                        "amount" => "$stripeamount",
466
+                        "currency" => "$currency",
467
+                        "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
468
+                        "description" => "Stripe payment: ".$description,
469
+                        "capture"  => $capture,
470
+                        "metadata" => $metadata,
471
+                        "source" => "$source",
472
+                        "customer" => "$customer"
473
+                    );
474
+                    if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
475
+                    {
476
+                        $paymentarray["application_fee"] = $fee;
477
+                    }
478
+                    if ($societe->email && $usethirdpartyemailforreceiptemail)
479
+                    {
480
+                        $paymentarray["receipt_email"] = $societe->email;
481
+                    }
482
+
483
+                    $charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref","stripe_account" => "$account"));
484
+            }
485
+            if (isset($charge->id)) {}
486
+
487
+            $return->statut = 'success';
488
+            $return->id = $charge->id;
489
+            if ($charge->source->type == 'card') {
490
+                $return->message = $charge->source->card->brand . " ...." . $charge->source->card->last4;
491
+            } elseif ($charge->source->type == 'three_d_secure') {
492
+                $stripe = new Stripe($this->db);
493
+                $src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
494
+                "stripe_account" => $stripe->getStripeAccount($service)
495
+                ));
496
+                $return->message = $src->card->brand . " ...." . $src->card->last4;
497
+            } else {
498
+                $return->message = $charge->id;
499
+            }
500
+        } catch (\Stripe\Error\Card $e) {
501
+            include DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
502
+            // Since it's a decline, \Stripe\Error\Card will be caught
503
+            $body = $e->getJsonBody();
504
+            $err = $body['error'];
505
+
506
+            $return->statut = 'error';
507
+            $return->id = $err['charge'];
508
+            $return->type = $err['type'];
509
+            $return->code = $err['code'];
510
+            $return->message = $err['message'];
511
+            $body = "Error: <br>" . $return->id . " " . $return->message . " ";
512
+            $subject = '[Alert] Payment error using Stripe';
513
+            $cmailfile = new CMailFile($subject, $conf->global->ONLINE_PAYMENT_SENDEMAIL, $conf->global->MAIN_INFO_SOCIETE_MAIL, $body);
514
+            $cmailfile->sendfile();
515
+
516
+            $error++;
517
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
518
+        } catch (\Stripe\Error\RateLimit $e) {
519
+            // Too many requests made to the API too quickly
520
+            $error++;
521
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
522
+        } catch (\Stripe\Error\InvalidRequest $e) {
523
+            // Invalid parameters were supplied to Stripe's API
524
+            $error++;
525
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
526
+        } catch (\Stripe\Error\Authentication $e) {
527
+            // Authentication with Stripe's API failed
528
+            // (maybe you changed API keys recently)
529
+            $error++;
530
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
531
+        } catch (\Stripe\Error\ApiConnection $e) {
532
+            // Network communication with Stripe failed
533
+            $error++;
534
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
535
+        } catch (\Stripe\Error\Base $e) {
536
+            // Display a very generic error to the user, and maybe send
537
+            // yourself an email
538
+            $error++;
539
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
540
+        } catch (Exception $e) {
541
+            // Something else happened, completely unrelated to Stripe
542
+            $error++;
543
+            dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
544
+        }
545
+        return $return;
546
+    }
547 547
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
21 21
 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
22 22
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
23
-require_once DOL_DOCUMENT_ROOT.'/stripe/config.php';						// This set stripe global env
23
+require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; // This set stripe global env
24 24
 
25 25
 
26 26
 /**
@@ -80,29 +80,29 @@  discard block
 block discarded – undo
80 80
 	 * @param 	string	$mode		'StripeTest' or 'StripeLive'
81 81
 	 * @return 	string				Stripe account 'acc_....' or '' if no OAuth token found
82 82
 	 */
83
-	public function getStripeAccount($mode='StripeTest')
83
+	public function getStripeAccount($mode = 'StripeTest')
84 84
 	{
85 85
 		global $conf;
86 86
 
87 87
 		$sql = "SELECT tokenstring";
88
-		$sql.= " FROM ".MAIN_DB_PREFIX."oauth_token";
89
-		$sql.= " WHERE entity = ".$conf->entity;
90
-		$sql.= " AND service = '".$mode."'";
88
+		$sql .= " FROM ".MAIN_DB_PREFIX."oauth_token";
89
+		$sql .= " WHERE entity = ".$conf->entity;
90
+		$sql .= " AND service = '".$mode."'";
91 91
 
92
-		dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
92
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
93 93
 		$result = $this->db->query($sql);
94 94
     	if ($result)
95 95
 		{
96 96
 			if ($this->db->num_rows($result))
97 97
 			{
98 98
 				$obj = $this->db->fetch_object($result);
99
-    			$tokenstring=$obj->tokenstring;
99
+    			$tokenstring = $obj->tokenstring;
100 100
 
101 101
     			$tmparray = dol_json_decode($tokenstring);
102 102
     			$key = $tmparray->stripe_user_id;
103 103
     		}
104 104
     		else {
105
-    			$tokenstring='';
105
+    			$tokenstring = '';
106 106
     		}
107 107
     	}
108 108
     	else {
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
 	 * @param	int		$status		Status
121 121
 	 * @return	string				Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
122 122
 	 */
123
-	public function getStripeCustomerAccount($id, $status=0)
123
+	public function getStripeCustomerAccount($id, $status = 0)
124 124
 	{
125 125
 		include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
126 126
 		$societeaccount = new SocieteAccount($this->db);
127
-		return $societeaccount->getCustomerAccount($id, 'stripe', $status);		// Get thirdparty cus_...
127
+		return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cus_...
128 128
 	}
129 129
 
130 130
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @param	int		$createifnotlinkedtostripe		1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer
138 138
 	 * @return 	\Stripe\StripeCustomer|null 			Stripe Customer or null if not found
139 139
 	 */
140
-	public function customerStripe(Societe $object, $key='', $status=0, $createifnotlinkedtostripe=0)
140
+	public function customerStripe(Societe $object, $key = '', $status = 0, $createifnotlinkedtostripe = 0)
141 141
 	{
142 142
 		global $conf, $user;
143 143
 
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 
150 150
 		$customer = null;
151 151
 
152
-		$sql = "SELECT sa.key_account as key_account, sa.entity";			// key_account is cus_....
153
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
154
-		$sql.= " WHERE sa.fk_soc = " . $object->id;
155
-		$sql.= " AND sa.entity IN (".getEntity('societe').")";
156
-		$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
157
-		$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
152
+		$sql = "SELECT sa.key_account as key_account, sa.entity"; // key_account is cus_....
153
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
154
+		$sql .= " WHERE sa.fk_soc = ".$object->id;
155
+		$sql .= " AND sa.entity IN (".getEntity('societe').")";
156
+		$sql .= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
157
+		$sql .= " AND key_account IS NOT NULL AND key_account <> ''";
158 158
 
159
-		dol_syslog(get_class($this) . "::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
159
+		dol_syslog(get_class($this)."::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
160 160
 		$resql = $this->db->query($sql);
161 161
 		if ($resql) {
162 162
 			$num = $this->db->num_rows($resql);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 				$obj = $this->db->fetch_object($resql);
166 166
 				$tiers = $obj->key_account;
167 167
 
168
-				dol_syslog(get_class($this) . "::customerStripe found stripe customer key_account = ".$tiers);
168
+				dol_syslog(get_class($this)."::customerStripe found stripe customer key_account = ".$tiers);
169 169
 
170 170
 				// Force to use the correct API key
171 171
 				global $stripearrayofkeysbyenv;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 						$customer = \Stripe\Customer::retrieve("$tiers", array("stripe_account" => $key));
179 179
 					}
180 180
 				}
181
-				catch(Exception $e)
181
+				catch (Exception $e)
182 182
 				{
183 183
 					$this->error = $e->getMessage();
184 184
 				}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 				$dataforcustomer = array(
189 189
 					"email" => $object->email,
190 190
 					"description" => $object->name,
191
-					"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
191
+					"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR']))
192 192
 				);
193 193
 
194 194
 				$vatcleaned = $object->tva_intra ? $object->tva_intra : null;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 					$taxinfo["tax_id"] = $vatcleaned;
200 200
 				}
201 201
 				// We force data to "null" if not defined as expected by Stripe
202
-				if (empty($vatcleaned)) $taxinfo=null;
202
+				if (empty($vatcleaned)) $taxinfo = null;
203 203
 
204 204
 				$dataforcustomer["tax_info"] = $taxinfo;
205 205
 
@@ -216,15 +216,15 @@  discard block
 block discarded – undo
216 216
 						$customer = \Stripe\Customer::create($dataforcustomer, array("stripe_account" => $key));
217 217
 					}
218 218
 
219
-					$sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)";
220
-					$sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer->id)."', 'stripe', " . $status . ", " . $conf->entity . ", '".$this->db->idate(dol_now())."', ".$user->id.")";
219
+					$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)";
220
+					$sql .= " VALUES (".$object->id.", '', '".$this->db->escape($customer->id)."', 'stripe', ".$status.", ".$conf->entity.", '".$this->db->idate(dol_now())."', ".$user->id.")";
221 221
 					$resql = $this->db->query($sql);
222
-					if (! $resql)
222
+					if (!$resql)
223 223
 					{
224 224
 						$this->error = $this->db->lasterror();
225 225
 					}
226 226
 				}
227
-				catch(Exception $e)
227
+				catch (Exception $e)
228 228
 				{
229 229
 					$this->error = $e->getMessage();
230 230
 				}
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
 	 * @param	int						$createifnotlinkedtostripe		1=Create the stripe card and the link if the card is not yet linked to a stripe card
249 249
 	 * @return 	\Stripe\StripeCard|null 								Stripe Card or null if not found
250 250
 	 */
251
-	public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $status=0, $createifnotlinkedtostripe=0)
251
+	public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0)
252 252
 	{
253 253
 		global $conf, $user;
254 254
 
255 255
 		$card = null;
256 256
 
257
-		$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";			// stripe_card_ref is card_....
258
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa";
259
-		$sql.= " WHERE sa.rowid = " . $object->id;
257
+		$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn"; // stripe_card_ref is card_....
258
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as sa";
259
+		$sql .= " WHERE sa.rowid = ".$object->id;
260 260
 		//$sql.= " AND sa.entity IN (".getEntity('societe').")";
261
-		$sql.= " AND sa.type = 'card'";
261
+		$sql .= " AND sa.type = 'card'";
262 262
 
263
-		dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id.", stripeacc=".$stripeacc.", status=".$status.", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
263
+		dol_syslog(get_class($this)."::fetch search stripe card id for paymentmode id=".$object->id.", stripeacc=".$stripeacc.", status=".$status.", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
264 264
 		$resql = $this->db->query($sql);
265 265
 		if ($resql) {
266 266
 			$num = $this->db->num_rows($resql);
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 							$card = $cu->sources->retrieve($cardref);
280 280
 						}
281 281
 					}
282
-					catch(Exception $e)
282
+					catch (Exception $e)
283 283
 					{
284 284
 						$this->error = $e->getMessage();
285 285
 						dol_syslog($this->error, LOG_WARNING);
@@ -287,15 +287,15 @@  discard block
 block discarded – undo
287 287
 				}
288 288
 				elseif ($createifnotlinkedtostripe)
289 289
 				{
290
-					$exp_date_month=$obj->exp_date_month;
291
-					$exp_date_year=$obj->exp_date_year;
292
-					$number=$obj->number;
293
-					$cvc=$obj->cvn;								// cvn in database, cvc for stripe
294
-					$cardholdername=$obj->proprio;
290
+					$exp_date_month = $obj->exp_date_month;
291
+					$exp_date_year = $obj->exp_date_year;
292
+					$number = $obj->number;
293
+					$cvc = $obj->cvn; // cvn in database, cvc for stripe
294
+					$cardholdername = $obj->proprio;
295 295
 
296 296
 					$dataforcard = array(
297 297
 						"source" => array('object'=>'card', 'exp_month'=>$exp_date_month, 'exp_year'=>$exp_date_year, 'number'=>$number, 'cvc'=>$cvc, 'name'=>$cardholdername),
298
-						"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
298
+						"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR']))
299 299
 					);
300 300
 
301 301
 					//$a = \Stripe\Stripe::getApiKey();
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
 
311 311
 						if ($card)
312 312
 						{
313
-							$sql = "UPDATE " . MAIN_DB_PREFIX . "societe_rib";
314
-							$sql.= " SET stripe_card_ref = '".$this->db->escape($card->id)."', card_type = '".$this->db->escape($card->brand)."',";
315
-							$sql.= " country_code = '".$this->db->escape($card->country)."',";
316
-							$sql.= " approved = ".($card->cvc_check == 'pass' ? 1 : 0);
317
-							$sql.= " WHERE rowid = " . $object->id;
318
-							$sql.= " AND type = 'card'";
313
+							$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib";
314
+							$sql .= " SET stripe_card_ref = '".$this->db->escape($card->id)."', card_type = '".$this->db->escape($card->brand)."',";
315
+							$sql .= " country_code = '".$this->db->escape($card->country)."',";
316
+							$sql .= " approved = ".($card->cvc_check == 'pass' ? 1 : 0);
317
+							$sql .= " WHERE rowid = ".$object->id;
318
+							$sql .= " AND type = 'card'";
319 319
 							$resql = $this->db->query($sql);
320
-							if (! $resql)
320
+							if (!$resql)
321 321
 							{
322 322
 								$this->error = $this->db->lasterror();
323 323
 							}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 							$this->error = 'Call to cu->source->create return empty card';
328 328
 						}
329 329
 					}
330
-					catch(Exception $e)
330
+					catch (Exception $e)
331 331
 					{
332 332
 						$this->error = $e->getMessage();
333 333
 						dol_syslog($this->error, LOG_WARNING);
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 * @param	boolean	$capture								Set capture flag to true (take payment) or false (wait)
359 359
 	 * @return Stripe
360 360
 	 */
361
-	public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
361
+	public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status = 0, $usethirdpartyemailforreceiptemail = 0, $capture = true)
362 362
 	{
363 363
 		global $conf;
364 364
 
@@ -368,12 +368,12 @@  discard block
 block discarded – undo
368 368
 		else $service = 'StripeLive';
369 369
 
370 370
 		$sql = "SELECT sa.key_account as key_account, sa.fk_soc, sa.entity";
371
-		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
372
-		$sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'";
371
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
372
+		$sql .= " WHERE sa.key_account = '".$this->db->escape($customer)."'";
373 373
 		//$sql.= " AND sa.entity IN (".getEntity('societe').")";
374
-		$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
374
+		$sql .= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
375 375
 
376
-		dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
376
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
377 377
 		$result = $this->db->query($sql);
378 378
 		if ($result) {
379 379
 			if ($this->db->num_rows($result)) {
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 			$key = null;
387 387
 		}
388 388
 
389
-		$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
390
-		if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100;
389
+		$arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
390
+		if (!in_array($currency, $arrayzerounitcurrency)) $stripeamount = $amount * 100;
391 391
 		else $stripeamount = $amount;
392 392
 
393 393
 		$societe = new Societe($this->db);
@@ -399,22 +399,22 @@  discard block
 block discarded – undo
399 399
 			$order = new Commande($this->db);
400 400
 			$order->fetch($item);
401 401
 			$ref = $order->ref;
402
-			$description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
402
+			$description = "ORD=".$ref.".CUS=".$societe->id.".PM=stripe";
403 403
 		} elseif ($origin == invoice) {
404 404
 			$invoice = new Facture($this->db);
405 405
 			$invoice->fetch($item);
406 406
 			$ref = $invoice->ref;
407
-			$description = "INV=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
407
+			$description = "INV=".$ref.".CUS=".$societe->id.".PM=stripe";
408 408
 		}
409 409
 
410 410
 		$metadata = array(
411
-			"dol_id" => "" . $item . "",
412
-			"dol_type" => "" . $origin . "",
413
-			"dol_thirdparty_id" => "" . $societe->id . "",
411
+			"dol_id" => "".$item."",
412
+			"dol_type" => "".$origin."",
413
+			"dol_thirdparty_id" => "".$societe->id."",
414 414
 			'dol_thirdparty_name' => $societe->name,
415 415
 			'dol_version'=>DOL_VERSION,
416 416
 			'dol_entity'=>$conf->entity,
417
-			'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])
417
+			'ipaddress'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'])
418 418
 		);
419 419
 		$return = new Stripe($this->db);
420 420
 		try {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 					$charge = \Stripe\Charge::create(array(
430 430
 						"amount" => "$stripeamount",
431 431
 						"currency" => "$currency",
432
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
432
+						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
433 433
 						"description" => "Stripe payment: ".$description,
434 434
 						"capture"  => $capture,
435 435
 						"metadata" => $metadata,
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 					$paymentarray = array(
440 440
 						"amount" => "$stripeamount",
441 441
 						"currency" => "$currency",
442
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
442
+						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
443 443
 						"description" => "Stripe payment: ".$description,
444 444
 						"capture"  => $capture,
445 445
 						"metadata" => $metadata,
@@ -464,14 +464,14 @@  discard block
 block discarded – undo
464 464
         		$paymentarray = array(
465 465
 						"amount" => "$stripeamount",
466 466
 						"currency" => "$currency",
467
-						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
467
+						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
468 468
 						"description" => "Stripe payment: ".$description,
469 469
 						"capture"  => $capture,
470 470
 						"metadata" => $metadata,
471 471
 						"source" => "$source",
472 472
 						"customer" => "$customer"
473 473
 					);
474
-					if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
474
+					if ($conf->entity != $conf->global->STRIPECONNECT_PRINCIPAL && $fee > 0)
475 475
 					{
476 476
 						$paymentarray["application_fee"] = $fee;
477 477
 					}
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
 						$paymentarray["receipt_email"] = $societe->email;
481 481
 					}
482 482
 
483
-					$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref","stripe_account" => "$account"));
483
+					$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref", "stripe_account" => "$account"));
484 484
 			}
485 485
 			if (isset($charge->id)) {}
486 486
 
487 487
 			$return->statut = 'success';
488 488
 			$return->id = $charge->id;
489 489
 			if ($charge->source->type == 'card') {
490
-				$return->message = $charge->source->card->brand . " ...." . $charge->source->card->last4;
490
+				$return->message = $charge->source->card->brand." ....".$charge->source->card->last4;
491 491
 			} elseif ($charge->source->type == 'three_d_secure') {
492 492
 				$stripe = new Stripe($this->db);
493
-				$src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
493
+				$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card."", array(
494 494
 				"stripe_account" => $stripe->getStripeAccount($service)
495 495
 				));
496
-				$return->message = $src->card->brand . " ...." . $src->card->last4;
496
+				$return->message = $src->card->brand." ....".$src->card->last4;
497 497
 			} else {
498 498
 				$return->message = $charge->id;
499 499
 			}
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 			$return->type = $err['type'];
509 509
 			$return->code = $err['code'];
510 510
 			$return->message = $err['message'];
511
-			$body = "Error: <br>" . $return->id . " " . $return->message . " ";
511
+			$body = "Error: <br>".$return->id." ".$return->message." ";
512 512
 			$subject = '[Alert] Payment error using Stripe';
513 513
 			$cmailfile = new CMailFile($subject, $conf->global->ONLINE_PAYMENT_SENDEMAIL, $conf->global->MAIN_INFO_SOCIETE_MAIL, $body);
514 514
 			$cmailfile->sendfile();
Please login to merge, or discard this patch.
Braces   +27 added lines, -28 removed lines patch added patch discarded remove patch
@@ -100,12 +100,10 @@  discard block
 block discarded – undo
100 100
 
101 101
     			$tmparray = dol_json_decode($tokenstring);
102 102
     			$key = $tmparray->stripe_user_id;
103
-    		}
104
-    		else {
103
+    		} else {
105 104
     			$tokenstring='';
106 105
     		}
107
-    	}
108
-    	else {
106
+    	} else {
109 107
     		dol_print_error($this->db);
110 108
     	}
111 109
 
@@ -177,13 +175,11 @@  discard block
 block discarded – undo
177 175
 					} else {
178 176
 						$customer = \Stripe\Customer::retrieve("$tiers", array("stripe_account" => $key));
179 177
 					}
180
-				}
181
-				catch(Exception $e)
178
+				} catch(Exception $e)
182 179
 				{
183 180
 					$this->error = $e->getMessage();
184 181
 				}
185
-			}
186
-			elseif ($createifnotlinkedtostripe)
182
+			} elseif ($createifnotlinkedtostripe)
187 183
 			{
188 184
 				$dataforcustomer = array(
189 185
 					"email" => $object->email,
@@ -199,7 +195,9 @@  discard block
 block discarded – undo
199 195
 					$taxinfo["tax_id"] = $vatcleaned;
200 196
 				}
201 197
 				// We force data to "null" if not defined as expected by Stripe
202
-				if (empty($vatcleaned)) $taxinfo=null;
198
+				if (empty($vatcleaned)) {
199
+				    $taxinfo=null;
200
+				}
203 201
 
204 202
 				$dataforcustomer["tax_info"] = $taxinfo;
205 203
 
@@ -223,14 +221,12 @@  discard block
 block discarded – undo
223 221
 					{
224 222
 						$this->error = $this->db->lasterror();
225 223
 					}
226
-				}
227
-				catch(Exception $e)
224
+				} catch(Exception $e)
228 225
 				{
229 226
 					$this->error = $e->getMessage();
230 227
 				}
231 228
 			}
232
-		}
233
-		else
229
+		} else
234 230
 		{
235 231
 			dol_print_error($this->db);
236 232
 		}
@@ -278,14 +274,12 @@  discard block
 block discarded – undo
278 274
 							//$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc));		// this API fails when array stripe_account is provided
279 275
 							$card = $cu->sources->retrieve($cardref);
280 276
 						}
281
-					}
282
-					catch(Exception $e)
277
+					} catch(Exception $e)
283 278
 					{
284 279
 						$this->error = $e->getMessage();
285 280
 						dol_syslog($this->error, LOG_WARNING);
286 281
 					}
287
-				}
288
-				elseif ($createifnotlinkedtostripe)
282
+				} elseif ($createifnotlinkedtostripe)
289 283
 				{
290 284
 					$exp_date_month=$obj->exp_date_month;
291 285
 					$exp_date_year=$obj->exp_date_year;
@@ -321,21 +315,18 @@  discard block
 block discarded – undo
321 315
 							{
322 316
 								$this->error = $this->db->lasterror();
323 317
 							}
324
-						}
325
-						else
318
+						} else
326 319
 						{
327 320
 							$this->error = 'Call to cu->source->create return empty card';
328 321
 						}
329
-					}
330
-					catch(Exception $e)
322
+					} catch(Exception $e)
331 323
 					{
332 324
 						$this->error = $e->getMessage();
333 325
 						dol_syslog($this->error, LOG_WARNING);
334 326
 					}
335 327
 				}
336 328
 			}
337
-		}
338
-		else
329
+		} else
339 330
 		{
340 331
 			dol_print_error($this->db);
341 332
 		}
@@ -364,8 +355,11 @@  discard block
 block discarded – undo
364 355
 
365 356
 		$error = 0;
366 357
 
367
-		if (empty($status)) $service = 'StripeTest';
368
-		else $service = 'StripeLive';
358
+		if (empty($status)) {
359
+		    $service = 'StripeTest';
360
+		} else {
361
+		    $service = 'StripeLive';
362
+		}
369 363
 
370 364
 		$sql = "SELECT sa.key_account as key_account, sa.fk_soc, sa.entity";
371 365
 		$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
@@ -387,11 +381,16 @@  discard block
 block discarded – undo
387 381
 		}
388 382
 
389 383
 		$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
390
-		if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100;
391
-		else $stripeamount = $amount;
384
+		if (! in_array($currency, $arrayzerounitcurrency)) {
385
+		    $stripeamount=$amount * 100;
386
+		} else {
387
+		    $stripeamount = $amount;
388
+		}
392 389
 
393 390
 		$societe = new Societe($this->db);
394
-		if ($key > 0) $societe->fetch($key);
391
+		if ($key > 0) {
392
+		    $societe->fetch($key);
393
+		}
395 394
 
396 395
 		$description = "";
397 396
 		$ref = "";
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/class/actions_stripe.class.php 3 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -36,203 +36,203 @@
 block discarded – undo
36 36
  */
37 37
 class ActionsStripeconnect
38 38
 {
39
-	/**
39
+    /**
40 40
      * @var DoliDB Database handler.
41 41
      */
42 42
     public $db;
43 43
 
44
-	private $config=array();
44
+    private $config=array();
45 45
 
46
-	// For Hookmanager return
47
-	public $resprints;
48
-	public $results=array();
46
+    // For Hookmanager return
47
+    public $resprints;
48
+    public $results=array();
49 49
 
50 50
 
51
-	/**
52
-	 *	Constructor
53
-	 *
54
-	 *	@param	DoliDB	$db		Database handler
55
-	 */
56
-	function __construct($db)
57
-	{
58
-		$this->db = $db;
59
-	}
60
-
61
-
62
-	/**
63
-	 * formObjectOptions
64
-	 *
65
-	 * @param	array	$parameters		Parameters
66
-	 * @param	Object	$object			Object
67
-	 * @param	string	$action			Action
51
+    /**
52
+     *	Constructor
53
+     *
54
+     *	@param	DoliDB	$db		Database handler
55
+     */
56
+    function __construct($db)
57
+    {
58
+        $this->db = $db;
59
+    }
60
+
61
+
62
+    /**
63
+     * formObjectOptions
64
+     *
65
+     * @param	array	$parameters		Parameters
66
+     * @param	Object	$object			Object
67
+     * @param	string	$action			Action
68 68
      * @return bool
69
-	 */
70
-	function formObjectOptions($parameters, &$object, &$action)
71
-	{
72
-		global $db,$conf,$user,$langs,$form;
73
-
74
-		if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
75
-		{
76
-			$service = 'StripeTest';
77
-			dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
78
-		}
79
-		else
80
-		{
81
-			$service = 'StripeLive';
82
-		}
83
-
84
-		if (is_array($parameters) && ! empty($parameters))
85
-		{
86
-			foreach($parameters as $key=>$value)
87
-			{
88
-				$key=$value;
89
-			}
90
-		}
91
-
92
-
93
-		if (is_object($object) && $object->element == 'societe')
94
-		{
95
-			$this->resprints.= '<tr><td>';
96
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
97
-			$this->resprints.= $langs->trans('StripeCustomer');
98
-			$this->resprints.= '<td><td align="right">';
99
-			//				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
100
-			$this->resprints.= '</td></tr></table>';
101
-			$this->resprints.= '</td>';
102
-			$this->resprints.= '<td colspan="3">';
103
-			$stripe=new Stripe($db);
104
-			if ($stripe->getStripeAccount($service)&&$object->client!=0) {
105
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
106
-				$this->resprints.= $customer->id;
107
-			}
108
-			else {
109
-				$this->resprints.= $langs->trans("NoStripe");
110
-			}
111
-			$this->resprints.= '</td></tr>';
112
-		}
113
-		elseif (is_object($object) && $object->element == 'member'){
114
-			$this->resprints.= '<tr><td>';
115
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
116
-			$this->resprints.= $langs->trans('StripeCustomer');
117
-			$this->resprints.= '<td><td align="right">';
118
-			$this->resprints.= '</td></tr></table>';
119
-			$this->resprints.= '</td>';
120
-			$this->resprints.= '<td colspan="3">';
121
-			$stripe=new Stripe($db);
122
-			if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
123
-				$object->fetch_thirdparty();
124
-				$customer=$stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
125
-				$this->resprints.= $customer->id;
126
-			}
127
-			else {
128
-				$this->resprints.= $langs->trans("NoStripe");
129
-			}
130
-			$this->resprints.= '</td></tr>';
131
-
132
-			$this->resprints.= '<tr><td>';
133
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
134
-			$this->resprints.= $langs->trans('SubscriptionStripe');
135
-			$this->resprints.= '<td><td align="right">';
136
-			$this->resprints.= '</td></tr></table>';
137
-			$this->resprints.= '</td>';
138
-			$this->resprints.= '<td colspan="3">';
139
-			$stripe=new Stripe($db);
140
-			if (7==4) {
141
-				$object->fetch_thirdparty();
142
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
143
-				$this->resprints.= $customer->id;
144
-			}
145
-			else {
146
-				$this->resprints.= $langs->trans("NoStripe");
147
-			}
148
-			$this->resprints.= '</td></tr>';
149
-		}
150
-		elseif (is_object($object) && $object->element == 'adherent_type'){
151
-			$this->resprints.= '<tr><td>';
152
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
153
-			$this->resprints.= $langs->trans('PlanStripe');
154
-			$this->resprints.= '<td><td align="right">';
155
-			//				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
156
-			$this->resprints.= '</td></tr></table>';
157
-			$this->resprints.= '</td>';
158
-			$this->resprints.= '<td colspan="3">';
159
-			$stripe=new Stripe($db);
160
-			if (7==4) {
161
-				$object->fetch_thirdparty();
162
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
163
-				$this->resprints.= $customer->id;
164
-			}
165
-			else {
166
-				$this->resprints.= $langs->trans("NoStripe");
167
-			}
168
-			$this->resprints.= '</td></tr>';
169
-		}
170
-		return 0;
171
-	}
172
-
173
-	/**
174
-	 * addMoreActionsButtons
175
-	 *
176
-	 * @param arra	 	$parameters	Parameters
177
-	 * @param Object	$object		Object
178
-	 * @param string	$action		action
179
-	 * @return int					0
180
-	 */
181
-	function addMoreActionsButtons($parameters, &$object, &$action)
182
-	{
183
-		global $db,$conf,$user,$langs,$form;
184
-		if (is_object($object) && $object->element == 'facture'){
185
-			// On verifie si la facture a des paiements
186
-			$sql = 'SELECT pf.amount';
187
-			$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf';
188
-			$sql .= ' WHERE pf.fk_facture = ' . $object->id;
189
-
190
-			$result = $db->query($sql);
191
-			if ($result) {
192
-				$i = 0;
193
-				$num = $db->num_rows($result);
194
-
195
-				while ($i < $num) {
196
-					$objp = $db->fetch_object($result);
197
-					$totalpaye += $objp->amount;
198
-					$i ++;
199
-				}
200
-			} else {
201
-				dol_print_error($db, '');
202
-			}
203
-
204
-			$resteapayer = $object->total_ttc - $totalpaye;
205
-			// Request a direct debit order
206
-			if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0)
207
-			{
208
-				$stripe=new Stripe($db);
209
-				if ($resteapayer > 0)
210
-				{
211
-					if ($stripe->getStripeAccount($conf->entity))  // a modifier avec droit stripe
212
-					{
213
-						$langs->load("withdrawals");
214
-						print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
215
-					}
216
-					else
217
-					{
218
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
219
-					}
220
-				}
221
-				elseif ($resteapayer == 0)
222
-				{
223
-					print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
224
-				}
225
-			}
226
-			else {
227
-				print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
228
-			}
229
-		}
230
-		elseif (is_object($object) && $object->element == 'invoice_supplier'){
231
-			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
232
-		}
233
-		elseif (is_object($object) && $object->element == 'member'){
234
-			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
235
-		}
236
-		return 0;
237
-	}
69
+     */
70
+    function formObjectOptions($parameters, &$object, &$action)
71
+    {
72
+        global $db,$conf,$user,$langs,$form;
73
+
74
+        if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
75
+        {
76
+            $service = 'StripeTest';
77
+            dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
78
+        }
79
+        else
80
+        {
81
+            $service = 'StripeLive';
82
+        }
83
+
84
+        if (is_array($parameters) && ! empty($parameters))
85
+        {
86
+            foreach($parameters as $key=>$value)
87
+            {
88
+                $key=$value;
89
+            }
90
+        }
91
+
92
+
93
+        if (is_object($object) && $object->element == 'societe')
94
+        {
95
+            $this->resprints.= '<tr><td>';
96
+            $this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
97
+            $this->resprints.= $langs->trans('StripeCustomer');
98
+            $this->resprints.= '<td><td align="right">';
99
+            //				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
100
+            $this->resprints.= '</td></tr></table>';
101
+            $this->resprints.= '</td>';
102
+            $this->resprints.= '<td colspan="3">';
103
+            $stripe=new Stripe($db);
104
+            if ($stripe->getStripeAccount($service)&&$object->client!=0) {
105
+                $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
106
+                $this->resprints.= $customer->id;
107
+            }
108
+            else {
109
+                $this->resprints.= $langs->trans("NoStripe");
110
+            }
111
+            $this->resprints.= '</td></tr>';
112
+        }
113
+        elseif (is_object($object) && $object->element == 'member'){
114
+            $this->resprints.= '<tr><td>';
115
+            $this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
116
+            $this->resprints.= $langs->trans('StripeCustomer');
117
+            $this->resprints.= '<td><td align="right">';
118
+            $this->resprints.= '</td></tr></table>';
119
+            $this->resprints.= '</td>';
120
+            $this->resprints.= '<td colspan="3">';
121
+            $stripe=new Stripe($db);
122
+            if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
123
+                $object->fetch_thirdparty();
124
+                $customer=$stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
125
+                $this->resprints.= $customer->id;
126
+            }
127
+            else {
128
+                $this->resprints.= $langs->trans("NoStripe");
129
+            }
130
+            $this->resprints.= '</td></tr>';
131
+
132
+            $this->resprints.= '<tr><td>';
133
+            $this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
134
+            $this->resprints.= $langs->trans('SubscriptionStripe');
135
+            $this->resprints.= '<td><td align="right">';
136
+            $this->resprints.= '</td></tr></table>';
137
+            $this->resprints.= '</td>';
138
+            $this->resprints.= '<td colspan="3">';
139
+            $stripe=new Stripe($db);
140
+            if (7==4) {
141
+                $object->fetch_thirdparty();
142
+                $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
143
+                $this->resprints.= $customer->id;
144
+            }
145
+            else {
146
+                $this->resprints.= $langs->trans("NoStripe");
147
+            }
148
+            $this->resprints.= '</td></tr>';
149
+        }
150
+        elseif (is_object($object) && $object->element == 'adherent_type'){
151
+            $this->resprints.= '<tr><td>';
152
+            $this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
153
+            $this->resprints.= $langs->trans('PlanStripe');
154
+            $this->resprints.= '<td><td align="right">';
155
+            //				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
156
+            $this->resprints.= '</td></tr></table>';
157
+            $this->resprints.= '</td>';
158
+            $this->resprints.= '<td colspan="3">';
159
+            $stripe=new Stripe($db);
160
+            if (7==4) {
161
+                $object->fetch_thirdparty();
162
+                $customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
163
+                $this->resprints.= $customer->id;
164
+            }
165
+            else {
166
+                $this->resprints.= $langs->trans("NoStripe");
167
+            }
168
+            $this->resprints.= '</td></tr>';
169
+        }
170
+        return 0;
171
+    }
172
+
173
+    /**
174
+     * addMoreActionsButtons
175
+     *
176
+     * @param arra	 	$parameters	Parameters
177
+     * @param Object	$object		Object
178
+     * @param string	$action		action
179
+     * @return int					0
180
+     */
181
+    function addMoreActionsButtons($parameters, &$object, &$action)
182
+    {
183
+        global $db,$conf,$user,$langs,$form;
184
+        if (is_object($object) && $object->element == 'facture'){
185
+            // On verifie si la facture a des paiements
186
+            $sql = 'SELECT pf.amount';
187
+            $sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf';
188
+            $sql .= ' WHERE pf.fk_facture = ' . $object->id;
189
+
190
+            $result = $db->query($sql);
191
+            if ($result) {
192
+                $i = 0;
193
+                $num = $db->num_rows($result);
194
+
195
+                while ($i < $num) {
196
+                    $objp = $db->fetch_object($result);
197
+                    $totalpaye += $objp->amount;
198
+                    $i ++;
199
+                }
200
+            } else {
201
+                dol_print_error($db, '');
202
+            }
203
+
204
+            $resteapayer = $object->total_ttc - $totalpaye;
205
+            // Request a direct debit order
206
+            if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0)
207
+            {
208
+                $stripe=new Stripe($db);
209
+                if ($resteapayer > 0)
210
+                {
211
+                    if ($stripe->getStripeAccount($conf->entity))  // a modifier avec droit stripe
212
+                    {
213
+                        $langs->load("withdrawals");
214
+                        print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
215
+                    }
216
+                    else
217
+                    {
218
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
219
+                    }
220
+                }
221
+                elseif ($resteapayer == 0)
222
+                {
223
+                    print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
224
+                }
225
+            }
226
+            else {
227
+                print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
228
+            }
229
+        }
230
+        elseif (is_object($object) && $object->element == 'invoice_supplier'){
231
+            print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
232
+        }
233
+        elseif (is_object($object) && $object->element == 'member'){
234
+            print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
235
+        }
236
+        return 0;
237
+    }
238 238
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public $db;
43 43
 
44
-	private $config=array();
44
+	private $config = array();
45 45
 
46 46
 	// For Hookmanager return
47 47
 	public $resprints;
48
-	public $results=array();
48
+	public $results = array();
49 49
 
50 50
 
51 51
 	/**
@@ -69,103 +69,103 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	function formObjectOptions($parameters, &$object, &$action)
71 71
 	{
72
-		global $db,$conf,$user,$langs,$form;
72
+		global $db, $conf, $user, $langs, $form;
73 73
 
74
-		if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
74
+		if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')))
75 75
 		{
76 76
 			$service = 'StripeTest';
77
-			dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
77
+			dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
78 78
 		}
79 79
 		else
80 80
 		{
81 81
 			$service = 'StripeLive';
82 82
 		}
83 83
 
84
-		if (is_array($parameters) && ! empty($parameters))
84
+		if (is_array($parameters) && !empty($parameters))
85 85
 		{
86
-			foreach($parameters as $key=>$value)
86
+			foreach ($parameters as $key=>$value)
87 87
 			{
88
-				$key=$value;
88
+				$key = $value;
89 89
 			}
90 90
 		}
91 91
 
92 92
 
93 93
 		if (is_object($object) && $object->element == 'societe')
94 94
 		{
95
-			$this->resprints.= '<tr><td>';
96
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
97
-			$this->resprints.= $langs->trans('StripeCustomer');
98
-			$this->resprints.= '<td><td align="right">';
95
+			$this->resprints .= '<tr><td>';
96
+			$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
97
+			$this->resprints .= $langs->trans('StripeCustomer');
98
+			$this->resprints .= '<td><td align="right">';
99 99
 			//				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
100
-			$this->resprints.= '</td></tr></table>';
101
-			$this->resprints.= '</td>';
102
-			$this->resprints.= '<td colspan="3">';
103
-			$stripe=new Stripe($db);
104
-			if ($stripe->getStripeAccount($service)&&$object->client!=0) {
105
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
106
-				$this->resprints.= $customer->id;
100
+			$this->resprints .= '</td></tr></table>';
101
+			$this->resprints .= '</td>';
102
+			$this->resprints .= '<td colspan="3">';
103
+			$stripe = new Stripe($db);
104
+			if ($stripe->getStripeAccount($service) && $object->client != 0) {
105
+				$customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
106
+				$this->resprints .= $customer->id;
107 107
 			}
108 108
 			else {
109
-				$this->resprints.= $langs->trans("NoStripe");
109
+				$this->resprints .= $langs->trans("NoStripe");
110 110
 			}
111
-			$this->resprints.= '</td></tr>';
111
+			$this->resprints .= '</td></tr>';
112 112
 		}
113
-		elseif (is_object($object) && $object->element == 'member'){
114
-			$this->resprints.= '<tr><td>';
115
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
116
-			$this->resprints.= $langs->trans('StripeCustomer');
117
-			$this->resprints.= '<td><td align="right">';
118
-			$this->resprints.= '</td></tr></table>';
119
-			$this->resprints.= '</td>';
120
-			$this->resprints.= '<td colspan="3">';
121
-			$stripe=new Stripe($db);
113
+		elseif (is_object($object) && $object->element == 'member') {
114
+			$this->resprints .= '<tr><td>';
115
+			$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
116
+			$this->resprints .= $langs->trans('StripeCustomer');
117
+			$this->resprints .= '<td><td align="right">';
118
+			$this->resprints .= '</td></tr></table>';
119
+			$this->resprints .= '</td>';
120
+			$this->resprints .= '<td colspan="3">';
121
+			$stripe = new Stripe($db);
122 122
 			if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
123 123
 				$object->fetch_thirdparty();
124
-				$customer=$stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
125
-				$this->resprints.= $customer->id;
124
+				$customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
125
+				$this->resprints .= $customer->id;
126 126
 			}
127 127
 			else {
128
-				$this->resprints.= $langs->trans("NoStripe");
128
+				$this->resprints .= $langs->trans("NoStripe");
129 129
 			}
130
-			$this->resprints.= '</td></tr>';
131
-
132
-			$this->resprints.= '<tr><td>';
133
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
134
-			$this->resprints.= $langs->trans('SubscriptionStripe');
135
-			$this->resprints.= '<td><td align="right">';
136
-			$this->resprints.= '</td></tr></table>';
137
-			$this->resprints.= '</td>';
138
-			$this->resprints.= '<td colspan="3">';
139
-			$stripe=new Stripe($db);
140
-			if (7==4) {
130
+			$this->resprints .= '</td></tr>';
131
+
132
+			$this->resprints .= '<tr><td>';
133
+			$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
134
+			$this->resprints .= $langs->trans('SubscriptionStripe');
135
+			$this->resprints .= '<td><td align="right">';
136
+			$this->resprints .= '</td></tr></table>';
137
+			$this->resprints .= '</td>';
138
+			$this->resprints .= '<td colspan="3">';
139
+			$stripe = new Stripe($db);
140
+			if (7 == 4) {
141 141
 				$object->fetch_thirdparty();
142
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
143
-				$this->resprints.= $customer->id;
142
+				$customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
143
+				$this->resprints .= $customer->id;
144 144
 			}
145 145
 			else {
146
-				$this->resprints.= $langs->trans("NoStripe");
146
+				$this->resprints .= $langs->trans("NoStripe");
147 147
 			}
148
-			$this->resprints.= '</td></tr>';
148
+			$this->resprints .= '</td></tr>';
149 149
 		}
150
-		elseif (is_object($object) && $object->element == 'adherent_type'){
151
-			$this->resprints.= '<tr><td>';
152
-			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
153
-			$this->resprints.= $langs->trans('PlanStripe');
154
-			$this->resprints.= '<td><td align="right">';
150
+		elseif (is_object($object) && $object->element == 'adherent_type') {
151
+			$this->resprints .= '<tr><td>';
152
+			$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
153
+			$this->resprints .= $langs->trans('PlanStripe');
154
+			$this->resprints .= '<td><td align="right">';
155 155
 			//				$this->resprints.= '<a href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
156
-			$this->resprints.= '</td></tr></table>';
157
-			$this->resprints.= '</td>';
158
-			$this->resprints.= '<td colspan="3">';
159
-			$stripe=new Stripe($db);
160
-			if (7==4) {
156
+			$this->resprints .= '</td></tr></table>';
157
+			$this->resprints .= '</td>';
158
+			$this->resprints .= '<td colspan="3">';
159
+			$stripe = new Stripe($db);
160
+			if (7 == 4) {
161 161
 				$object->fetch_thirdparty();
162
-				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
163
-				$this->resprints.= $customer->id;
162
+				$customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
163
+				$this->resprints .= $customer->id;
164 164
 			}
165 165
 			else {
166
-				$this->resprints.= $langs->trans("NoStripe");
166
+				$this->resprints .= $langs->trans("NoStripe");
167 167
 			}
168
-			$this->resprints.= '</td></tr>';
168
+			$this->resprints .= '</td></tr>';
169 169
 		}
170 170
 		return 0;
171 171
 	}
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 	 */
181 181
 	function addMoreActionsButtons($parameters, &$object, &$action)
182 182
 	{
183
-		global $db,$conf,$user,$langs,$form;
184
-		if (is_object($object) && $object->element == 'facture'){
183
+		global $db, $conf, $user, $langs, $form;
184
+		if (is_object($object) && $object->element == 'facture') {
185 185
 			// On verifie si la facture a des paiements
186 186
 			$sql = 'SELECT pf.amount';
187
-			$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf';
188
-			$sql .= ' WHERE pf.fk_facture = ' . $object->id;
187
+			$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
188
+			$sql .= ' WHERE pf.fk_facture = '.$object->id;
189 189
 
190 190
 			$result = $db->query($sql);
191 191
 			if ($result) {
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 				while ($i < $num) {
196 196
 					$objp = $db->fetch_object($result);
197 197
 					$totalpaye += $objp->amount;
198
-					$i ++;
198
+					$i++;
199 199
 				}
200 200
 			} else {
201 201
 				dol_print_error($db, '');
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 			// Request a direct debit order
206 206
 			if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0)
207 207
 			{
208
-				$stripe=new Stripe($db);
208
+				$stripe = new Stripe($db);
209 209
 				if ($resteapayer > 0)
210 210
 				{
211 211
 					if ($stripe->getStripeAccount($conf->entity))  // a modifier avec droit stripe
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 				print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
228 228
 			}
229 229
 		}
230
-		elseif (is_object($object) && $object->element == 'invoice_supplier'){
230
+		elseif (is_object($object) && $object->element == 'invoice_supplier') {
231 231
 			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
232 232
 		}
233
-		elseif (is_object($object) && $object->element == 'member'){
233
+		elseif (is_object($object) && $object->element == 'member') {
234 234
 			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
235 235
 		}
236 236
 		return 0;
Please login to merge, or discard this patch.
Braces   +15 added lines, -25 removed lines patch added patch discarded remove patch
@@ -75,8 +75,7 @@  discard block
 block discarded – undo
75 75
 		{
76 76
 			$service = 'StripeTest';
77 77
 			dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
78
-		}
79
-		else
78
+		} else
80 79
 		{
81 80
 			$service = 'StripeLive';
82 81
 		}
@@ -104,13 +103,11 @@  discard block
 block discarded – undo
104 103
 			if ($stripe->getStripeAccount($service)&&$object->client!=0) {
105 104
 				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
106 105
 				$this->resprints.= $customer->id;
107
-			}
108
-			else {
106
+			} else {
109 107
 				$this->resprints.= $langs->trans("NoStripe");
110 108
 			}
111 109
 			$this->resprints.= '</td></tr>';
112
-		}
113
-		elseif (is_object($object) && $object->element == 'member'){
110
+		} elseif (is_object($object) && $object->element == 'member'){
114 111
 			$this->resprints.= '<tr><td>';
115 112
 			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
116 113
 			$this->resprints.= $langs->trans('StripeCustomer');
@@ -123,8 +120,7 @@  discard block
 block discarded – undo
123 120
 				$object->fetch_thirdparty();
124 121
 				$customer=$stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
125 122
 				$this->resprints.= $customer->id;
126
-			}
127
-			else {
123
+			} else {
128 124
 				$this->resprints.= $langs->trans("NoStripe");
129 125
 			}
130 126
 			$this->resprints.= '</td></tr>';
@@ -141,13 +137,11 @@  discard block
 block discarded – undo
141 137
 				$object->fetch_thirdparty();
142 138
 				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
143 139
 				$this->resprints.= $customer->id;
144
-			}
145
-			else {
140
+			} else {
146 141
 				$this->resprints.= $langs->trans("NoStripe");
147 142
 			}
148 143
 			$this->resprints.= '</td></tr>';
149
-		}
150
-		elseif (is_object($object) && $object->element == 'adherent_type'){
144
+		} elseif (is_object($object) && $object->element == 'adherent_type'){
151 145
 			$this->resprints.= '<tr><td>';
152 146
 			$this->resprints.= '<table width="100%" class="nobordernopadding"><tr><td>';
153 147
 			$this->resprints.= $langs->trans('PlanStripe');
@@ -161,8 +155,7 @@  discard block
 block discarded – undo
161 155
 				$object->fetch_thirdparty();
162 156
 				$customer=$stripe->customerStripe($object,$stripe->getStripeAccount($service));
163 157
 				$this->resprints.= $customer->id;
164
-			}
165
-			else {
158
+			} else {
166 159
 				$this->resprints.= $langs->trans("NoStripe");
167 160
 			}
168 161
 			$this->resprints.= '</td></tr>';
@@ -208,29 +201,26 @@  discard block
 block discarded – undo
208 201
 				$stripe=new Stripe($db);
209 202
 				if ($resteapayer > 0)
210 203
 				{
211
-					if ($stripe->getStripeAccount($conf->entity))  // a modifier avec droit stripe
204
+					if ($stripe->getStripeAccount($conf->entity)) {
205
+					    // a modifier avec droit stripe
212 206
 					{
213 207
 						$langs->load("withdrawals");
214
-						print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
215 208
 					}
216
-					else
209
+						print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
210
+					} else
217 211
 					{
218 212
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
219 213
 					}
220
-				}
221
-				elseif ($resteapayer == 0)
214
+				} elseif ($resteapayer == 0)
222 215
 				{
223 216
 					print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
224 217
 				}
225
-			}
226
-			else {
218
+			} else {
227 219
 				print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
228 220
 			}
229
-		}
230
-		elseif (is_object($object) && $object->element == 'invoice_supplier'){
221
+		} elseif (is_object($object) && $object->element == 'invoice_supplier'){
231 222
 			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
232
-		}
233
-		elseif (is_object($object) && $object->element == 'member'){
223
+		} elseif (is_object($object) && $object->element == 'member'){
234 224
 			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
235 225
 		}
236 226
 		return 0;
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/lib/stripe.lib.php 3 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -28,25 +28,25 @@  discard block
 block discarded – undo
28 28
  */
29 29
 function stripeadmin_prepare_head()
30 30
 {
31
-	global $langs, $conf;
31
+    global $langs, $conf;
32 32
 
33
-	$h = 0;
34
-	$head = array();
33
+    $h = 0;
34
+    $head = array();
35 35
 
36
-	$head[$h][0] = DOL_URL_ROOT."/stripe/admin/stripe.php";
37
-	$head[$h][1] = $langs->trans("Stripe");
38
-	$head[$h][2] = 'stripeaccount';
39
-	$h++;
36
+    $head[$h][0] = DOL_URL_ROOT."/stripe/admin/stripe.php";
37
+    $head[$h][1] = $langs->trans("Stripe");
38
+    $head[$h][2] = 'stripeaccount';
39
+    $h++;
40 40
 
41
-	$object=new stdClass();
41
+    $object=new stdClass();
42 42
 
43 43
     // Show more tabs from modules
44 44
     // Entries must be declared in modules descriptor with line
45 45
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
46 46
     // $this->tabs = array('entity:-tabname);   												to remove a tab
47
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin');
47
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin');
48 48
 
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin','remove');
49
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin','remove');
50 50
 
51 51
     return $head;
52 52
 }
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
  */
63 63
 function showStripePaymentUrl($type,$ref)
64 64
 {
65
-	global $conf, $langs;
65
+    global $conf, $langs;
66 66
 
67
-	$langs->load("paypal");
67
+    $langs->load("paypal");
68 68
     $langs->load("paybox");
69
-	$langs->load("stripe");
69
+    $langs->load("stripe");
70 70
 
71 71
     $servicename='Stripe';
72 72
     $out='<br><br>';
@@ -89,41 +89,41 @@  discard block
 block discarded – undo
89 89
  */
90 90
 function getStripePaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
91 91
 {
92
-	global $conf;
92
+    global $conf;
93 93
 
94
-	$ref=str_replace(' ','',$ref);
94
+    $ref=str_replace(' ','',$ref);
95 95
 	
96 96
     if ($type == 'free')
97 97
     {
98
-	    $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
98
+        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
99 99
     }
100 100
     if ($type == 'order')
101 101
     {
102 102
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
103 103
         if ($mode == 1) $out.='order_ref';
104 104
         if ($mode == 0) $out.=urlencode($ref);
105
-	    $out.=($mode?'</font>':'');
105
+        $out.=($mode?'</font>':'');
106 106
     }
107 107
     if ($type == 'invoice')
108 108
     {
109 109
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
110 110
         if ($mode == 1) $out.='invoice_ref';
111 111
         if ($mode == 0) $out.=urlencode($ref);
112
-	    $out.=($mode?'</font>':'');
112
+        $out.=($mode?'</font>':'');
113 113
     }
114 114
     if ($type == 'contractline')
115 115
     {
116 116
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
117 117
         if ($mode == 1) $out.='contractline_ref';
118 118
         if ($mode == 0) $out.=urlencode($ref);
119
-	    $out.=($mode?'</font>':'');
119
+        $out.=($mode?'</font>':'');
120 120
     }
121 121
     if ($type == 'membersubscription')
122 122
     {
123 123
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
124 124
         if ($mode == 1) $out.='member_ref';
125 125
         if ($mode == 0) $out.=urlencode($ref);
126
-	    $out.=($mode?'</font>':'');
126
+        $out.=($mode?'</font>':'');
127 127
     }
128 128
 
129 129
     // For multicompany
@@ -142,61 +142,61 @@  discard block
 block discarded – undo
142 142
  */
143 143
 function html_print_stripe_footer($fromcompany,$langs)
144 144
 {
145
-	global $conf;
146
-
147
-	// Juridical status
148
-	$line1="";
149
-	if ($fromcompany->forme_juridique_code)
150
-	{
151
-		$line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
152
-	}
153
-	// Capital
154
-	if ($fromcompany->capital)
155
-	{
156
-		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
157
-	}
158
-	// Prof Id 1
159
-	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
160
-	{
161
-		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
162
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
163
-		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
164
-	}
165
-	// Prof Id 2
166
-	if ($fromcompany->idprof2)
167
-	{
168
-		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
169
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
170
-		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
171
-	}
172
-
173
-	// Second line of company infos
174
-	$line2="";
175
-	// Prof Id 3
176
-	if ($fromcompany->idprof3)
177
-	{
178
-		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
179
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
180
-		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
181
-	}
182
-	// Prof Id 4
183
-	if ($fromcompany->idprof4)
184
-	{
185
-		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
186
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
187
-		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
188
-	}
189
-	// IntraCommunautary VAT
190
-	if ($fromcompany->tva_intra != '')
191
-	{
192
-		$line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
193
-	}
194
-
195
-	print '<br><br><hr>'."\n";
196
-	print '<div class="center"><font style="font-size: 10px;">'."\n";
197
-	print $fromcompany->name.'<br>';
198
-	print $line1.'<br>';
199
-	print $line2;
200
-	print '</font></div>'."\n";
145
+    global $conf;
146
+
147
+    // Juridical status
148
+    $line1="";
149
+    if ($fromcompany->forme_juridique_code)
150
+    {
151
+        $line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
152
+    }
153
+    // Capital
154
+    if ($fromcompany->capital)
155
+    {
156
+        $line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
157
+    }
158
+    // Prof Id 1
159
+    if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
160
+    {
161
+        $field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
162
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
163
+        $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
164
+    }
165
+    // Prof Id 2
166
+    if ($fromcompany->idprof2)
167
+    {
168
+        $field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
169
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
170
+        $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
171
+    }
172
+
173
+    // Second line of company infos
174
+    $line2="";
175
+    // Prof Id 3
176
+    if ($fromcompany->idprof3)
177
+    {
178
+        $field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
179
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
180
+        $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
181
+    }
182
+    // Prof Id 4
183
+    if ($fromcompany->idprof4)
184
+    {
185
+        $field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
186
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
187
+        $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
188
+    }
189
+    // IntraCommunautary VAT
190
+    if ($fromcompany->tva_intra != '')
191
+    {
192
+        $line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
193
+    }
194
+
195
+    print '<br><br><hr>'."\n";
196
+    print '<div class="center"><font style="font-size: 10px;">'."\n";
197
+    print $fromcompany->name.'<br>';
198
+    print $line1.'<br>';
199
+    print $line2;
200
+    print '</font></div>'."\n";
201 201
 }
202 202
 
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	$head[$h][2] = 'stripeaccount';
39 39
 	$h++;
40 40
 
41
-	$object=new stdClass();
41
+	$object = new stdClass();
42 42
 
43 43
     // Show more tabs from modules
44 44
     // Entries must be declared in modules descriptor with line
45 45
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
46 46
     // $this->tabs = array('entity:-tabname);   												to remove a tab
47
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin');
47
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'stripeadmin');
48 48
 
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin','remove');
49
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'stripeadmin', 'remove');
50 50
 
51 51
     return $head;
52 52
 }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @param	string	$ref		Ref of object
61 61
  * @return	string				Url string
62 62
  */
63
-function showStripePaymentUrl($type,$ref)
63
+function showStripePaymentUrl($type, $ref)
64 64
 {
65 65
 	global $conf, $langs;
66 66
 
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
     $langs->load("paybox");
69 69
 	$langs->load("stripe");
70 70
 
71
-    $servicename='Stripe';
72
-    $out='<br><br>';
73
-    $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
74
-    $url=getStripePaymentUrl(0,$type,$ref);
75
-    $out.='<input type="text" id="stripeurl" class="quatrevingtpercent" value="'.$url.'"><br>';
76
-    $out.=ajax_autoselect("stripeurl", 0);
71
+    $servicename = 'Stripe';
72
+    $out = '<br><br>';
73
+    $out .= img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
74
+    $url = getStripePaymentUrl(0, $type, $ref);
75
+    $out .= '<input type="text" id="stripeurl" class="quatrevingtpercent" value="'.$url.'"><br>';
76
+    $out .= ajax_autoselect("stripeurl", 0);
77 77
     return $out;
78 78
 }
79 79
 
@@ -87,47 +87,47 @@  discard block
 block discarded – undo
87 87
  * @param	string	$freetag	Free tag
88 88
  * @return	string				Url string
89 89
  */
90
-function getStripePaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
90
+function getStripePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag')
91 91
 {
92 92
 	global $conf;
93 93
 
94
-	$ref=str_replace(' ','',$ref);
94
+	$ref = str_replace(' ', '', $ref);
95 95
 	
96 96
     if ($type == 'free')
97 97
     {
98
-	    $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
98
+	    $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
99 99
     }
100 100
     if ($type == 'order')
101 101
     {
102
-        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
103
-        if ($mode == 1) $out.='order_ref';
104
-        if ($mode == 0) $out.=urlencode($ref);
105
-	    $out.=($mode?'</font>':'');
102
+        $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
103
+        if ($mode == 1) $out .= 'order_ref';
104
+        if ($mode == 0) $out .= urlencode($ref);
105
+	    $out .= ($mode ? '</font>' : '');
106 106
     }
107 107
     if ($type == 'invoice')
108 108
     {
109
-        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
110
-        if ($mode == 1) $out.='invoice_ref';
111
-        if ($mode == 0) $out.=urlencode($ref);
112
-	    $out.=($mode?'</font>':'');
109
+        $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
110
+        if ($mode == 1) $out .= 'invoice_ref';
111
+        if ($mode == 0) $out .= urlencode($ref);
112
+	    $out .= ($mode ? '</font>' : '');
113 113
     }
114 114
     if ($type == 'contractline')
115 115
     {
116
-        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
117
-        if ($mode == 1) $out.='contractline_ref';
118
-        if ($mode == 0) $out.=urlencode($ref);
119
-	    $out.=($mode?'</font>':'');
116
+        $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
117
+        if ($mode == 1) $out .= 'contractline_ref';
118
+        if ($mode == 0) $out .= urlencode($ref);
119
+	    $out .= ($mode ? '</font>' : '');
120 120
     }
121 121
     if ($type == 'membersubscription')
122 122
     {
123
-        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
124
-        if ($mode == 1) $out.='member_ref';
125
-        if ($mode == 0) $out.=urlencode($ref);
126
-	    $out.=($mode?'</font>':'');
123
+        $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
124
+        if ($mode == 1) $out .= 'member_ref';
125
+        if ($mode == 0) $out .= urlencode($ref);
126
+	    $out .= ($mode ? '</font>' : '');
127 127
     }
128 128
 
129 129
     // For multicompany
130
-    $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
130
+    $out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
131 131
 
132 132
     return $out;
133 133
 }
@@ -140,56 +140,56 @@  discard block
 block discarded – undo
140 140
  * @param   Translate	$langs			Output language
141 141
  * @return	void
142 142
  */
143
-function html_print_stripe_footer($fromcompany,$langs)
143
+function html_print_stripe_footer($fromcompany, $langs)
144 144
 {
145 145
 	global $conf;
146 146
 
147 147
 	// Juridical status
148
-	$line1="";
148
+	$line1 = "";
149 149
 	if ($fromcompany->forme_juridique_code)
150 150
 	{
151
-		$line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
151
+		$line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
152 152
 	}
153 153
 	// Capital
154 154
 	if ($fromcompany->capital)
155 155
 	{
156
-		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
156
+		$line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
157 157
 	}
158 158
 	// Prof Id 1
159
-	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
159
+	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2))
160 160
 	{
161
-		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
162
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
163
-		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
161
+		$field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
162
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
163
+		$line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
164 164
 	}
165 165
 	// Prof Id 2
166 166
 	if ($fromcompany->idprof2)
167 167
 	{
168
-		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
169
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
170
-		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
168
+		$field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
169
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
170
+		$line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
171 171
 	}
172 172
 
173 173
 	// Second line of company infos
174
-	$line2="";
174
+	$line2 = "";
175 175
 	// Prof Id 3
176 176
 	if ($fromcompany->idprof3)
177 177
 	{
178
-		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
179
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
180
-		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
178
+		$field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
179
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
180
+		$line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
181 181
 	}
182 182
 	// Prof Id 4
183 183
 	if ($fromcompany->idprof4)
184 184
 	{
185
-		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
186
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
187
-		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
185
+		$field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
186
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
187
+		$line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
188 188
 	}
189 189
 	// IntraCommunautary VAT
190 190
 	if ($fromcompany->tva_intra != '')
191 191
 	{
192
-		$line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
192
+		$line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
193 193
 	}
194 194
 
195 195
 	print '<br><br><hr>'."\n";
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -100,29 +100,45 @@  discard block
 block discarded – undo
100 100
     if ($type == 'order')
101 101
     {
102 102
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
103
-        if ($mode == 1) $out.='order_ref';
104
-        if ($mode == 0) $out.=urlencode($ref);
103
+        if ($mode == 1) {
104
+            $out.='order_ref';
105
+        }
106
+        if ($mode == 0) {
107
+            $out.=urlencode($ref);
108
+        }
105 109
 	    $out.=($mode?'</font>':'');
106 110
     }
107 111
     if ($type == 'invoice')
108 112
     {
109 113
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
110
-        if ($mode == 1) $out.='invoice_ref';
111
-        if ($mode == 0) $out.=urlencode($ref);
114
+        if ($mode == 1) {
115
+            $out.='invoice_ref';
116
+        }
117
+        if ($mode == 0) {
118
+            $out.=urlencode($ref);
119
+        }
112 120
 	    $out.=($mode?'</font>':'');
113 121
     }
114 122
     if ($type == 'contractline')
115 123
     {
116 124
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
117
-        if ($mode == 1) $out.='contractline_ref';
118
-        if ($mode == 0) $out.=urlencode($ref);
125
+        if ($mode == 1) {
126
+            $out.='contractline_ref';
127
+        }
128
+        if ($mode == 0) {
129
+            $out.=urlencode($ref);
130
+        }
119 131
 	    $out.=($mode?'</font>':'');
120 132
     }
121 133
     if ($type == 'membersubscription')
122 134
     {
123 135
         $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
124
-        if ($mode == 1) $out.='member_ref';
125
-        if ($mode == 0) $out.=urlencode($ref);
136
+        if ($mode == 1) {
137
+            $out.='member_ref';
138
+        }
139
+        if ($mode == 0) {
140
+            $out.=urlencode($ref);
141
+        }
126 142
 	    $out.=($mode?'</font>':'');
127 143
     }
128 144
 
@@ -159,14 +175,18 @@  discard block
 block discarded – undo
159 175
 	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
160 176
 	{
161 177
 		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
162
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
178
+		if (preg_match('/\((.*)\)/i',$field,$reg)) {
179
+		    $field=$reg[1];
180
+		}
163 181
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
164 182
 	}
165 183
 	// Prof Id 2
166 184
 	if ($fromcompany->idprof2)
167 185
 	{
168 186
 		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
169
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
187
+		if (preg_match('/\((.*)\)/i',$field,$reg)) {
188
+		    $field=$reg[1];
189
+		}
170 190
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
171 191
 	}
172 192
 
@@ -176,14 +196,18 @@  discard block
 block discarded – undo
176 196
 	if ($fromcompany->idprof3)
177 197
 	{
178 198
 		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
179
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
199
+		if (preg_match('/\((.*)\)/i',$field,$reg)) {
200
+		    $field=$reg[1];
201
+		}
180 202
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
181 203
 	}
182 204
 	// Prof Id 4
183 205
 	if ($fromcompany->idprof4)
184 206
 	{
185 207
 		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
186
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
208
+		if (preg_match('/\((.*)\)/i',$field,$reg)) {
209
+		    $field=$reg[1];
210
+		}
187 211
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
188 212
 	}
189 213
 	// IntraCommunautary VAT
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/payment.php 3 patches
Indentation   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -75,21 +75,21 @@  discard block
 block discarded – undo
75 75
 // Load object
76 76
 if ($facid > 0)
77 77
 {
78
-	$ret=$object->fetch($facid);
78
+    $ret=$object->fetch($facid);
79 79
 }
80 80
 
81 81
 if (! empty($conf->stripe->enabled))
82 82
 {
83
-	$service = 'StripeTest';
84
-	$servicestatus = 0;
85
-	if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha'))
86
-	{
87
-		$service = 'StripeLive';
88
-		$servicestatus = 0;
89
-	}
90
-
91
-	$stripe=new Stripe($db);
92
-	$stripeacc = $stripe->getStripeAccount($service);								// Stripe OAuth connect account of dolibarr user (no network access here)
83
+    $service = 'StripeTest';
84
+    $servicestatus = 0;
85
+    if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha'))
86
+    {
87
+        $service = 'StripeLive';
88
+        $servicestatus = 0;
89
+    }
90
+
91
+    $stripe=new Stripe($db);
92
+    $stripeacc = $stripe->getStripeAccount($service);								// Stripe OAuth connect account of dolibarr user (no network access here)
93 93
 }
94 94
 
95 95
 // Initialize technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array
@@ -106,100 +106,100 @@  discard block
 block discarded – undo
106 106
 
107 107
 if (empty($reshook))
108 108
 {
109
-	if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
110
-	{
111
-	    $error = 0;
112
-
113
-	    $datepaye = dol_now();
114
-	    $paiement_id = 0;
115
-	    $totalpayment = 0;
116
-		$multicurrency_totalpayment = 0;
117
-	    $atleastonepaymentnotnull = 0;
118
-
119
-	    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
120
-	    $tmpinvoice=new Facture($db);
121
-	    foreach ($_POST as $key => $value)
122
-	    {
123
-	        if (substr($key,0,7) == 'amount_')
124
-	        {
125
-	            $cursorfacid = substr($key,7);
126
-	            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
127
-	            $totalpayment = $totalpayment + $amounts[$cursorfacid];
128
-	            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
129
-	            $result=$tmpinvoice->fetch($cursorfacid);
130
-	            if ($result <= 0) dol_print_error($db);
131
-	            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
132
-	            if ($amounts[$cursorfacid])
133
-	            {
134
-		            // Check amount
135
-		            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
136
-		            {
137
-		                $addwarning=1;
138
-		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
139
-		            }
140
-		            // Check date
141
-		            if ($datepaye && ($datepaye < $tmpinvoice->date))
142
-		            {
143
-		            	$langs->load("errors");
144
-		                //$error++;
145
-		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
146
-		            }
147
-	            }
148
-
149
-	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
150
-	        }
151
-			elseif (substr($key,0,21) == 'multicurrency_amount_')
152
-			{
153
-				$cursorfacid = substr($key,21);
154
-	            $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
155
-	            $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
156
-	            if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
157
-	            $result=$tmpinvoice->fetch($cursorfacid);
158
-	            if ($result <= 0) dol_print_error($db);
159
-	            $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
160
-	            if ($multicurrency_amounts[$cursorfacid])
161
-	            {
162
-		            // Check amount
163
-		            if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
164
-		            {
165
-		                $addwarning=1;
166
-		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
167
-		            }
168
-		            // Check date
169
-		            if ($datepaye && ($datepaye < $tmpinvoice->date))
170
-		            {
171
-		            	$langs->load("errors");
172
-		                //$error++;
173
-		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
174
-		            }
175
-	            }
176
-
177
-	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => GETPOST($key, 'int'));
178
-			}
179
-	    }
180
-
181
-	    // Check parameters
109
+    if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
110
+    {
111
+        $error = 0;
112
+
113
+        $datepaye = dol_now();
114
+        $paiement_id = 0;
115
+        $totalpayment = 0;
116
+        $multicurrency_totalpayment = 0;
117
+        $atleastonepaymentnotnull = 0;
118
+
119
+        // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
120
+        $tmpinvoice=new Facture($db);
121
+        foreach ($_POST as $key => $value)
122
+        {
123
+            if (substr($key,0,7) == 'amount_')
124
+            {
125
+                $cursorfacid = substr($key,7);
126
+                $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
127
+                $totalpayment = $totalpayment + $amounts[$cursorfacid];
128
+                if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
129
+                $result=$tmpinvoice->fetch($cursorfacid);
130
+                if ($result <= 0) dol_print_error($db);
131
+                $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
132
+                if ($amounts[$cursorfacid])
133
+                {
134
+                    // Check amount
135
+                    if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
136
+                    {
137
+                        $addwarning=1;
138
+                        $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
139
+                    }
140
+                    // Check date
141
+                    if ($datepaye && ($datepaye < $tmpinvoice->date))
142
+                    {
143
+                        $langs->load("errors");
144
+                        //$error++;
145
+                        setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
146
+                    }
147
+                }
148
+
149
+                $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
150
+            }
151
+            elseif (substr($key,0,21) == 'multicurrency_amount_')
152
+            {
153
+                $cursorfacid = substr($key,21);
154
+                $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
155
+                $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
156
+                if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
157
+                $result=$tmpinvoice->fetch($cursorfacid);
158
+                if ($result <= 0) dol_print_error($db);
159
+                $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
160
+                if ($multicurrency_amounts[$cursorfacid])
161
+                {
162
+                    // Check amount
163
+                    if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
164
+                    {
165
+                        $addwarning=1;
166
+                        $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
167
+                    }
168
+                    // Check date
169
+                    if ($datepaye && ($datepaye < $tmpinvoice->date))
170
+                    {
171
+                        $langs->load("errors");
172
+                        //$error++;
173
+                        setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
174
+                    }
175
+                }
176
+
177
+                $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => GETPOST($key, 'int'));
178
+            }
179
+        }
180
+
181
+        // Check parameters
182 182
 //	    if (! GETPOST('paiementcode'))
183 183
 //	    {
184 184
 //	        setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), null, 'errors');
185 185
 //	        $error++;
186 186
 //	    }
187 187
 
188
-	    if (! empty($conf->banque->enabled))
189
-	    {
190
-	        // If bank module is on, account is required to enter a payment
191
-	        if (GETPOST('accountid') <= 0)
192
-	        {
193
-	            setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
194
-	            $error++;
195
-	        }
196
-	    }
197
-
198
-	    if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
199
-	    {
200
-	        setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors');
201
-	        $error++;
202
-	    }
188
+        if (! empty($conf->banque->enabled))
189
+        {
190
+            // If bank module is on, account is required to enter a payment
191
+            if (GETPOST('accountid') <= 0)
192
+            {
193
+                setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
194
+                $error++;
195
+            }
196
+        }
197
+
198
+        if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
199
+        {
200
+            setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors');
201
+            $error++;
202
+        }
203 203
 
204 204
 //	    if (empty($datepaye))
205 205
 //	    {
@@ -207,200 +207,200 @@  discard block
 block discarded – undo
207 207
 //	        $error++;
208 208
 //	    }
209 209
 
210
-		// Check if payments in both currency
211
-		if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
212
-		{
213
-			setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
214
-	        $error++;
215
-		}
216
-	}
210
+        // Check if payments in both currency
211
+        if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
212
+        {
213
+            setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
214
+            $error++;
215
+        }
216
+    }
217 217
 
218
-	/*
218
+    /*
219 219
 	 * Action add_paiement
220 220
 	 */
221
-	if ($action == 'add_paiement') {
222
-	    if ($error) {
221
+    if ($action == 'add_paiement') {
222
+        if ($error) {
223 223
             $action = 'create';
224 224
             if (!$source) {
225
-			    setEventMessages($langs->transnoentities('NoSource'), null, 'errors');
226
-	        }
227
-	        $error++;
228
-	    }
229
-	    // Le reste propre a cette action s'affiche en bas de page.
230
-	}
231
-
232
-	/*
225
+                setEventMessages($langs->transnoentities('NoSource'), null, 'errors');
226
+            }
227
+            $error++;
228
+        }
229
+        // Le reste propre a cette action s'affiche en bas de page.
230
+    }
231
+
232
+    /*
233 233
 	 * Action confirm_paiement
234 234
 	 */
235
-	if ($action == 'confirm_paiement' && $confirm == 'yes')
236
-	{
235
+    if ($action == 'confirm_paiement' && $confirm == 'yes')
236
+    {
237 237
 
238
-		$error=0;
238
+        $error=0;
239 239
 
240
-		$datepaye = dol_now();
240
+        $datepaye = dol_now();
241 241
 
242
-		$db->begin();
242
+        $db->begin();
243 243
 
244
-		// Clean parameters amount if payment is for a credit note
245
-		if (GETPOST('type') == 2)
246
-		{
247
-			foreach ($amounts as $key => $value)	// How payment is dispatch
248
-			{
249
-				$newvalue = price2num($value,'MT');
250
-				$amounts[$key] = -$newvalue;
251
-			}
252
-
253
-			foreach ($multicurrency_amounts as $key => $value)	// How payment is dispatch
254
-			{
255
-				$newvalue = price2num($value,'MT');
256
-				$multicurrency_amounts[$key] = -$newvalue;
257
-			}
258
-		}
259
-
260
-		if (! empty($conf->banque->enabled))
261
-		{
262
-			// Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
263
-			if (GETPOST('accountid') <= 0)
264
-			{
265
-				setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
266
-				$error++;
267
-			}
268
-		}
244
+        // Clean parameters amount if payment is for a credit note
245
+        if (GETPOST('type') == 2)
246
+        {
247
+            foreach ($amounts as $key => $value)	// How payment is dispatch
248
+            {
249
+                $newvalue = price2num($value,'MT');
250
+                $amounts[$key] = -$newvalue;
251
+            }
269 252
 
270
-		$facture = new Facture($db);
271
-		$facture->fetch($facid);
272
-		$facture->fetch_thirdparty();
253
+            foreach ($multicurrency_amounts as $key => $value)	// How payment is dispatch
254
+            {
255
+                $newvalue = price2num($value,'MT');
256
+                $multicurrency_amounts[$key] = -$newvalue;
257
+            }
258
+        }
273 259
 
274
-		$error = 0;
260
+        if (! empty($conf->banque->enabled))
261
+        {
262
+            // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
263
+            if (GETPOST('accountid') <= 0)
264
+            {
265
+                setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
266
+                $error++;
267
+            }
268
+        }
275 269
 
276
-		if (is_object($stripe) && $stripeacc)
277
-		{
278
-			$customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
270
+        $facture = new Facture($db);
271
+        $facture->fetch($facid);
272
+        $facture->fetch_thirdparty();
279 273
 
280
-			if ($customerstripe->id) {
281
-				$listofsources=$customerstripe->sources->data;
282
-			}
283
-		}
274
+        $error = 0;
284 275
 
285
-		$stripeamount=0;
286
-		foreach ($amounts as $key => $value)	// How payment is dispatch
287
-		{
288
-			$stripeamount+=price2num($value,'MT');
289
-		}
276
+        if (is_object($stripe) && $stripeacc)
277
+        {
278
+            $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
290 279
 
291
-		if (preg_match('/acct_/i',$source))
292
-		{
293
-			$paiementcode ="VIR";
294
-		}
295
-		elseif (preg_match('/card_/i',$source))
296
-		{
297
-			$paiementcode ="CB";
298
-		}
299
-		elseif (preg_match('/src_/i',$source))
300
-		{
280
+            if ($customerstripe->id) {
281
+                $listofsources=$customerstripe->sources->data;
282
+            }
283
+        }
301 284
 
302
-		        $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
303
-			$src = $customer2->sources->retrieve("$source");
304
-			if ($src->type=='card')
305
-			{
306
-				$paiementcode ="CB";
307
-			}
308
-		}
285
+        $stripeamount=0;
286
+        foreach ($amounts as $key => $value)	// How payment is dispatch
287
+        {
288
+            $stripeamount+=price2num($value,'MT');
289
+        }
309 290
 
291
+        if (preg_match('/acct_/i',$source))
292
+        {
293
+            $paiementcode ="VIR";
294
+        }
295
+        elseif (preg_match('/card_/i',$source))
296
+        {
297
+            $paiementcode ="CB";
298
+        }
299
+        elseif (preg_match('/src_/i',$source))
300
+        {
310 301
 
302
+                $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
303
+            $src = $customer2->sources->retrieve("$source");
304
+            if ($src->type=='card')
305
+            {
306
+                $paiementcode ="CB";
307
+            }
308
+        }
311 309
 
312
-		$societe = new Societe($db);
313
-		$societe->fetch($facture->socid);
314
-		dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
315 310
 
316
-		$stripecu = $stripe->getStripeCustomerAccount($societe->id, $servicestatus);		// Get thirdparty cu_...
317 311
 
318
-		$charge=$stripe->createPaymentStripe($stripeamount,$facture->multicurrency_code,"invoice",$facid,$source,$stripecu,$stripeacc,$servicestatus);
312
+        $societe = new Societe($db);
313
+        $societe->fetch($facture->socid);
314
+        dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
319 315
 
320
-		if (!$error)
321
-		{
322
-			// Creation of payment line
323
-			$paiement = new Paiement($db);
324
-			$paiement->datepaye     = $datepaye;
325
-			$paiement->amounts      = $amounts;   // Array with all payments dispatching
326
-			$paiement->multicurrency_amounts = $multicurrency_amounts;   // Array with all payments dispatching
327
-			$paiement->paiementid   = dol_getIdFromCode($db,$paiementcode,'c_paiement');
328
-			$paiement->num_paiement = $charge->message;
329
-			$paiement->note         = GETPOST('comment');
330
-			$paiement->ext_payment_id = $charge->id;
331
-			$paiement->ext_payment_site = $service;
332
-		}
333
-
334
-		if (! $error)
335
-		{
316
+        $stripecu = $stripe->getStripeCustomerAccount($societe->id, $servicestatus);		// Get thirdparty cu_...
336 317
 
337
-			$paiement_id = $paiement->create($user, 0);
338
-			if ($paiement_id < 0)
339
-			{
340
-				setEventMessages($paiement->error, $paiement->errors, 'errors');
341
-				$error++;
342
-			}
343
-			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($facture->lines))
344
-			{
345
-				$outputlangs = $langs;
346
-				$newlang = '';
347
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
348
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $facture->thirdparty->default_lang;
349
-				if (! empty($newlang)) {
350
-					$outputlangs = new Translate("", $conf);
351
-					$outputlangs->setDefaultLang($newlang);
352
-				}
353
-				$model=$facture->modelpdf;
354
-				$ret = $facture->fetch($facid); // Reload to get new records
355
-
356
-				$facture->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
357
-			}
358
-		}
359
-
360
-		if (! $error)
361
-		{
362
-			$label='(CustomerInvoicePayment)';
363
-			if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
364
-			$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'','');
365
-			if ($result < 0)
366
-			{
367
-				setEventMessages($paiement->error, $paiement->errors, 'errors');
368
-				$error++;
369
-			}
370
-			elseif (GETPOST('closepaidinvoices')=='on') {
371
-				$facture->set_paid($user);
372
-			}
373
-		}
374
-
375
-		if (! $error)
376
-		{
377
-			$db->commit();
378
-
379
-			// If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
380
-			$invoiceid=0;
381
-			foreach ($paiement->amounts as $key => $amount)
382
-			{
383
-				$facid = $key;
384
-				if (is_numeric($amount) && $amount <> 0)
385
-				{
386
-					if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
387
-					else $invoiceid=$facid;
388
-				}
389
-			}
390
-			if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
391
-			else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
392
-			header('Location: '.$loc);
393
-			exit;
394
-		}
395
-		else
396
-		{
397
-			$loc = DOL_URL_ROOT.'/stripe/payment.php?facid='.$facid.'&action=create&error='.$charge->message;
398
-			$db->rollback();
318
+        $charge=$stripe->createPaymentStripe($stripeamount,$facture->multicurrency_code,"invoice",$facid,$source,$stripecu,$stripeacc,$servicestatus);
319
+
320
+        if (!$error)
321
+        {
322
+            // Creation of payment line
323
+            $paiement = new Paiement($db);
324
+            $paiement->datepaye     = $datepaye;
325
+            $paiement->amounts      = $amounts;   // Array with all payments dispatching
326
+            $paiement->multicurrency_amounts = $multicurrency_amounts;   // Array with all payments dispatching
327
+            $paiement->paiementid   = dol_getIdFromCode($db,$paiementcode,'c_paiement');
328
+            $paiement->num_paiement = $charge->message;
329
+            $paiement->note         = GETPOST('comment');
330
+            $paiement->ext_payment_id = $charge->id;
331
+            $paiement->ext_payment_site = $service;
332
+        }
333
+
334
+        if (! $error)
335
+        {
336
+
337
+            $paiement_id = $paiement->create($user, 0);
338
+            if ($paiement_id < 0)
339
+            {
340
+                setEventMessages($paiement->error, $paiement->errors, 'errors');
341
+                $error++;
342
+            }
343
+            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($facture->lines))
344
+            {
345
+                $outputlangs = $langs;
346
+                $newlang = '';
347
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
348
+                if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $facture->thirdparty->default_lang;
349
+                if (! empty($newlang)) {
350
+                    $outputlangs = new Translate("", $conf);
351
+                    $outputlangs->setDefaultLang($newlang);
352
+                }
353
+                $model=$facture->modelpdf;
354
+                $ret = $facture->fetch($facid); // Reload to get new records
355
+
356
+                $facture->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
357
+            }
358
+        }
359
+
360
+        if (! $error)
361
+        {
362
+            $label='(CustomerInvoicePayment)';
363
+            if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
364
+            $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'','');
365
+            if ($result < 0)
366
+            {
367
+                setEventMessages($paiement->error, $paiement->errors, 'errors');
368
+                $error++;
369
+            }
370
+            elseif (GETPOST('closepaidinvoices')=='on') {
371
+                $facture->set_paid($user);
372
+            }
373
+        }
374
+
375
+        if (! $error)
376
+        {
377
+            $db->commit();
378
+
379
+            // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
380
+            $invoiceid=0;
381
+            foreach ($paiement->amounts as $key => $amount)
382
+            {
383
+                $facid = $key;
384
+                if (is_numeric($amount) && $amount <> 0)
385
+                {
386
+                    if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
387
+                    else $invoiceid=$facid;
388
+                }
389
+            }
390
+            if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
391
+            else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
392
+            header('Location: '.$loc);
393
+            exit;
394
+        }
395
+        else
396
+        {
397
+            $loc = DOL_URL_ROOT.'/stripe/payment.php?facid='.$facid.'&action=create&error='.$charge->message;
398
+            $db->rollback();
399 399
 
400
-			header('Location: '.$loc);
401
-			exit;
402
-		}
403
-	}
400
+            header('Location: '.$loc);
401
+            exit;
402
+        }
403
+    }
404 404
 }
405 405
 
406 406
 
@@ -413,46 +413,46 @@  discard block
 block discarded – undo
413 413
 llxHeader();
414 414
 
415 415
 if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) {
416
-	$service = 'StripeLive';
417
-	$servicestatus = 0;
416
+    $service = 'StripeLive';
417
+    $servicestatus = 0;
418 418
 } else {
419
-	dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
419
+    dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
420 420
 }
421 421
 
422 422
 if (GETPOST('error')){
423
-	setEventMessages(GETPOST('error'), null, 'errors');
423
+    setEventMessages(GETPOST('error'), null, 'errors');
424 424
 }
425 425
 
426 426
 if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
427 427
 {
428
-	$facture = new Facture($db);
429
-	$result=$facture->fetch($facid);
428
+    $facture = new Facture($db);
429
+    $result=$facture->fetch($facid);
430 430
 
431
-	if ($result >= 0)
432
-	{
433
-		$facture->fetch_thirdparty();
431
+    if ($result >= 0)
432
+    {
433
+        $facture->fetch_thirdparty();
434 434
 
435
-		$title='';
436
-		if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
437
-		if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
438
-		print load_fiche_titre($title);
435
+        $title='';
436
+        if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
437
+        if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
438
+        print load_fiche_titre($title);
439 439
 
440
-		// Initialize data for confirmation (this is used because data can be change during confirmation)
441
-		if ($action == 'add_paiement')
442
-		{
443
-			$i=0;
440
+        // Initialize data for confirmation (this is used because data can be change during confirmation)
441
+        if ($action == 'add_paiement')
442
+        {
443
+            $i=0;
444 444
 
445
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
446
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
447
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'type',  'value' => $facture->type);
448
-		}
445
+            $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
446
+            $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
447
+            $formquestion[$i++]=array('type' => 'hidden','name' => 'type',  'value' => $facture->type);
448
+        }
449 449
 
450 450
 
451
-		// Add realtime total information
452
-		if ($conf->use_javascript_ajax)
453
-		{
454
-			print "\n".'<script type="text/javascript" language="javascript">';
455
-			print '$(document).ready(function () {
451
+        // Add realtime total information
452
+        if ($conf->use_javascript_ajax)
453
+        {
454
+            print "\n".'<script type="text/javascript" language="javascript">';
455
+            print '$(document).ready(function () {
456 456
             			setPaiementCode();
457 457
 
458 458
             			$("#selectpaiementcode").change(function() {
@@ -538,32 +538,32 @@  discard block
 block discarded – undo
538 538
 						});
539 539
 			';
540 540
 
541
-			print '	});'."\n";
542
-			if (!empty($conf->use_javascript_ajax)){
543
-				//Add js for AutoFill
544
-				print ' $(document).ready(function () {';
545
-				print ' 	$(".AutoFillAmout").on(\'click touchstart\', function(){
541
+            print '	});'."\n";
542
+            if (!empty($conf->use_javascript_ajax)){
543
+                //Add js for AutoFill
544
+                print ' $(document).ready(function () {';
545
+                print ' 	$(".AutoFillAmout").on(\'click touchstart\', function(){
546 546
 								$("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
547 547
 							});';
548
-				print '	});'."\n";
549
-			}
550
-			print '	</script>'."\n";
551
-		}
548
+                print '	});'."\n";
549
+            }
550
+            print '	</script>'."\n";
551
+        }
552 552
 
553
-		print '<form id="payment_form" name="add_paiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
554
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
555
-		print '<input type="hidden" name="action" value="add_paiement">';
556
-		print '<input type="hidden" name="facid" value="'.$facture->id.'">';
557
-		print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
558
-		print '<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.'">';
559
-		print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).'">';
553
+        print '<form id="payment_form" name="add_paiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
554
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
555
+        print '<input type="hidden" name="action" value="add_paiement">';
556
+        print '<input type="hidden" name="facid" value="'.$facture->id.'">';
557
+        print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
558
+        print '<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.'">';
559
+        print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).'">';
560 560
 
561
-		dol_fiche_head();
561
+        dol_fiche_head();
562 562
 
563
-		print '<table class="border" width="100%">';
563
+        print '<table class="border" width="100%">';
564 564
 
565
-		// Invoice
566
-		/*if ($facture->id > 0)
565
+        // Invoice
566
+        /*if ($facture->id > 0)
567 567
 		{
568 568
 			print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans('Invoice').'</span></td><td>'.$facture->getNomUrl(4)."</td></tr>\n";
569 569
 		}*/
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
         //print '</td>';
601 601
         //print '<td><input name="chqbank" size="30" type="text" value="'.GETPOST('chqbank').'"></td></tr>';
602 602
 
603
-		// Comments
604
-		print '<tr><td>'.$langs->trans('Comments').'</td>';
605
-		print '<td class="tdtop">';
606
-		print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('comment','none').'</textarea></td></tr>';
603
+        // Comments
604
+        print '<tr><td>'.$langs->trans('Comments').'</td>';
605
+        print '<td class="tdtop">';
606
+        print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('comment','none').'</textarea></td></tr>';
607 607
 
608 608
         print '</table>';
609 609
 
@@ -766,16 +766,16 @@  discard block
 block discarded – undo
766 766
         $sql.= ' f.datef as df, f.fk_soc as socid';
767 767
         $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
768 768
 
769
-		if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) {
770
-			$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
771
-		}
769
+        if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) {
770
+            $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
771
+        }
772 772
 
773
-		$sql.= ' WHERE f.entity = '.$conf->entity;
773
+        $sql.= ' WHERE f.entity = '.$conf->entity;
774 774
         $sql.= ' AND (f.fk_soc = '.$facture->socid;
775 775
 
776
-		if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
777
-			$sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')';
778
-		}
776
+        if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
777
+            $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')';
778
+        }
779 779
 
780 780
         $sql.= ') AND f.paye = 0';
781 781
         $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
@@ -797,17 +797,17 @@  discard block
 block discarded – undo
797 797
             $num = $db->num_rows($resql);
798 798
             if ($num > 0)
799 799
             {
800
-            	$sign=1;
801
-            	if ($facture->type == 2) $sign=-1;
802
-
803
-				$arraytitle=$langs->trans('Invoice');
804
-				if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
805
-				$alreadypayedlabel=$langs->trans('Received');
806
-				$multicurrencyalreadypayedlabel=$langs->trans('MulticurrencyReceived');
807
-				if ($facture->type == 2) { $alreadypayedlabel=$langs->trans("PaidBack"); $multicurrencyalreadypayedlabel=$langs->trans("MulticurrencyPaidBack"); }
808
-				$remaindertopay=$langs->trans('RemainderToTake');
809
-				$multicurrencyremaindertopay=$langs->trans('MulticurrencyRemainderToTake');
810
-				if ($facture->type == 2) { $remaindertopay=$langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay=$langs->trans("MulticurrencyRemainderToPayBack"); }
800
+                $sign=1;
801
+                if ($facture->type == 2) $sign=-1;
802
+
803
+                $arraytitle=$langs->trans('Invoice');
804
+                if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
805
+                $alreadypayedlabel=$langs->trans('Received');
806
+                $multicurrencyalreadypayedlabel=$langs->trans('MulticurrencyReceived');
807
+                if ($facture->type == 2) { $alreadypayedlabel=$langs->trans("PaidBack"); $multicurrencyalreadypayedlabel=$langs->trans("MulticurrencyPaidBack"); }
808
+                $remaindertopay=$langs->trans('RemainderToTake');
809
+                $multicurrencyremaindertopay=$langs->trans('MulticurrencyRemainderToTake');
810
+                if ($facture->type == 2) { $remaindertopay=$langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay=$langs->trans("MulticurrencyRemainderToPayBack"); }
811 811
 
812 812
                 $i = 0;
813 813
                 //print '<tr><td colspan="3">';
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
                 {
843 843
                     $objp = $db->fetch_object($resql);
844 844
 
845
-					$soc = new Societe($db);
846
-					$soc->fetch($objp->socid);
845
+                    $soc = new Societe($db);
846
+                    $soc->fetch($objp->socid);
847 847
 
848 848
                     $invoice=new Facture($db);
849 849
                     $invoice->fetch($objp->facid);
@@ -853,15 +853,15 @@  discard block
 block discarded – undo
853 853
                     $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
854 854
                     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
855 855
 
856
-					// Multicurrency Price
857
-					if (!empty($conf->multicurrency->enabled))
858
-					{
859
-						$multicurrency_payment = $invoice->getSommePaiement(1);
860
-						$multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1);
861
-						$multicurrency_deposits=$invoice->getSumDepositsUsed(1);
862
-						$multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT');
863
-	                    $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT');
864
-					}
856
+                    // Multicurrency Price
857
+                    if (!empty($conf->multicurrency->enabled))
858
+                    {
859
+                        $multicurrency_payment = $invoice->getSommePaiement(1);
860
+                        $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1);
861
+                        $multicurrency_deposits=$invoice->getSumDepositsUsed(1);
862
+                        $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT');
863
+                        $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT');
864
+                    }
865 865
 
866 866
                     print '<tr class="oddeven">';
867 867
 
@@ -876,30 +876,30 @@  discard block
 block discarded – undo
876 876
                     // Currency
877 877
                     if (!empty($conf->multicurrency->enabled)) print '<td align="center">'.$objp->multicurrency_code."</td>\n";
878 878
 
879
-					// Multicurrency Price
880
-					if (!empty($conf->multicurrency->enabled))
881
-					{
882
-					    print '<td align="right">';
883
-					    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc);
884
-					    print '</td>';
885
-
886
-                    	// Multicurrency Price
887
-						print '<td align="right">';
888
-						if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
889
-						{
890
-						    print price($sign * $multicurrency_payment);
891
-    		                if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes);
892
-    		                if ($multicurrency_deposits) print '+'.price($multicurrency_deposits);
893
-						}
894
-		                print '</td>';
895
-
896
-    					// Multicurrency Price
897
-    				    print '<td align="right">';
898
-    				    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay);
899
-    				    print '</td>';
900
-					}
879
+                    // Multicurrency Price
880
+                    if (!empty($conf->multicurrency->enabled))
881
+                    {
882
+                        print '<td align="right">';
883
+                        if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc);
884
+                        print '</td>';
885
+
886
+                        // Multicurrency Price
887
+                        print '<td align="right">';
888
+                        if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
889
+                        {
890
+                            print price($sign * $multicurrency_payment);
891
+                            if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes);
892
+                            if ($multicurrency_deposits) print '+'.price($multicurrency_deposits);
893
+                        }
894
+                        print '</td>';
895
+
896
+                        // Multicurrency Price
897
+                        print '<td align="right">';
898
+                        if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay);
899
+                        print '</td>';
900
+                    }
901 901
 
902
-					// Price
902
+                    // Price
903 903
                     print '<td align="right">'.price($sign * $objp->total_ttc).'</td>';
904 904
 
905 905
                     // Received or paid back
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
                     if ($action != 'add_paiement')
923 923
                     {
924 924
                         if (!empty($conf->use_javascript_ajax))
925
-							print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
925
+                            print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
926 926
                         print '<input type=hidden class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
927 927
                         print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
928 928
                     }
@@ -933,45 +933,45 @@  discard block
 block discarded – undo
933 933
                     }
934 934
                     print "</td>";
935 935
 
936
-					// Multicurrency Price
937
-					if (! empty($conf->multicurrency->enabled))
938
-					{
939
-						print '<td align="right">';
940
-
941
-						// Add remind multicurrency amount
942
-	                    $namef = 'multicurrency_amount_'.$objp->facid;
943
-	                    $nameRemain = 'multicurrency_remain_'.$objp->facid;
944
-
945
-	                    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
946
-	                    {
947
-    	                    if ($action != 'add_paiement')
948
-    	                    {
949
-    	                        if (!empty($conf->use_javascript_ajax))
950
-    								print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
951
-    	                        print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
952
-    	                        print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
953
-    	                    }
954
-    	                    else
955
-    	                    {
956
-    	                        print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
957
-    	                        print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
958
-    	                    }
959
-	                    }
960
-	                    print "</td>";
961
-					}
936
+                    // Multicurrency Price
937
+                    if (! empty($conf->multicurrency->enabled))
938
+                    {
939
+                        print '<td align="right">';
940
+
941
+                        // Add remind multicurrency amount
942
+                        $namef = 'multicurrency_amount_'.$objp->facid;
943
+                        $nameRemain = 'multicurrency_remain_'.$objp->facid;
944
+
945
+                        if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
946
+                        {
947
+                            if ($action != 'add_paiement')
948
+                            {
949
+                                if (!empty($conf->use_javascript_ajax))
950
+                                    print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
951
+                                print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
952
+                                print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
953
+                            }
954
+                            else
955
+                            {
956
+                                print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
957
+                                print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
958
+                            }
959
+                        }
960
+                        print "</td>";
961
+                    }
962 962
 
963 963
                     // Warning
964 964
                     print '<td align="center" width="16">';
965 965
                     //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."<br>";
966 966
                     if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id]))
967
-                    	|| $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id])))
967
+                        || $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id])))
968 968
                     {
969 969
                         print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay"));
970 970
                     }
971 971
                     print '</td>';
972 972
 
973
-					$parameters=array();
974
-					$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
973
+                    $parameters=array();
974
+                    $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
975 975
 
976 976
                     print "</tr>\n";
977 977
 
@@ -988,19 +988,19 @@  discard block
 block discarded – undo
988 988
                     // Print total
989 989
                     print '<tr class="liste_total">';
990 990
                     print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').'</td>';
991
-					if (!empty($conf->multicurrency->enabled)) {
991
+                    if (!empty($conf->multicurrency->enabled)) {
992
+                        print '<td></td>';
993
+                        print '<td></td>';
992 994
                         print '<td></td>';
993
-					    print '<td></td>';
994
-					    print '<td></td>';
995 995
                     }
996
-					print '<td align="right"><b>'.price($sign * $total_ttc).'</b></td>';
996
+                    print '<td align="right"><b>'.price($sign * $total_ttc).'</b></td>';
997 997
                     print '<td align="right"><b>'.price($sign * $totalrecu);
998 998
                     if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
999 999
                     if ($totalrecudeposits) print '+'.price($totalrecudeposits);
1000 1000
                     print '</b></td>';
1001 1001
                     print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
1002 1002
                     print '<td align="right" id="result" style="font-weight: bold;"></td>';
1003
-					if (!empty($conf->multicurrency->enabled)) {
1003
+                    if (!empty($conf->multicurrency->enabled)) {
1004 1004
                         print '<td align="right" id="multicurrency_result" style="font-weight: bold;"></td>';
1005 1005
                     }
1006 1006
                     print "</tr>\n";
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
             $db->free($resql);
1012 1012
         }
1013 1013
         else
1014
-		{
1014
+        {
1015 1015
             dol_print_error($db);
1016 1016
         }
1017 1017
 
@@ -1019,13 +1019,13 @@  discard block
 block discarded – undo
1019 1019
         // Bouton Enregistrer
1020 1020
         if ($action != 'add_paiement')
1021 1021
         {
1022
-        	$checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically");
1023
-        	if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
1024
-        	$buttontitle=$langs->trans('ToMakePayment');
1025
-        	if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack');
1022
+            $checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically");
1023
+            if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
1024
+            $buttontitle=$langs->trans('ToMakePayment');
1025
+            if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack');
1026 1026
 
1027
-        	print '<br><div class="center">';
1028
-        	print '<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
1027
+            print '<br><div class="center">';
1028
+            print '<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
1029 1029
             /*if (! empty($conf->prelevement->enabled))
1030 1030
             {
1031 1031
                 $langs->load("withdrawals");
@@ -1044,9 +1044,9 @@  discard block
 block discarded – undo
1044 1044
             if (!empty($totalpayment)) {
1045 1045
                 $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency));
1046 1046
             }
1047
-			if (!empty($multicurrency_totalpayment)) {
1048
-				$text.='<br>'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency"));
1049
-			}
1047
+            if (!empty($multicurrency_totalpayment)) {
1048
+                $text.='<br>'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency"));
1049
+            }
1050 1050
             if (GETPOST('closepaidinvoices'))
1051 1051
             {
1052 1052
                 $text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
@@ -1099,7 +1099,7 @@  discard block
 block discarded – undo
1099 1099
         print_liste_field_titre('Date',$_SERVER["PHP_SELF"],'dp','','','',$sortfield,$sortorder);
1100 1100
         print_liste_field_titre('Type',$_SERVER["PHP_SELF"],'libelle','','','',$sortfield,$sortorder);
1101 1101
         print_liste_field_titre('Amount',$_SERVER["PHP_SELF"],'fa_amount','','','align="right"',$sortfield,$sortorder);
1102
-		print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
1102
+        print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
1103 1103
         print "</tr>\n";
1104 1104
 
1105 1105
         while ($i < min($num,$limit))
@@ -1111,8 +1111,8 @@  discard block
 block discarded – undo
1111 1111
             print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
1112 1112
             print '<td align="right">'.price($objp->amount).'</td><td>&nbsp;</td>';
1113 1113
 
1114
-			$parameters=array();
1115
-			$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
1114
+            $parameters=array();
1115
+            $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
1116 1116
 
1117 1117
             print '</tr>';
1118 1118
             $i++;
Please login to merge, or discard this patch.
Braces   +118 added lines, -58 removed lines patch added patch discarded remove patch
@@ -102,7 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
 $parameters=array('socid'=>$socid);
104 104
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
105
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105
+if ($reshook < 0) {
106
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107
+}
106 108
 
107 109
 if (empty($reshook))
108 110
 {
@@ -125,9 +127,13 @@  discard block
 block discarded – undo
125 127
 	            $cursorfacid = substr($key,7);
126 128
 	            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
127 129
 	            $totalpayment = $totalpayment + $amounts[$cursorfacid];
128
-	            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
130
+	            if (! empty($amounts[$cursorfacid])) {
131
+	                $atleastonepaymentnotnull++;
132
+	            }
129 133
 	            $result=$tmpinvoice->fetch($cursorfacid);
130
-	            if ($result <= 0) dol_print_error($db);
134
+	            if ($result <= 0) {
135
+	                dol_print_error($db);
136
+	            }
131 137
 	            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
132 138
 	            if ($amounts[$cursorfacid])
133 139
 	            {
@@ -147,15 +153,18 @@  discard block
 block discarded – undo
147 153
 	            }
148 154
 
149 155
 	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
150
-	        }
151
-			elseif (substr($key,0,21) == 'multicurrency_amount_')
156
+	        } elseif (substr($key,0,21) == 'multicurrency_amount_')
152 157
 			{
153 158
 				$cursorfacid = substr($key,21);
154 159
 	            $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
155 160
 	            $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
156
-	            if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
161
+	            if (! empty($multicurrency_amounts[$cursorfacid])) {
162
+	                $atleastonepaymentnotnull++;
163
+	            }
157 164
 	            $result=$tmpinvoice->fetch($cursorfacid);
158
-	            if ($result <= 0) dol_print_error($db);
165
+	            if ($result <= 0) {
166
+	                dol_print_error($db);
167
+	            }
159 168
 	            $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
160 169
 	            if ($multicurrency_amounts[$cursorfacid])
161 170
 	            {
@@ -244,15 +253,19 @@  discard block
 block discarded – undo
244 253
 		// Clean parameters amount if payment is for a credit note
245 254
 		if (GETPOST('type') == 2)
246 255
 		{
247
-			foreach ($amounts as $key => $value)	// How payment is dispatch
256
+			foreach ($amounts as $key => $value) {
257
+			    // How payment is dispatch
248 258
 			{
249 259
 				$newvalue = price2num($value,'MT');
260
+			}
250 261
 				$amounts[$key] = -$newvalue;
251 262
 			}
252 263
 
253
-			foreach ($multicurrency_amounts as $key => $value)	// How payment is dispatch
264
+			foreach ($multicurrency_amounts as $key => $value) {
265
+			    // How payment is dispatch
254 266
 			{
255 267
 				$newvalue = price2num($value,'MT');
268
+			}
256 269
 				$multicurrency_amounts[$key] = -$newvalue;
257 270
 			}
258 271
 		}
@@ -283,20 +296,20 @@  discard block
 block discarded – undo
283 296
 		}
284 297
 
285 298
 		$stripeamount=0;
286
-		foreach ($amounts as $key => $value)	// How payment is dispatch
299
+		foreach ($amounts as $key => $value) {
300
+		    // How payment is dispatch
287 301
 		{
288 302
 			$stripeamount+=price2num($value,'MT');
289 303
 		}
304
+		}
290 305
 
291 306
 		if (preg_match('/acct_/i',$source))
292 307
 		{
293 308
 			$paiementcode ="VIR";
294
-		}
295
-		elseif (preg_match('/card_/i',$source))
309
+		} elseif (preg_match('/card_/i',$source))
296 310
 		{
297 311
 			$paiementcode ="CB";
298
-		}
299
-		elseif (preg_match('/src_/i',$source))
312
+		} elseif (preg_match('/src_/i',$source))
300 313
 		{
301 314
 
302 315
 		        $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
@@ -344,8 +357,12 @@  discard block
 block discarded – undo
344 357
 			{
345 358
 				$outputlangs = $langs;
346 359
 				$newlang = '';
347
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
348
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $facture->thirdparty->default_lang;
360
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
361
+				    $newlang = GETPOST('lang_id','aZ09');
362
+				}
363
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
364
+				    $newlang = $facture->thirdparty->default_lang;
365
+				}
349 366
 				if (! empty($newlang)) {
350 367
 					$outputlangs = new Translate("", $conf);
351 368
 					$outputlangs->setDefaultLang($newlang);
@@ -360,14 +377,15 @@  discard block
 block discarded – undo
360 377
 		if (! $error)
361 378
 		{
362 379
 			$label='(CustomerInvoicePayment)';
363
-			if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
380
+			if (GETPOST('type') == 2) {
381
+			    $label='(CustomerInvoicePaymentBack)';
382
+			}
364 383
 			$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'','');
365 384
 			if ($result < 0)
366 385
 			{
367 386
 				setEventMessages($paiement->error, $paiement->errors, 'errors');
368 387
 				$error++;
369
-			}
370
-			elseif (GETPOST('closepaidinvoices')=='on') {
388
+			} elseif (GETPOST('closepaidinvoices')=='on') {
371 389
 				$facture->set_paid($user);
372 390
 			}
373 391
 		}
@@ -383,16 +401,23 @@  discard block
 block discarded – undo
383 401
 				$facid = $key;
384 402
 				if (is_numeric($amount) && $amount <> 0)
385 403
 				{
386
-					if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
387
-					else $invoiceid=$facid;
404
+					if ($invoiceid != 0) {
405
+					    $invoiceid=-1;
406
+					}
407
+					// There is more than one invoice payed by this payment
408
+					else {
409
+					    $invoiceid=$facid;
410
+					}
388 411
 				}
389 412
 			}
390
-			if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
391
-			else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
413
+			if ($invoiceid > 0) {
414
+			    $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
415
+			} else {
416
+			    $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
417
+			}
392 418
 			header('Location: '.$loc);
393 419
 			exit;
394
-		}
395
-		else
420
+		} else
396 421
 		{
397 422
 			$loc = DOL_URL_ROOT.'/stripe/payment.php?facid='.$facid.'&action=create&error='.$charge->message;
398 423
 			$db->rollback();
@@ -433,8 +458,12 @@  discard block
 block discarded – undo
433 458
 		$facture->fetch_thirdparty();
434 459
 
435 460
 		$title='';
436
-		if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
437
-		if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
461
+		if ($facture->type != 2) {
462
+		    $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
463
+		}
464
+		if ($facture->type == 2) {
465
+		    $title.=$langs->trans("EnterPaymentDueToCustomer");
466
+		}
438 467
 		print load_fiche_titre($title);
439 468
 
440 469
 		// Initialize data for confirmation (this is used because data can be change during confirmation)
@@ -576,8 +605,7 @@  discard block
 block discarded – undo
576 605
         {
577 606
             //$form->select_comptes($accountid,'accountid',0,'',2);
578 607
             print '<input name="accountid" type="hidden" value="'.$conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS.'">';
579
-        }
580
-        else
608
+        } else
581 609
         {
582 610
             print '<input name="accountid" type="hidden" value="'.$conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS.'">';
583 611
         }
@@ -782,8 +810,7 @@  discard block
 block discarded – undo
782 810
         if ($facture->type != 2)
783 811
         {
784 812
             $sql .= ' AND type IN (0,1,3,5)';	// Standard invoice, replacement, deposit, situation
785
-        }
786
-        else
813
+        } else
787 814
         {
788 815
             $sql .= ' AND type = 2';		// If paying back a credit note, we show all credit notes
789 816
         }
@@ -798,10 +825,14 @@  discard block
 block discarded – undo
798 825
             if ($num > 0)
799 826
             {
800 827
             	$sign=1;
801
-            	if ($facture->type == 2) $sign=-1;
828
+            	if ($facture->type == 2) {
829
+            	    $sign=-1;
830
+            	}
802 831
 
803 832
 				$arraytitle=$langs->trans('Invoice');
804
-				if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
833
+				if ($facture->type == 2) {
834
+				    $arraytitle=$langs->trans("CreditNotes");
835
+				}
805 836
 				$alreadypayedlabel=$langs->trans('Received');
806 837
 				$multicurrencyalreadypayedlabel=$langs->trans('MulticurrencyReceived');
807 838
 				if ($facture->type == 2) { $alreadypayedlabel=$langs->trans("PaidBack"); $multicurrencyalreadypayedlabel=$langs->trans("MulticurrencyPaidBack"); }
@@ -867,20 +898,26 @@  discard block
 block discarded – undo
867 898
 
868 899
                     print '<td>';
869 900
                     print $invoice->getNomUrl(1,'');
870
-                    if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
901
+                    if($objp->socid != $facture->thirdparty->id) {
902
+                        print ' - '.$soc->getNomUrl(1).' ';
903
+                    }
871 904
                     print "</td>\n";
872 905
 
873 906
                     // Date
874 907
                     print '<td align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";
875 908
 
876 909
                     // Currency
877
-                    if (!empty($conf->multicurrency->enabled)) print '<td align="center">'.$objp->multicurrency_code."</td>\n";
910
+                    if (!empty($conf->multicurrency->enabled)) {
911
+                        print '<td align="center">'.$objp->multicurrency_code."</td>\n";
912
+                    }
878 913
 
879 914
 					// Multicurrency Price
880 915
 					if (!empty($conf->multicurrency->enabled))
881 916
 					{
882 917
 					    print '<td align="right">';
883
-					    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc);
918
+					    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
919
+					        print price($sign * $objp->multicurrency_total_ttc);
920
+					    }
884 921
 					    print '</td>';
885 922
 
886 923
                     	// Multicurrency Price
@@ -888,14 +925,20 @@  discard block
 block discarded – undo
888 925
 						if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
889 926
 						{
890 927
 						    print price($sign * $multicurrency_payment);
891
-    		                if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes);
892
-    		                if ($multicurrency_deposits) print '+'.price($multicurrency_deposits);
928
+    		                if ($multicurrency_creditnotes) {
929
+    		                    print '+'.price($multicurrency_creditnotes);
930
+    		                }
931
+    		                if ($multicurrency_deposits) {
932
+    		                    print '+'.price($multicurrency_deposits);
933
+    		                }
893 934
 						}
894 935
 		                print '</td>';
895 936
 
896 937
     					// Multicurrency Price
897 938
     				    print '<td align="right">';
898
-    				    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay);
939
+    				    if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
940
+    				        print price($sign * $multicurrency_remaintopay);
941
+    				    }
899 942
     				    print '</td>';
900 943
 					}
901 944
 
@@ -904,8 +947,12 @@  discard block
 block discarded – undo
904 947
 
905 948
                     // Received or paid back
906 949
                     print '<td align="right">'.price($sign * $paiement);
907
-                    if ($creditnotes) print '+'.price($creditnotes);
908
-                    if ($deposits) print '+'.price($deposits);
950
+                    if ($creditnotes) {
951
+                        print '+'.price($creditnotes);
952
+                    }
953
+                    if ($deposits) {
954
+                        print '+'.price($deposits);
955
+                    }
909 956
                     print '</td>';
910 957
 
911 958
                     // Remain to take or to pay back
@@ -921,12 +968,12 @@  discard block
 block discarded – undo
921 968
 
922 969
                     if ($action != 'add_paiement')
923 970
                     {
924
-                        if (!empty($conf->use_javascript_ajax))
925
-							print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
971
+                        if (!empty($conf->use_javascript_ajax)) {
972
+                        							print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
973
+                        }
926 974
                         print '<input type=hidden class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
927 975
                         print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
928
-                    }
929
-                    else
976
+                    } else
930 977
                     {
931 978
                         print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.dol_escape_htmltag(GETPOST($namef)).'" disabled>';
932 979
                         print '<input type="hidden" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
@@ -946,12 +993,12 @@  discard block
 block discarded – undo
946 993
 	                    {
947 994
     	                    if ($action != 'add_paiement')
948 995
     	                    {
949
-    	                        if (!empty($conf->use_javascript_ajax))
950
-    								print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
996
+    	                        if (!empty($conf->use_javascript_ajax)) {
997
+    	                            								print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
998
+    	                        }
951 999
     	                        print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
952 1000
     	                        print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
953
-    	                    }
954
-    	                    else
1001
+    	                    } else
955 1002
     	                    {
956 1003
     	                        print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
957 1004
     	                        print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
@@ -995,8 +1042,12 @@  discard block
 block discarded – undo
995 1042
                     }
996 1043
 					print '<td align="right"><b>'.price($sign * $total_ttc).'</b></td>';
997 1044
                     print '<td align="right"><b>'.price($sign * $totalrecu);
998
-                    if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
999
-                    if ($totalrecudeposits) print '+'.price($totalrecudeposits);
1045
+                    if ($totalrecucreditnote) {
1046
+                        print '+'.price($totalrecucreditnote);
1047
+                    }
1048
+                    if ($totalrecudeposits) {
1049
+                        print '+'.price($totalrecudeposits);
1050
+                    }
1000 1051
                     print '</b></td>';
1001 1052
                     print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
1002 1053
                     print '<td align="right" id="result" style="font-weight: bold;"></td>';
@@ -1009,8 +1060,7 @@  discard block
 block discarded – undo
1009 1060
                 //print "</td></tr>\n";
1010 1061
             }
1011 1062
             $db->free($resql);
1012
-        }
1013
-        else
1063
+        } else
1014 1064
 		{
1015 1065
             dol_print_error($db);
1016 1066
         }
@@ -1020,9 +1070,13 @@  discard block
 block discarded – undo
1020 1070
         if ($action != 'add_paiement')
1021 1071
         {
1022 1072
         	$checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically");
1023
-        	if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
1073
+        	if ($facture->type == 2) {
1074
+        	    $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
1075
+        	}
1024 1076
         	$buttontitle=$langs->trans('ToMakePayment');
1025
-        	if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack');
1077
+        	if ($facture->type == 2) {
1078
+        	    $buttontitle=$langs->trans('ToMakePaymentBack');
1079
+        	}
1026 1080
 
1027 1081
         	print '<br><div class="center">';
1028 1082
         	print '<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
@@ -1066,12 +1120,18 @@  discard block
 block discarded – undo
1066 1120
 
1067 1121
 if (! GETPOST('action'))
1068 1122
 {
1069
-    if ($page == -1) $page = 0 ;
1123
+    if ($page == -1) {
1124
+        $page = 0 ;
1125
+    }
1070 1126
     $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
1071 1127
     $offset = $limit * $page ;
1072 1128
 
1073
-    if (! $sortorder) $sortorder='DESC';
1074
-    if (! $sortfield) $sortfield='p.datep';
1129
+    if (! $sortorder) {
1130
+        $sortorder='DESC';
1131
+    }
1132
+    if (! $sortfield) {
1133
+        $sortfield='p.datep';
1134
+    }
1075 1135
 
1076 1136
     $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.ref';
1077 1137
     $sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
Please login to merge, or discard this patch.
Spacing   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
37 37
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
38
-require DOL_BASE_PATH . '/main.inc.php';
38
+require DOL_BASE_PATH.'/main.inc.php';
39 39
 
40 40
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41 41
 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
@@ -47,70 +47,70 @@  discard block
 block discarded – undo
47 47
 // Load translation files required by the page
48 48
 $langs->loadLangs(array('companies', 'bills', 'banks', 'multicurrency', 'stripe'));
49 49
 
50
-$action		= GETPOST('action','alpha');
50
+$action		= GETPOST('action', 'alpha');
51 51
 $confirm	= GETPOST('confirm');
52 52
 
53
-$facid		= GETPOST('facid','int');
53
+$facid		= GETPOST('facid', 'int');
54 54
 $socname	= GETPOST('socname');
55 55
 $source = GETPOST('source_id');
56 56
 $accountid	= GETPOST('accountid');
57 57
 $paymentnum = GETPOST('num_paiement');
58 58
 
59
-$sortfield	= GETPOST('sortfield','alpha');
60
-$sortorder	= GETPOST('sortorder','alpha');
61
-$page		= GETPOST('page','int');
59
+$sortfield	= GETPOST('sortfield', 'alpha');
60
+$sortorder	= GETPOST('sortorder', 'alpha');
61
+$page = GETPOST('page', 'int');
62 62
 
63
-$amounts=array();
64
-$amountsresttopay=array();
65
-$addwarning=0;
63
+$amounts = array();
64
+$amountsresttopay = array();
65
+$addwarning = 0;
66 66
 
67
-$multicurrency_amounts=array();
68
-$multicurrency_amountsresttopay=array();
67
+$multicurrency_amounts = array();
68
+$multicurrency_amountsresttopay = array();
69 69
 
70 70
 // Security check
71
-$socid=0;
71
+$socid = 0;
72 72
 if ($user->societe_id > 0)
73 73
 {
74 74
     $socid = $user->societe_id;
75 75
 }
76 76
 
77
-$object=new Facture($db);
77
+$object = new Facture($db);
78 78
 
79 79
 // Load object
80 80
 if ($facid > 0)
81 81
 {
82
-	$ret=$object->fetch($facid);
82
+	$ret = $object->fetch($facid);
83 83
 }
84 84
 
85
-if (! empty($conf->stripe->enabled))
85
+if (!empty($conf->stripe->enabled))
86 86
 {
87 87
 	$service = 'StripeTest';
88 88
 	$servicestatus = 0;
89
-	if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha'))
89
+	if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha'))
90 90
 	{
91 91
 		$service = 'StripeLive';
92 92
 		$servicestatus = 0;
93 93
 	}
94 94
 
95
-	$stripe=new Stripe($db);
96
-	$stripeacc = $stripe->getStripeAccount($service);								// Stripe OAuth connect account of dolibarr user (no network access here)
95
+	$stripe = new Stripe($db);
96
+	$stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
97 97
 }
98 98
 
99 99
 // Initialize technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array
100
-$hookmanager->initHooks(array('paiementcard','globalcard'));
100
+$hookmanager->initHooks(array('paiementcard', 'globalcard'));
101 101
 
102 102
 
103 103
 /*
104 104
  * Actions
105 105
  */
106 106
 
107
-$parameters=array('socid'=>$socid);
108
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
107
+$parameters = array('socid'=>$socid);
108
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109 109
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 110
 
111 111
 if (empty($reshook))
112 112
 {
113
-	if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
113
+	if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes'))
114 114
 	{
115 115
 	    $error = 0;
116 116
 
@@ -121,24 +121,24 @@  discard block
 block discarded – undo
121 121
 	    $atleastonepaymentnotnull = 0;
122 122
 
123 123
 	    // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
124
-	    $tmpinvoice=new Facture($db);
124
+	    $tmpinvoice = new Facture($db);
125 125
 	    foreach ($_POST as $key => $value)
126 126
 	    {
127
-	        if (substr($key,0,7) == 'amount_')
127
+	        if (substr($key, 0, 7) == 'amount_')
128 128
 	        {
129
-	            $cursorfacid = substr($key,7);
129
+	            $cursorfacid = substr($key, 7);
130 130
 	            $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
131 131
 	            $totalpayment = $totalpayment + $amounts[$cursorfacid];
132
-	            if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
133
-	            $result=$tmpinvoice->fetch($cursorfacid);
132
+	            if (!empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
133
+	            $result = $tmpinvoice->fetch($cursorfacid);
134 134
 	            if ($result <= 0) dol_print_error($db);
135
-	            $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
135
+	            $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
136 136
 	            if ($amounts[$cursorfacid])
137 137
 	            {
138 138
 		            // Check amount
139 139
 		            if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
140 140
 		            {
141
-		                $addwarning=1;
141
+		                $addwarning = 1;
142 142
 		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
143 143
 		            }
144 144
 		            // Check date
@@ -146,27 +146,27 @@  discard block
 block discarded – undo
146 146
 		            {
147 147
 		            	$langs->load("errors");
148 148
 		                //$error++;
149
-		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
149
+		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
150 150
 		            }
151 151
 	            }
152 152
 
153
-	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => $_POST[$key]);
153
+	            $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]);
154 154
 	        }
155
-			elseif (substr($key,0,21) == 'multicurrency_amount_')
155
+			elseif (substr($key, 0, 21) == 'multicurrency_amount_')
156 156
 			{
157
-				$cursorfacid = substr($key,21);
157
+				$cursorfacid = substr($key, 21);
158 158
 	            $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
159 159
 	            $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
160
-	            if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
161
-	            $result=$tmpinvoice->fetch($cursorfacid);
160
+	            if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
161
+	            $result = $tmpinvoice->fetch($cursorfacid);
162 162
 	            if ($result <= 0) dol_print_error($db);
163
-	            $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
163
+	            $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
164 164
 	            if ($multicurrency_amounts[$cursorfacid])
165 165
 	            {
166 166
 		            // Check amount
167 167
 		            if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
168 168
 		            {
169
-		                $addwarning=1;
169
+		                $addwarning = 1;
170 170
 		                $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
171 171
 		            }
172 172
 		            // Check date
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 		            {
175 175
 		            	$langs->load("errors");
176 176
 		                //$error++;
177
-		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
177
+		                setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
178 178
 		            }
179 179
 	            }
180 180
 
181
-	            $formquestion[$i++]=array('type' => 'hidden','name' => $key,  'value' => GETPOST($key, 'int'));
181
+	            $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int'));
182 182
 			}
183 183
 	    }
184 184
 
@@ -189,19 +189,19 @@  discard block
 block discarded – undo
189 189
 //	        $error++;
190 190
 //	    }
191 191
 
192
-	    if (! empty($conf->banque->enabled))
192
+	    if (!empty($conf->banque->enabled))
193 193
 	    {
194 194
 	        // If bank module is on, account is required to enter a payment
195 195
 	        if (GETPOST('accountid') <= 0)
196 196
 	        {
197
-	            setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
197
+	            setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
198 198
 	            $error++;
199 199
 	        }
200 200
 	    }
201 201
 
202 202
 	    if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
203 203
 	    {
204
-	        setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors');
204
+	        setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors');
205 205
 	        $error++;
206 206
 	    }
207 207
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	if ($action == 'confirm_paiement' && $confirm == 'yes')
240 240
 	{
241 241
 
242
-		$error=0;
242
+		$error = 0;
243 243
 
244 244
 		$datepaye = dol_now();
245 245
 
@@ -250,23 +250,23 @@  discard block
 block discarded – undo
250 250
 		{
251 251
 			foreach ($amounts as $key => $value)	// How payment is dispatch
252 252
 			{
253
-				$newvalue = price2num($value,'MT');
253
+				$newvalue = price2num($value, 'MT');
254 254
 				$amounts[$key] = -$newvalue;
255 255
 			}
256 256
 
257 257
 			foreach ($multicurrency_amounts as $key => $value)	// How payment is dispatch
258 258
 			{
259
-				$newvalue = price2num($value,'MT');
259
+				$newvalue = price2num($value, 'MT');
260 260
 				$multicurrency_amounts[$key] = -$newvalue;
261 261
 			}
262 262
 		}
263 263
 
264
-		if (! empty($conf->banque->enabled))
264
+		if (!empty($conf->banque->enabled))
265 265
 		{
266 266
 			// Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
267 267
 			if (GETPOST('accountid') <= 0)
268 268
 			{
269
-				setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
269
+				setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
270 270
 				$error++;
271 271
 			}
272 272
 		}
@@ -279,35 +279,35 @@  discard block
 block discarded – undo
279 279
 
280 280
 		if (is_object($stripe) && $stripeacc)
281 281
 		{
282
-			$customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
282
+			$customerstripe = $stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
283 283
 
284 284
 			if ($customerstripe->id) {
285
-				$listofsources=$customerstripe->sources->data;
285
+				$listofsources = $customerstripe->sources->data;
286 286
 			}
287 287
 		}
288 288
 
289
-		$stripeamount=0;
289
+		$stripeamount = 0;
290 290
 		foreach ($amounts as $key => $value)	// How payment is dispatch
291 291
 		{
292
-			$stripeamount+=price2num($value,'MT');
292
+			$stripeamount += price2num($value, 'MT');
293 293
 		}
294 294
 
295
-		if (preg_match('/acct_/i',$source))
295
+		if (preg_match('/acct_/i', $source))
296 296
 		{
297
-			$paiementcode ="VIR";
297
+			$paiementcode = "VIR";
298 298
 		}
299
-		elseif (preg_match('/card_/i',$source))
299
+		elseif (preg_match('/card_/i', $source))
300 300
 		{
301
-			$paiementcode ="CB";
301
+			$paiementcode = "CB";
302 302
 		}
303
-		elseif (preg_match('/src_/i',$source))
303
+		elseif (preg_match('/src_/i', $source))
304 304
 		{
305 305
 
306
-		        $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
306
+		        $customer2 = $customerstripe = $stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
307 307
 			$src = $customer2->sources->retrieve("$source");
308
-			if ($src->type=='card')
308
+			if ($src->type == 'card')
309 309
 			{
310
-				$paiementcode ="CB";
310
+				$paiementcode = "CB";
311 311
 			}
312 312
 		}
313 313
 
@@ -317,25 +317,25 @@  discard block
 block discarded – undo
317 317
 		$societe->fetch($facture->socid);
318 318
 		dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
319 319
 
320
-		$stripecu = $stripe->getStripeCustomerAccount($societe->id, $servicestatus);		// Get thirdparty cu_...
320
+		$stripecu = $stripe->getStripeCustomerAccount($societe->id, $servicestatus); // Get thirdparty cu_...
321 321
 
322
-		$charge=$stripe->createPaymentStripe($stripeamount,$facture->multicurrency_code,"invoice",$facid,$source,$stripecu,$stripeacc,$servicestatus);
322
+		$charge = $stripe->createPaymentStripe($stripeamount, $facture->multicurrency_code, "invoice", $facid, $source, $stripecu, $stripeacc, $servicestatus);
323 323
 
324 324
 		if (!$error)
325 325
 		{
326 326
 			// Creation of payment line
327 327
 			$paiement = new Paiement($db);
328 328
 			$paiement->datepaye     = $datepaye;
329
-			$paiement->amounts      = $amounts;   // Array with all payments dispatching
330
-			$paiement->multicurrency_amounts = $multicurrency_amounts;   // Array with all payments dispatching
331
-			$paiement->paiementid   = dol_getIdFromCode($db,$paiementcode,'c_paiement');
329
+			$paiement->amounts      = $amounts; // Array with all payments dispatching
330
+			$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
331
+			$paiement->paiementid   = dol_getIdFromCode($db, $paiementcode, 'c_paiement');
332 332
 			$paiement->num_paiement = $charge->message;
333 333
 			$paiement->note         = GETPOST('comment');
334 334
 			$paiement->ext_payment_id = $charge->id;
335 335
 			$paiement->ext_payment_site = $service;
336 336
 		}
337 337
 
338
-		if (! $error)
338
+		if (!$error)
339 339
 		{
340 340
 
341 341
 			$paiement_id = $paiement->create($user, 0);
@@ -348,47 +348,47 @@  discard block
 block discarded – undo
348 348
 			{
349 349
 				$outputlangs = $langs;
350 350
 				$newlang = '';
351
-				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
351
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
352 352
 				if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $facture->thirdparty->default_lang;
353
-				if (! empty($newlang)) {
353
+				if (!empty($newlang)) {
354 354
 					$outputlangs = new Translate("", $conf);
355 355
 					$outputlangs->setDefaultLang($newlang);
356 356
 				}
357
-				$model=$facture->modelpdf;
357
+				$model = $facture->modelpdf;
358 358
 				$ret = $facture->fetch($facid); // Reload to get new records
359 359
 
360 360
 				$facture->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
361 361
 			}
362 362
 		}
363 363
 
364
-		if (! $error)
364
+		if (!$error)
365 365
 		{
366
-			$label='(CustomerInvoicePayment)';
367
-			if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
368
-			$result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'','');
366
+			$label = '(CustomerInvoicePayment)';
367
+			if (GETPOST('type') == 2) $label = '(CustomerInvoicePaymentBack)';
368
+			$result = $paiement->addPaymentToBank($user, 'payment', $label, GETPOST('accountid'), '', '');
369 369
 			if ($result < 0)
370 370
 			{
371 371
 				setEventMessages($paiement->error, $paiement->errors, 'errors');
372 372
 				$error++;
373 373
 			}
374
-			elseif (GETPOST('closepaidinvoices')=='on') {
374
+			elseif (GETPOST('closepaidinvoices') == 'on') {
375 375
 				$facture->set_paid($user);
376 376
 			}
377 377
 		}
378 378
 
379
-		if (! $error)
379
+		if (!$error)
380 380
 		{
381 381
 			$db->commit();
382 382
 
383 383
 			// If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
384
-			$invoiceid=0;
384
+			$invoiceid = 0;
385 385
 			foreach ($paiement->amounts as $key => $amount)
386 386
 			{
387 387
 				$facid = $key;
388 388
 				if (is_numeric($amount) && $amount <> 0)
389 389
 				{
390
-					if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
391
-					else $invoiceid=$facid;
390
+					if ($invoiceid != 0) $invoiceid = -1; // There is more than one invoice payed by this payment
391
+					else $invoiceid = $facid;
392 392
 				}
393 393
 			}
394 394
 			if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
@@ -416,39 +416,39 @@  discard block
 block discarded – undo
416 416
 
417 417
 llxHeader();
418 418
 
419
-if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) {
419
+if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
420 420
 	$service = 'StripeLive';
421 421
 	$servicestatus = 0;
422 422
 } else {
423
-	dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
423
+	dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
424 424
 }
425 425
 
426
-if (GETPOST('error')){
426
+if (GETPOST('error')) {
427 427
 	setEventMessages(GETPOST('error'), null, 'errors');
428 428
 }
429 429
 
430 430
 if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
431 431
 {
432 432
 	$facture = new Facture($db);
433
-	$result=$facture->fetch($facid);
433
+	$result = $facture->fetch($facid);
434 434
 
435 435
 	if ($result >= 0)
436 436
 	{
437 437
 		$facture->fetch_thirdparty();
438 438
 
439
-		$title='';
440
-		if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
441
-		if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
439
+		$title = '';
440
+		if ($facture->type != 2) $title .= $langs->trans("EnterPaymentReceivedFromCustomer");
441
+		if ($facture->type == 2) $title .= $langs->trans("EnterPaymentDueToCustomer");
442 442
 		print load_fiche_titre($title);
443 443
 
444 444
 		// Initialize data for confirmation (this is used because data can be change during confirmation)
445 445
 		if ($action == 'add_paiement')
446 446
 		{
447
-			$i=0;
447
+			$i = 0;
448 448
 
449
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
450
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
451
-			$formquestion[$i++]=array('type' => 'hidden','name' => 'type',  'value' => $facture->type);
449
+			$formquestion[$i++] = array('type' => 'hidden', 'name' => 'facid', 'value' => $facture->id);
450
+			$formquestion[$i++] = array('type' => 'hidden', 'name' => 'socid', 'value' => $facture->socid);
451
+			$formquestion[$i++] = array('type' => 'hidden', 'name' => 'type', 'value' => $facture->type);
452 452
 		}
453 453
 
454 454
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 			';
544 544
 
545 545
 			print '	});'."\n";
546
-			if (!empty($conf->use_javascript_ajax)){
546
+			if (!empty($conf->use_javascript_ajax)) {
547 547
 				//Add js for AutoFill
548 548
 				print ' $(document).ready(function () {';
549 549
 				print ' 	$(".AutoFillAmout").on(\'click touchstart\', function(){
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
         print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans('Company').'</span></td><td>'.$facture->thirdparty->getNomUrl(4)."</td></tr>\n";
577 577
 
578 578
         // Bank account
579
-        if (! empty($conf->banque->enabled))
579
+        if (!empty($conf->banque->enabled))
580 580
         {
581 581
             //$form->select_comptes($accountid,'accountid',0,'',2);
582 582
             print '<input name="accountid" type="hidden" value="'.$conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS.'">';
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
 		// Comments
608 608
 		print '<tr><td>'.$langs->trans('Comments').'</td>';
609 609
 		print '<td class="tdtop">';
610
-		print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('comment','none').'</textarea></td></tr>';
610
+		print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('comment', 'none').'</textarea></td></tr>';
611 611
 
612 612
         print '</table>';
613 613
 
614 614
         dol_fiche_end();
615 615
 
616 616
 
617
-        $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
617
+        $customerstripe = $stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus);
618 618
 
619 619
         print '<br>';
620
-        print_barre_liste($langs->trans('StripeSourceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', '');
620
+        print_barre_liste($langs->trans('StripeSourceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
621 621
 
622 622
         print '<table class="liste" width="100%">'."\n";
623 623
         // Titles with sort buttons
@@ -631,75 +631,75 @@  discard block
 block discarded – undo
631 631
             print '<tr>';
632 632
 
633 633
             print '<td align="center" width="20" ';
634
-            if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) {
634
+            if (($action == 'add_paiement' && $src->id != $source) or ($src->object == 'source' && $src->card->three_d_secure == 'required')) {
635 635
                 print'class="opacitymedium"';
636 636
             }
637 637
             print '><input type="radio" id="source_id" class="flat" name="source_id"  value="'.$src->id.'"';
638
-            if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) {
638
+            if (($action == 'add_paiement' && $src->id != $source) or ($src->object == 'source' && $src->card->three_d_secure == 'required')) {
639 639
                 print ' disabled';
640
-            } elseif (($customerstripe->default_source==$src->id && $action != 'add_paiement') or ($source==$src->id && $action == 'add_paiement')) {
640
+            } elseif (($customerstripe->default_source == $src->id && $action != 'add_paiement') or ($source == $src->id && $action == 'add_paiement')) {
641 641
                 print ' checked';
642 642
             }
643 643
             print '></td>';
644 644
 
645 645
             print '<td ';
646
-            if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) {
646
+            if (($action == 'add_paiement' && $src->id != $source) or ($src->object == 'source' && $src->card->three_d_secure == 'required')) {
647 647
                 print'class="opacitymedium"';
648 648
             }
649 649
 
650 650
             print' >';
651
-            if ($src->object=='card') {
651
+            if ($src->object == 'card') {
652 652
                 print img_credit_card($src->brand);
653
-            } elseif ($src->object=='source' && $src->type=='card') {
653
+            } elseif ($src->object == 'source' && $src->type == 'card') {
654 654
                 print img_credit_card($src->card->brand);
655
-            } elseif ($src->object=='source' && $src->type=='sepa_debit') {
655
+            } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
656 656
                 print '<span class="fa fa-university fa-2x fa-fw"></span>';
657 657
             }
658 658
             print '</td>';
659 659
             print '<td ';
660
-            if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) {
660
+            if (($action == 'add_paiement' && $src->id != $source) or ($src->object == 'source' && $src->card->three_d_secure == 'required')) {
661 661
                 print'class="opacitymedium"';
662 662
             }
663 663
             print' >';
664
-            if ($src->object=='card') {
664
+            if ($src->object == 'card') {
665 665
                 print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.'';
666 666
                 print '</td><td>';
667 667
                 if ($src->country) {
668 668
                     $img = picto_from_langcode($src->country);
669
-                    print $img?$img.' ':'';
670
-                    print getCountry($src->country,1);
669
+                    print $img ? $img.' ' : '';
670
+                    print getCountry($src->country, 1);
671 671
                 } else {
672
-                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
672
+                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
673 673
                 }
674
-            } elseif ($src->object=='source' && $src->type=='card') {
674
+            } elseif ($src->object == 'source' && $src->type == 'card') {
675 675
                 print $src->owner->name.'<br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
676 676
                 print '</td><td>';
677 677
                 if ($src->card->country) {
678 678
                     $img = picto_from_langcode($src->card->country);
679
-                    print $img?$img.' ':'';
680
-                    print getCountry($src->card->country,1);
679
+                    print $img ? $img.' ' : '';
680
+                    print getCountry($src->card->country, 1);
681 681
                 } else {
682
-                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
682
+                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
683 683
                 }
684
-            } elseif ($src->object=='source' && $src->type=='sepa_debit') {
684
+            } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
685 685
                 print 'info sepa';
686 686
                 print '</td><td>';
687 687
                 if ($src->sepa_debit->country) {
688 688
                     $img = picto_from_langcode($src->sepa_debit->country);
689
-                    print $img?$img.' ':'';
690
-                    print getCountry($src->sepa_debit->country,1);
689
+                    print $img ? $img.' ' : '';
690
+                    print getCountry($src->sepa_debit->country, 1);
691 691
                 } else {
692
-                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
692
+                    print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
693 693
                 }
694 694
             }
695 695
             print '</td>';
696 696
             // Default
697 697
             print '<td align="center" width="50" ';
698
-            if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) {
698
+            if (($action == 'add_paiement' && $src->id != $source) or ($src->object == 'source' && $src->card->three_d_secure == 'required')) {
699 699
                 print'class="opacitymedium"';
700 700
             }
701 701
             print'>';
702
-            if (($customerstripe->default_source==$src->id)) {
702
+            if (($customerstripe->default_source == $src->id)) {
703 703
                 print "<SPAN class=' fa fa-star  fa-2x'></SPAN>";
704 704
             }
705 705
             print '</td>';
@@ -710,32 +710,32 @@  discard block
 block discarded – undo
710 710
         //    $account=\Stripe\Account::retrieve("".$stripe->getStripeCustomerAccount($facture->socid)."");
711 711
         //}
712 712
 
713
-        if (($account->type=='custom' or $account->type=='express') && $entity==1) {
713
+        if (($account->type == 'custom' or $account->type == 'express') && $entity == 1) {
714 714
             print '<tr class="oddeven">';
715 715
 
716 716
             print '<td align="center" width="20" ';
717
-            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid)!=$source) {
717
+            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid) != $source) {
718 718
                 print'class="opacitymedium"';
719 719
             }
720 720
             print'><input type="radio" id="source_id" class="flat" name="source_id"  value="'.$conf->global->STRIPE_EXTERNAL_ACCOUNT.'"';
721
-            if ((empty($input) && $action != 'add_paiement') or ($source==$conf->global->STRIPE_EXTERNAL_ACCOUNT && $action == 'add_paiement')) {
721
+            if ((empty($input) && $action != 'add_paiement') or ($source == $conf->global->STRIPE_EXTERNAL_ACCOUNT && $action == 'add_paiement')) {
722 722
                 print ' checked';
723
-            } elseif ($action == 'add_paiement' && $conf->global->STRIPE_EXTERNAL_ACCOUNT!=$source) {
723
+            } elseif ($action == 'add_paiement' && $conf->global->STRIPE_EXTERNAL_ACCOUNT != $source) {
724 724
                 print ' disabled';
725 725
             }
726 726
             print '></td><td ';
727
-            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid)!=$source) {
727
+            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid) != $source) {
728 728
                 print'class="opacitymedium"';
729 729
             }
730 730
             print '><span class="fa fa-cc-stripe fa-3x fa-fw"></span></td>';
731 731
 
732 732
             print '<td ';
733
-            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid)!=$source) {
733
+            if ($action == 'add_paiement' && $stripe->getStripeCustomerAccount($facture->socid) != $source) {
734 734
                 print'class="opacitymedium"';
735 735
             }
736 736
             print'>'.$langs->trans('sold');
737 737
             print'</td><td ';
738
-            if ($action == 'add_paiement' && $src->id!=$source) {
738
+            if ($action == 'add_paiement' && $src->id != $source) {
739 739
                 print'class="opacitymedium"';
740 740
             }
741 741
             print'>';
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
             print '</td>';
744 744
             // Default
745 745
             print '<td align="center" width="50" ';
746
-            if ($action == 'add_paiement' && $src->id!=$source) {
746
+            if ($action == 'add_paiement' && $src->id != $source) {
747 747
                 print'class="opacitymedium"';
748 748
             }
749 749
             print'>';
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
             print '</td>';
756 756
             print '</tr>';
757 757
         }
758
-        if (empty($input)&&!$stripe->getStripeCustomerAccount($facture->socid)) {
758
+        if (empty($input) && !$stripe->getStripeCustomerAccount($facture->socid)) {
759 759
             print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
760 760
         }
761 761
 
@@ -767,33 +767,33 @@  discard block
 block discarded – undo
767 767
          */
768 768
 
769 769
         $sql = 'SELECT f.rowid as facid, f.ref, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type, ';
770
-        $sql.= ' f.datef as df, f.fk_soc as socid';
771
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
770
+        $sql .= ' f.datef as df, f.fk_soc as socid';
771
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f';
772 772
 
773 773
 		if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) {
774
-			$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
774
+			$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
775 775
 		}
776 776
 
777
-		$sql.= ' WHERE f.entity = '.$conf->entity;
778
-        $sql.= ' AND (f.fk_soc = '.$facture->socid;
777
+		$sql .= ' WHERE f.entity = '.$conf->entity;
778
+        $sql .= ' AND (f.fk_soc = '.$facture->socid;
779 779
 
780 780
 		if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
781
-			$sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')';
781
+			$sql .= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')';
782 782
 		}
783 783
 
784
-        $sql.= ') AND f.paye = 0';
785
-        $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
784
+        $sql .= ') AND f.paye = 0';
785
+        $sql .= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
786 786
         if ($facture->type != 2)
787 787
         {
788
-            $sql .= ' AND type IN (0,1,3,5)';	// Standard invoice, replacement, deposit, situation
788
+            $sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
789 789
         }
790 790
         else
791 791
         {
792
-            $sql .= ' AND type = 2';		// If paying back a credit note, we show all credit notes
792
+            $sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
793 793
         }
794 794
 
795 795
         // Sort invoices by date and serial number: the older one comes first
796
-        $sql.=' ORDER BY f.datef ASC, f.ref ASC';
796
+        $sql .= ' ORDER BY f.datef ASC, f.ref ASC';
797 797
 
798 798
         $resql = $db->query($sql);
799 799
         if ($resql)
@@ -801,22 +801,22 @@  discard block
 block discarded – undo
801 801
             $num = $db->num_rows($resql);
802 802
             if ($num > 0)
803 803
             {
804
-            	$sign=1;
805
-            	if ($facture->type == 2) $sign=-1;
806
-
807
-				$arraytitle=$langs->trans('Invoice');
808
-				if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
809
-				$alreadypayedlabel=$langs->trans('Received');
810
-				$multicurrencyalreadypayedlabel=$langs->trans('MulticurrencyReceived');
811
-				if ($facture->type == 2) { $alreadypayedlabel=$langs->trans("PaidBack"); $multicurrencyalreadypayedlabel=$langs->trans("MulticurrencyPaidBack"); }
812
-				$remaindertopay=$langs->trans('RemainderToTake');
813
-				$multicurrencyremaindertopay=$langs->trans('MulticurrencyRemainderToTake');
814
-				if ($facture->type == 2) { $remaindertopay=$langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay=$langs->trans("MulticurrencyRemainderToPayBack"); }
804
+            	$sign = 1;
805
+            	if ($facture->type == 2) $sign = -1;
806
+
807
+				$arraytitle = $langs->trans('Invoice');
808
+				if ($facture->type == 2) $arraytitle = $langs->trans("CreditNotes");
809
+				$alreadypayedlabel = $langs->trans('Received');
810
+				$multicurrencyalreadypayedlabel = $langs->trans('MulticurrencyReceived');
811
+				if ($facture->type == 2) { $alreadypayedlabel = $langs->trans("PaidBack"); $multicurrencyalreadypayedlabel = $langs->trans("MulticurrencyPaidBack"); }
812
+				$remaindertopay = $langs->trans('RemainderToTake');
813
+				$multicurrencyremaindertopay = $langs->trans('MulticurrencyRemainderToTake');
814
+				if ($facture->type == 2) { $remaindertopay = $langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay = $langs->trans("MulticurrencyRemainderToPayBack"); }
815 815
 
816 816
                 $i = 0;
817 817
                 //print '<tr><td colspan="3">';
818 818
                 print '<br>';
819
-                print_barre_liste($langs->trans('StripeInvoiceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', '');
819
+                print_barre_liste($langs->trans('StripeInvoiceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
820 820
                 print '<table class="noborder" width="100%">';
821 821
                 print '<tr class="liste_titre">';
822 822
                 print '<td>'.$arraytitle.'</td>';
@@ -837,10 +837,10 @@  discard block
 block discarded – undo
837 837
                 print '<td align="right">&nbsp;</td>';
838 838
                 print "</tr>\n";
839 839
 
840
-                $total=0;
841
-                $totalrecu=0;
842
-                $totalrecucreditnote=0;
843
-                $totalrecudeposits=0;
840
+                $total = 0;
841
+                $totalrecu = 0;
842
+                $totalrecucreditnote = 0;
843
+                $totalrecudeposits = 0;
844 844
 
845 845
                 while ($i < $num)
846 846
                 {
@@ -849,33 +849,33 @@  discard block
 block discarded – undo
849 849
 					$soc = new Societe($db);
850 850
 					$soc->fetch($objp->socid);
851 851
 
852
-                    $invoice=new Facture($db);
852
+                    $invoice = new Facture($db);
853 853
                     $invoice->fetch($objp->facid);
854 854
                     $paiement = $invoice->getSommePaiement();
855
-                    $creditnotes=$invoice->getSumCreditNotesUsed();
856
-                    $deposits=$invoice->getSumDepositsUsed();
857
-                    $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
858
-                    $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
855
+                    $creditnotes = $invoice->getSumCreditNotesUsed();
856
+                    $deposits = $invoice->getSumDepositsUsed();
857
+                    $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
858
+                    $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
859 859
 
860 860
 					// Multicurrency Price
861 861
 					if (!empty($conf->multicurrency->enabled))
862 862
 					{
863 863
 						$multicurrency_payment = $invoice->getSommePaiement(1);
864
-						$multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1);
865
-						$multicurrency_deposits=$invoice->getSumDepositsUsed(1);
866
-						$multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT');
867
-	                    $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT');
864
+						$multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
865
+						$multicurrency_deposits = $invoice->getSumDepositsUsed(1);
866
+						$multicurrency_alreadypayed = price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits, 'MT');
867
+	                    $multicurrency_remaintopay = price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT');
868 868
 					}
869 869
 
870 870
                     print '<tr class="oddeven">';
871 871
 
872 872
                     print '<td>';
873
-                    print $invoice->getNomUrl(1,'');
874
-                    if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
873
+                    print $invoice->getNomUrl(1, '');
874
+                    if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
875 875
                     print "</td>\n";
876 876
 
877 877
                     // Date
878
-                    print '<td align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";
878
+                    print '<td align="center">'.dol_print_date($db->jdate($objp->df), 'day')."</td>\n";
879 879
 
880 880
                     // Currency
881 881
                     if (!empty($conf->multicurrency->enabled)) print '<td align="center">'.$objp->multicurrency_code."</td>\n";
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
                     if ($action != 'add_paiement')
927 927
                     {
928 928
                         if (!empty($conf->use_javascript_ajax))
929
-							print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
929
+							print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
930 930
                         print '<input type=hidden class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
931 931
                         print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
932 932
                     }
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
                     print "</td>";
939 939
 
940 940
 					// Multicurrency Price
941
-					if (! empty($conf->multicurrency->enabled))
941
+					if (!empty($conf->multicurrency->enabled))
942 942
 					{
943 943
 						print '<td align="right">';
944 944
 
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
     	                    if ($action != 'add_paiement')
952 952
     	                    {
953 953
     	                        if (!empty($conf->use_javascript_ajax))
954
-    								print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
954
+    								print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
955 955
     	                        print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
956 956
     	                        print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
957 957
     	                    }
@@ -974,21 +974,21 @@  discard block
 block discarded – undo
974 974
                     }
975 975
                     print '</td>';
976 976
 
977
-					$parameters=array();
978
-					$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
977
+					$parameters = array();
978
+					$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook
979 979
 
980 980
                     print "</tr>\n";
981 981
 
982
-                    $total+=$objp->total;
983
-                    $total_ttc+=$objp->total_ttc;
984
-                    $totalrecu+=$paiement;
985
-                    $totalrecucreditnote+=$creditnotes;
986
-                    $totalrecudeposits+=$deposits;
982
+                    $total += $objp->total;
983
+                    $total_ttc += $objp->total_ttc;
984
+                    $totalrecu += $paiement;
985
+                    $totalrecucreditnote += $creditnotes;
986
+                    $totalrecudeposits += $deposits;
987 987
                     $i++;
988 988
                 }
989 989
                 if ($i > 1)
990 990
                 {
991
-                $amount=round(price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT'))*100);
991
+                $amount = round(price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')) * 100);
992 992
                     // Print total
993 993
                     print '<tr class="liste_total">';
994 994
                     print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').'</td>';
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
                     if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
1003 1003
                     if ($totalrecudeposits) print '+'.price($totalrecudeposits);
1004 1004
                     print '</b></td>';
1005
-                    print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
1005
+                    print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
1006 1006
                     print '<td align="right" id="result" style="font-weight: bold;"></td>';
1007 1007
 					if (!empty($conf->multicurrency->enabled)) {
1008 1008
                         print '<td align="right" id="multicurrency_result" style="font-weight: bold;"></td>';
@@ -1023,10 +1023,10 @@  discard block
 block discarded – undo
1023 1023
         // Bouton Enregistrer
1024 1024
         if ($action != 'add_paiement')
1025 1025
         {
1026
-        	$checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically");
1027
-        	if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
1028
-        	$buttontitle=$langs->trans('ToMakePayment');
1029
-        	if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack');
1026
+        	$checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically");
1027
+        	if ($facture->type == 2) $checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically");
1028
+        	$buttontitle = $langs->trans('ToMakePayment');
1029
+        	if ($facture->type == 2) $buttontitle = $langs->trans('ToMakePaymentBack');
1030 1030
 
1031 1031
         	print '<br><div class="center">';
1032 1032
         	print '<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
@@ -1042,21 +1042,21 @@  discard block
 block discarded – undo
1042 1042
         // Form to confirm payment
1043 1043
         if ($action == 'add_paiement')
1044 1044
         {
1045
-            $preselectedchoice=$addwarning?'no':'yes';
1045
+            $preselectedchoice = $addwarning ? 'no' : 'yes';
1046 1046
 
1047 1047
             print '<br>';
1048 1048
             if (!empty($totalpayment)) {
1049 1049
                 $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency));
1050 1050
             }
1051 1051
 			if (!empty($multicurrency_totalpayment)) {
1052
-				$text.='<br>'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency"));
1052
+				$text .= '<br>'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency"));
1053 1053
 			}
1054 1054
             if (GETPOST('closepaidinvoices'))
1055 1055
             {
1056
-                $text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
1056
+                $text .= '<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
1057 1057
                 print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
1058 1058
             }
1059
-            print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice);
1059
+            print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice);
1060 1060
         }
1061 1061
 
1062 1062
         print "</form>\n";
@@ -1068,27 +1068,27 @@  discard block
 block discarded – undo
1068 1068
  *  Show list of payments
1069 1069
  */
1070 1070
 
1071
-if (! GETPOST('action'))
1071
+if (!GETPOST('action'))
1072 1072
 {
1073
-    if ($page == -1) $page = 0 ;
1074
-    $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
1075
-    $offset = $limit * $page ;
1073
+    if ($page == -1) $page = 0;
1074
+    $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
1075
+    $offset = $limit * $page;
1076 1076
 
1077
-    if (! $sortorder) $sortorder='DESC';
1078
-    if (! $sortfield) $sortfield='p.datep';
1077
+    if (!$sortorder) $sortorder = 'DESC';
1078
+    if (!$sortfield) $sortfield = 'p.datep';
1079 1079
 
1080 1080
     $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.ref';
1081
-    $sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
1082
-    $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
1083
-    $sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
1084
-    $sql.= ' AND f.entity = '.$conf->entity;
1081
+    $sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
1082
+    $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
1083
+    $sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
1084
+    $sql .= ' AND f.entity = '.$conf->entity;
1085 1085
     if ($socid)
1086 1086
     {
1087
-        $sql.= ' AND f.fk_soc = '.$socid;
1087
+        $sql .= ' AND f.fk_soc = '.$socid;
1088 1088
     }
1089 1089
 
1090
-    $sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
1091
-    $sql.= $db->plimit($limit+1, $offset);
1090
+    $sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
1091
+    $sql .= $db->plimit($limit + 1, $offset);
1092 1092
     $resql = $db->query($sql);
1093 1093
 
1094 1094
     if ($resql)
@@ -1096,17 +1096,17 @@  discard block
 block discarded – undo
1096 1096
         $num = $db->num_rows($resql);
1097 1097
         $i = 0;
1098 1098
 
1099
-        print_barre_liste($langs->trans('Payments'), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
1099
+        print_barre_liste($langs->trans('Payments'), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num);
1100 1100
         print '<table class="noborder" width="100%">';
1101 1101
         print '<tr class="liste_titre">';
1102
-        print_liste_field_titre('Invoice',$_SERVER["PHP_SELF"],'ref','','','',$sortfield,$sortorder);
1103
-        print_liste_field_titre('Date',$_SERVER["PHP_SELF"],'dp','','','',$sortfield,$sortorder);
1104
-        print_liste_field_titre('Type',$_SERVER["PHP_SELF"],'libelle','','','',$sortfield,$sortorder);
1105
-        print_liste_field_titre('Amount',$_SERVER["PHP_SELF"],'fa_amount','','','align="right"',$sortfield,$sortorder);
1106
-		print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
1102
+        print_liste_field_titre('Invoice', $_SERVER["PHP_SELF"], 'ref', '', '', '', $sortfield, $sortorder);
1103
+        print_liste_field_titre('Date', $_SERVER["PHP_SELF"], 'dp', '', '', '', $sortfield, $sortorder);
1104
+        print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'libelle', '', '', '', $sortfield, $sortorder);
1105
+        print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], 'fa_amount', '', '', 'align="right"', $sortfield, $sortorder);
1106
+		print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
1107 1107
         print "</tr>\n";
1108 1108
 
1109
-        while ($i < min($num,$limit))
1109
+        while ($i < min($num, $limit))
1110 1110
         {
1111 1111
             $objp = $db->fetch_object($resql);
1112 1112
             print '<tr class="oddeven">';
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
             print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
1116 1116
             print '<td align="right">'.price($objp->amount).'</td><td>&nbsp;</td>';
1117 1117
 
1118
-			$parameters=array();
1119
-			$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
1118
+			$parameters = array();
1119
+			$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook
1120 1120
 
1121 1121
             print '</tr>';
1122 1122
             $i++;
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/admin/stripe.php 3 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -43,92 +43,92 @@  discard block
 block discarded – undo
43 43
 
44 44
 if ($action == 'setvalue' && $user->admin)
45 45
 {
46
-	$db->begin();
47
-
48
-	if (empty($conf->stripeconnect->enabled)) {
49
-		$result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
50
-		if (! $result > 0)
51
-			$error ++;
52
-		$result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
53
-		if (! $result > 0)
54
-			$error ++;
55
-		$result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
56
-		if (! $result > 0)
57
-			$error ++;
58
-		$result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
59
-		if (! $result > 0)
60
-			$error ++;
61
-		$result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
62
-		if (! $result > 0)
63
-			$error ++;
64
-		$result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
65
-		if (! $result > 0)
66
-			$error ++;
67
-	}
68
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
69
-	if (! $result > 0)
70
-		$error ++;
71
-	$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
72
-	if (! $result > 0)
73
-		$error ++;
46
+    $db->begin();
47
+
48
+    if (empty($conf->stripeconnect->enabled)) {
49
+        $result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
50
+        if (! $result > 0)
51
+            $error ++;
52
+        $result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
53
+        if (! $result > 0)
54
+            $error ++;
55
+        $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
56
+        if (! $result > 0)
57
+            $error ++;
58
+        $result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
59
+        if (! $result > 0)
60
+            $error ++;
61
+        $result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
62
+        if (! $result > 0)
63
+            $error ++;
64
+        $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
65
+        if (! $result > 0)
66
+            $error ++;
67
+    }
68
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
69
+    if (! $result > 0)
70
+        $error ++;
71
+    $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
72
+    if (! $result > 0)
73
+        $error ++;
74 74
     $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
75 75
     if (! $result > 0) {
76 76
         $error ++;
77 77
     }
78 78
     $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
79
-	if (! $result > 0)
80
-		$error ++;
79
+    if (! $result > 0)
80
+        $error ++;
81 81
     $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
82
-	if (! $result > 0)
83
-		$error ++;
84
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
85
-	if (! $result > 0)
86
-		$error ++;
87
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'alpha'), 'chaine', 0, '', $conf->entity);
88
-	if (! $result > 0)
89
-		$error ++;
90
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'alpha'), 'chaine', 0, '', $conf->entity);
91
-	if (! $result > 0)
92
-		$error ++;
93
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'alpha'), 'chaine', 0, '', $conf->entity);
94
-	if (! $result > 0)
95
-		$error ++;
96
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
97
-	if (! $result > 0)
98
-		$error ++;
99
-	// Stock decrement
100
-	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
101
-	if (! $result > 0)
102
-		$error ++;
103
-
104
-	// Payment token for URL
105
-	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
106
-	if (! $result > 0)
107
-		$error ++;
108
-	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
109
-	if (! $result > 0)
110
-		$error ++;
111
-
112
-	if (! $error) {
113
-		$db->commit();
114
-		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
115
-	} else {
116
-		$db->rollback();
117
-		dol_print_error($db);
118
-	}
82
+    if (! $result > 0)
83
+        $error ++;
84
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
85
+    if (! $result > 0)
86
+        $error ++;
87
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'alpha'), 'chaine', 0, '', $conf->entity);
88
+    if (! $result > 0)
89
+        $error ++;
90
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'alpha'), 'chaine', 0, '', $conf->entity);
91
+    if (! $result > 0)
92
+        $error ++;
93
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'alpha'), 'chaine', 0, '', $conf->entity);
94
+    if (! $result > 0)
95
+        $error ++;
96
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
97
+    if (! $result > 0)
98
+        $error ++;
99
+    // Stock decrement
100
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
101
+    if (! $result > 0)
102
+        $error ++;
103
+
104
+    // Payment token for URL
105
+    $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
106
+    if (! $result > 0)
107
+        $error ++;
108
+    $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
109
+    if (! $result > 0)
110
+        $error ++;
111
+
112
+    if (! $error) {
113
+        $db->commit();
114
+        setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
115
+    } else {
116
+        $db->rollback();
117
+        dol_print_error($db);
118
+    }
119 119
 }
120 120
 
121 121
 if ($action=="setlive")
122 122
 {
123
-	$liveenable = GETPOST('value','int');
124
-	$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
125
-	if ($res > 0) {
126
-		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
127
-	}
128
-	else
129
-	{
130
-		setEventMessages($langs->trans("Error"), null, 'errors');
131
-	}
123
+    $liveenable = GETPOST('value','int');
124
+    $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
125
+    if ($res > 0) {
126
+        setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
127
+    }
128
+    else
129
+    {
130
+        setEventMessages($langs->trans("Error"), null, 'errors');
131
+    }
132 132
 }
133 133
 //TODO: import script for stripe account saving in alone or connect mode for stripe.class.php
134 134
 
@@ -168,72 +168,72 @@  discard block
 block discarded – undo
168 168
 print $langs->trans("StripeLiveEnabled").'</td><td>';
169 169
 if (!empty($conf->global->STRIPE_LIVE))
170 170
 {
171
-	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
172
-	print img_picto($langs->trans("Activated"),'switch_on');
173
-	print '</a>';
171
+    print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
172
+    print img_picto($langs->trans("Activated"),'switch_on');
173
+    print '</a>';
174 174
 }
175 175
 else
176 176
 {
177
-	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
178
-	print img_picto($langs->trans("Disabled"),'switch_off');
179
-	print '</a>';
177
+    print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
178
+    print img_picto($langs->trans("Disabled"),'switch_off');
179
+    print '</a>';
180 180
 }
181 181
 print '</td></tr>';
182 182
 
183 183
 if (empty($conf->stripeconnect->enabled))
184 184
 {
185
-	print '<tr class="oddeven"><td>';
186
-	print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
187
-	print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">';
188
-	print ' &nbsp; '.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
189
-	print '</td></tr>';
190
-
191
-	print '<tr class="oddeven"><td>';
192
-	print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
193
-	print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
194
-	print ' &nbsp; '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
195
-	print '</td></tr>';
196
-
197
-	print '<tr class="oddeven"><td>';
198
-	print '<span>'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
199
-	print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.$conf->global->STRIPE_TEST_WEBHOOK_KEY.'">';
200
-	print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
201
-	print '</td></tr>';
185
+    print '<tr class="oddeven"><td>';
186
+    print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
187
+    print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">';
188
+    print ' &nbsp; '.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
189
+    print '</td></tr>';
190
+
191
+    print '<tr class="oddeven"><td>';
192
+    print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
193
+    print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
194
+    print ' &nbsp; '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
195
+    print '</td></tr>';
196
+
197
+    print '<tr class="oddeven"><td>';
198
+    print '<span>'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
199
+    print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.$conf->global->STRIPE_TEST_WEBHOOK_KEY.'">';
200
+    print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
201
+    print '</td></tr>';
202 202
 } else {
203
-	print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
204
-	print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br/>';
205
-	print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
206
-	print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
207
-	print '% + ';
208
-	print price($conf->global->STRIPE_APPLICATION_FEE);
209
-	print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency).' </td></tr>';
210
-	print '</td></tr>';
203
+    print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
204
+    print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br/>';
205
+    print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
206
+    print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
207
+    print '% + ';
208
+    print price($conf->global->STRIPE_APPLICATION_FEE);
209
+    print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency).' </td></tr>';
210
+    print '</td></tr>';
211 211
 }
212 212
 
213 213
 if (empty($conf->stripeconnect->enabled))
214 214
 {
215
-	print '<tr class="oddeven"><td>';
216
-	print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
217
-	print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">';
218
-	print ' &nbsp; '.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
219
-	print '</td></tr>';
220
-
221
-	print '<tr class="oddeven"><td>';
222
-	print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
223
-	print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
224
-	print ' &nbsp; '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
225
-	print '</td></tr>';
226
-
227
-	print '<tr class="oddeven"><td>';
228
-	print '<span>'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
229
-	print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">';
230
-	print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
231
-	print '</td></tr>';
215
+    print '<tr class="oddeven"><td>';
216
+    print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
217
+    print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">';
218
+    print ' &nbsp; '.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
219
+    print '</td></tr>';
220
+
221
+    print '<tr class="oddeven"><td>';
222
+    print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
223
+    print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
224
+    print ' &nbsp; '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
225
+    print '</td></tr>';
226
+
227
+    print '<tr class="oddeven"><td>';
228
+    print '<span>'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
229
+    print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">';
230
+    print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
231
+    print '</td></tr>';
232 232
 }
233 233
 else
234 234
 {
235
-	print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
236
-	print '<td>'.$langs->trans("StripeConnect_Mode").'</td></tr>';
235
+    print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
236
+    print '<td>'.$langs->trans("StripeConnect_Mode").'</td></tr>';
237 237
 }
238 238
 
239 239
 
@@ -266,27 +266,27 @@  discard block
 block discarded – undo
266 266
 
267 267
 if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// What is this for ?
268 268
 {
269
-	print '<tr class="oddeven"><td>';
270
-	print $langs->trans("BankAccountForBankTransfer").'</td><td>';
271
-	print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
272
-	print '</td></tr>';
269
+    print '<tr class="oddeven"><td>';
270
+    print $langs->trans("BankAccountForBankTransfer").'</td><td>';
271
+    print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
272
+    print '</td></tr>';
273 273
 }
274 274
 
275 275
 // Minimal amount for force 3Dsecure if it's optionnal
276 276
 if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// TODO Not used by current code
277 277
 {
278
-	print '<tr class="oddeven"><td>';
279
-	print $langs->trans("STRIPE_MINIMAL_3DSECURE").'</td><td>';
280
-	print '<input class="flat" name="STRIPE_MINIMAL_3DSECURE" size="3" value="' .$conf->global->STRIPE_MINIMAL_3DSECURE . '">'.$langs->getCurrencySymbol($conf->currency).'</td></tr>';
278
+    print '<tr class="oddeven"><td>';
279
+    print $langs->trans("STRIPE_MINIMAL_3DSECURE").'</td><td>';
280
+    print '<input class="flat" name="STRIPE_MINIMAL_3DSECURE" size="3" value="' .$conf->global->STRIPE_MINIMAL_3DSECURE . '">'.$langs->getCurrencySymbol($conf->currency).'</td></tr>';
281 281
 }
282 282
 
283 283
 // Warehouse for automatic decrement
284 284
 if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// What is this for ?
285 285
 {
286
-	print '<tr class="oddeven"><td>';
287
-	print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").'</td><td>';
288
-	print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled);
289
-	print '</td></tr>';
286
+    print '<tr class="oddeven"><td>';
287
+    print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").'</td><td>';
288
+    print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled);
289
+    print '</td></tr>';
290 290
 }
291 291
 
292 292
 print '<tr class="oddeven"><td>';
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 print $langs->trans("SecurityToken").'</td><td>';
325 325
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
326 326
 if (! empty($conf->use_javascript_ajax))
327
-	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
327
+    print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
328 328
 print '</td></tr>';
329 329
 
330 330
 print '<tr class="oddeven"><td>';
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
 
352 352
 if (! empty($conf->use_javascript_ajax))
353 353
 {
354
-	print "\n".'<script type="text/javascript">';
355
-	print '$(document).ready(function () {
354
+    print "\n".'<script type="text/javascript">';
355
+    print '$(document).ready(function () {
356 356
             $("#apidoc").hide();
357 357
             $("#apidoca").click(function() {
358 358
                 $("#apidoc").show();
359 359
             	$("#apidoca").hide();
360 360
             });
361 361
     });';
362
-	print '</script>';
362
+    print '</script>';
363 363
 }
364 364
 
365 365
 // End of page
Please login to merge, or discard this patch.
Braces   +71 added lines, -47 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 // Load translation files required by the page
37 37
 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
38 38
 
39
-if (! $user->admin) accessforbidden();
39
+if (! $user->admin) {
40
+    accessforbidden();
41
+}
40 42
 
41 43
 $action = GETPOST('action','alpha');
42 44
 
@@ -47,67 +49,85 @@  discard block
 block discarded – undo
47 49
 
48 50
 	if (empty($conf->stripeconnect->enabled)) {
49 51
 		$result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
50
-		if (! $result > 0)
51
-			$error ++;
52
+		if (! $result > 0) {
53
+					$error ++;
54
+		}
52 55
 		$result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
53
-		if (! $result > 0)
54
-			$error ++;
56
+		if (! $result > 0) {
57
+					$error ++;
58
+		}
55 59
 		$result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
56
-		if (! $result > 0)
57
-			$error ++;
60
+		if (! $result > 0) {
61
+					$error ++;
62
+		}
58 63
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
59
-		if (! $result > 0)
60
-			$error ++;
64
+		if (! $result > 0) {
65
+					$error ++;
66
+		}
61 67
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
62
-		if (! $result > 0)
63
-			$error ++;
68
+		if (! $result > 0) {
69
+					$error ++;
70
+		}
64 71
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
65
-		if (! $result > 0)
66
-			$error ++;
72
+		if (! $result > 0) {
73
+					$error ++;
74
+		}
67 75
 	}
68 76
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
69
-	if (! $result > 0)
70
-		$error ++;
77
+	if (! $result > 0) {
78
+			$error ++;
79
+	}
71 80
 	$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
72
-	if (! $result > 0)
73
-		$error ++;
81
+	if (! $result > 0) {
82
+			$error ++;
83
+	}
74 84
     $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
75 85
     if (! $result > 0) {
76 86
         $error ++;
77 87
     }
78 88
     $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
79
-	if (! $result > 0)
80
-		$error ++;
89
+	if (! $result > 0) {
90
+			$error ++;
91
+	}
81 92
     $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
82
-	if (! $result > 0)
83
-		$error ++;
93
+	if (! $result > 0) {
94
+			$error ++;
95
+	}
84 96
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
85
-	if (! $result > 0)
86
-		$error ++;
97
+	if (! $result > 0) {
98
+			$error ++;
99
+	}
87 100
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'alpha'), 'chaine', 0, '', $conf->entity);
88
-	if (! $result > 0)
89
-		$error ++;
101
+	if (! $result > 0) {
102
+			$error ++;
103
+	}
90 104
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'alpha'), 'chaine', 0, '', $conf->entity);
91
-	if (! $result > 0)
92
-		$error ++;
105
+	if (! $result > 0) {
106
+			$error ++;
107
+	}
93 108
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'alpha'), 'chaine', 0, '', $conf->entity);
94
-	if (! $result > 0)
95
-		$error ++;
109
+	if (! $result > 0) {
110
+			$error ++;
111
+	}
96 112
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
97
-	if (! $result > 0)
98
-		$error ++;
113
+	if (! $result > 0) {
114
+			$error ++;
115
+	}
99 116
 	// Stock decrement
100 117
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
101
-	if (! $result > 0)
102
-		$error ++;
118
+	if (! $result > 0) {
119
+			$error ++;
120
+	}
103 121
 
104 122
 	// Payment token for URL
105 123
 	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
106
-	if (! $result > 0)
107
-		$error ++;
124
+	if (! $result > 0) {
125
+			$error ++;
126
+	}
108 127
 	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
109
-	if (! $result > 0)
110
-		$error ++;
128
+	if (! $result > 0) {
129
+			$error ++;
130
+	}
111 131
 
112 132
 	if (! $error) {
113 133
 		$db->commit();
@@ -124,8 +144,7 @@  discard block
 block discarded – undo
124 144
 	$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
125 145
 	if ($res > 0) {
126 146
 		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
127
-	}
128
-	else
147
+	} else
129 148
 	{
130 149
 		setEventMessages($langs->trans("Error"), null, 'errors');
131 150
 	}
@@ -171,8 +190,7 @@  discard block
 block discarded – undo
171 190
 	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
172 191
 	print img_picto($langs->trans("Activated"),'switch_on');
173 192
 	print '</a>';
174
-}
175
-else
193
+} else
176 194
 {
177 195
 	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
178 196
 	print img_picto($langs->trans("Disabled"),'switch_off');
@@ -229,8 +247,7 @@  discard block
 block discarded – undo
229 247
 	print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">';
230 248
 	print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
231 249
 	print '</td></tr>';
232
-}
233
-else
250
+} else
234 251
 {
235 252
 	print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
236 253
 	print '<td>'.$langs->trans("StripeConnect_Mode").'</td></tr>';
@@ -264,26 +281,32 @@  discard block
 block discarded – undo
264 281
 print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
265 282
 print '</td></tr>';
266 283
 
267
-if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// What is this for ?
284
+if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
285
+    // What is this for ?
268 286
 {
269 287
 	print '<tr class="oddeven"><td>';
288
+}
270 289
 	print $langs->trans("BankAccountForBankTransfer").'</td><td>';
271 290
 	print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
272 291
 	print '</td></tr>';
273 292
 }
274 293
 
275 294
 // Minimal amount for force 3Dsecure if it's optionnal
276
-if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// TODO Not used by current code
295
+if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
296
+    // TODO Not used by current code
277 297
 {
278 298
 	print '<tr class="oddeven"><td>';
299
+}
279 300
 	print $langs->trans("STRIPE_MINIMAL_3DSECURE").'</td><td>';
280 301
 	print '<input class="flat" name="STRIPE_MINIMAL_3DSECURE" size="3" value="' .$conf->global->STRIPE_MINIMAL_3DSECURE . '">'.$langs->getCurrencySymbol($conf->currency).'</td></tr>';
281 302
 }
282 303
 
283 304
 // Warehouse for automatic decrement
284
-if ($conf->global->MAIN_FEATURES_LEVEL >= 2)	// What is this for ?
305
+if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
306
+    // What is this for ?
285 307
 {
286 308
 	print '<tr class="oddeven"><td>';
309
+}
287 310
 	print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").'</td><td>';
288 311
 	print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled);
289 312
 	print '</td></tr>';
@@ -323,8 +346,9 @@  discard block
 block discarded – undo
323 346
 print '<tr class="oddeven"><td>';
324 347
 print $langs->trans("SecurityToken").'</td><td>';
325 348
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
326
-if (! empty($conf->use_javascript_ajax))
349
+if (! empty($conf->use_javascript_ajax)) {
327 350
 	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
351
+}
328 352
 print '</td></tr>';
329 353
 
330 354
 print '<tr class="oddeven"><td>';
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -28,20 +28,20 @@  discard block
 block discarded – undo
28 28
 
29 29
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
30 30
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
31
-require DOL_BASE_PATH . '/main.inc.php';
31
+require DOL_BASE_PATH.'/main.inc.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
36 36
 
37
-$servicename='Stripe';
37
+$servicename = 'Stripe';
38 38
 
39 39
 // Load translation files required by the page
40 40
 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
41 41
 
42
-if (! $user->admin) accessforbidden();
42
+if (!$user->admin) accessforbidden();
43 43
 
44
-$action = GETPOST('action','alpha');
44
+$action = GETPOST('action', 'alpha');
45 45
 
46 46
 
47 47
 if ($action == 'setvalue' && $user->admin)
@@ -50,69 +50,69 @@  discard block
 block discarded – undo
50 50
 
51 51
 	if (empty($conf->stripeconnect->enabled)) {
52 52
 		$result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
53
-		if (! $result > 0)
54
-			$error ++;
53
+		if (!$result > 0)
54
+			$error++;
55 55
 		$result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
56
-		if (! $result > 0)
57
-			$error ++;
56
+		if (!$result > 0)
57
+			$error++;
58 58
 		$result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
59
-		if (! $result > 0)
60
-			$error ++;
59
+		if (!$result > 0)
60
+			$error++;
61 61
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
62
-		if (! $result > 0)
63
-			$error ++;
62
+		if (!$result > 0)
63
+			$error++;
64 64
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
65
-		if (! $result > 0)
66
-			$error ++;
65
+		if (!$result > 0)
66
+			$error++;
67 67
 		$result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
68
-		if (! $result > 0)
69
-			$error ++;
68
+		if (!$result > 0)
69
+			$error++;
70 70
 	}
71 71
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
72
-	if (! $result > 0)
73
-		$error ++;
72
+	if (!$result > 0)
73
+		$error++;
74 74
 	$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
75
-	if (! $result > 0)
76
-		$error ++;
75
+	if (!$result > 0)
76
+		$error++;
77 77
     $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
78
-    if (! $result > 0) {
79
-        $error ++;
78
+    if (!$result > 0) {
79
+        $error++;
80 80
     }
81 81
     $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
82
-	if (! $result > 0)
83
-		$error ++;
82
+	if (!$result > 0)
83
+		$error++;
84 84
     $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
85
-	if (! $result > 0)
86
-		$error ++;
85
+	if (!$result > 0)
86
+		$error++;
87 87
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
88
-	if (! $result > 0)
89
-		$error ++;
88
+	if (!$result > 0)
89
+		$error++;
90 90
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'alpha'), 'chaine', 0, '', $conf->entity);
91
-	if (! $result > 0)
92
-		$error ++;
91
+	if (!$result > 0)
92
+		$error++;
93 93
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'alpha'), 'chaine', 0, '', $conf->entity);
94
-	if (! $result > 0)
95
-		$error ++;
94
+	if (!$result > 0)
95
+		$error++;
96 96
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'alpha'), 'chaine', 0, '', $conf->entity);
97
-	if (! $result > 0)
98
-		$error ++;
97
+	if (!$result > 0)
98
+		$error++;
99 99
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
100
-	if (! $result > 0)
101
-		$error ++;
100
+	if (!$result > 0)
101
+		$error++;
102 102
 	// Stock decrement
103 103
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
104
-	if (! $result > 0)
105
-		$error ++;
104
+	if (!$result > 0)
105
+		$error++;
106 106
 
107 107
 	// Payment token for URL
108 108
 	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
109
-	if (! $result > 0)
110
-		$error ++;
109
+	if (!$result > 0)
110
+		$error++;
111 111
 	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
112
-	if (! $result > 0)
113
-		$error ++;
112
+	if (!$result > 0)
113
+		$error++;
114 114
 
115
-	if (! $error) {
115
+	if (!$error) {
116 116
 		$db->commit();
117 117
 		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
118 118
 	} else {
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	}
122 122
 }
123 123
 
124
-if ($action=="setlive")
124
+if ($action == "setlive")
125 125
 {
126
-	$liveenable = GETPOST('value','int');
126
+	$liveenable = GETPOST('value', 'int');
127 127
 	$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
128 128
 	if ($res > 0) {
129 129
 		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
  *	View
141 141
  */
142 142
 
143
-$form=new Form($db);
144
-$formproduct=new FormProduct($db);
143
+$form = new Form($db);
144
+$formproduct = new FormProduct($db);
145 145
 
146
-llxHeader('',$langs->trans("StripeSetup"));
146
+llxHeader('', $langs->trans("StripeSetup"));
147 147
 
148
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
149
-print load_fiche_titre($langs->trans("ModuleSetup").' Stripe',$linkback);
148
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
149
+print load_fiche_titre($langs->trans("ModuleSetup").' Stripe', $linkback);
150 150
 
151
-$head=stripeadmin_prepare_head();
151
+$head = stripeadmin_prepare_head();
152 152
 
153 153
 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
154 154
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
 if (!empty($conf->global->STRIPE_LIVE))
173 173
 {
174 174
 	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
175
-	print img_picto($langs->trans("Activated"),'switch_on');
175
+	print img_picto($langs->trans("Activated"), 'switch_on');
176 176
 	print '</a>';
177 177
 }
178 178
 else
179 179
 {
180 180
 	print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
181
-	print img_picto($langs->trans("Disabled"),'switch_off');
181
+	print img_picto($langs->trans("Disabled"), 'switch_off');
182 182
 	print '</a>';
183 183
 }
184 184
 print '</td></tr>';
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 {
281 281
 	print '<tr class="oddeven"><td>';
282 282
 	print $langs->trans("STRIPE_MINIMAL_3DSECURE").'</td><td>';
283
-	print '<input class="flat" name="STRIPE_MINIMAL_3DSECURE" size="3" value="' .$conf->global->STRIPE_MINIMAL_3DSECURE . '">'.$langs->getCurrencySymbol($conf->currency).'</td></tr>';
283
+	print '<input class="flat" name="STRIPE_MINIMAL_3DSECURE" size="3" value="'.$conf->global->STRIPE_MINIMAL_3DSECURE.'">'.$langs->getCurrencySymbol($conf->currency).'</td></tr>';
284 284
 }
285 285
 
286 286
 // Warehouse for automatic decrement
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 {
289 289
 	print '<tr class="oddeven"><td>';
290 290
 	print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").'</td><td>';
291
-	print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled);
291
+	print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE, 'ONLINE_PAYMENT_WAREHOUSE', '', 1, $disabled);
292 292
 	print '</td></tr>';
293 293
 }
294 294
 
@@ -300,19 +300,19 @@  discard block
 block discarded – undo
300 300
 
301 301
 print '<tr class="oddeven"><td>';
302 302
 print $langs->trans("MessageForm").'</td><td>';
303
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM',$conf->global->ONLINE_PAYMENT_MESSAGE_FORM,'',100,'dolibarr_details','In',false,true,true,ROWS_2,'90%');
303
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
304 304
 $doleditor->Create();
305 305
 print '</td></tr>';
306 306
 
307 307
 print '<tr class="oddeven"><td>';
308 308
 print $langs->trans("MessageOK").'</td><td>';
309
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_OK',$conf->global->ONLINE_PAYMENT_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_2,'90%');
309
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
310 310
 $doleditor->Create();
311 311
 print '</td></tr>';
312 312
 
313 313
 print '<tr class="oddeven"><td>';
314 314
 print $langs->trans("MessageKO").'</td><td>';
315
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_KO',$conf->global->ONLINE_PAYMENT_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_2,'90%');
315
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
316 316
 $doleditor->Create();
317 317
 print '</td></tr>';
318 318
 
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
 print '<tr class="oddeven"><td>';
327 327
 print $langs->trans("SecurityToken").'</td><td>';
328 328
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
329
-if (! empty($conf->use_javascript_ajax))
329
+if (!empty($conf->use_javascript_ajax))
330 330
 	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
331 331
 print '</td></tr>';
332 332
 
333 333
 print '<tr class="oddeven"><td>';
334 334
 print $langs->trans("SecurityTokenIsUnique").'</td><td>';
335
-print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
335
+print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE", (empty($conf->global->PAYMENT_SECURITY_TOKEN) ? 0 : $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE), 1);
336 336
 print '</td></tr>';
337 337
 
338 338
 print '</table>';
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
 print '<br><br>';
347 347
 
348 348
 
349
-$token='';
349
+$token = '';
350 350
 
351 351
 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
352 352
 
353 353
 print info_admin($langs->trans("ExampleOfTestCreditCard", '4242424242424242', '4000000000000101', '4000000000000069', '4000000000000341'));
354 354
 
355
-if (! empty($conf->use_javascript_ajax))
355
+if (!empty($conf->use_javascript_ajax))
356 356
 {
357 357
 	print "\n".'<script type="text/javascript">';
358 358
 	print '$(document).ready(function () {
Please login to merge, or discard this patch.
dolibarr/htdocs/stripe/transaction.php 3 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 
63 63
 if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
64 64
 {
65
-	$service = 'StripeTest';
66
-	$servicestatus = '0';
67
-	dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
65
+    $service = 'StripeTest';
66
+    $servicestatus = '0';
67
+    dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
68 68
 }
69 69
 else
70 70
 {
71
-	$service = 'StripeLive';
72
-	$servicestatus = '1';
71
+    $service = 'StripeLive';
72
+    $servicestatus = '1';
73 73
 }
74 74
 
75 75
 $stripeacc = $stripe->getStripeAccount($service);
@@ -80,54 +80,54 @@  discard block
 block discarded – undo
80 80
 
81 81
 if (! $rowid) {
82 82
 
83
-	print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
84
-	if ($optioncss != '')
85
-		print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
86
-	print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
87
-	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
88
-	print '<input type="hidden" name="action" value="list">';
89
-	print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
90
-	print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
91
-	print '<input type="hidden" name="page" value="' . $page . '">';
92
-
93
-	$title=$langs->trans("StripeTransactionList");
94
-	$title.=($stripeaccount?' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')':' (Stripe connection with keys from Stripe module setup)');
95
-
96
-	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
97
-
98
-	print '<div class="div-table-responsive">';
99
-	print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
100
-
101
-	print '<tr class="liste_titre">';
102
-	print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
103
-	//print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
104
-	//print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
105
-	//print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
106
-	print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", 'align="center"', $sortfield, $sortorder);
107
-	print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", 'align="left"', $sortfield, $sortorder);
108
-	print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
109
-	print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
110
-	print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", 'align="right"');
111
-	print "</tr>\n";
112
-
113
-	print "</tr>\n";
114
-
115
-	if ($stripeacc)
116
-	{
117
-		$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
118
-	}
119
-	else
120
-	{
121
-		$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit));
122
-	}
123
-
124
-	foreach ($txn->data as $txn)
125
-	{
126
-		//$charge = $txn;
127
-		//var_dump($txn);
128
-
129
-		// The metadata FULLTAG is defined by the online payment page
130
-		/*$FULLTAG=$charge->metadata->FULLTAG;
83
+    print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
84
+    if ($optioncss != '')
85
+        print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
86
+    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
87
+    print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
88
+    print '<input type="hidden" name="action" value="list">';
89
+    print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
90
+    print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
91
+    print '<input type="hidden" name="page" value="' . $page . '">';
92
+
93
+    $title=$langs->trans("StripeTransactionList");
94
+    $title.=($stripeaccount?' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')':' (Stripe connection with keys from Stripe module setup)');
95
+
96
+    print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
97
+
98
+    print '<div class="div-table-responsive">';
99
+    print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
100
+
101
+    print '<tr class="liste_titre">';
102
+    print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
103
+    //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
104
+    //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
105
+    //print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
106
+    print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", 'align="center"', $sortfield, $sortorder);
107
+    print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", 'align="left"', $sortfield, $sortorder);
108
+    print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
109
+    print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
110
+    print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", 'align="right"');
111
+    print "</tr>\n";
112
+
113
+    print "</tr>\n";
114
+
115
+    if ($stripeacc)
116
+    {
117
+        $txn = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
118
+    }
119
+    else
120
+    {
121
+        $txn = \Stripe\BalanceTransaction::all(array("limit" => $limit));
122
+    }
123
+
124
+    foreach ($txn->data as $txn)
125
+    {
126
+        //$charge = $txn;
127
+        //var_dump($txn);
128
+
129
+        // The metadata FULLTAG is defined by the online payment page
130
+        /*$FULLTAG=$charge->metadata->FULLTAG;
131 131
 
132 132
 		// Save into $tmparray all metadata
133 133
 		$tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
@@ -149,21 +149,21 @@  discard block
 block discarded – undo
149 149
 			$memberstatic->id = 0;
150 150
 		}*/
151 151
 
152
-		$societestatic->fetch($charge->metadata->idcustomer);
153
-		$societestatic->id = $charge->metadata->idcustomer;
154
-		$societestatic->lastname = $obj->lastname;
155
-		$societestatic->firstname = $obj->firstname;
156
-		$societestatic->admin = $obj->admin;
157
-		$societestatic->login = $obj->login;
158
-		$societestatic->email = $obj->email;
159
-		$societestatic->societe_id = $obj->fk_soc;
152
+        $societestatic->fetch($charge->metadata->idcustomer);
153
+        $societestatic->id = $charge->metadata->idcustomer;
154
+        $societestatic->lastname = $obj->lastname;
155
+        $societestatic->firstname = $obj->firstname;
156
+        $societestatic->admin = $obj->admin;
157
+        $societestatic->login = $obj->login;
158
+        $societestatic->email = $obj->email;
159
+        $societestatic->societe_id = $obj->fk_soc;
160 160
 
161
-		print '<tr class="oddeven">';
161
+        print '<tr class="oddeven">';
162 162
 
163
-		// Ref
163
+        // Ref
164 164
         if (!empty($stripeacc)) $connect=$stripeacc.'/';
165 165
     
166
-		// Ref
166
+        // Ref
167 167
         if (preg_match('/po_/i', $txn->source)){
168 168
             $origin="payouts";
169 169
         } elseif (preg_match('/fee_/i', $txn->source)) {
@@ -172,20 +172,20 @@  discard block
 block discarded – undo
172 172
             $origin="payments";
173 173
         }
174 174
 
175
-		$url='https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
176
-		if ($servicestatus) {
177
-			$url='https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
178
-		}
175
+        $url='https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
176
+        if ($servicestatus) {
177
+            $url='https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
178
+        }
179 179
         if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
180 180
             print "<td>".$txn->type."</td>";
181 181
         } else {
182 182
             print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'object_globe')." " . $txn->source . "</a></td>\n";
183 183
         }
184 184
 
185
-		// Stripe customer
186
-		//print "<td>".$charge->customer."</td>\n";
187
-		// Link
188
-		/*print "<td>";
185
+        // Stripe customer
186
+        //print "<td>".$charge->customer."</td>\n";
187
+        // Link
188
+        /*print "<td>";
189 189
 		if ($societestatic->id > 0)
190 190
 		{
191 191
 			print $societestatic->getNomUrl(1);
@@ -195,39 +195,39 @@  discard block
 block discarded – undo
195 195
 			print $memberstatic->getNomUrl(1);
196 196
 		}
197 197
 		print "</td>\n";*/
198
-		// Origine
199
-		//print "<td>";
200
-		////if ($charge->metadata->dol_type=="order"){
201
-		//	$object = new Commande($db);
202
-		//	$object->fetch($charge->metadata->dol_id);
203
-		//	print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
204
-		//} elseif ($charge->metadata->dol_type=="invoice"){
205
-		//	$object = new Facture($db);
206
-		//	$object->fetch($charge->metadata->dol_id);
207
-		//	print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
208
-		//}
209
-		//print "</td>\n";
210
-		// Date payment
211
-		print '<td align="center">' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "</td>\n";
212
-		// Type
213
-		print '<td>' . $txn->type . '</td>';
214
-		// Amount
215
-		print "<td align=\"right\">" . price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
216
-		print "<td align=\"right\">" . price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
217
-		// Status
218
-		print "<td align='right'>";
219
-		if ($txn->status=='available')
220
- 		{print img_picto($langs->trans("".$txn->status.""),'statut4');}
221
-		elseif ($txn->status=='pending')
222
-		{print img_picto($langs->trans("".$txn->status.""),'statut7');}
223
-		elseif ($txn->status=='failed')
224
-		{print img_picto($langs->trans("".$txn->status.""),'statut8');}
225
-		print '</td>';
226
-		print "</tr>\n";
227
-	}
228
-	print "</table>";
229
-	print '</div>';
230
-	print '</form>';
198
+        // Origine
199
+        //print "<td>";
200
+        ////if ($charge->metadata->dol_type=="order"){
201
+        //	$object = new Commande($db);
202
+        //	$object->fetch($charge->metadata->dol_id);
203
+        //	print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
204
+        //} elseif ($charge->metadata->dol_type=="invoice"){
205
+        //	$object = new Facture($db);
206
+        //	$object->fetch($charge->metadata->dol_id);
207
+        //	print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
208
+        //}
209
+        //print "</td>\n";
210
+        // Date payment
211
+        print '<td align="center">' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "</td>\n";
212
+        // Type
213
+        print '<td>' . $txn->type . '</td>';
214
+        // Amount
215
+        print "<td align=\"right\">" . price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
216
+        print "<td align=\"right\">" . price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
217
+        // Status
218
+        print "<td align='right'>";
219
+        if ($txn->status=='available')
220
+            {print img_picto($langs->trans("".$txn->status.""),'statut4');}
221
+        elseif ($txn->status=='pending')
222
+        {print img_picto($langs->trans("".$txn->status.""),'statut7');}
223
+        elseif ($txn->status=='failed')
224
+        {print img_picto($langs->trans("".$txn->status.""),'statut8');}
225
+        print '</td>';
226
+        print "</tr>\n";
227
+    }
228
+    print "</table>";
229
+    print '</div>';
230
+    print '</form>';
231 231
 }
232 232
 
233 233
 // End of page
Please login to merge, or discard this patch.
Braces   +16 added lines, -13 removed lines patch added patch discarded remove patch
@@ -26,14 +26,18 @@  discard block
 block discarded – undo
26 26
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
27 27
 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
28 28
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
29
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
29
+if (! empty($conf->accounting->enabled)) {
30
+    require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
31
+}
30 32
 
31 33
 // Load translation files required by the page
32 34
 $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
33 35
 
34 36
 // Security check
35 37
 $socid = GETPOST("socid","int");
36
-if ($user->societe_id) $socid=$user->societe_id;
38
+if ($user->societe_id) {
39
+    $socid=$user->societe_id;
40
+}
37 41
 //$result = restrictedArea($user, 'salaries', '', '', '');
38 42
 
39 43
 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
@@ -65,8 +69,7 @@  discard block
 block discarded – undo
65 69
 	$service = 'StripeTest';
66 70
 	$servicestatus = '0';
67 71
 	dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
68
-}
69
-else
72
+} else
70 73
 {
71 74
 	$service = 'StripeLive';
72 75
 	$servicestatus = '1';
@@ -81,8 +84,9 @@  discard block
 block discarded – undo
81 84
 if (! $rowid) {
82 85
 
83 86
 	print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
84
-	if ($optioncss != '')
85
-		print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
87
+	if ($optioncss != '') {
88
+			print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
89
+	}
86 90
 	print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
87 91
 	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
88 92
 	print '<input type="hidden" name="action" value="list">';
@@ -115,8 +119,7 @@  discard block
 block discarded – undo
115 119
 	if ($stripeacc)
116 120
 	{
117 121
 		$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
118
-	}
119
-	else
122
+	} else
120 123
 	{
121 124
 		$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit));
122 125
 	}
@@ -161,7 +164,9 @@  discard block
 block discarded – undo
161 164
 		print '<tr class="oddeven">';
162 165
 
163 166
 		// Ref
164
-        if (!empty($stripeacc)) $connect=$stripeacc.'/';
167
+        if (!empty($stripeacc)) {
168
+            $connect=$stripeacc.'/';
169
+        }
165 170
     
166 171
 		// Ref
167 172
         if (preg_match('/po_/i', $txn->source)){
@@ -217,10 +222,8 @@  discard block
 block discarded – undo
217 222
 		// Status
218 223
 		print "<td align='right'>";
219 224
 		if ($txn->status=='available')
220
- 		{print img_picto($langs->trans("".$txn->status.""),'statut4');}
221
-		elseif ($txn->status=='pending')
222
-		{print img_picto($langs->trans("".$txn->status.""),'statut7');}
223
-		elseif ($txn->status=='failed')
225
+ 		{print img_picto($langs->trans("".$txn->status.""),'statut4');} elseif ($txn->status=='pending')
226
+		{print img_picto($langs->trans("".$txn->status.""),'statut7');} elseif ($txn->status=='failed')
224 227
 		{print img_picto($langs->trans("".$txn->status.""),'statut8');}
225 228
 		print '</td>';
226 229
 		print "</tr>\n";
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
23 23
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
24
-require DOL_BASE_PATH . '/main.inc.php';
24
+require DOL_BASE_PATH.'/main.inc.php';
25 25
 
26 26
 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
27 27
 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
@@ -30,21 +30,21 @@  discard block
 block discarded – undo
30 30
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33
-if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
33
+if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
34 34
 
35 35
 // Load translation files required by the page
36 36
 $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
37 37
 
38 38
 // Security check
39
-$socid = GETPOST("socid","int");
40
-if ($user->societe_id) $socid=$user->societe_id;
39
+$socid = GETPOST("socid", "int");
40
+if ($user->societe_id) $socid = $user->societe_id;
41 41
 //$result = restrictedArea($user, 'salaries', '', '', '');
42 42
 
43
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
44
-$rowid = GETPOST("rowid",'alpha');
45
-$sortfield = GETPOST("sortfield",'alpha');
46
-$sortorder = GETPOST("sortorder",'alpha');
47
-$page = GETPOST("page",'int');
43
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
44
+$rowid = GETPOST("rowid", 'alpha');
45
+$sortfield = GETPOST("sortfield", 'alpha');
46
+$sortorder = GETPOST("sortorder", 'alpha');
47
+$page = GETPOST("page", 'int');
48 48
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
49 49
 $offset = $conf->liste_limit * $page;
50 50
 $pageprev = $page - 1;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
 llxHeader('', $langs->trans("StripeTransactionList"));
66 66
 
67
-if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
67
+if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')))
68 68
 {
69 69
 	$service = 'StripeTest';
70 70
 	$servicestatus = '0';
@@ -82,25 +82,25 @@  discard block
 block discarded – undo
82 82
 	print $langs->trans('ErrorStripeAccountNotDefined');
83 83
 }*/
84 84
 
85
-if (! $rowid) {
85
+if (!$rowid) {
86 86
 
87
-	print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
87
+	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
88 88
 	if ($optioncss != '')
89
-		print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
90
-	print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
89
+		print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
90
+	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
91 91
 	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
92 92
 	print '<input type="hidden" name="action" value="list">';
93
-	print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
94
-	print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
95
-	print '<input type="hidden" name="page" value="' . $page . '">';
93
+	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
94
+	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
95
+	print '<input type="hidden" name="page" value="'.$page.'">';
96 96
 
97
-	$title=$langs->trans("StripeTransactionList");
98
-	$title.=($stripeaccount?' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')':' (Stripe connection with keys from Stripe module setup)');
97
+	$title = $langs->trans("StripeTransactionList");
98
+	$title .= ($stripeaccount ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
99 99
 
100 100
 	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
101 101
 
102 102
 	print '<div class="div-table-responsive">';
103
-	print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
103
+	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
104 104
 
105 105
 	print '<tr class="liste_titre">';
106 106
 	print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
@@ -165,25 +165,25 @@  discard block
 block discarded – undo
165 165
 		print '<tr class="oddeven">';
166 166
 
167 167
 		// Ref
168
-        if (!empty($stripeacc)) $connect=$stripeacc.'/';
168
+        if (!empty($stripeacc)) $connect = $stripeacc.'/';
169 169
     
170 170
 		// Ref
171
-        if (preg_match('/po_/i', $txn->source)){
172
-            $origin="payouts";
171
+        if (preg_match('/po_/i', $txn->source)) {
172
+            $origin = "payouts";
173 173
         } elseif (preg_match('/fee_/i', $txn->source)) {
174
-            $origin="connect/application_fees";
174
+            $origin = "connect/application_fees";
175 175
         } else {
176
-            $origin="payments";
176
+            $origin = "payments";
177 177
         }
178 178
 
179
-		$url='https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
179
+		$url = 'https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
180 180
 		if ($servicestatus) {
181
-			$url='https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
181
+			$url = 'https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
182 182
 		}
183 183
         if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
184 184
             print "<td>".$txn->type."</td>";
185 185
         } else {
186
-            print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'object_globe')." " . $txn->source . "</a></td>\n";
186
+            print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'object_globe')." ".$txn->source."</a></td>\n";
187 187
         }
188 188
 
189 189
 		// Stripe customer
@@ -212,20 +212,20 @@  discard block
 block discarded – undo
212 212
 		//}
213 213
 		//print "</td>\n";
214 214
 		// Date payment
215
-		print '<td align="center">' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "</td>\n";
215
+		print '<td align="center">'.dol_print_date($txn->created, '%d/%m/%Y %H:%M')."</td>\n";
216 216
 		// Type
217
-		print '<td>' . $txn->type . '</td>';
217
+		print '<td>'.$txn->type.'</td>';
218 218
 		// Amount
219
-		print "<td align=\"right\">" . price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
220
-		print "<td align=\"right\">" . price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
219
+		print "<td align=\"right\">".price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</td>";
220
+		print "<td align=\"right\">".price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</td>";
221 221
 		// Status
222 222
 		print "<td align='right'>";
223
-		if ($txn->status=='available')
224
- 		{print img_picto($langs->trans("".$txn->status.""),'statut4');}
225
-		elseif ($txn->status=='pending')
226
-		{print img_picto($langs->trans("".$txn->status.""),'statut7');}
227
-		elseif ($txn->status=='failed')
228
-		{print img_picto($langs->trans("".$txn->status.""),'statut8');}
223
+		if ($txn->status == 'available')
224
+ 		{print img_picto($langs->trans("".$txn->status.""), 'statut4'); }
225
+		elseif ($txn->status == 'pending')
226
+		{print img_picto($langs->trans("".$txn->status.""), 'statut7'); }
227
+		elseif ($txn->status == 'failed')
228
+		{print img_picto($langs->trans("".$txn->status.""), 'statut8'); }
229 229
 		print '</td>';
230 230
 		print "</tr>\n";
231 231
 	}
Please login to merge, or discard this patch.