Test Failed
Branch develop (86e751)
by Laurent
34:11
created
htdocs/core/modules/cheque/doc/pdf_blochet.class.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -366,10 +366,10 @@
 block discarded – undo
366 366
 	 *   	Show footer of page. Need this->emetteur object
367 367
      *
368 368
 	 *   	@param	PDF			$pdf     			PDF
369
-	 * 		@param	Object		$object				Object to show
369
+	 * 		@param	string		$object				Object to show
370 370
 	 *      @param	Translate	$outputlangs		Object lang for output
371 371
 	 *      @param	int			$hidefreetext		1=Hide free text
372
-	 *      @return	void
372
+	 *      @return	integer
373 373
 	 */
374 374
 	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
375 375
 	{
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
 		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
65 65
 		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
66 66
 
67
-        // Recupere emmetteur
68
-        $this->emetteur=$mysoc;
69
-        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
67
+		// Recupere emmetteur
68
+		$this->emetteur=$mysoc;
69
+		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
70 70
 
71
-        // Defini position des colonnes
72
-        $this->line_height = 5;
71
+		// Defini position des colonnes
72
+		$this->line_height = 5;
73 73
 		$this->line_per_page = 40;
74 74
 		$this->tab_height = 200;	//$this->line_height * $this->line_per_page;
75 75
 	}
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
 	 *	@param	string			$_dir			Directory
82 82
 	 *	@param	string			$number			Number
83 83
 	 *	@param	Translate		$outputlangs	Lang output object
84
-     *	@return	int     						1=ok, 0=ko
84
+	 *	@return	int     						1=ok, 0=ko
85 85
 	 */
86 86
 	function write_file($object, $_dir, $number, $outputlangs)
87 87
 	{
88 88
 		global $user,$conf,$langs,$hookmanager;
89 89
 
90
-        if (! is_object($outputlangs)) $outputlangs=$langs;
91
-        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
92
-        $sav_charset_output=$outputlangs->charset_output;
93
-        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
90
+		if (! is_object($outputlangs)) $outputlangs=$langs;
91
+		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
92
+		$sav_charset_output=$outputlangs->charset_output;
93
+		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
94 94
 
95 95
 		$outputlangs->load("main");
96 96
 		$outputlangs->load("companies");
97 97
 		$outputlangs->load("bills");
98 98
 		$outputlangs->load("products");
99
-        $outputlangs->load("compta");
99
+		$outputlangs->load("compta");
100 100
 
101 101
 		$dir = $_dir . "/".get_exdir($number,0,1,0,$object,'cheque').$number;
102 102
 
@@ -125,18 +125,18 @@  discard block
 block discarded – undo
125 125
 		$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
126 126
 
127 127
 		// Create PDF instance
128
-        $pdf=pdf_getInstance($this->format);
129
-        $heightforinfotot = 50;	// Height reserved to output the info and total part
130
-        $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
131
-        $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
132
-        $pdf->SetAutoPageBreak(1,0);
133
-
134
-        if (class_exists('TCPDF'))
135
-        {
136
-            $pdf->setPrintHeader(false);
137
-            $pdf->setPrintFooter(false);
138
-        }
139
-        $pdf->SetFont(pdf_getPDFFont($outputlangs));
128
+		$pdf=pdf_getInstance($this->format);
129
+		$heightforinfotot = 50;	// Height reserved to output the info and total part
130
+		$heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
131
+		$heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
132
+		$pdf->SetAutoPageBreak(1,0);
133
+
134
+		if (class_exists('TCPDF'))
135
+		{
136
+			$pdf->setPrintHeader(false);
137
+			$pdf->setPrintFooter(false);
138
+		}
139
+		$pdf->SetFont(pdf_getPDFFont($outputlangs));
140 140
 
141 141
 		$pdf->Open();
142 142
 		$pagenb=0;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		}
167 167
 
168 168
 		$pdf->AddPage();
169
-        $pagenb++;
169
+		$pagenb++;
170 170
 		$this->Header($pdf, $pagenb, $pages, $outputlangs);
171 171
 
172 172
 		$this->Body($pdf, $pagenb, $pages, $outputlangs);
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 
196 196
 		$this->result = array('fullpath'=>$file);
197 197
 		
198
-        $outputlangs->charset_output=$sav_charset_output;
199
-	    return 1;   // Pas d'erreur
198
+		$outputlangs->charset_output=$sav_charset_output;
199
+		return 1;   // Pas d'erreur
200 200
 	}
201 201
 
202 202
 
@@ -219,47 +219,47 @@  discard block
 block discarded – undo
219 219
 
220 220
 		$title = $outputlangs->transnoentities("CheckReceipt");
221 221
 		$pdf->SetFont('','B', $default_font_size);
222
-        $pdf->SetXY(10,8);
223
-        $pdf->MultiCell(0,2,$title,0,'L');
222
+		$pdf->SetXY(10,8);
223
+		$pdf->MultiCell(0,2,$title,0,'L');
224 224
 
225 225
 		$pdf->SetFont('','', $default_font_size);
226
-        $pdf->SetXY(10,15);
226
+		$pdf->SetXY(10,15);
227 227
 		$pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
228
-        $pdf->SetXY(32,15);
228
+		$pdf->SetXY(32,15);
229 229
 		$pdf->SetFont('','', $default_font_size);
230
-        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
230
+		$pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
231 231
 
232 232
 		$pdf->SetFont('','', $default_font_size);
233
-        $pdf->SetXY(10,20);
234
-        $pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
235
-        $pdf->SetXY(32,20);
236
-        $pdf->SetFont('','', $default_font_size);
237
-        $pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
233
+		$pdf->SetXY(10,20);
234
+		$pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
235
+		$pdf->SetXY(32,20);
236
+		$pdf->SetFont('','', $default_font_size);
237
+		$pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
238 238
 
239 239
 		$pdf->SetFont('','', $default_font_size);
240
-        $pdf->SetXY(10,26);
241
-        $pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
240
+		$pdf->SetXY(10,26);
241
+		$pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
242 242
 		$pdf->SetFont('','', $default_font_size);
243
-        $pdf->SetXY(32,26);
244
-        $pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
243
+		$pdf->SetXY(32,26);
244
+		$pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
245 245
 
246 246
 		$pdf->SetFont('','', $default_font_size);
247
-        $pdf->SetXY(10,32);
248
-        $pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
249
-        pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
247
+		$pdf->SetXY(10,32);
248
+		$pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
249
+		pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
250 250
 
251 251
 		$pdf->SetFont('','', $default_font_size);
252
-        $pdf->SetXY(114,15);
252
+		$pdf->SetXY(114,15);
253 253
 		$pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
254 254
 
255
-        $pdf->Rect(9, 14, 192, 35);
256
-        $pdf->line(9, 19, 112, 19);
257
-        $pdf->line(9, 25, 112, 25);
258
-        //$pdf->line(9, 31, 201, 31);
259
-        $pdf->line(9, 31, 112, 31);
255
+		$pdf->Rect(9, 14, 192, 35);
256
+		$pdf->line(9, 19, 112, 19);
257
+		$pdf->line(9, 25, 112, 25);
258
+		//$pdf->line(9, 31, 201, 31);
259
+		$pdf->line(9, 31, 112, 31);
260 260
 
261
-        $pdf->line(30, 14, 30, 49);
262
-        $pdf->line(112, 14, 112, 49);
261
+		$pdf->line(30, 14, 30, 49);
262
+		$pdf->line(112, 14, 112, 49);
263 263
 
264 264
 		// Number of cheques
265 265
 		$posy=51;
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 		$pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
274 274
 
275 275
 		$pdf->SetFont('','B', $default_font_size);
276
-        $pdf->SetXY(57,$posy+1);
277
-        $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
276
+		$pdf->SetXY(57,$posy+1);
277
+		$pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
278 278
 
279 279
 		$pdf->SetFont('','', $default_font_size);
280
-        $pdf->SetXY(148,$posy+1);
280
+		$pdf->SetXY(148,$posy+1);
281 281
 		$pdf->MultiCell(40, 2, $langs->trans("Total"));
282 282
 
283 283
 		$pdf->SetFont('','B', $default_font_size);
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
 		$pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
292 292
 
293 293
 		$pdf->SetXY(41, $this->tab_top+2);
294
-        $pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
294
+		$pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
295 295
 		$pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
296 296
 
297
-        $pdf->SetXY(101, $this->tab_top+2);
298
-        $pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
297
+		$pdf->SetXY(101, $this->tab_top+2);
298
+		$pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
299 299
 		$pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
300 300
 
301 301
 		$pdf->SetXY(180, $this->tab_top+2);
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		$num=count($this->lines);
330 330
 		for ($j = 0; $j < $num; $j++)
331 331
 		{
332
-		    $lineinpage++;
332
+			$lineinpage++;
333 333
 
334 334
 			$pdf->SetXY(1, $this->tab_top + 10 + $yp);
335 335
 			$pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
@@ -350,15 +350,15 @@  discard block
 block discarded – undo
350 350
 
351 351
 			if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
352 352
 			{
353
-			    $lineinpage=0; $yp=0;
354
-
355
-                // New page
356
-                $pdf->AddPage();
357
-                $pagenb++;
358
-                $this->Header($pdf, $pagenb, $pages, $outputlangs);
359
-                $pdf->SetFont('','', $default_font_size - 1);
360
-                $pdf->MultiCell(0, 3, '');      // Set interline to 3
361
-                $pdf->SetTextColor(0,0,0);
353
+				$lineinpage=0; $yp=0;
354
+
355
+				// New page
356
+				$pdf->AddPage();
357
+				$pagenb++;
358
+				$this->Header($pdf, $pagenb, $pages, $outputlangs);
359
+				$pdf->SetFont('','', $default_font_size - 1);
360
+				$pdf->MultiCell(0, 3, '');      // Set interline to 3
361
+				$pdf->SetTextColor(0,0,0);
362 362
 			}
363 363
 		}
364 364
 	}
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 
367 367
 	/**
368 368
 	 *   	Show footer of page. Need this->emetteur object
369
-     *
369
+	 *
370 370
 	 *   	@param	PDF			$pdf     			PDF
371 371
 	 * 		@param	Object		$object				Object to show
372 372
 	 *      @param	Translate	$outputlangs		Object lang for output
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 		$paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
386 386
 		if (! empty($conf->global->$paramfreetext))
387 387
 		{
388
-		    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
388
+			$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
389 389
 		}
390 390
 		
391 391
 		return pdf_pagefoot($pdf,$outputlangs,$newfreetext,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class BordereauChequeBlochet extends ModeleChequeReceipts
36 36
 {
37
-	var $emetteur;	// Objet societe qui emet
37
+	var $emetteur; // Objet societe qui emet
38 38
 
39 39
 	/**
40 40
 	 *	Constructor
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	function __construct($db)
45 45
 	{
46
-		global $conf,$langs,$mysoc;
46
+		global $conf, $langs, $mysoc;
47 47
 
48 48
 		$langs->load("main");
49 49
 		$langs->load("bills");
@@ -55,23 +55,23 @@  discard block
 block discarded – undo
55 55
 
56 56
 		// Dimension page pour format A4
57 57
 		$this->type = 'pdf';
58
-		$formatarray=pdf_getFormat();
58
+		$formatarray = pdf_getFormat();
59 59
 		$this->page_largeur = $formatarray['width'];
60 60
 		$this->page_hauteur = $formatarray['height'];
61
-		$this->format = array($this->page_largeur,$this->page_hauteur);
62
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
63
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
64
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
65
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
61
+		$this->format = array($this->page_largeur, $this->page_hauteur);
62
+		$this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
63
+		$this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
64
+		$this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
65
+		$this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
66 66
 
67 67
         // Recupere emmetteur
68
-        $this->emetteur=$mysoc;
69
-        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
68
+        $this->emetteur = $mysoc;
69
+        if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
70 70
 
71 71
         // Defini position des colonnes
72 72
         $this->line_height = 5;
73 73
 		$this->line_per_page = 40;
74
-		$this->tab_height = 200;	//$this->line_height * $this->line_per_page;
74
+		$this->tab_height = 200; //$this->line_height * $this->line_per_page;
75 75
 	}
76 76
 
77 77
 	/**
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	function write_file($object, $_dir, $number, $outputlangs)
87 87
 	{
88
-		global $user,$conf,$langs,$hookmanager;
88
+		global $user, $conf, $langs, $hookmanager;
89 89
 
90
-        if (! is_object($outputlangs)) $outputlangs=$langs;
90
+        if (!is_object($outputlangs)) $outputlangs = $langs;
91 91
         // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
92
-        $sav_charset_output=$outputlangs->charset_output;
93
-        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
92
+        $sav_charset_output = $outputlangs->charset_output;
93
+        if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
94 94
 
95 95
 		$outputlangs->load("main");
96 96
 		$outputlangs->load("companies");
@@ -98,38 +98,38 @@  discard block
 block discarded – undo
98 98
 		$outputlangs->load("products");
99 99
         $outputlangs->load("compta");
100 100
 
101
-		$dir = $_dir . "/".get_exdir($number,0,1,0,$object,'cheque').$number;
101
+		$dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'cheque').$number;
102 102
 
103
-		if (! is_dir($dir))
103
+		if (!is_dir($dir))
104 104
 		{
105
-			$result=dol_mkdir($dir);
105
+			$result = dol_mkdir($dir);
106 106
 
107 107
 			if ($result < 0)
108 108
 			{
109
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
109
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
110 110
 				return -1;
111 111
 			}
112 112
 		}
113 113
 
114
-		$file = $dir . "/bordereau-".$number.".pdf";
114
+		$file = $dir."/bordereau-".$number.".pdf";
115 115
 
116 116
 		// Add pdfgeneration hook
117
-		if (! is_object($hookmanager))
117
+		if (!is_object($hookmanager))
118 118
 		{
119 119
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
120
-			$hookmanager=new HookManager($this->db);
120
+			$hookmanager = new HookManager($this->db);
121 121
 		}
122 122
 		$hookmanager->initHooks(array('pdfgeneration'));
123
-		$parameters=array('file'=>$file, 'outputlangs'=>$outputlangs);
123
+		$parameters = array('file'=>$file, 'outputlangs'=>$outputlangs);
124 124
 		global $action;
125
-		$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
125
+		$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
126 126
 
127 127
 		// Create PDF instance
128
-        $pdf=pdf_getInstance($this->format);
129
-        $heightforinfotot = 50;	// Height reserved to output the info and total part
130
-        $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
131
-        $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
132
-        $pdf->SetAutoPageBreak(1,0);
128
+        $pdf = pdf_getInstance($this->format);
129
+        $heightforinfotot = 50; // Height reserved to output the info and total part
130
+        $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
131
+        $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
132
+        $pdf->SetAutoPageBreak(1, 0);
133 133
 
134 134
         if (class_exists('TCPDF'))
135 135
         {
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
         $pdf->SetFont(pdf_getPDFFont($outputlangs));
140 140
 
141 141
 		$pdf->Open();
142
-		$pagenb=0;
143
-		$pdf->SetDrawColor(128,128,128);
142
+		$pagenb = 0;
143
+		$pdf->SetDrawColor(128, 128, 128);
144 144
 
145 145
 		$pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
146 146
 		$pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
147 147
 		$pdf->SetCreator("Dolibarr ".DOL_VERSION);
148 148
 		$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
149 149
 		$pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
150
-		if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
150
+		if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
151 151
 
152
-		$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
152
+		$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
153 153
 
154
-		$nboflines=count($this->lines);
154
+		$nboflines = count($this->lines);
155 155
 
156 156
 		// Define nb of page
157 157
 		$pages = intval($nboflines / $this->line_per_page);
158
-		if (($nboflines % $this->line_per_page)>0)
158
+		if (($nboflines % $this->line_per_page) > 0)
159 159
 		{
160 160
 			$pages++;
161 161
 		}
@@ -172,31 +172,31 @@  discard block
 block discarded – undo
172 172
 		$this->Body($pdf, $pagenb, $pages, $outputlangs);
173 173
 
174 174
 		// Pied de page
175
-		$this->_pagefoot($pdf,'',$outputlangs);
176
-		if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
175
+		$this->_pagefoot($pdf, '', $outputlangs);
176
+		if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
177 177
 
178 178
 		$pdf->Close();
179 179
 
180
-		$pdf->Output($file,'F');
180
+		$pdf->Output($file, 'F');
181 181
 
182 182
 		// Add pdfgeneration hook
183
-		if (! is_object($hookmanager))
183
+		if (!is_object($hookmanager))
184 184
 		{
185 185
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
186
-			$hookmanager=new HookManager($this->db);
186
+			$hookmanager = new HookManager($this->db);
187 187
 		}
188 188
 		$hookmanager->initHooks(array('pdfgeneration'));
189
-		$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
189
+		$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
190 190
 		global $action;
191
-		$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
191
+		$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
192 192
 
193
-		if (! empty($conf->global->MAIN_UMASK))
193
+		if (!empty($conf->global->MAIN_UMASK))
194 194
 			@chmod($file, octdec($conf->global->MAIN_UMASK));
195 195
 
196 196
 		$this->result = array('fullpath'=>$file);
197 197
 		
198
-        $outputlangs->charset_output=$sav_charset_output;
199
-	    return 1;   // Pas d'erreur
198
+        $outputlangs->charset_output = $sav_charset_output;
199
+	    return 1; // Pas d'erreur
200 200
 	}
201 201
 
202 202
 
@@ -218,38 +218,38 @@  discard block
 block discarded – undo
218 218
 		$outputlangs->load("banks");
219 219
 
220 220
 		$title = $outputlangs->transnoentities("CheckReceipt");
221
-		$pdf->SetFont('','B', $default_font_size);
222
-        $pdf->SetXY(10,8);
223
-        $pdf->MultiCell(0,2,$title,0,'L');
224
-
225
-		$pdf->SetFont('','', $default_font_size);
226
-        $pdf->SetXY(10,15);
227
-		$pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
228
-        $pdf->SetXY(32,15);
229
-		$pdf->SetFont('','', $default_font_size);
230
-        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
231
-
232
-		$pdf->SetFont('','', $default_font_size);
233
-        $pdf->SetXY(10,20);
234
-        $pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
235
-        $pdf->SetXY(32,20);
236
-        $pdf->SetFont('','', $default_font_size);
237
-        $pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
238
-
239
-		$pdf->SetFont('','', $default_font_size);
240
-        $pdf->SetXY(10,26);
241
-        $pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
242
-		$pdf->SetFont('','', $default_font_size);
243
-        $pdf->SetXY(32,26);
244
-        $pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
245
-
246
-		$pdf->SetFont('','', $default_font_size);
247
-        $pdf->SetXY(10,32);
248
-        $pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
249
-        pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
250
-
251
-		$pdf->SetFont('','', $default_font_size);
252
-        $pdf->SetXY(114,15);
221
+		$pdf->SetFont('', 'B', $default_font_size);
222
+        $pdf->SetXY(10, 8);
223
+        $pdf->MultiCell(0, 2, $title, 0, 'L');
224
+
225
+		$pdf->SetFont('', '', $default_font_size);
226
+        $pdf->SetXY(10, 15);
227
+		$pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L');
228
+        $pdf->SetXY(32, 15);
229
+		$pdf->SetFont('', '', $default_font_size);
230
+        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L');
231
+
232
+		$pdf->SetFont('', '', $default_font_size);
233
+        $pdf->SetXY(10, 20);
234
+        $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L');
235
+        $pdf->SetXY(32, 20);
236
+        $pdf->SetFont('', '', $default_font_size);
237
+        $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs));
238
+
239
+		$pdf->SetFont('', '', $default_font_size);
240
+        $pdf->SetXY(10, 26);
241
+        $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L');
242
+		$pdf->SetFont('', '', $default_font_size);
243
+        $pdf->SetXY(32, 26);
244
+        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->account->proprio), 0, 'L');
245
+
246
+		$pdf->SetFont('', '', $default_font_size);
247
+        $pdf->SetXY(10, 32);
248
+        $pdf->MultiCell(0, 2, $outputlangs->transnoentities("Account"), 0, 'L');
249
+        pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1);
250
+
251
+		$pdf->SetFont('', '', $default_font_size);
252
+        $pdf->SetXY(114, 15);
253 253
 		$pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
254 254
 
255 255
         $pdf->Rect(9, 14, 192, 35);
@@ -262,44 +262,44 @@  discard block
 block discarded – undo
262 262
         $pdf->line(112, 14, 112, 49);
263 263
 
264 264
 		// Number of cheques
265
-		$posy=51;
265
+		$posy = 51;
266 266
 		$pdf->Rect(9, $posy, 192, 6);
267
-		$pdf->line(55, $posy, 55, $posy+6);
268
-		$pdf->line(140, $posy, 140, $posy+6);
269
-		$pdf->line(170, $posy, 170, $posy+6);
267
+		$pdf->line(55, $posy, 55, $posy + 6);
268
+		$pdf->line(140, $posy, 140, $posy + 6);
269
+		$pdf->line(170, $posy, 170, $posy + 6);
270 270
 
271
-		$pdf->SetFont('','', $default_font_size);
272
-		$pdf->SetXY(10,$posy+1);
271
+		$pdf->SetFont('', '', $default_font_size);
272
+		$pdf->SetXY(10, $posy + 1);
273 273
 		$pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
274 274
 
275
-		$pdf->SetFont('','B', $default_font_size);
276
-        $pdf->SetXY(57,$posy+1);
275
+		$pdf->SetFont('', 'B', $default_font_size);
276
+        $pdf->SetXY(57, $posy + 1);
277 277
         $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
278 278
 
279
-		$pdf->SetFont('','', $default_font_size);
280
-        $pdf->SetXY(148,$posy+1);
279
+		$pdf->SetFont('', '', $default_font_size);
280
+        $pdf->SetXY(148, $posy + 1);
281 281
 		$pdf->MultiCell(40, 2, $langs->trans("Total"));
282 282
 
283
-		$pdf->SetFont('','B', $default_font_size);
284
-		$pdf->SetXY(170, $posy+1);
283
+		$pdf->SetFont('', 'B', $default_font_size);
284
+		$pdf->SetXY(170, $posy + 1);
285 285
 		$pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
286 286
 
287 287
 		// Tableau
288
-		$pdf->SetFont('','', $default_font_size - 2);
289
-		$pdf->SetXY(11, $this->tab_top+2);
290
-		$pdf->MultiCell(40,2,$outputlangs->transnoentities("Num"), 0, 'L');
288
+		$pdf->SetFont('', '', $default_font_size - 2);
289
+		$pdf->SetXY(11, $this->tab_top + 2);
290
+		$pdf->MultiCell(40, 2, $outputlangs->transnoentities("Num"), 0, 'L');
291 291
 		$pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
292 292
 
293
-		$pdf->SetXY(41, $this->tab_top+2);
294
-        $pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
293
+		$pdf->SetXY(41, $this->tab_top + 2);
294
+        $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L');
295 295
 		$pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
296 296
 
297
-        $pdf->SetXY(101, $this->tab_top+2);
298
-        $pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
297
+        $pdf->SetXY(101, $this->tab_top + 2);
298
+        $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
299 299
 		$pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
300 300
 
301
-		$pdf->SetXY(180, $this->tab_top+2);
302
-		$pdf->MultiCell(20,2,$outputlangs->transnoentities("Amount"), 0, 'R');
301
+		$pdf->SetXY(180, $this->tab_top + 2);
302
+		$pdf->MultiCell(20, 2, $outputlangs->transnoentities("Amount"), 0, 'R');
303 303
 		$pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
304 304
 
305 305
 		$pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
@@ -321,44 +321,44 @@  discard block
 block discarded – undo
321 321
 		// x=30 - Banque
322 322
 		// x=100 - Emetteur
323 323
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
324
-		$pdf->SetFont('','', $default_font_size - 1);
324
+		$pdf->SetFont('', '', $default_font_size - 1);
325 325
 		$oldprowid = 0;
326
-		$pdf->SetFillColor(220,220,220);
326
+		$pdf->SetFillColor(220, 220, 220);
327 327
 		$yp = 0;
328
-		$lineinpage=0;
329
-		$num=count($this->lines);
328
+		$lineinpage = 0;
329
+		$num = count($this->lines);
330 330
 		for ($j = 0; $j < $num; $j++)
331 331
 		{
332 332
 		    $lineinpage++;
333 333
 
334 334
 			$pdf->SetXY(1, $this->tab_top + 10 + $yp);
335
-			$pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
335
+			$pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0);
336 336
 
337 337
 			$pdf->SetXY(10, $this->tab_top + 10 + $yp);
338
-			$pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq?$this->lines[$j]->num_chq:'', 0, 'L', 0);
338
+			$pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq ? $this->lines[$j]->num_chq : '', 0, 'L', 0);
339 339
 
340 340
 			$pdf->SetXY(40, $this->tab_top + 10 + $yp);
341
-			$pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq),44), 0, 'L', 0);
341
+			$pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq), 44), 0, 'L', 0);
342 342
 
343 343
 			$pdf->SetXY(100, $this->tab_top + 10 + $yp);
344
-			$pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq),50), 0, 'L', 0);
344
+			$pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq), 50), 0, 'L', 0);
345 345
 
346 346
 			$pdf->SetXY(180, $this->tab_top + 10 + $yp);
347 347
 			$pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
348 348
 
349 349
 			$yp = $yp + $this->line_height;
350 350
 
351
-			if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
351
+			if ($lineinpage >= $this->line_per_page && $j < (count($this->lines) - 1))
352 352
 			{
353
-			    $lineinpage=0; $yp=0;
353
+			    $lineinpage = 0; $yp = 0;
354 354
 
355 355
                 // New page
356 356
                 $pdf->AddPage();
357 357
                 $pagenb++;
358 358
                 $this->Header($pdf, $pagenb, $pages, $outputlangs);
359
-                $pdf->SetFont('','', $default_font_size - 1);
360
-                $pdf->MultiCell(0, 3, '');      // Set interline to 3
361
-                $pdf->SetTextColor(0,0,0);
359
+                $pdf->SetFont('', '', $default_font_size - 1);
360
+                $pdf->MultiCell(0, 3, ''); // Set interline to 3
361
+                $pdf->SetTextColor(0, 0, 0);
362 362
 			}
363 363
 		}
364 364
 	}
@@ -373,22 +373,22 @@  discard block
 block discarded – undo
373 373
 	 *      @param	int			$hidefreetext		1=Hide free text
374 374
 	 *      @return	void
375 375
 	 */
376
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
376
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
377 377
 	{
378 378
 		global $conf;
379 379
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
380 380
 
381
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
381
+		$showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
382 382
 
383 383
 		// Line of free text
384
-		$newfreetext='';
385
-		$paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
386
-		if (! empty($conf->global->$paramfreetext))
384
+		$newfreetext = '';
385
+		$paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT';
386
+		if (!empty($conf->global->$paramfreetext))
387 387
 		{
388
-		    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
388
+		    $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
389 389
 		}
390 390
 		
391
-		return pdf_pagefoot($pdf,$outputlangs,$newfreetext,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
391
+		return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
392 392
 	}
393 393
 }
394 394
 
Please login to merge, or discard this patch.
Braces   +19 added lines, -7 removed lines patch added patch discarded remove patch
@@ -66,7 +66,10 @@  discard block
 block discarded – undo
66 66
 
67 67
         // Recupere emmetteur
68 68
         $this->emetteur=$mysoc;
69
-        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
69
+        if (! $this->emetteur->country_code) {
70
+        	$this->emetteur->country_code=substr($langs->defaultlang,-2);
71
+        }
72
+        // By default if not defined
70 73
 
71 74
         // Defini position des colonnes
72 75
         $this->line_height = 5;
@@ -87,10 +90,14 @@  discard block
 block discarded – undo
87 90
 	{
88 91
 		global $user,$conf,$langs,$hookmanager;
89 92
 
90
-        if (! is_object($outputlangs)) $outputlangs=$langs;
93
+        if (! is_object($outputlangs)) {
94
+        	$outputlangs=$langs;
95
+        }
91 96
         // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
92 97
         $sav_charset_output=$outputlangs->charset_output;
93
-        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
98
+        if (! empty($conf->global->MAIN_USE_FPDF)) {
99
+        	$outputlangs->charset_output='ISO-8859-1';
100
+        }
94 101
 
95 102
 		$outputlangs->load("main");
96 103
 		$outputlangs->load("companies");
@@ -147,7 +154,9 @@  discard block
 block discarded – undo
147 154
 		$pdf->SetCreator("Dolibarr ".DOL_VERSION);
148 155
 		$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
149 156
 		$pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
150
-		if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
157
+		if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
158
+			$pdf->SetCompression(false);
159
+		}
151 160
 
152 161
 		$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
153 162
 
@@ -173,7 +182,9 @@  discard block
 block discarded – undo
173 182
 
174 183
 		// Pied de page
175 184
 		$this->_pagefoot($pdf,'',$outputlangs);
176
-		if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
185
+		if (method_exists($pdf,'AliasNbPages')) {
186
+			$pdf->AliasNbPages();
187
+		}
177 188
 
178 189
 		$pdf->Close();
179 190
 
@@ -190,8 +201,9 @@  discard block
 block discarded – undo
190 201
 		global $action;
191 202
 		$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
192 203
 
193
-		if (! empty($conf->global->MAIN_UMASK))
194
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
204
+		if (! empty($conf->global->MAIN_UMASK)) {
205
+					@chmod($file, octdec($conf->global->MAIN_UMASK));
206
+		}
195 207
 
196 208
 		$this->result = array('fullpath'=>$file);
197 209
 		
Please login to merge, or discard this patch.
htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@
 block discarded – undo
125 125
 	 * Return next value
126 126
 	 *
127 127
 	 * @param	Societe		$objsoc     Object third party
128
-	 * @param  	Object	    $object		Object invoice
128
+	 * @param  	string	    $object		Object invoice
129 129
      * @param	string		$mode       'next' for next value or 'last' for last value
130 130
      * @return 	string      			Value if OK, 0 if KO
131 131
 	 */
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 	var $nom = 'Tulip';
42 42
 
43 43
 
44
-    /**
45
-     *  Returns the description of the model numbering
46
-     *
47
-     * 	@return     string      Description Text
48
-     */
44
+	/**
45
+	 *  Returns the description of the model numbering
46
+	 *
47
+	 * 	@return     string      Description Text
48
+	 */
49 49
 	function info()
50
-    {
51
-    	global $conf,$langs;
50
+	{
51
+		global $conf,$langs;
52 52
 
53 53
 		$langs->load("bills");
54 54
 		$langs->load("admin");
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
61 61
 		$texte.= '<input type="hidden" name="action" value="updateMask">';
62 62
 		$texte.= '<input type="hidden" name="maskconstinvoice" value="SUPPLIER_INVOICE_TULIP_MASK">';
63
-        $texte.= '<input type="hidden" name="maskconstreplacement" value="SUPPLIER_REPLACEMENT_TULIP_MASK">';
64
-        $texte.= '<input type="hidden" name="maskconstcredit" value="SUPPLIER_CREDIT_TULIP_MASK">';
63
+		$texte.= '<input type="hidden" name="maskconstreplacement" value="SUPPLIER_REPLACEMENT_TULIP_MASK">';
64
+		$texte.= '<input type="hidden" name="maskconstcredit" value="SUPPLIER_CREDIT_TULIP_MASK">';
65 65
 		$texte.= '<input type="hidden" name="maskconstdeposit" value="SUPPLIER_DEPOSIT_TULIP_MASK">';
66 66
 		$texte.= '<table class="nobordernopadding" width="100%">';
67 67
 
@@ -83,40 +83,40 @@  discard block
 block discarded – undo
83 83
 
84 84
 		if ($conf->global->MAIN_FEATURE_LEVEL >= 2)
85 85
 		{
86
-    		// Parametrage du prefix des replacement
87
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
88
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskreplacement" value="'.$conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
89
-    		$texte.= '</tr>';
90
-
91
-    		// Parametrage du prefix des avoirs
92
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
93
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->SUPPLIER_CREDIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
94
-    		$texte.= '</tr>';
95
-
96
-    		// Parametrage du prefix des acomptes
97
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
98
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskdeposit" value="'.$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
99
-    		$texte.= '</tr>';
86
+			// Parametrage du prefix des replacement
87
+			$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
88
+			$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskreplacement" value="'.$conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
89
+			$texte.= '</tr>';
90
+
91
+			// Parametrage du prefix des avoirs
92
+			$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
93
+			$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->SUPPLIER_CREDIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
94
+			$texte.= '</tr>';
95
+
96
+			// Parametrage du prefix des acomptes
97
+			$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
98
+			$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskdeposit" value="'.$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
99
+			$texte.= '</tr>';
100 100
 		}
101 101
 
102 102
 		$texte.= '</table>';
103 103
 		$texte.= '</form>';
104 104
 
105 105
 		return $texte;
106
-    }
107
-
108
-    /**
109
-     *  Returns a numbering example
110
-     *
111
-     *  @return     string     Example
112
-     */
113
-    function getExample()
114
-    {
115
-    	global $conf,$langs,$mysoc;
116
-
117
-    	$old_code_client=$mysoc->code_client;
118
-    	$mysoc->code_client='CCCCCCCCCC';
119
-    	$numExample = $this->getNextValue($mysoc,'');
106
+	}
107
+
108
+	/**
109
+	 *  Returns a numbering example
110
+	 *
111
+	 *  @return     string     Example
112
+	 */
113
+	function getExample()
114
+	{
115
+		global $conf,$langs,$mysoc;
116
+
117
+		$old_code_client=$mysoc->code_client;
118
+		$mysoc->code_client='CCCCCCCCCC';
119
+		$numExample = $this->getNextValue($mysoc,'');
120 120
 		$mysoc->code_client=$old_code_client;
121 121
 
122 122
 		if (! $numExample)
@@ -124,18 +124,18 @@  discard block
 block discarded – undo
124 124
 			$numExample = $langs->trans('NotConfigured');
125 125
 		}
126 126
 		return $numExample;
127
-    }
127
+	}
128 128
 
129 129
 	/**
130 130
 	 * Return next value
131 131
 	 *
132 132
 	 * @param	Societe		$objsoc     Object third party
133 133
 	 * @param  	Object	    $object		Object invoice
134
-     * @param	string		$mode       'next' for next value or 'last' for last value
135
-     * @return 	string      			Value if OK, 0 if KO
134
+	 * @param	string		$mode       'next' for next value or 'last' for last value
135
+	 * @return 	string      			Value if OK, 0 if KO
136 136
 	 */
137
-    function getNextValue($objsoc,$object,$mode='next')
138
-    {
137
+	function getNextValue($objsoc,$object,$mode='next')
138
+	{
139 139
 		global $db,$conf;
140 140
 
141 141
 		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 		return  $numFinal;
166 166
 	}
167 167
 
168
-    /**
168
+	/**
169 169
 	 * Return next free value
170 170
 	 *
171
-     * @param	Societe		$objsoc     	Object third party
172
-     * @param	string		$objforref		Object for number to search
173
-     * @param   string		$mode       	'next' for next value or 'last' for last value
174
-     * @return  string      				Next free value
175
-     */
171
+	 * @param	Societe		$objsoc     	Object third party
172
+	 * @param	string		$objforref		Object for number to search
173
+	 * @param   string		$mode       	'next' for next value or 'last' for last value
174
+	 * @return  string      				Next free value
175
+	 */
176 176
 	function getNumRef($objsoc,$objforref,$mode='next')
177 177
 	{
178 178
 		return $this->getNextValue($objsoc,$objforref,$mode);
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  *	\brief      File containing the Tulip Class of numbering models of suppliers invoices references
28 28
  */
29 29
 
30
-require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_invoice/modules_facturefournisseur.php';
30
+require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
31 31
 
32 32
 
33 33
 /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 */
37 37
 class mod_facture_fournisseur_tulip extends ModeleNumRefSuppliersInvoices
38 38
 {
39
-	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
39
+	var $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40 40
 	var $error = '';
41 41
 	var $nom = 'Tulip';
42 42
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
 	function info()
50 50
     {
51
-    	global $conf,$langs;
51
+    	global $conf, $langs;
52 52
 
53 53
 		$langs->load("bills");
54 54
 		$langs->load("admin");
@@ -56,51 +56,51 @@  discard block
 block discarded – undo
56 56
 		$form = new Form($this->db);
57 57
 
58 58
 		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
59
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
60
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
61
-		$texte.= '<input type="hidden" name="action" value="updateMask">';
62
-		$texte.= '<input type="hidden" name="maskconstinvoice" value="SUPPLIER_INVOICE_TULIP_MASK">';
63
-        $texte.= '<input type="hidden" name="maskconstreplacement" value="SUPPLIER_REPLACEMENT_TULIP_MASK">';
64
-        $texte.= '<input type="hidden" name="maskconstcredit" value="SUPPLIER_CREDIT_TULIP_MASK">';
65
-		$texte.= '<input type="hidden" name="maskconstdeposit" value="SUPPLIER_DEPOSIT_TULIP_MASK">';
66
-		$texte.= '<table class="nobordernopadding" width="100%">';
67
-
68
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
69
-		$tooltip.=$langs->trans("GenericMaskCodes2");
70
-		$tooltip.=$langs->trans("GenericMaskCodes3");
71
-		$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
72
-		$tooltip.=$langs->trans("GenericMaskCodes5");
59
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
60
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
61
+		$texte .= '<input type="hidden" name="action" value="updateMask">';
62
+		$texte .= '<input type="hidden" name="maskconstinvoice" value="SUPPLIER_INVOICE_TULIP_MASK">';
63
+        $texte .= '<input type="hidden" name="maskconstreplacement" value="SUPPLIER_REPLACEMENT_TULIP_MASK">';
64
+        $texte .= '<input type="hidden" name="maskconstcredit" value="SUPPLIER_CREDIT_TULIP_MASK">';
65
+		$texte .= '<input type="hidden" name="maskconstdeposit" value="SUPPLIER_DEPOSIT_TULIP_MASK">';
66
+		$texte .= '<table class="nobordernopadding" width="100%">';
67
+
68
+		$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
69
+		$tooltip .= $langs->trans("GenericMaskCodes2");
70
+		$tooltip .= $langs->trans("GenericMaskCodes3");
71
+		$tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
72
+		$tooltip .= $langs->trans("GenericMaskCodes5");
73 73
 
74 74
 		// Parametrage du prefix
75
-		$texte.= '<tr><td>'.$langs->trans("Mask");
75
+		$texte .= '<tr><td>'.$langs->trans("Mask");
76 76
 		//$texte.= ' ('.$langs->trans("InvoiceStandard").')';
77
-		$texte.= ':</td>';
78
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->SUPPLIER_INVOICE_TULIP_MASK.'">',$tooltip,1,1).'</td>';
77
+		$texte .= ':</td>';
78
+		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->SUPPLIER_INVOICE_TULIP_MASK.'">', $tooltip, 1, 1).'</td>';
79 79
 
80
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
80
+		$texte .= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
81 81
 
82
-		$texte.= '</tr>';
82
+		$texte .= '</tr>';
83 83
 
84 84
 		if ($conf->global->MAIN_FEATURE_LEVEL >= 2)
85 85
 		{
86 86
     		// Parametrage du prefix des replacement
87
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
88
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskreplacement" value="'.$conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
89
-    		$texte.= '</tr>';
87
+    		$texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
88
+    		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskreplacement" value="'.$conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK.'">', $tooltip, 1, 1).'</td>';
89
+    		$texte .= '</tr>';
90 90
 
91 91
     		// Parametrage du prefix des avoirs
92
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
93
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->SUPPLIER_CREDIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
94
-    		$texte.= '</tr>';
92
+    		$texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
93
+    		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->SUPPLIER_CREDIT_TULIP_MASK.'">', $tooltip, 1, 1).'</td>';
94
+    		$texte .= '</tr>';
95 95
 
96 96
     		// Parametrage du prefix des acomptes
97
-    		$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
98
-    		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskdeposit" value="'.$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK.'">',$tooltip,1,1).'</td>';
99
-    		$texte.= '</tr>';
97
+    		$texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
98
+    		$texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskdeposit" value="'.$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK.'">', $tooltip, 1, 1).'</td>';
99
+    		$texte .= '</tr>';
100 100
 		}
101 101
 
102
-		$texte.= '</table>';
103
-		$texte.= '</form>';
102
+		$texte .= '</table>';
103
+		$texte .= '</form>';
104 104
 
105 105
 		return $texte;
106 106
     }
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
      */
113 113
     function getExample()
114 114
     {
115
-    	global $conf,$langs,$mysoc;
115
+    	global $conf, $langs, $mysoc;
116 116
 
117
-    	$old_code_client=$mysoc->code_client;
118
-    	$mysoc->code_client='CCCCCCCCCC';
119
-    	$numExample = $this->getNextValue($mysoc,'');
120
-		$mysoc->code_client=$old_code_client;
117
+    	$old_code_client = $mysoc->code_client;
118
+    	$mysoc->code_client = 'CCCCCCCCCC';
119
+    	$numExample = $this->getNextValue($mysoc, '');
120
+		$mysoc->code_client = $old_code_client;
121 121
 
122
-		if (! $numExample)
122
+		if (!$numExample)
123 123
 		{
124 124
 			$numExample = $langs->trans('NotConfigured');
125 125
 		}
@@ -134,33 +134,33 @@  discard block
 block discarded – undo
134 134
      * @param	string		$mode       'next' for next value or 'last' for last value
135 135
      * @return 	string      			Value if OK, 0 if KO
136 136
 	 */
137
-    function getNextValue($objsoc,$object,$mode='next')
137
+    function getNextValue($objsoc, $object, $mode = 'next')
138 138
     {
139
-		global $db,$conf;
139
+		global $db, $conf;
140 140
 
141
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
141
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
142 142
 
143 143
 		// Get Mask value
144 144
 		$mask = '';
145 145
 		if (is_object($object) && $object->type == 1)
146 146
 		{
147
-			$mask=$conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK;
148
-			if (! $mask)
147
+			$mask = $conf->global->SUPPLIER_REPLACEMENT_TULIP_MASK;
148
+			if (!$mask)
149 149
 			{
150
-				$mask=$conf->global->SUPPLIER_INVOICE_TULIP_MASK;
150
+				$mask = $conf->global->SUPPLIER_INVOICE_TULIP_MASK;
151 151
 			}
152 152
 		}
153
-		else if (is_object($object) && $object->type == 2) $mask=$conf->global->SUPPLIER_CREDIT_TULIP_MASK;
154
-		else if (is_object($object) && $object->type == 3) $mask=$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK;
155
-		else $mask=$conf->global->SUPPLIER_INVOICE_TULIP_MASK;
156
-		if (! $mask)
153
+		else if (is_object($object) && $object->type == 2) $mask = $conf->global->SUPPLIER_CREDIT_TULIP_MASK;
154
+		else if (is_object($object) && $object->type == 3) $mask = $conf->global->SUPPLIER_DEPOSIT_TULIP_MASK;
155
+		else $mask = $conf->global->SUPPLIER_INVOICE_TULIP_MASK;
156
+		if (!$mask)
157 157
 		{
158
-			$this->error='NotConfigured';
158
+			$this->error = 'NotConfigured';
159 159
 			return 0;
160 160
 		}
161 161
 
162 162
 		// Supplier invoices take invoice date instead of creation date for the mask
163
-		$numFinal=get_next_value($db,$mask,'facture_fourn','ref','',$objsoc,$object->date);
163
+		$numFinal = get_next_value($db, $mask, 'facture_fourn', 'ref', '', $objsoc, $object->date);
164 164
 
165 165
 		return  $numFinal;
166 166
 	}
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
      * @param   string		$mode       	'next' for next value or 'last' for last value
174 174
      * @return  string      				Next free value
175 175
      */
176
-	function getNumRef($objsoc,$objforref,$mode='next')
176
+	function getNumRef($objsoc, $objforref, $mode = 'next')
177 177
 	{
178
-		return $this->getNextValue($objsoc,$objforref,$mode);
178
+		return $this->getNextValue($objsoc, $objforref, $mode);
179 179
 	}
180 180
 }
181 181
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -149,10 +149,13 @@
 block discarded – undo
149 149
 			{
150 150
 				$mask=$conf->global->SUPPLIER_INVOICE_TULIP_MASK;
151 151
 			}
152
+		} else if (is_object($object) && $object->type == 2) {
153
+			$mask=$conf->global->SUPPLIER_CREDIT_TULIP_MASK;
154
+		} else if (is_object($object) && $object->type == 3) {
155
+			$mask=$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK;
156
+		} else {
157
+			$mask=$conf->global->SUPPLIER_INVOICE_TULIP_MASK;
152 158
 		}
153
-		else if (is_object($object) && $object->type == 2) $mask=$conf->global->SUPPLIER_CREDIT_TULIP_MASK;
154
-		else if (is_object($object) && $object->type == 3) $mask=$conf->global->SUPPLIER_DEPOSIT_TULIP_MASK;
155
-		else $mask=$conf->global->SUPPLIER_INVOICE_TULIP_MASK;
156 159
 		if (! $mask)
157 160
 		{
158 161
 			$this->error='NotConfigured';
Please login to merge, or discard this patch.
htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	/**
69 69
 	 * 	Tests if the numbers already in force in the database do not cause conflicts that would prevent this numbering.
70 70
 	 *
71
-	 *  @return     boolean     false if conflict, true if ok
71
+	 *  @return     false|null     false if conflict, true if ok
72 72
 	 */
73 73
 	function canBeActivated()
74 74
 	{
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      * Return next value
145 145
 	 *
146 146
 	 * @param	Societe		$objsoc     Object third party
147
-	 * @param  	Object		$object		Object invoice
147
+	 * @param  	string		$object		Object invoice
148 148
      * @param   string		$mode       'next' for next value or 'last' for last value
149 149
 	 * @return 	string      			Value if OK, 0 if KO
150 150
      */
Please login to merge, or discard this patch.
Braces   +35 added lines, -16 removed lines patch added patch discarded remove patch
@@ -152,9 +152,13 @@  discard block
 block discarded – undo
152 152
     {
153 153
         global $db,$conf;
154 154
 
155
-        if ($object->type == 2) $prefix=$this->prefixcreditnote;
156
-        else if ($facture->type == 3) $prefix=$this->prefixdeposit;
157
-        else $prefix=$this->prefixinvoice;
155
+        if ($object->type == 2) {
156
+        	$prefix=$this->prefixcreditnote;
157
+        } else if ($facture->type == 3) {
158
+        	$prefix=$this->prefixdeposit;
159
+        } else {
160
+        	$prefix=$this->prefixinvoice;
161
+        }
158 162
 
159 163
         // D'abord on recupere la valeur max
160 164
         $posindice=8;
@@ -168,18 +172,25 @@  discard block
 block discarded – undo
168 172
         if ($resql)
169 173
         {
170 174
         	$obj = $db->fetch_object($resql);
171
-        	if ($obj) $max = intval($obj->max);
172
-        	else $max=0;
173
-        }
174
-        else
175
+        	if ($obj) {
176
+        		$max = intval($obj->max);
177
+        	} else {
178
+        		$max=0;
179
+        	}
180
+        } else
175 181
         {
176 182
         	return -1;
177 183
         }
178 184
 
179 185
         if ($mode == 'last')
180 186
         {
181
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
182
-    		else $num = sprintf("%04s",$max);
187
+    		if ($max >= (pow(10, 4) - 1)) {
188
+    			$num=$max;
189
+    		}
190
+    		// If counter > 9999, we do not format on 4 chars, we take number as it is
191
+    		else {
192
+    			$num = sprintf("%04s",$max);
193
+    		}
183 194
 
184 195
         	$ref='';
185 196
         	$sql = "SELECT ref as ref";
@@ -192,24 +203,32 @@  discard block
 block discarded – undo
192 203
         	if ($resql)
193 204
         	{
194 205
         		$obj = $db->fetch_object($resql);
195
-        		if ($obj) $ref = $obj->ref;
206
+        		if ($obj) {
207
+        			$ref = $obj->ref;
208
+        		}
209
+        	} else {
210
+        		dol_print_error($db);
196 211
         	}
197
-        	else dol_print_error($db);
198 212
 
199 213
         	return $ref;
200
-        }
201
-        else if ($mode == 'next')
214
+        } else if ($mode == 'next')
202 215
         {
203 216
         	$date=$object->date;	// This is invoice date (not creation date)
204 217
         	$yymm = strftime("%y%m",$date);
205 218
         	
206
-        	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
207
-        	else $num = sprintf("%04s",$max+1);
219
+        	if ($max >= (pow(10, 4) - 1)) {
220
+        		$num=$max+1;
221
+        	}
222
+        	// If counter > 9999, we do not format on 4 chars, we take number as it is
223
+        	else {
224
+        		$num = sprintf("%04s",$max+1);
225
+        	}
208 226
 
209 227
         	dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
210 228
         	return $prefix.$yymm."-".$num;
229
+        } else {
230
+        	dol_print_error('','Bad parameter for getNextValue');
211 231
         }
212
-        else dol_print_error('','Bad parameter for getNextValue');
213 232
     }
214 233
 
215 234
 
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -41,28 +41,28 @@  discard block
 block discarded – undo
41 41
 	var $prefixdeposit='SD';
42 42
 
43 43
 
44
-    /**
45
-     * 	Return description of numbering model
46
-     *
47
-     *  @return     string      Text with description
48
-     */
49
-    function info()
50
-    {
51
-    	global $langs;
44
+	/**
45
+	 * 	Return description of numbering model
46
+	 *
47
+	 *  @return     string      Text with description
48
+	 */
49
+	function info()
50
+	{
51
+		global $langs;
52 52
 		$langs->load("bills");
53
-      	return $langs->trans("CactusNumRefModelDesc1",$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit);
54
-    }
53
+	  	return $langs->trans("CactusNumRefModelDesc1",$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * 	Returns a numbering example
59
-     *
60
-     *  @return     string      Example
61
-     */
62
-    function getExample()
63
-    {
64
-        return $this->prefixinvoice."1301-0001";
65
-    }
57
+	/**
58
+	 * 	Returns a numbering example
59
+	 *
60
+	 *  @return     string      Example
61
+	 */
62
+	function getExample()
63
+	{
64
+		return $this->prefixinvoice."1301-0001";
65
+	}
66 66
 
67 67
 
68 68
 	/**
@@ -138,89 +138,89 @@  discard block
 block discarded – undo
138 138
 			$this->error=$langs->trans('ErrorNumRefModel',$max);
139 139
 			return false;
140 140
 		}
141
-    }
141
+	}
142 142
 
143
-    /**
144
-     * Return next value
143
+	/**
144
+	 * Return next value
145 145
 	 *
146 146
 	 * @param	Societe		$objsoc     Object third party
147 147
 	 * @param  	Object		$object		Object invoice
148
-     * @param   string		$mode       'next' for next value or 'last' for last value
148
+	 * @param   string		$mode       'next' for next value or 'last' for last value
149 149
 	 * @return 	string      			Value if OK, 0 if KO
150
-     */
151
-    function getNextValue($objsoc,$object,$mode='next')
152
-    {
153
-        global $db,$conf;
154
-
155
-        if ($object->type == 2) $prefix=$this->prefixcreditnote;
156
-        else if ($facture->type == 3) $prefix=$this->prefixdeposit;
157
-        else $prefix=$this->prefixinvoice;
158
-
159
-        // D'abord on recupere la valeur max
160
-        $posindice=8;
161
-        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
162
-        $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
163
-        $sql.= " WHERE ref LIKE '".$prefix."____-%'";
164
-        $sql.= " AND entity = ".$conf->entity;
165
-
166
-        $resql=$db->query($sql);
167
-        dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
168
-        if ($resql)
169
-        {
170
-        	$obj = $db->fetch_object($resql);
171
-        	if ($obj) $max = intval($obj->max);
172
-        	else $max=0;
173
-        }
174
-        else
175
-        {
176
-        	return -1;
177
-        }
178
-
179
-        if ($mode == 'last')
180
-        {
181
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
182
-    		else $num = sprintf("%04s",$max);
183
-
184
-        	$ref='';
185
-        	$sql = "SELECT ref as ref";
186
-        	$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
187
-        	$sql.= " WHERE ref LIKE '".$prefix."____-".$num."'";
188
-        	$sql.= " AND entity = ".$conf->entity;
189
-
190
-        	dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
191
-        	$resql=$db->query($sql);
192
-        	if ($resql)
193
-        	{
194
-        		$obj = $db->fetch_object($resql);
195
-        		if ($obj) $ref = $obj->ref;
196
-        	}
197
-        	else dol_print_error($db);
198
-
199
-        	return $ref;
200
-        }
201
-        else if ($mode == 'next')
202
-        {
203
-        	$date=$object->date;	// This is invoice date (not creation date)
204
-        	$yymm = strftime("%y%m",$date);
205
-
206
-        	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
207
-        	else $num = sprintf("%04s",$max+1);
208
-
209
-        	dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
210
-        	return $prefix.$yymm."-".$num;
211
-        }
212
-        else dol_print_error('','Bad parameter for getNextValue');
213
-    }
214
-
215
-
216
-    /**
150
+	 */
151
+	function getNextValue($objsoc,$object,$mode='next')
152
+	{
153
+		global $db,$conf;
154
+
155
+		if ($object->type == 2) $prefix=$this->prefixcreditnote;
156
+		else if ($facture->type == 3) $prefix=$this->prefixdeposit;
157
+		else $prefix=$this->prefixinvoice;
158
+
159
+		// D'abord on recupere la valeur max
160
+		$posindice=8;
161
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
162
+		$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
163
+		$sql.= " WHERE ref LIKE '".$prefix."____-%'";
164
+		$sql.= " AND entity = ".$conf->entity;
165
+
166
+		$resql=$db->query($sql);
167
+		dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
168
+		if ($resql)
169
+		{
170
+			$obj = $db->fetch_object($resql);
171
+			if ($obj) $max = intval($obj->max);
172
+			else $max=0;
173
+		}
174
+		else
175
+		{
176
+			return -1;
177
+		}
178
+
179
+		if ($mode == 'last')
180
+		{
181
+			if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
182
+			else $num = sprintf("%04s",$max);
183
+
184
+			$ref='';
185
+			$sql = "SELECT ref as ref";
186
+			$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
187
+			$sql.= " WHERE ref LIKE '".$prefix."____-".$num."'";
188
+			$sql.= " AND entity = ".$conf->entity;
189
+
190
+			dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
191
+			$resql=$db->query($sql);
192
+			if ($resql)
193
+			{
194
+				$obj = $db->fetch_object($resql);
195
+				if ($obj) $ref = $obj->ref;
196
+			}
197
+			else dol_print_error($db);
198
+
199
+			return $ref;
200
+		}
201
+		else if ($mode == 'next')
202
+		{
203
+			$date=$object->date;	// This is invoice date (not creation date)
204
+			$yymm = strftime("%y%m",$date);
205
+
206
+			if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
207
+			else $num = sprintf("%04s",$max+1);
208
+
209
+			dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
210
+			return $prefix.$yymm."-".$num;
211
+		}
212
+		else dol_print_error('','Bad parameter for getNextValue');
213
+	}
214
+
215
+
216
+	/**
217 217
 	 * Return next free value
218 218
 	 *
219
-     * @param	Societe		$objsoc     	Object third party
220
-     * @param	string		$objforref		Object for number to search
221
-     * @param   string		$mode       	'next' for next value or 'last' for last value
222
-     * @return  string      				Next free value
223
-     */
219
+	 * @param	Societe		$objsoc     	Object third party
220
+	 * @param	string		$objforref		Object for number to search
221
+	 * @param   string		$mode       	'next' for next value or 'last' for last value
222
+	 * @return  string      				Next free value
223
+	 */
224 224
 	function getNumRef($objsoc,$objforref,$mode='next')
225 225
 	{
226 226
 		return $this->getNextValue($objsoc,$objforref,$mode);
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File containing class for the numbering module Cactus
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_invoice/modules_facturefournisseur.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
29 29
 
30 30
 
31 31
 /**
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
35 35
 {
36
-	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
36
+	var $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
37 37
 	var $error = '';
38 38
 	var $nom = 'Cactus';
39
-	var $prefixinvoice='SI';
40
-	var $prefixcreditnote='SA';
41
-	var $prefixdeposit='SD';
39
+	var $prefixinvoice = 'SI';
40
+	var $prefixcreditnote = 'SA';
41
+	var $prefixdeposit = 'SD';
42 42
 
43 43
 
44 44
     /**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     {
51 51
     	global $langs;
52 52
 		$langs->load("bills");
53
-      	return $langs->trans("CactusNumRefModelDesc1",$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit);
53
+      	return $langs->trans("CactusNumRefModelDesc1", $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
54 54
     }
55 55
 
56 56
 
@@ -72,70 +72,70 @@  discard block
 block discarded – undo
72 72
 	 */
73 73
 	function canBeActivated()
74 74
 	{
75
-		global $conf,$langs,$db;
75
+		global $conf, $langs, $db;
76 76
 
77 77
 		$langs->load("bills");
78 78
 
79 79
 		// Check invoice num
80
-		$siyymm=''; $max='';
80
+		$siyymm = ''; $max = '';
81 81
 
82
-		$posindice=8;
82
+		$posindice = 8;
83 83
 		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
84
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
85
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
86
-		$sql.= " AND entity = ".$conf->entity;
87
-		$resql=$db->query($sql);
84
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
85
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
86
+		$sql .= " AND entity = ".$conf->entity;
87
+		$resql = $db->query($sql);
88 88
 		if ($resql)
89 89
 		{
90 90
 			$row = $db->fetch_row($resql);
91
-			if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
91
+			if ($row) { $siyymm = substr($row[0], 0, 6); $max = $row[0]; }
92 92
 		}
93
-		if ($siyymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$siyymm))
93
+		if ($siyymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $siyymm))
94 94
 		{
95 95
 			$langs->load("errors");
96
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
96
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
97 97
 			return false;
98 98
 		}
99 99
 
100 100
 		// Check credit note num
101
-		$siyymm='';
101
+		$siyymm = '';
102 102
 
103
-		$posindice=8;
104
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
105
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
106
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
107
-		$sql.= " AND entity = ".$conf->entity;
103
+		$posindice = 8;
104
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
105
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
106
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
107
+		$sql .= " AND entity = ".$conf->entity;
108 108
 
109
-		$resql=$db->query($sql);
109
+		$resql = $db->query($sql);
110 110
 		if ($resql)
111 111
 		{
112 112
 			$row = $db->fetch_row($resql);
113
-			if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
113
+			if ($row) { $siyymm = substr($row[0], 0, 6); $max = $row[0]; }
114 114
 		}
115
-		if ($siyymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$siyymm))
115
+		if ($siyymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $siyymm))
116 116
 		{
117
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
117
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
118 118
 			return false;
119 119
 		}
120 120
 
121 121
 		// Check deposit num
122
-		$siyymm='';
122
+		$siyymm = '';
123 123
 
124
-		$posindice=8;
125
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
126
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
127
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'";
128
-		$sql.= " AND entity = ".$conf->entity;
124
+		$posindice = 8;
125
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
126
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
127
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'";
128
+		$sql .= " AND entity = ".$conf->entity;
129 129
 
130
-		$resql=$db->query($sql);
130
+		$resql = $db->query($sql);
131 131
 		if ($resql)
132 132
 		{
133 133
 			$row = $db->fetch_row($resql);
134
-			if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
134
+			if ($row) { $siyymm = substr($row[0], 0, 6); $max = $row[0]; }
135 135
 		}
136
-		if ($siyymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$siyymm))
136
+		if ($siyymm && !preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i', $siyymm))
137 137
 		{
138
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
138
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
139 139
 			return false;
140 140
 		}
141 141
     }
@@ -148,28 +148,28 @@  discard block
 block discarded – undo
148 148
      * @param   string		$mode       'next' for next value or 'last' for last value
149 149
 	 * @return 	string      			Value if OK, 0 if KO
150 150
      */
151
-    function getNextValue($objsoc,$object,$mode='next')
151
+    function getNextValue($objsoc, $object, $mode = 'next')
152 152
     {
153
-        global $db,$conf;
153
+        global $db, $conf;
154 154
 
155
-        if ($object->type == 2) $prefix=$this->prefixcreditnote;
156
-        else if ($facture->type == 3) $prefix=$this->prefixdeposit;
157
-        else $prefix=$this->prefixinvoice;
155
+        if ($object->type == 2) $prefix = $this->prefixcreditnote;
156
+        else if ($facture->type == 3) $prefix = $this->prefixdeposit;
157
+        else $prefix = $this->prefixinvoice;
158 158
 
159 159
         // D'abord on recupere la valeur max
160
-        $posindice=8;
161
-        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
162
-        $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
163
-        $sql.= " WHERE ref LIKE '".$prefix."____-%'";
164
-        $sql.= " AND entity = ".$conf->entity;
160
+        $posindice = 8;
161
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
162
+        $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
163
+        $sql .= " WHERE ref LIKE '".$prefix."____-%'";
164
+        $sql .= " AND entity = ".$conf->entity;
165 165
 
166
-        $resql=$db->query($sql);
166
+        $resql = $db->query($sql);
167 167
         dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
168 168
         if ($resql)
169 169
         {
170 170
         	$obj = $db->fetch_object($resql);
171 171
         	if ($obj) $max = intval($obj->max);
172
-        	else $max=0;
172
+        	else $max = 0;
173 173
         }
174 174
         else
175 175
         {
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
 
179 179
         if ($mode == 'last')
180 180
         {
181
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
182
-    		else $num = sprintf("%04s",$max);
181
+    		if ($max >= (pow(10, 4) - 1)) $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is
182
+    		else $num = sprintf("%04s", $max);
183 183
 
184
-        	$ref='';
184
+        	$ref = '';
185 185
         	$sql = "SELECT ref as ref";
186
-        	$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
187
-        	$sql.= " WHERE ref LIKE '".$prefix."____-".$num."'";
188
-        	$sql.= " AND entity = ".$conf->entity;
186
+        	$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
187
+        	$sql .= " WHERE ref LIKE '".$prefix."____-".$num."'";
188
+        	$sql .= " AND entity = ".$conf->entity;
189 189
 
190 190
         	dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
191
-        	$resql=$db->query($sql);
191
+        	$resql = $db->query($sql);
192 192
         	if ($resql)
193 193
         	{
194 194
         		$obj = $db->fetch_object($resql);
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
         }
201 201
         else if ($mode == 'next')
202 202
         {
203
-        	$date=$object->date;	// This is invoice date (not creation date)
204
-        	$yymm = strftime("%y%m",$date);
203
+        	$date = $object->date; // This is invoice date (not creation date)
204
+        	$yymm = strftime("%y%m", $date);
205 205
 
206
-        	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
207
-        	else $num = sprintf("%04s",$max+1);
206
+        	if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
207
+        	else $num = sprintf("%04s", $max + 1);
208 208
 
209 209
         	dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
210 210
         	return $prefix.$yymm."-".$num;
211 211
         }
212
-        else dol_print_error('','Bad parameter for getNextValue');
212
+        else dol_print_error('', 'Bad parameter for getNextValue');
213 213
     }
214 214
 
215 215
 
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
      * @param   string		$mode       	'next' for next value or 'last' for last value
222 222
      * @return  string      				Next free value
223 223
      */
224
-	function getNumRef($objsoc,$objforref,$mode='next')
224
+	function getNumRef($objsoc, $objforref, $mode = 'next')
225 225
 	{
226
-		return $this->getNextValue($objsoc,$objforref,$mode);
226
+		return $this->getNextValue($objsoc, $objforref, $mode);
227 227
 	}
228 228
 }
229 229
 
Please login to merge, or discard this patch.
htdocs/expedition/class/expedition.class.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @param 	int		$entrepot_id		Id of warehouse
366 366
 	 * @param 	int		$origin_line_id		Id of source line
367 367
 	 * @param 	int		$qty				Quantity
368
-	 * @param	array	$array_options		extrafields array
368
+	 * @param	integer	$array_options		extrafields array
369 369
 	 * @return	int							<0 if KO, line_id if OK
370 370
 	 */
371 371
 	function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0)
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * Create the detail (eat-by date) of the expedition line
420 420
 	 *
421 421
 	 * @param 	object		$line_ext		full line informations
422
-	 * @param	array		$array_options		extrafields array
422
+	 * @param	integer		$array_options		extrafields array
423 423
 	 * @return	int							<0 if KO, >0 if OK
424 424
 	 */
425 425
 	function create_line_batch($line_ext,$array_options=0)
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 	 * @param 	int		$entrepot_id		Id of warehouse
858 858
 	 * @param 	int		$id					Id of source line (order line)
859 859
 	 * @param 	int		$qty				Quantity
860
-	 * @param	array	$array_options		extrafields array
860
+	 * @param	integer	$array_options		extrafields array
861 861
 	 * @return	int							<0 if KO, >0 if OK
862 862
 	 */
863 863
 	function addline($entrepot_id, $id, $qty,$array_options=0)
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
 	 * Add a shipment line with batch record
928 928
 	 *
929 929
 	 * @param 	array		$dbatch		Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
930
-	 * @param	array		$array_options		extrafields array
930
+	 * @param	integer		$array_options		extrafields array
931 931
 	 * @return	int						<0 if KO, >0 if OK
932 932
 	 */
933 933
 	function addline_batch($dbatch,$array_options=0)
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	public $table_element="expedition";
49 49
 	public $table_element_line="expeditiondet";
50 50
 	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
51
-    public $picto = 'sending';
51
+	public $picto = 'sending';
52 52
 
53 53
 	var $socid;
54 54
 	var $ref_customer;
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
 		global $langs, $conf;
132 132
 		$langs->load("sendings");
133 133
 
134
-	    if (!empty($conf->global->EXPEDITION_ADDON_NUMBER))
135
-        {
134
+		if (!empty($conf->global->EXPEDITION_ADDON_NUMBER))
135
+		{
136 136
 			$mybool = false;
137 137
 
138 138
 			$file = $conf->global->EXPEDITION_ADDON_NUMBER.".php";
139 139
 			$classname = $conf->global->EXPEDITION_ADDON_NUMBER;
140 140
 
141
-	        // Include file with class
142
-	        $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
141
+			// Include file with class
142
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
143 143
 
144
-	        foreach ($dirmodels as $reldir) {
144
+			foreach ($dirmodels as $reldir) {
145 145
 
146
-		        $dir = dol_buildpath($reldir."core/modules/expedition/");
146
+				$dir = dol_buildpath($reldir."core/modules/expedition/");
147 147
 
148
-		        // Load file with numbering class (if found)
149
-		        $mybool|=@include_once $dir.$file;
150
-	        }
148
+				// Load file with numbering class (if found)
149
+				$mybool|=@include_once $dir.$file;
150
+			}
151 151
 
152
-	        if (! $mybool)
153
-	        {
154
-		        dol_print_error('',"Failed to include file ".$file);
155
-		        return '';
156
-	        }
152
+			if (! $mybool)
153
+			{
154
+				dol_print_error('',"Failed to include file ".$file);
155
+				return '';
156
+			}
157 157
 
158 158
 			$obj = new $classname();
159 159
 			$numref = "";
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
 				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
169 169
 				return "";
170 170
 			}
171
-        }
172
-	    else
173
-	    {
174
-		    print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
175
-		    return "";
176
-	    }
171
+		}
172
+		else
173
+		{
174
+			print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
175
+			return "";
176
+		}
177 177
 	}
178 178
 
179 179
 	/**
180 180
 	 *  Create expedition en base
181 181
 	 *
182 182
 	 *  @param	User	$user       Objet du user qui cree
183
-   * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
183
+	 * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
184 184
 	 *  @return int 				<0 si erreur, id expedition creee si ok
185 185
 	 */
186 186
 	function create($user, $notrigger=0)
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
250 250
 		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
251 251
 		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
252
-        $sql.= ", ".(int) $this->fk_incoterms;
253
-        $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
252
+		$sql.= ", ".(int) $this->fk_incoterms;
253
+		$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
254 254
 		$sql.= ")";
255 255
 
256 256
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
@@ -315,10 +315,10 @@  discard block
 block discarded – undo
315 315
 
316 316
 				if (! $error && ! $notrigger)
317 317
 				{
318
-                    // Call trigger
319
-                    $result=$this->call_trigger('SHIPPING_CREATE',$user);
320
-                    if ($result < 0) { $error++; }
321
-                    // End call triggers
318
+					// Call trigger
319
+					$result=$this->call_trigger('SHIPPING_CREATE',$user);
320
+					if ($result < 0) { $error++; }
321
+					// End call triggers
322 322
 
323 323
 					if (! $error)
324 324
 					{
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 		$resql = $this->db->query($sql);
394 394
 		if ($resql)
395 395
 		{
396
-		    $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
396
+			$line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
397 397
 		}
398 398
 		else
399 399
 		{
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 	 *	@param	int		$id       	Id of object to load
472 472
 	 * 	@param	string	$ref		Ref of object
473 473
 	 * 	@param	string	$ref_ext	External reference of object
474
-     * 	@param	string	$ref_int	Internal reference of other object
474
+	 * 	@param	string	$ref_int	Internal reference of other object
475 475
 	 *	@return int			        >0 if OK, 0 if not found, <0 if KO
476 476
 	 */
477 477
 	function fetch($id, $ref='', $ref_ext='', $ref_int='')
@@ -487,16 +487,16 @@  discard block
 block discarded – undo
487 487
 		$sql.= ", e.fk_shipping_method, e.tracking_number";
488 488
 		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
489 489
 		$sql.= ", e.note_private, e.note_public";
490
-        $sql.= ', e.fk_incoterms, e.location_incoterms';
491
-        $sql.= ', i.libelle as libelle_incoterms';
490
+		$sql.= ', e.fk_incoterms, e.location_incoterms';
491
+		$sql.= ', i.libelle as libelle_incoterms';
492 492
 		$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
493 493
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
494 494
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
495 495
 		$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
496 496
 		if ($id)   	  $sql.= " AND e.rowid=".$id;
497
-        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
498
-        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
499
-        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
497
+		if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
498
+		if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
499
+		if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
500 500
 
501 501
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
502 502
 		$result = $this->db->query($sql);
@@ -600,14 +600,14 @@  discard block
 block discarded – undo
600 600
 	 *  Validate object and update stock if option enabled
601 601
 	 *
602 602
 	 *  @param      User		$user       Object user that validate
603
-     *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
603
+	 *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
604 604
 	 *  @return     int						<0 if OK, >0 if KO
605 605
 	 */
606 606
 	function valid($user, $notrigger=0)
607 607
 	{
608 608
 		global $conf, $langs;
609 609
 
610
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
610
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
611 611
 
612 612
 		dol_syslog(get_class($this)."::valid");
613 613
 
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 			return 0;
619 619
 		}
620 620
 
621
-        if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
622
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))))
621
+		if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
622
+	   	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))))
623 623
 		{
624 624
 			$this->error='Permission denied';
625 625
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 		{
647 647
 			$numref = "EXP".$this->id;
648 648
 		}
649
-        $this->newref = $numref;
649
+		$this->newref = $numref;
650 650
 
651 651
 		$now=dol_now();
652 652
 
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 						// line with batch detail
726 726
 
727 727
 						// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
728
-					    // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
728
+						// Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
729 729
 						$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
730 730
 						if ($result < 0) {
731 731
 							$error++;
@@ -748,22 +748,22 @@  discard block
 block discarded – undo
748 748
 		// Change status of order to "shipment in process"
749 749
 		$ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin);
750 750
 
751
-        if (! $ret)
751
+		if (! $ret)
752 752
 		{
753
-		    $error++;
753
+			$error++;
754 754
 		}
755 755
 
756 756
 		if (! $error && ! $notrigger)
757 757
 		{
758
-            // Call trigger
759
-            $result=$this->call_trigger('SHIPPING_VALIDATE',$user);
760
-            if ($result < 0) { $error++; }
761
-            // End call triggers
758
+			// Call trigger
759
+			$result=$this->call_trigger('SHIPPING_VALIDATE',$user);
760
+			if ($result < 0) { $error++; }
761
+			// End call triggers
762 762
 		}
763 763
 
764 764
 		if (! $error)
765 765
 		{
766
-            $this->oldref = $this->ref;
766
+			$this->oldref = $this->ref;
767 767
 
768 768
 			// Rename directory if dir was a temporary ref
769 769
 			if (preg_match('/^[\(]?PROV/i', $this->ref))
@@ -780,17 +780,17 @@  discard block
 block discarded – undo
780 780
 
781 781
 					if (@rename($dirsource, $dirdest))
782 782
 					{
783
-					    dol_syslog("Rename ok");
784
-                        // Rename docs starting with $oldref with $newref
785
-                        $listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
786
-                        foreach($listoffiles as $fileentry)
787
-                        {
788
-                        	$dirsource=$fileentry['name'];
789
-                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
790
-                        	$dirsource=$fileentry['path'].'/'.$dirsource;
791
-                        	$dirdest=$fileentry['path'].'/'.$dirdest;
792
-                        	@rename($dirsource, $dirdest);
793
-                        }
783
+						dol_syslog("Rename ok");
784
+						// Rename docs starting with $oldref with $newref
785
+						$listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
786
+						foreach($listoffiles as $fileentry)
787
+						{
788
+							$dirsource=$fileentry['name'];
789
+							$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
790
+							$dirsource=$fileentry['path'].'/'.$dirsource;
791
+							$dirdest=$fileentry['path'].'/'.$dirdest;
792
+							@rename($dirsource, $dirdest);
793
+						}
794 794
 					}
795 795
 				}
796 796
 			}
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 		{
813 813
 			foreach($this->errors as $errmsg)
814 814
 			{
815
-	            dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
816
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
815
+				dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
816
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
817 817
 			}
818 818
 			$this->db->rollback();
819 819
 			return -1*$error;
@@ -885,14 +885,14 @@  discard block
 block discarded – undo
885 885
 
886 886
 			if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
887 887
 			{
888
-			    $langs->load("errors");
888
+				$langs->load("errors");
889 889
 				$this->error=$langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
890 890
 				return -1;
891 891
 			}
892 892
 
893 893
 			if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
894 894
 			{
895
-			    // Check must be done for stock of product into warehouse if $entrepot_id defined
895
+				// Check must be done for stock of product into warehouse if $entrepot_id defined
896 896
 				$product=new Product($this->db);
897 897
 				$result=$product->fetch($fk_product);
898 898
 
@@ -906,8 +906,8 @@  discard block
 block discarded – undo
906 906
 				$product_type=$product->type;
907 907
 				if ($product_type == 0 && $product_stock < $qty)
908 908
 				{
909
-                    $langs->load("errors");
910
-				    $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
909
+					$langs->load("errors");
910
+					$this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
911 911
 					$this->db->rollback();
912 912
 					return -3;
913 913
 				}
@@ -917,8 +917,8 @@  discard block
 block discarded – undo
917 917
 		// If product need a batch number, we should not have called this function but addline_batch instead.
918 918
 		if (! empty($conf->productbatch->enabled) && ! empty($orderline->fk_product) && ! empty($orderline->product_tobatch))
919 919
 		{
920
-		    $this->error='ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
921
-		    return -4;
920
+			$this->error='ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
921
+			return -4;
922 922
 		}
923 923
 
924 924
 		// extrafields
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 		$this->lines[$num] = $line;
929 929
 	}
930 930
 
931
-    /**
931
+	/**
932 932
 	 * Add a shipment line with batch record
933 933
 	 *
934 934
 	 * @param 	array		$dbatch		Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 					// $value['id_batch']=id into llx_product_batch of record to move
953 953
 					//var_dump($value);
954 954
 
955
-				    $linebatch = new ExpeditionLineBatch($this->db);
955
+					$linebatch = new ExpeditionLineBatch($this->db);
956 956
 					$ret=$linebatch->fetchFromStock($value['id_batch']);	// load serial, sellby, eatby
957 957
 					if ($ret<0)
958 958
 					{
@@ -970,8 +970,8 @@  discard block
 block discarded – undo
970 970
 
971 971
 						if ($prod_batch->qty < $linebatch->dluo_qty)
972 972
 						{
973
-                            $langs->load("errors");
974
-        				    $this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
973
+							$langs->load("errors");
974
+							$this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
975 975
 							dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR);
976 976
 							$this->db->rollback();
977 977
 							return -1;
@@ -996,16 +996,16 @@  discard block
 block discarded – undo
996 996
 		}
997 997
 	}
998 998
 
999
-    /**
1000
-     *  Update database
1001
-     *
1002
-     *  @param	User	$user        	User that modify
1003
-     *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
1004
-     *  @return int 			       	<0 if KO, >0 if OK
1005
-     */
1006
-    function update($user=null, $notrigger=0)
1007
-    {
1008
-    	global $conf;
999
+	/**
1000
+	 *  Update database
1001
+	 *
1002
+	 *  @param	User	$user        	User that modify
1003
+	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
1004
+	 *  @return int 			       	<0 if KO, >0 if OK
1005
+	 */
1006
+	function update($user=null, $notrigger=0)
1007
+	{
1008
+		global $conf;
1009 1009
 		$error=0;
1010 1010
 
1011 1011
 		// Clean parameters
@@ -1035,8 +1035,8 @@  discard block
 block discarded – undo
1035 1035
 		// Check parameters
1036 1036
 		// Put here code to add control on parameters values
1037 1037
 
1038
-        // Update request
1039
-        $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
1038
+		// Update request
1039
+		$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
1040 1040
 
1041 1041
 		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
1042 1042
 		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
@@ -1063,32 +1063,32 @@  discard block
 block discarded – undo
1063 1063
 		$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
1064 1064
 		$sql.= " entity=".$conf->entity;
1065 1065
 
1066
-        $sql.= " WHERE rowid=".$this->id;
1066
+		$sql.= " WHERE rowid=".$this->id;
1067 1067
 
1068 1068
 		$this->db->begin();
1069 1069
 
1070 1070
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
1071
-        $resql = $this->db->query($sql);
1072
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
1071
+		$resql = $this->db->query($sql);
1072
+		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
1073 1073
 
1074 1074
 		if (! $error)
1075 1075
 		{
1076 1076
 			if (! $notrigger)
1077 1077
 			{
1078
-                // Call trigger
1079
-                $result=$this->call_trigger('SHIPPING_MODIFY',$user);
1080
-                if ($result < 0) { $error++; }
1081
-                // End call triggers
1082
-	    	}
1078
+				// Call trigger
1079
+				$result=$this->call_trigger('SHIPPING_MODIFY',$user);
1080
+				if ($result < 0) { $error++; }
1081
+				// End call triggers
1082
+			}
1083 1083
 		}
1084 1084
 
1085
-        // Commit or rollback
1085
+		// Commit or rollback
1086 1086
 		if ($error)
1087 1087
 		{
1088 1088
 			foreach($this->errors as $errmsg)
1089 1089
 			{
1090
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1091
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
1090
+				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1091
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
1092 1092
 			}
1093 1093
 			$this->db->rollback();
1094 1094
 			return -1*$error;
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 			$this->db->commit();
1099 1099
 			return 1;
1100 1100
 		}
1101
-    }
1101
+	}
1102 1102
 
1103 1103
 	/**
1104 1104
 	 * 	Delete shipment.
@@ -1231,18 +1231,18 @@  discard block
 block discarded – undo
1231 1231
 
1232 1232
 						if (! empty($this->origin) && $this->origin_id > 0)
1233 1233
 						{
1234
-						    $this->fetch_origin();
1235
-						    $origin=$this->origin;
1236
-						    if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS)     // If order source of shipment is "shipment in progress"
1237
-						    {
1238
-                                // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress"
1239
-						        $this->$origin->loadExpeditions();
1240
-						        //var_dump($this->$origin->expeditions);exit;
1241
-						        if (count($this->$origin->expeditions) <= 0)
1242
-						        {
1243
-                                    $this->$origin->setStatut(Commande::STATUS_VALIDATED);
1244
-						        }
1245
-						    }
1234
+							$this->fetch_origin();
1235
+							$origin=$this->origin;
1236
+							if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS)     // If order source of shipment is "shipment in progress"
1237
+							{
1238
+								// Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress"
1239
+								$this->$origin->loadExpeditions();
1240
+								//var_dump($this->$origin->expeditions);exit;
1241
+								if (count($this->$origin->expeditions) <= 0)
1242
+								{
1243
+									$this->$origin->setStatut(Commande::STATUS_VALIDATED);
1244
+								}
1245
+							}
1246 1246
 						}
1247 1247
 
1248 1248
 						if (! $error)
@@ -1354,13 +1354,13 @@  discard block
 block discarded – undo
1354 1354
 			{
1355 1355
 				$obj = $this->db->fetch_object($resql);
1356 1356
 
1357
-			    if ($originline == $obj->fk_origin_line) {
1358
-			        $line->entrepot_id       = 0; // entrepod_id in details_entrepot
1359
-				    $line->qty_shipped    	+= $obj->qty_shipped;
1357
+				if ($originline == $obj->fk_origin_line) {
1358
+					$line->entrepot_id       = 0; // entrepod_id in details_entrepot
1359
+					$line->qty_shipped    	+= $obj->qty_shipped;
1360 1360
 				} else {
1361
-				    $line = new ExpeditionLigne($this->db);
1362
-				    $line->entrepot_id    	= $obj->fk_entrepot;
1363
-				    $line->qty_shipped    	= $obj->qty_shipped;
1361
+					$line = new ExpeditionLigne($this->db);
1362
+					$line->entrepot_id    	= $obj->fk_entrepot;
1363
+					$line->qty_shipped    	= $obj->qty_shipped;
1364 1364
 				}
1365 1365
 
1366 1366
 				$detail_entrepot              = new stdClass;
@@ -1368,13 +1368,13 @@  discard block
 block discarded – undo
1368 1368
 				$detail_entrepot->qty_shipped = $obj->qty_shipped;
1369 1369
 				$line->details_entrepot[]     = $detail_entrepot;
1370 1370
 
1371
-                $line->line_id          = $obj->line_id;
1372
-                $line->rowid            = $obj->line_id;    // TODO deprecated
1373
-                $line->id               = $obj->line_id;
1371
+				$line->line_id          = $obj->line_id;
1372
+				$line->rowid            = $obj->line_id;    // TODO deprecated
1373
+				$line->id               = $obj->line_id;
1374 1374
 
1375
-                $line->fk_origin     	= 'orderline';
1376
-                $line->fk_origin_line 	= $obj->fk_origin_line;
1377
-                $line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
1375
+				$line->fk_origin     	= 'orderline';
1376
+				$line->fk_origin_line 	= $obj->fk_origin_line;
1377
+				$line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
1378 1378
 
1379 1379
 				$line->fk_expedition    = $this->id;                // id of parent
1380 1380
 
@@ -1382,8 +1382,8 @@  discard block
 block discarded – undo
1382 1382
 				$line->fk_product     	= $obj->fk_product;
1383 1383
 				$line->fk_product_type	= $obj->fk_product_type;
1384 1384
 				$line->ref				= $obj->product_ref;		// TODO deprecated
1385
-                $line->product_ref		= $obj->product_ref;
1386
-                $line->product_label	= $obj->product_label;
1385
+				$line->product_ref		= $obj->product_ref;
1386
+				$line->product_label	= $obj->product_label;
1387 1387
 				$line->libelle        	= $obj->product_label;		// TODO deprecated
1388 1388
 				$line->product_tobatch  = $obj->product_tobatch;
1389 1389
 				$line->label			= $obj->custom_label;
@@ -1440,34 +1440,34 @@  discard block
 block discarded – undo
1440 1440
 				// Eat-by date
1441 1441
 				if (! empty($conf->productbatch->enabled) && $obj->line_id > 0)
1442 1442
 				{
1443
-                    require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1444
-
1445
-                    $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db,$obj->line_id);
1446
-                    if (is_array($newdetailbatch))
1447
-                    {
1448
-	                    if ($originline != $obj->fk_origin_line)
1449
-	                    {
1450
-	                        $line->detail_batch = $newdetailbatch;
1451
-	                    }
1452
-	                    else
1443
+					require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1444
+
1445
+					$newdetailbatch = ExpeditionLineBatch::fetchAll($this->db,$obj->line_id);
1446
+					if (is_array($newdetailbatch))
1447
+					{
1448
+						if ($originline != $obj->fk_origin_line)
1449
+						{
1450
+							$line->detail_batch = $newdetailbatch;
1451
+						}
1452
+						else
1453 1453
 						{
1454
-	                        $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1455
-	                    }
1456
-                    }
1454
+							$line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1455
+						}
1456
+					}
1457 1457
 				}
1458 1458
 
1459 1459
 				if ($originline != $obj->fk_origin_line)
1460 1460
 				{
1461
-				    $this->lines[$lineindex] = $line;
1462
-				    $lineindex++;
1461
+					$this->lines[$lineindex] = $line;
1462
+					$lineindex++;
1463 1463
 				}
1464 1464
 				else
1465 1465
 				{
1466
-				    $line->total_ht			+= $tabprice[0];
1467
-				    $line->total_localtax1 	+= $tabprice[9];
1468
-				    $line->total_localtax2 	+= $tabprice[10];
1469
-				    $line->total_ttc	 	+= $tabprice[2];
1470
-				    $line->total_tva	 	+= $tabprice[1];
1466
+					$line->total_ht			+= $tabprice[0];
1467
+					$line->total_localtax1 	+= $tabprice[9];
1468
+					$line->total_localtax2 	+= $tabprice[10];
1469
+					$line->total_ttc	 	+= $tabprice[2];
1470
+					$line->total_tva	 	+= $tabprice[1];
1471 1471
 				}
1472 1472
 
1473 1473
 				$i++;
@@ -1484,24 +1484,24 @@  discard block
 block discarded – undo
1484 1484
 	}
1485 1485
 
1486 1486
 	/**
1487
-     *	Return clicable link of object (with eventually picto)
1488
-     *
1489
-     *	@param      int			$withpicto      			Add picto into link
1490
-     *	@param      int			$option         			Where point the link
1491
-     *	@param      int			$max          				Max length to show
1492
-     *	@param      int			$short						Use short labels
1493
-     *  @param      int         $notooltip      			1=No tooltip
1494
-     *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1495
-     *	@return     string          						String with URL
1496
-     */
1487
+	 *	Return clicable link of object (with eventually picto)
1488
+	 *
1489
+	 *	@param      int			$withpicto      			Add picto into link
1490
+	 *	@param      int			$option         			Where point the link
1491
+	 *	@param      int			$max          				Max length to show
1492
+	 *	@param      int			$short						Use short labels
1493
+	 *  @param      int         $notooltip      			1=No tooltip
1494
+	 *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1495
+	 *	@return     string          						String with URL
1496
+	 */
1497 1497
 	function getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
1498 1498
 	{
1499 1499
 		global $langs;
1500 1500
 
1501 1501
 		$result='';
1502
-        $label = '<u>' . $langs->trans("ShowSending") . '</u>';
1503
-        $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1504
-        $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1502
+		$label = '<u>' . $langs->trans("ShowSending") . '</u>';
1503
+		$label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1504
+		$label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1505 1505
 
1506 1506
 		$url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id;
1507 1507
 
@@ -1518,16 +1518,16 @@  discard block
 block discarded – undo
1518 1518
 		$linkclose='';
1519 1519
 		if (empty($notooltip))
1520 1520
 		{
1521
-		    if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1522
-		    {
1523
-		        $label=$langs->trans("ShowSending");
1524
-		        $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1525
-		    }
1526
-		    $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1527
-		    $linkclose.=' class="classfortooltip"';
1521
+			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1522
+			{
1523
+				$label=$langs->trans("ShowSending");
1524
+				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1525
+			}
1526
+			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1527
+			$linkclose.=' class="classfortooltip"';
1528 1528
 		}
1529 1529
 
1530
-        $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1530
+		$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1531 1531
 		$linkend='</a>';
1532 1532
 
1533 1533
 		$picto='sending';
@@ -1539,11 +1539,11 @@  discard block
 block discarded – undo
1539 1539
 	}
1540 1540
 
1541 1541
 	/**
1542
-     *	Return status label
1543
-     *
1544
-     *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1545
-     *	@return     string      		Libelle
1546
-     */
1542
+	 *	Return status label
1543
+	 *
1544
+	 *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1545
+	 *	@return     string      		Libelle
1546
+	 */
1547 1547
 	function getLibStatut($mode=0)
1548 1548
 	{
1549 1549
 		return $this->LibStatut($this->statut,$mode);
@@ -1593,11 +1593,11 @@  discard block
 block discarded – undo
1593 1593
 	}
1594 1594
 
1595 1595
 	/**
1596
-     *  Initialise an instance with random values.
1597
-     *  Used to build previews or test instances.
1598
-     *	id must be 0 if object instance is a specimen.
1599
-     *
1600
-     *  @return	void
1596
+	 *  Initialise an instance with random values.
1597
+	 *  Used to build previews or test instances.
1598
+	 *	id must be 0 if object instance is a specimen.
1599
+	 *
1600
+	 *  @return	void
1601 1601
 	 */
1602 1602
 	function initAsSpecimen()
1603 1603
 	{
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 
1608 1608
 		dol_syslog(get_class($this)."::initAsSpecimen");
1609 1609
 
1610
-        // Load array of products prodids
1610
+		// Load array of products prodids
1611 1611
 		$num_prods = 0;
1612 1612
 		$prodids = array();
1613 1613
 		$sql = "SELECT rowid";
@@ -1648,11 +1648,11 @@  discard block
 block discarded – undo
1648 1648
 		$this->commande_id          = 0;
1649 1649
 		$this->commande             = $order;
1650 1650
 
1651
-        $this->origin_id            = 1;
1652
-        $this->origin               = 'commande';
1651
+		$this->origin_id            = 1;
1652
+		$this->origin               = 'commande';
1653 1653
 
1654
-        $this->note_private			= 'Private note';
1655
-        $this->note_public			= 'Public note';
1654
+		$this->note_private			= 'Private note';
1655
+		$this->note_public			= 'Public note';
1656 1656
 
1657 1657
 		$nbp = 5;
1658 1658
 		$xnbp = 0;
@@ -1732,99 +1732,99 @@  discard block
 block discarded – undo
1732 1732
 		}
1733 1733
 	}
1734 1734
 
1735
-    /**
1736
-     *  Fetch all deliveries method and return an array. Load array this->listmeths.
1737
-     *
1738
-     *  @param  id      $id     only this carrier, all if none
1739
-     *  @return void
1740
-     */
1741
-    function list_delivery_methods($id='')
1742
-    {
1743
-        global $langs;
1744
-
1745
-        $this->listmeths = array();
1746
-        $i=0;
1747
-
1748
-        $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1749
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1750
-        if ($id!='') $sql.= " WHERE em.rowid=".$id;
1751
-
1752
-        $resql = $this->db->query($sql);
1753
-        if ($resql)
1754
-        {
1755
-            while ($obj = $this->db->fetch_object($resql))
1756
-            {
1757
-                $this->listmeths[$i]['rowid'] = $obj->rowid;
1758
-                $this->listmeths[$i]['code'] = $obj->code;
1759
-                $label=$langs->trans('SendingMethod'.$obj->code);
1760
-                $this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1761
-                $this->listmeths[$i]['description'] = $obj->description;
1762
-                $this->listmeths[$i]['tracking'] = $obj->tracking;
1763
-                $this->listmeths[$i]['active'] = $obj->active;
1764
-                $i++;
1765
-            }
1766
-        }
1767
-    }
1768
-
1769
-    /**
1770
-     *  Update/create delivery method.
1771
-     *
1772
-     *  @param	string      $id     id method to activate
1773
-     *
1774
-     *  @return void
1775
-     */
1776
-    function update_delivery_method($id='')
1777
-    {
1778
-        if ($id=='')
1779
-        {
1780
-            $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1781
-            $sql.=" VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1782
-            $resql = $this->db->query($sql);
1783
-        }
1784
-        else
1785
-        {
1786
-            $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1787
-            $sql.= " code='".$this->db->escape($this->update['code'])."'";
1788
-            $sql.= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1789
-            $sql.= ",description='".$this->db->escape($this->update['description'])."'";
1790
-            $sql.= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1791
-            $sql.= " WHERE rowid=".$id;
1792
-            $resql = $this->db->query($sql);
1793
-        }
1794
-        if ($resql < 0) dol_print_error($this->db,'');
1795
-    }
1796
-
1797
-    /**
1798
-     *  Activate delivery method.
1799
-     *
1800
-     *  @param      id      $id     id method to activate
1801
-     *
1802
-     *  @return void
1803
-     */
1804
-    function activ_delivery_method($id)
1805
-    {
1806
-        $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1807
-        $sql.= ' WHERE rowid='.$id;
1808
-
1809
-        $resql = $this->db->query($sql);
1810
-
1811
-    }
1812
-
1813
-    /**
1814
-     *  DesActivate delivery method.
1815
-     *
1816
-     *  @param      id      $id     id method to desactivate
1817
-     *
1818
-     *  @return void
1819
-     */
1820
-    function disable_delivery_method($id)
1821
-    {
1822
-        $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1823
-        $sql.= ' WHERE rowid='.$id;
1824
-
1825
-        $resql = $this->db->query($sql);
1826
-
1827
-    }
1735
+	/**
1736
+	 *  Fetch all deliveries method and return an array. Load array this->listmeths.
1737
+	 *
1738
+	 *  @param  id      $id     only this carrier, all if none
1739
+	 *  @return void
1740
+	 */
1741
+	function list_delivery_methods($id='')
1742
+	{
1743
+		global $langs;
1744
+
1745
+		$this->listmeths = array();
1746
+		$i=0;
1747
+
1748
+		$sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1749
+		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1750
+		if ($id!='') $sql.= " WHERE em.rowid=".$id;
1751
+
1752
+		$resql = $this->db->query($sql);
1753
+		if ($resql)
1754
+		{
1755
+			while ($obj = $this->db->fetch_object($resql))
1756
+			{
1757
+				$this->listmeths[$i]['rowid'] = $obj->rowid;
1758
+				$this->listmeths[$i]['code'] = $obj->code;
1759
+				$label=$langs->trans('SendingMethod'.$obj->code);
1760
+				$this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1761
+				$this->listmeths[$i]['description'] = $obj->description;
1762
+				$this->listmeths[$i]['tracking'] = $obj->tracking;
1763
+				$this->listmeths[$i]['active'] = $obj->active;
1764
+				$i++;
1765
+			}
1766
+		}
1767
+	}
1768
+
1769
+	/**
1770
+	 *  Update/create delivery method.
1771
+	 *
1772
+	 *  @param	string      $id     id method to activate
1773
+	 *
1774
+	 *  @return void
1775
+	 */
1776
+	function update_delivery_method($id='')
1777
+	{
1778
+		if ($id=='')
1779
+		{
1780
+			$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1781
+			$sql.=" VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1782
+			$resql = $this->db->query($sql);
1783
+		}
1784
+		else
1785
+		{
1786
+			$sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1787
+			$sql.= " code='".$this->db->escape($this->update['code'])."'";
1788
+			$sql.= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1789
+			$sql.= ",description='".$this->db->escape($this->update['description'])."'";
1790
+			$sql.= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1791
+			$sql.= " WHERE rowid=".$id;
1792
+			$resql = $this->db->query($sql);
1793
+		}
1794
+		if ($resql < 0) dol_print_error($this->db,'');
1795
+	}
1796
+
1797
+	/**
1798
+	 *  Activate delivery method.
1799
+	 *
1800
+	 *  @param      id      $id     id method to activate
1801
+	 *
1802
+	 *  @return void
1803
+	 */
1804
+	function activ_delivery_method($id)
1805
+	{
1806
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1807
+		$sql.= ' WHERE rowid='.$id;
1808
+
1809
+		$resql = $this->db->query($sql);
1810
+
1811
+	}
1812
+
1813
+	/**
1814
+	 *  DesActivate delivery method.
1815
+	 *
1816
+	 *  @param      id      $id     id method to desactivate
1817
+	 *
1818
+	 *  @return void
1819
+	 */
1820
+	function disable_delivery_method($id)
1821
+	{
1822
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1823
+		$sql.= ' WHERE rowid='.$id;
1824
+
1825
+		$resql = $this->db->query($sql);
1826
+
1827
+	}
1828 1828
 
1829 1829
 
1830 1830
 	/**
@@ -1959,8 +1959,8 @@  discard block
 block discarded – undo
1959 1959
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
1960 1960
 							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref));
1961 1961
 							if ($result < 0) {
1962
-							    $this->error = $mouvS->error;
1963
-							    $this->errors = $mouvS->errors;
1962
+								$this->error = $mouvS->error;
1963
+								$this->errors = $mouvS->errors;
1964 1964
 								$error++; break;
1965 1965
 							}
1966 1966
 						}
@@ -1971,9 +1971,9 @@  discard block
 block discarded – undo
1971 1971
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
1972 1972
 							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1973 1973
 							if ($result < 0) {
1974
-							    $this->error = $mouvS->error;
1975
-							    $this->errors = $mouvS->errors;
1976
-							    $error++; break;
1974
+								$this->error = $mouvS->error;
1975
+								$this->errors = $mouvS->errors;
1976
+								$error++; break;
1977 1977
 							}
1978 1978
 						}
1979 1979
 					}
@@ -1988,27 +1988,27 @@  discard block
 block discarded – undo
1988 1988
 			// Call trigger
1989 1989
 			if (! $error)
1990 1990
 			{
1991
-    			$result=$this->call_trigger('SHIPPING_CLOSED',$user);
1992
-    			if ($result < 0) {
1993
-    			    $error++;
1994
-    			}
1991
+				$result=$this->call_trigger('SHIPPING_CLOSED',$user);
1992
+				if ($result < 0) {
1993
+					$error++;
1994
+				}
1995 1995
 			}
1996 1996
 		}
1997 1997
 		else
1998 1998
 		{
1999 1999
 			dol_print_error($this->db);
2000
-            $error++;
2000
+			$error++;
2001 2001
 		}
2002 2002
 
2003 2003
 		if (! $error)
2004 2004
 		{
2005
-		    $this->db->commit();
2006
-		    return 1;
2005
+			$this->db->commit();
2006
+			return 1;
2007 2007
 		}
2008 2008
 		else
2009 2009
 		{
2010
-		    $this->db->rollback();
2011
-		    return -1;
2010
+			$this->db->rollback();
2011
+			return -1;
2012 2012
 		}
2013 2013
 	}
2014 2014
 
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
 	 */
2020 2020
 	function set_billed()
2021 2021
 	{
2022
-	    global $user;
2022
+		global $user;
2023 2023
 		$error=0;
2024 2024
 
2025 2025
 		$this->db->begin();
@@ -2125,8 +2125,8 @@  discard block
 block discarded – undo
2125 2125
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2126 2126
 							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref));
2127 2127
 							if ($result < 0) {
2128
-							    $this->error = $mouvS->error;
2129
-							    $this->errors = $mouvS->errors;
2128
+								$this->error = $mouvS->error;
2129
+								$this->errors = $mouvS->errors;
2130 2130
 								$error++; break;
2131 2131
 							}
2132 2132
 						}
@@ -2137,9 +2137,9 @@  discard block
 block discarded – undo
2137 2137
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2138 2138
 							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2139 2139
 							if ($result < 0) {
2140
-							    $this->error = $mouvS->error;
2141
-							    $this->errors = $mouvS->errors;
2142
-							    $error++; break;
2140
+								$this->error = $mouvS->error;
2141
+								$this->errors = $mouvS->errors;
2142
+								$error++; break;
2143 2143
 							}
2144 2144
 						}
2145 2145
 					}
@@ -2153,11 +2153,11 @@  discard block
 block discarded – undo
2153 2153
 
2154 2154
 			if (! $error)
2155 2155
 			{
2156
-    			// Call trigger
2157
-    			$result=$this->call_trigger('SHIPPING_REOPEN',$user);
2158
-    			if ($result < 0) {
2159
-    				$error++;
2160
-    			}
2156
+				// Call trigger
2157
+				$result=$this->call_trigger('SHIPPING_REOPEN',$user);
2158
+				if ($result < 0) {
2159
+					$error++;
2160
+				}
2161 2161
    			}
2162 2162
 
2163 2163
 		} else {
@@ -2280,11 +2280,11 @@  discard block
 block discarded – undo
2280 2280
 	 */
2281 2281
 	var $libelle;
2282 2282
 
2283
-    /**
2284
-     *	Constructor
2285
-     *
2286
-     *  @param		DoliDB		$db      Database handler
2287
-     */
2283
+	/**
2284
+	 *	Constructor
2285
+	 *
2286
+	 *  @param		DoliDB		$db      Database handler
2287
+	 */
2288 2288
 	function __construct($db)
2289 2289
 	{
2290 2290
 		$this->db=$db;
Please login to merge, or discard this patch.
Spacing   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
36
-if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
37
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38
-if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
36
+if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
37
+if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38
+if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
39 39
 
40 40
 
41 41
 /**
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class Expedition extends CommonObject
45 45
 {
46
-	public $element="shipping";
47
-	public $fk_element="fk_expedition";
48
-	public $table_element="expedition";
49
-	public $table_element_line="expeditiondet";
50
-	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
46
+	public $element = "shipping";
47
+	public $fk_element = "fk_expedition";
48
+	public $table_element = "expedition";
49
+	public $table_element_line = "expeditiondet";
50
+	protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
51 51
     public $picto = 'sending';
52 52
 
53 53
 	var $socid;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	var $ref_int;
56 56
 	var $brouillon;
57 57
 	var $entrepot_id;
58
-	var $lines=array();
58
+	var $lines = array();
59 59
 	var $tracking_number;
60 60
 	var $tracking_url;
61 61
 	var $billed;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	// A denormalized value
73 73
 	var $trueSize;
74 74
 
75
-	var $date_delivery;		// Date delivery planed
75
+	var $date_delivery; // Date delivery planed
76 76
 	/**
77 77
 	 * @deprecated
78 78
 	 * @see date_shipping
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	var $date_valid;
93 93
 
94 94
 	var $meths;
95
-	var $listmeths;			// List of carriers
95
+	var $listmeths; // List of carriers
96 96
 
97 97
 
98 98
 	const STATUS_DRAFT = 0;
@@ -146,26 +146,26 @@  discard block
 block discarded – undo
146 146
 		        $dir = dol_buildpath($reldir."core/modules/expedition/");
147 147
 
148 148
 		        // Load file with numbering class (if found)
149
-		        $mybool|=@include_once $dir.$file;
149
+		        $mybool |= @include_once $dir.$file;
150 150
 	        }
151 151
 
152
-	        if (! $mybool)
152
+	        if (!$mybool)
153 153
 	        {
154
-		        dol_print_error('',"Failed to include file ".$file);
154
+		        dol_print_error('', "Failed to include file ".$file);
155 155
 		        return '';
156 156
 	        }
157 157
 
158 158
 			$obj = new $classname();
159 159
 			$numref = "";
160
-			$numref = $obj->getNextValue($soc,$this);
160
+			$numref = $obj->getNextValue($soc, $this);
161 161
 
162
-			if ( $numref != "")
162
+			if ($numref != "")
163 163
 			{
164 164
 				return $numref;
165 165
 			}
166 166
 			else
167 167
 			{
168
-				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
168
+				dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error);
169 169
 				return "";
170 170
 			}
171 171
         }
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
    * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
184 184
 	 *  @return int 				<0 si erreur, id expedition creee si ok
185 185
 	 */
186
-	function create($user, $notrigger=0)
186
+	function create($user, $notrigger = 0)
187 187
 	{
188 188
 		global $conf, $hookmanager;
189 189
 
190
-		$now=dol_now();
190
+		$now = dol_now();
191 191
 
192
-		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
192
+		require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
193 193
 		$error = 0;
194 194
 
195 195
 		// Clean parameters
@@ -203,90 +203,90 @@  discard block
 block discarded – undo
203 203
 		$this->db->begin();
204 204
 
205 205
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (";
206
-		$sql.= "ref";
207
-		$sql.= ", entity";
208
-		$sql.= ", ref_customer";
209
-		$sql.= ", ref_int";
210
-		$sql.= ", date_creation";
211
-		$sql.= ", fk_user_author";
212
-		$sql.= ", date_expedition";
213
-		$sql.= ", date_delivery";
214
-		$sql.= ", fk_soc";
215
-		$sql.= ", fk_projet";
216
-		$sql.= ", fk_address";
217
-		$sql.= ", fk_shipping_method";
218
-		$sql.= ", tracking_number";
219
-		$sql.= ", weight";
220
-		$sql.= ", size";
221
-		$sql.= ", width";
222
-		$sql.= ", height";
223
-		$sql.= ", weight_units";
224
-		$sql.= ", size_units";
225
-		$sql.= ", note_private";
226
-		$sql.= ", note_public";
227
-		$sql.= ", model_pdf";
228
-		$sql.= ", fk_incoterms, location_incoterms";
229
-		$sql.= ") VALUES (";
230
-		$sql.= "'(PROV)'";
231
-		$sql.= ", ".$conf->entity;
232
-		$sql.= ", ".($this->ref_customer?"'".$this->db->escape($this->ref_customer)."'":"null");
233
-		$sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null");
234
-		$sql.= ", '".$this->db->idate($now)."'";
235
-		$sql.= ", ".$user->id;
236
-		$sql.= ", ".($this->date_expedition>0?"'".$this->db->idate($this->date_expedition)."'":"null");
237
-		$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
238
-		$sql.= ", ".$this->socid;
239
-		$sql.= ", ".$this->fk_project;
240
-		$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:"null");
241
-		$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
242
-		$sql.= ", '".$this->db->escape($this->tracking_number)."'";
243
-		$sql.= ", ".$this->weight;
244
-		$sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
245
-		$sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
246
-		$sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
247
-		$sql.= ", ".$this->weight_units;
248
-		$sql.= ", ".$this->size_units;
249
-		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
250
-		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
251
-		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
252
-        $sql.= ", ".(int) $this->fk_incoterms;
253
-        $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
254
-		$sql.= ")";
206
+		$sql .= "ref";
207
+		$sql .= ", entity";
208
+		$sql .= ", ref_customer";
209
+		$sql .= ", ref_int";
210
+		$sql .= ", date_creation";
211
+		$sql .= ", fk_user_author";
212
+		$sql .= ", date_expedition";
213
+		$sql .= ", date_delivery";
214
+		$sql .= ", fk_soc";
215
+		$sql .= ", fk_projet";
216
+		$sql .= ", fk_address";
217
+		$sql .= ", fk_shipping_method";
218
+		$sql .= ", tracking_number";
219
+		$sql .= ", weight";
220
+		$sql .= ", size";
221
+		$sql .= ", width";
222
+		$sql .= ", height";
223
+		$sql .= ", weight_units";
224
+		$sql .= ", size_units";
225
+		$sql .= ", note_private";
226
+		$sql .= ", note_public";
227
+		$sql .= ", model_pdf";
228
+		$sql .= ", fk_incoterms, location_incoterms";
229
+		$sql .= ") VALUES (";
230
+		$sql .= "'(PROV)'";
231
+		$sql .= ", ".$conf->entity;
232
+		$sql .= ", ".($this->ref_customer ? "'".$this->db->escape($this->ref_customer)."'" : "null");
233
+		$sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null");
234
+		$sql .= ", '".$this->db->idate($now)."'";
235
+		$sql .= ", ".$user->id;
236
+		$sql .= ", ".($this->date_expedition > 0 ? "'".$this->db->idate($this->date_expedition)."'" : "null");
237
+		$sql .= ", ".($this->date_delivery > 0 ? "'".$this->db->idate($this->date_delivery)."'" : "null");
238
+		$sql .= ", ".$this->socid;
239
+		$sql .= ", ".$this->fk_project;
240
+		$sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
241
+		$sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : "null");
242
+		$sql .= ", '".$this->db->escape($this->tracking_number)."'";
243
+		$sql .= ", ".$this->weight;
244
+		$sql .= ", ".$this->sizeS; // TODO Should use this->trueDepth
245
+		$sql .= ", ".$this->sizeW; // TODO Should use this->trueWidth
246
+		$sql .= ", ".$this->sizeH; // TODO Should use this->trueHeight
247
+		$sql .= ", ".$this->weight_units;
248
+		$sql .= ", ".$this->size_units;
249
+		$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
250
+		$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
251
+		$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
252
+        $sql .= ", ".(int) $this->fk_incoterms;
253
+        $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
254
+		$sql .= ")";
255 255
 
256 256
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
257
-		$resql=$this->db->query($sql);
257
+		$resql = $this->db->query($sql);
258 258
 		if ($resql)
259 259
 		{
260 260
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
261 261
 
262 262
 			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
263
-			$sql.= " SET ref = '(PROV".$this->id.")'";
264
-			$sql.= " WHERE rowid = ".$this->id;
263
+			$sql .= " SET ref = '(PROV".$this->id.")'";
264
+			$sql .= " WHERE rowid = ".$this->id;
265 265
 
266 266
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
267 267
 			if ($this->db->query($sql))
268 268
 			{
269 269
 				// Insertion des lignes
270
-				$num=count($this->lines);
270
+				$num = count($this->lines);
271 271
 				for ($i = 0; $i < $num; $i++)
272 272
 				{
273
-					if (! isset($this->lines[$i]->detail_batch))
273
+					if (!isset($this->lines[$i]->detail_batch))
274 274
 					{	// no batch management
275
-						if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
275
+						if (!$this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
276 276
 						{
277 277
 							$error++;
278 278
 						}
279 279
 					}
280 280
 					else
281 281
 					{	// with batch management
282
-						if (! $this->create_line_batch($this->lines[$i],$this->lines[$i]->array_options) > 0)
282
+						if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0)
283 283
 						{
284 284
 							$error++;
285 285
 						}
286 286
 					}
287 287
 				}
288 288
 
289
-				if (! $error && $this->id && $this->origin_id)
289
+				if (!$error && $this->id && $this->origin_id)
290 290
 				{
291 291
 					$ret = $this->add_object_linked();
292 292
 					if (!$ret)
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
 				// Actions on extra fields (by external module or standard code)
299 299
 				// TODO le hook fait double emploi avec le trigger !!
300 300
 				$hookmanager->initHooks(array('expeditiondao'));
301
-				$parameters=array('socid'=>$this->id);
302
-				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
301
+				$parameters = array('socid'=>$this->id);
302
+				$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
303 303
 				if (empty($reshook))
304 304
 				{
305 305
 					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
306 306
 					{
307
-						$result=$this->insertExtraFields();
307
+						$result = $this->insertExtraFields();
308 308
 						if ($result < 0)
309 309
 						{
310 310
 							$error++;
@@ -313,34 +313,34 @@  discard block
 block discarded – undo
313 313
 				}
314 314
 				else if ($reshook < 0) $error++;
315 315
 
316
-				if (! $error && ! $notrigger)
316
+				if (!$error && !$notrigger)
317 317
 				{
318 318
                     // Call trigger
319
-                    $result=$this->call_trigger('SHIPPING_CREATE',$user);
319
+                    $result = $this->call_trigger('SHIPPING_CREATE', $user);
320 320
                     if ($result < 0) { $error++; }
321 321
                     // End call triggers
322 322
 
323
-					if (! $error)
323
+					if (!$error)
324 324
 					{
325 325
 						$this->db->commit();
326 326
 						return $this->id;
327 327
 					}
328 328
 					else
329 329
 					{
330
-						foreach($this->errors as $errmsg)
330
+						foreach ($this->errors as $errmsg)
331 331
 						{
332 332
 							dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
333
-							$this->error.=($this->error?', '.$errmsg:$errmsg);
333
+							$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
334 334
 						}
335 335
 						$this->db->rollback();
336
-						return -1*$error;
336
+						return -1 * $error;
337 337
 					}
338 338
 
339 339
 				}
340 340
 				else
341 341
 				{
342 342
 					$error++;
343
-					$this->error=$this->db->lasterror()." - sql=$sql";
343
+					$this->error = $this->db->lasterror()." - sql=$sql";
344 344
 					$this->db->rollback();
345 345
 					return -3;
346 346
 				}
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			else
349 349
 			{
350 350
 				$error++;
351
-				$this->error=$this->db->lasterror()." - sql=$sql";
351
+				$this->error = $this->db->lasterror()." - sql=$sql";
352 352
 				$this->db->rollback();
353 353
 				return -2;
354 354
 			}
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		else
357 357
 		{
358 358
 			$error++;
359
-			$this->error=$this->db->error()." - sql=$sql";
359
+			$this->error = $this->db->error()." - sql=$sql";
360 360
 			$this->db->rollback();
361 361
 			return -1;
362 362
 		}
@@ -371,23 +371,23 @@  discard block
 block discarded – undo
371 371
 	 * @param	array	$array_options		extrafields array
372 372
 	 * @return	int							<0 if KO, line_id if OK
373 373
 	 */
374
-	function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0)
374
+	function create_line($entrepot_id, $origin_line_id, $qty, $array_options = 0)
375 375
 	{
376 376
 		global $conf;
377 377
 		$error = 0;
378 378
 		$line_id = 0;
379 379
 
380 380
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (";
381
-		$sql.= "fk_expedition";
382
-		$sql.= ", fk_entrepot";
383
-		$sql.= ", fk_origin_line";
384
-		$sql.= ", qty";
385
-		$sql.= ") VALUES (";
386
-		$sql.= $this->id;
387
-		$sql.= ", ".($entrepot_id?$entrepot_id:'null');
388
-		$sql.= ", ".$origin_line_id;
389
-		$sql.= ", ".$qty;
390
-		$sql.= ")";
381
+		$sql .= "fk_expedition";
382
+		$sql .= ", fk_entrepot";
383
+		$sql .= ", fk_origin_line";
384
+		$sql .= ", qty";
385
+		$sql .= ") VALUES (";
386
+		$sql .= $this->id;
387
+		$sql .= ", ".($entrepot_id ? $entrepot_id : 'null');
388
+		$sql .= ", ".$origin_line_id;
389
+		$sql .= ", ".$qty;
390
+		$sql .= ")";
391 391
 
392 392
 		dol_syslog(get_class($this)."::create_line", LOG_DEBUG);
393 393
 		$resql = $this->db->query($sql);
@@ -400,20 +400,20 @@  discard block
 block discarded – undo
400 400
 			$error++;
401 401
 		}
402 402
 
403
-		if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
403
+		if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
404 404
 		{
405 405
 			$expeditionline = new ExpeditionLigne($this->db);
406
-			$expeditionline->array_options=$array_options;
407
-			$expeditionline->id= $this->db->last_insert_id(MAIN_DB_PREFIX.$expeditionline->table_element);
408
-			$result=$expeditionline->insertExtraFields();
406
+			$expeditionline->array_options = $array_options;
407
+			$expeditionline->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$expeditionline->table_element);
408
+			$result = $expeditionline->insertExtraFields();
409 409
 			if ($result < 0)
410 410
 			{
411
-				$this->error[]=$expeditionline->error;
411
+				$this->error[] = $expeditionline->error;
412 412
 				$error++;
413 413
 			}
414 414
 		}
415 415
 
416
-		if (! $error) return $line_id;
416
+		if (!$error) return $line_id;
417 417
 		else return -1;
418 418
 	}
419 419
 
@@ -425,12 +425,12 @@  discard block
 block discarded – undo
425 425
 	 * @param	array		$array_options		extrafields array
426 426
 	 * @return	int							<0 if KO, >0 if OK
427 427
 	 */
428
-	function create_line_batch($line_ext,$array_options=0)
428
+	function create_line_batch($line_ext, $array_options = 0)
429 429
 	{
430 430
 		$error = 0;
431 431
 		$stockLocationQty = array(); // associated array with batch qty in stock location
432 432
 
433
-		$tab=$line_ext->detail_batch;
433
+		$tab = $line_ext->detail_batch;
434 434
 		// create stockLocation Qty array
435 435
 		foreach ($tab as $detbatch)
436 436
 		{
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 		// create shipment lines
443 443
 		foreach ($stockLocationQty as $stockLocation => $qty)
444 444
 		{
445
-			if (($line_id = $this->create_line($stockLocation,$line_ext->origin_line_id,$qty,$array_options)) < 0)
445
+			if (($line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $array_options)) < 0)
446 446
 			{
447 447
 				$error++;
448 448
 			}
@@ -451,8 +451,8 @@  discard block
 block discarded – undo
451 451
 				// create shipment batch lines for stockLocation
452 452
 				foreach ($tab as $detbatch)
453 453
 				{
454
-					if ($detbatch->entrepot_id == $stockLocation){
455
-						if (! ($detbatch->create($line_id) >0))		// Create an expeditionlinebatch
454
+					if ($detbatch->entrepot_id == $stockLocation) {
455
+						if (!($detbatch->create($line_id) > 0))		// Create an expeditionlinebatch
456 456
 						{
457 457
 							$error++;
458 458
 						}
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 			}
462 462
 		}
463 463
 
464
-		if (! $error) return 1;
464
+		if (!$error) return 1;
465 465
 		else return -1;
466 466
 	}
467 467
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
      * 	@param	string	$ref_int	Internal reference of other object
475 475
 	 *	@return int			        >0 if OK, 0 if not found, <0 if KO
476 476
 	 */
477
-	function fetch($id, $ref='', $ref_ext='', $ref_int='')
477
+	function fetch($id, $ref = '', $ref_ext = '', $ref_int = '')
478 478
 	{
479 479
 		global $conf;
480 480
 
@@ -482,21 +482,21 @@  discard block
 block discarded – undo
482 482
 		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
483 483
 
484 484
 		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
485
-		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
486
-		$sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
487
-		$sql.= ", e.fk_shipping_method, e.tracking_number";
488
-		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
489
-		$sql.= ", e.note_private, e.note_public";
490
-        $sql.= ', e.fk_incoterms, e.location_incoterms';
491
-        $sql.= ', i.libelle as libelle_incoterms';
492
-		$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
493
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
494
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
495
-		$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
496
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
497
-        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
498
-        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
499
-        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
485
+		$sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
486
+		$sql .= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
487
+		$sql .= ", e.fk_shipping_method, e.tracking_number";
488
+		$sql .= ", el.fk_source as origin_id, el.sourcetype as origin";
489
+		$sql .= ", e.note_private, e.note_public";
490
+        $sql .= ', e.fk_incoterms, e.location_incoterms';
491
+        $sql .= ', i.libelle as libelle_incoterms';
492
+		$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
493
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
494
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
495
+		$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
496
+		if ($id)   	  $sql .= " AND e.rowid=".$id;
497
+        if ($ref)     $sql .= " AND e.ref='".$this->db->escape($ref)."'";
498
+        if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
499
+        if ($ref_int) $sql .= " AND e.ref_int='".$this->db->escape($ref_int)."'";
500 500
 
501 501
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
502 502
 		$result = $this->db->query($sql);
@@ -509,23 +509,23 @@  discard block
 block discarded – undo
509 509
 				$this->id                   = $obj->rowid;
510 510
 				$this->ref                  = $obj->ref;
511 511
 				$this->socid                = $obj->socid;
512
-				$this->ref_customer			= $obj->ref_customer;
512
+				$this->ref_customer = $obj->ref_customer;
513 513
 				$this->ref_ext				= $obj->ref_ext;
514 514
 				$this->ref_int				= $obj->ref_int;
515 515
 				$this->statut               = $obj->fk_statut;
516 516
 				$this->user_author_id       = $obj->fk_user_author;
517 517
 				$this->date_creation        = $this->db->jdate($obj->date_creation);
518
-				$this->date                 = $this->db->jdate($obj->date_expedition);	// TODO deprecated
519
-				$this->date_expedition      = $this->db->jdate($obj->date_expedition);	// TODO deprecated
520
-				$this->date_shipping        = $this->db->jdate($obj->date_expedition);	// Date real
521
-				$this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
518
+				$this->date                 = $this->db->jdate($obj->date_expedition); // TODO deprecated
519
+				$this->date_expedition      = $this->db->jdate($obj->date_expedition); // TODO deprecated
520
+				$this->date_shipping        = $this->db->jdate($obj->date_expedition); // Date real
521
+				$this->date_delivery        = $this->db->jdate($obj->date_delivery); // Date planed
522 522
 				$this->fk_delivery_address  = $obj->fk_address;
523 523
 				$this->modelpdf             = $obj->model_pdf;
524
-				$this->shipping_method_id	= $obj->fk_shipping_method;
524
+				$this->shipping_method_id = $obj->fk_shipping_method;
525 525
 				$this->tracking_number      = $obj->tracking_number;
526
-				$this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
526
+				$this->origin               = ($obj->origin ? $obj->origin : 'commande'); // For compatibility
527 527
 				$this->origin_id            = $obj->origin_id;
528
-				$this->billed				= ($obj->fk_statut==2?1:0);
528
+				$this->billed = ($obj->fk_statut == 2 ? 1 : 0);
529 529
 
530 530
 				$this->trueWeight           = $obj->weight;
531 531
 				$this->weight_units         = $obj->weight_units;
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 				$this->note_private         = $obj->note_private;
542 542
 
543 543
 				// A denormalized value
544
-				$this->trueSize           	= $obj->size."x".$obj->width."x".$obj->height;
545
-				$this->size_units           = $obj->size_units;
544
+				$this->trueSize = $obj->size."x".$obj->width."x".$obj->height;
545
+				$this->size_units = $obj->size_units;
546 546
 
547 547
 				//Incoterms
548 548
 				$this->fk_incoterms = $obj->fk_incoterms;
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
 				if ($this->statut == 0) $this->brouillon = 1;
555 555
 
556
-				$file = $conf->expedition->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'shipment') . "/" . $this->id.".pdf";
556
+				$file = $conf->expedition->dir_output."/".get_exdir($this->id, 2, 0, 0, $this, 'shipment')."/".$this->id.".pdf";
557 557
 				$this->pdf_filename = $file;
558 558
 
559 559
 				// Tracking url
@@ -562,19 +562,19 @@  discard block
 block discarded – undo
562 562
 				/*
563 563
 				 * Thirparty
564 564
 				 */
565
-				$result=$this->fetch_thirdparty();
565
+				$result = $this->fetch_thirdparty();
566 566
 
567 567
 				// Retrieve all extrafields for expedition
568 568
 				// fetch optionals attributes and labels
569 569
 				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
570
-				$extrafields=new ExtraFields($this->db);
571
-				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
572
-				$this->fetch_optionals($this->id,$extralabels);
570
+				$extrafields = new ExtraFields($this->db);
571
+				$extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
572
+				$this->fetch_optionals($this->id, $extralabels);
573 573
 
574 574
 				/*
575 575
 				 * Lines
576 576
 				 */
577
-				$result=$this->fetch_lines();
577
+				$result = $this->fetch_lines();
578 578
 				if ($result < 0)
579 579
 				{
580 580
 					return -3;
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
 			else
586 586
 			{
587 587
 				dol_syslog(get_class($this).'::Fetch no expedition found', LOG_ERR);
588
-				$this->error='Delivery with id '.$id.' not found';
588
+				$this->error = 'Delivery with id '.$id.' not found';
589 589
 				return 0;
590 590
 			}
591 591
 		}
592 592
 		else
593 593
 		{
594
-			$this->error=$this->db->error();
594
+			$this->error = $this->db->error();
595 595
 			return -1;
596 596
 		}
597 597
 	}
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      *  @param		int			$notrigger	1=Does not execute triggers, 0= execute triggers
604 604
 	 *  @return     int						<0 if OK, >0 if KO
605 605
 	 */
606
-	function valid($user, $notrigger=0)
606
+	function valid($user, $notrigger = 0)
607 607
 	{
608 608
 		global $conf, $langs;
609 609
 
@@ -618,10 +618,10 @@  discard block
 block discarded – undo
618 618
 			return 0;
619 619
 		}
620 620
 
621
-        if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
622
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))))
621
+        if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))
622
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))))
623 623
 		{
624
-			$this->error='Permission denied';
624
+			$this->error = 'Permission denied';
625 625
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
626 626
 			return -1;
627 627
 		}
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
 		$soc->fetch($this->socid);
636 636
 
637 637
 		// Class of company linked to order
638
-		$result=$soc->set_as_client();
638
+		$result = $soc->set_as_client();
639 639
 
640 640
 		// Define new ref
641
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
641
+		if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
642 642
 		{
643 643
 			$numref = $this->getNextNumRef($soc);
644 644
 		}
@@ -648,26 +648,26 @@  discard block
 block discarded – undo
648 648
 		}
649 649
         $this->newref = $numref;
650 650
 
651
-		$now=dol_now();
651
+		$now = dol_now();
652 652
 
653 653
 		// Validate
654 654
 		$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
655
-		$sql.= " ref='".$numref."'";
656
-		$sql.= ", fk_statut = 1";
657
-		$sql.= ", date_valid = '".$this->db->idate($now)."'";
658
-		$sql.= ", fk_user_valid = ".$user->id;
659
-		$sql.= " WHERE rowid = ".$this->id;
655
+		$sql .= " ref='".$numref."'";
656
+		$sql .= ", fk_statut = 1";
657
+		$sql .= ", date_valid = '".$this->db->idate($now)."'";
658
+		$sql .= ", fk_user_valid = ".$user->id;
659
+		$sql .= " WHERE rowid = ".$this->id;
660 660
 
661 661
 		dol_syslog(get_class($this)."::valid update expedition", LOG_DEBUG);
662
-		$resql=$this->db->query($sql);
663
-		if (! $resql)
662
+		$resql = $this->db->query($sql);
663
+		if (!$resql)
664 664
 		{
665
-			$this->error=$this->db->lasterror();
665
+			$this->error = $this->db->lasterror();
666 666
 			$error++;
667 667
 		}
668 668
 
669 669
 		// If stock increment is done on sending (recommanded choice)
670
-		if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
670
+		if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
671 671
 		{
672 672
 			require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
673 673
 
@@ -676,16 +676,16 @@  discard block
 block discarded – undo
676 676
 			// Loop on each product line to add a stock movement
677 677
 			// TODO in future, shipment lines may not be linked to order line
678 678
 			$sql = "SELECT cd.fk_product, cd.subprice,";
679
-			$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
680
-			$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
681
-			$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
682
-			$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
683
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
684
-			$sql.= " WHERE ed.fk_expedition = ".$this->id;
685
-			$sql.= " AND cd.rowid = ed.fk_origin_line";
679
+			$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
680
+			$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
681
+			$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
682
+			$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
683
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
684
+			$sql .= " WHERE ed.fk_expedition = ".$this->id;
685
+			$sql .= " AND cd.rowid = ed.fk_origin_line";
686 686
 
687 687
 			dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
688
-			$resql=$this->db->query($sql);
688
+			$resql = $this->db->query($sql);
689 689
 			if ($resql)
690 690
 			{
691 691
 				$cpt = $this->db->num_rows($resql);
@@ -712,10 +712,10 @@  discard block
 block discarded – undo
712 712
 						// line without batch detail
713 713
 
714 714
 						// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
715
-						$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref));
715
+						$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref));
716 716
 						if ($result < 0) {
717 717
 							$error++;
718
-							$this->errors[]=$mouvS->error;
718
+							$this->errors[] = $mouvS->error;
719 719
 							$this->errors = array_merge($this->errors, $mouvS->errors);
720 720
 							break;
721 721
 						}
@@ -726,10 +726,10 @@  discard block
 block discarded – undo
726 726
 
727 727
 						// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
728 728
 					    // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
729
-						$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
729
+						$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
730 730
 						if ($result < 0) {
731 731
 							$error++;
732
-							$this->errors[]=$mouvS->error;
732
+							$this->errors[] = $mouvS->error;
733 733
 							$this->errors = array_merge($this->errors, $mouvS->errors);
734 734
 							break;
735 735
 						}
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 			else
740 740
 			{
741 741
 				$this->db->rollback();
742
-				$this->error=$this->db->error();
742
+				$this->error = $this->db->error();
743 743
 				return -2;
744 744
 			}
745 745
 
@@ -748,20 +748,20 @@  discard block
 block discarded – undo
748 748
 		// Change status of order to "shipment in process"
749 749
 		$ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin);
750 750
 
751
-        if (! $ret)
751
+        if (!$ret)
752 752
 		{
753 753
 		    $error++;
754 754
 		}
755 755
 
756
-		if (! $error && ! $notrigger)
756
+		if (!$error && !$notrigger)
757 757
 		{
758 758
             // Call trigger
759
-            $result=$this->call_trigger('SHIPPING_VALIDATE',$user);
759
+            $result = $this->call_trigger('SHIPPING_VALIDATE', $user);
760 760
             if ($result < 0) { $error++; }
761 761
             // End call triggers
762 762
 		}
763 763
 
764
-		if (! $error)
764
+		if (!$error)
765 765
 		{
766 766
             $this->oldref = $this->ref;
767 767
 
@@ -782,13 +782,13 @@  discard block
 block discarded – undo
782 782
 					{
783 783
 					    dol_syslog("Rename ok");
784 784
                         // Rename docs starting with $oldref with $newref
785
-                        $listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
786
-                        foreach($listoffiles as $fileentry)
785
+                        $listoffiles = dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
786
+                        foreach ($listoffiles as $fileentry)
787 787
                         {
788
-                        	$dirsource=$fileentry['name'];
789
-                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
790
-                        	$dirsource=$fileentry['path'].'/'.$dirsource;
791
-                        	$dirdest=$fileentry['path'].'/'.$dirdest;
788
+                        	$dirsource = $fileentry['name'];
789
+                        	$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
790
+                        	$dirsource = $fileentry['path'].'/'.$dirsource;
791
+                        	$dirdest = $fileentry['path'].'/'.$dirdest;
792 792
                         	@rename($dirsource, $dirdest);
793 793
                         }
794 794
 					}
@@ -797,26 +797,26 @@  discard block
 block discarded – undo
797 797
 		}
798 798
 
799 799
 		// Set new ref and current status
800
-		if (! $error)
800
+		if (!$error)
801 801
 		{
802 802
 			$this->ref = $numref;
803 803
 			$this->statut = 1;
804 804
 		}
805 805
 
806
-		if (! $error)
806
+		if (!$error)
807 807
 		{
808 808
 			$this->db->commit();
809 809
 			return 1;
810 810
 		}
811 811
 		else
812 812
 		{
813
-			foreach($this->errors as $errmsg)
813
+			foreach ($this->errors as $errmsg)
814 814
 			{
815 815
 	            dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
816
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
816
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
817 817
 			}
818 818
 			$this->db->rollback();
819
-			return -1*$error;
819
+			return -1 * $error;
820 820
 		}
821 821
 	}
822 822
 
@@ -838,14 +838,14 @@  discard block
 block discarded – undo
838 838
 				// Expedition validee
839 839
 				include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
840 840
 				$delivery = new Livraison($this->db);
841
-				$result=$delivery->create_from_sending($user, $this->id);
841
+				$result = $delivery->create_from_sending($user, $this->id);
842 842
 				if ($result > 0)
843 843
 				{
844 844
 					return $result;
845 845
 				}
846 846
 				else
847 847
 				{
848
-					$this->error=$delivery->error;
848
+					$this->error = $delivery->error;
849 849
 					return $result;
850 850
 				}
851 851
 			}
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 	 * @param	array	$array_options		extrafields array
866 866
 	 * @return	int							<0 if KO, >0 if OK
867 867
 	 */
868
-	function addline($entrepot_id, $id, $qty,$array_options=0)
868
+	function addline($entrepot_id, $id, $qty, $array_options = 0)
869 869
 	{
870 870
 		global $conf, $langs;
871 871
 
@@ -879,22 +879,22 @@  discard block
 block discarded – undo
879 879
 		$orderline = new OrderLine($this->db);
880 880
 		$orderline->fetch($id);
881 881
 
882
-		if (! empty($conf->stock->enabled) && ! empty($orderline->fk_product))
882
+		if (!empty($conf->stock->enabled) && !empty($orderline->fk_product))
883 883
 		{
884 884
 			$fk_product = $orderline->fk_product;
885 885
 
886
-			if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
886
+			if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
887 887
 			{
888 888
 			    $langs->load("errors");
889
-				$this->error=$langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
889
+				$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
890 890
 				return -1;
891 891
 			}
892 892
 
893 893
 			if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
894 894
 			{
895 895
 			    // Check must be done for stock of product into warehouse if $entrepot_id defined
896
-				$product=new Product($this->db);
897
-				$result=$product->fetch($fk_product);
896
+				$product = new Product($this->db);
897
+				$result = $product->fetch($fk_product);
898 898
 
899 899
 				if ($entrepot_id > 0) {
900 900
 					$product->load_stock('warehouseopen');
@@ -903,11 +903,11 @@  discard block
 block discarded – undo
903 903
 				else
904 904
 					$product_stock = $product->stock_reel;
905 905
 
906
-				$product_type=$product->type;
906
+				$product_type = $product->type;
907 907
 				if ($product_type == 0 && $product_stock < $qty)
908 908
 				{
909 909
                     $langs->load("errors");
910
-				    $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
910
+				    $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
911 911
 					$this->db->rollback();
912 912
 					return -3;
913 913
 				}
@@ -915,14 +915,14 @@  discard block
 block discarded – undo
915 915
 		}
916 916
 
917 917
 		// If product need a batch number, we should not have called this function but addline_batch instead.
918
-		if (! empty($conf->productbatch->enabled) && ! empty($orderline->fk_product) && ! empty($orderline->product_tobatch))
918
+		if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch))
919 919
 		{
920
-		    $this->error='ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
920
+		    $this->error = 'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
921 921
 		    return -4;
922 922
 		}
923 923
 
924 924
 		// extrafields
925
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
925
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
926 926
 			$line->array_options = $array_options;
927 927
 
928 928
 		$this->lines[$num] = $line;
@@ -935,32 +935,32 @@  discard block
 block discarded – undo
935 935
 	 * @param	array		$array_options		extrafields array
936 936
 	 * @return	int						<0 if KO, >0 if OK
937 937
 	 */
938
-	function addline_batch($dbatch,$array_options=0)
938
+	function addline_batch($dbatch, $array_options = 0)
939 939
 	{
940
-		global $conf,$langs;
940
+		global $conf, $langs;
941 941
 
942 942
 		$num = count($this->lines);
943
-		if ($dbatch['qty']>0)
943
+		if ($dbatch['qty'] > 0)
944 944
 		{
945 945
 			$line = new ExpeditionLigne($this->db);
946
-			$tab=array();
946
+			$tab = array();
947 947
 			foreach ($dbatch['detail'] as $key=>$value)
948 948
 			{
949
-				if ($value['q']>0)
949
+				if ($value['q'] > 0)
950 950
 				{
951 951
 					// $value['q']=qty to move
952 952
 					// $value['id_batch']=id into llx_product_batch of record to move
953 953
 					//var_dump($value);
954 954
 
955 955
 				    $linebatch = new ExpeditionLineBatch($this->db);
956
-					$ret=$linebatch->fetchFromStock($value['id_batch']);	// load serial, sellby, eatby
957
-					if ($ret<0)
956
+					$ret = $linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby
957
+					if ($ret < 0)
958 958
 					{
959
-						$this->error=$linebatch->error;
959
+						$this->error = $linebatch->error;
960 960
 						return -1;
961 961
 					}
962
-					$linebatch->dluo_qty=$value['q'];
963
-					$tab[]=$linebatch;
962
+					$linebatch->dluo_qty = $value['q'];
963
+					$tab[] = $linebatch;
964 964
 
965 965
 					if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
966 966
 					{
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
 						if ($prod_batch->qty < $linebatch->dluo_qty)
972 972
 						{
973 973
                             $langs->load("errors");
974
-        				    $this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
974
+        				    $this->errors[] = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
975 975
 							dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR);
976 976
 							$this->db->rollback();
977 977
 							return -1;
@@ -984,10 +984,10 @@  discard block
 block discarded – undo
984 984
 			$line->entrepot_id = $linebatch->entrepot_id;
985 985
 			$line->origin_line_id = $dbatch['ix_l'];
986 986
 			$line->qty = $dbatch['qty'];
987
-			$line->detail_batch=$tab;
987
+			$line->detail_batch = $tab;
988 988
 
989 989
 			// extrafields
990
-			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
990
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
991 991
 				$line->array_options = $array_options;
992 992
 
993 993
 			//var_dump($line);
@@ -1003,32 +1003,32 @@  discard block
 block discarded – undo
1003 1003
      *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
1004 1004
      *  @return int 			       	<0 if KO, >0 if OK
1005 1005
      */
1006
-    function update($user=null, $notrigger=0)
1006
+    function update($user = null, $notrigger = 0)
1007 1007
     {
1008 1008
     	global $conf;
1009
-		$error=0;
1009
+		$error = 0;
1010 1010
 
1011 1011
 		// Clean parameters
1012 1012
 
1013
-		if (isset($this->ref)) $this->ref=trim($this->ref);
1014
-		if (isset($this->entity)) $this->entity=trim($this->entity);
1015
-		if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
1016
-		if (isset($this->socid)) $this->socid=trim($this->socid);
1017
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
1018
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
1019
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
1020
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
1021
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
1022
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
1023
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
1024
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
1025
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
1026
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
1027
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
1028
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
1029
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
1030
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
1031
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
1013
+		if (isset($this->ref)) $this->ref = trim($this->ref);
1014
+		if (isset($this->entity)) $this->entity = trim($this->entity);
1015
+		if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer);
1016
+		if (isset($this->socid)) $this->socid = trim($this->socid);
1017
+		if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author);
1018
+		if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid);
1019
+		if (isset($this->fk_delivery_address)) $this->fk_delivery_address = trim($this->fk_delivery_address);
1020
+		if (isset($this->shipping_method_id)) $this->shipping_method_id = trim($this->shipping_method_id);
1021
+		if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number);
1022
+		if (isset($this->statut)) $this->statut = (int) $this->statut;
1023
+		if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth);
1024
+		if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth);
1025
+		if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight);
1026
+		if (isset($this->size_units)) $this->size_units = trim($this->size_units);
1027
+		if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units);
1028
+		if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight);
1029
+		if (isset($this->note_private)) $this->note = trim($this->note_private);
1030
+		if (isset($this->note_public)) $this->note = trim($this->note_public);
1031
+		if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf);
1032 1032
 
1033 1033
 
1034 1034
 
@@ -1038,45 +1038,45 @@  discard block
 block discarded – undo
1038 1038
         // Update request
1039 1039
         $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
1040 1040
 
1041
-		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
1042
-		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
1043
-		$sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").",";
1044
-		$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
1045
-		$sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
1046
-		$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
1047
-		$sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
1048
-		$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
1049
-		$sql.= " date_expedition=".(dol_strlen($this->date_expedition)!=0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
1050
-		$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
1051
-		$sql.= " fk_address=".(isset($this->fk_delivery_address)?$this->fk_delivery_address:"null").",";
1052
-		$sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
1053
-		$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
1054
-		$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
1055
-		$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
1056
-		$sql.= " width=".(($this->trueWidth != '')?$this->trueWidth:"null").",";
1057
-		$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
1058
-		$sql.= " size=".(($this->trueDepth != '')?$this->trueDepth:"null").",";
1059
-		$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
1060
-		$sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").",";
1061
-		$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
1062
-		$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
1063
-		$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
1064
-		$sql.= " entity=".$conf->entity;
1065
-
1066
-        $sql.= " WHERE rowid=".$this->id;
1041
+		$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
1042
+		$sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").",";
1043
+		$sql .= " ref_customer=".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").",";
1044
+		$sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").",";
1045
+		$sql .= " date_creation=".(dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
1046
+		$sql .= " fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author : "null").",";
1047
+		$sql .= " date_valid=".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
1048
+		$sql .= " fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid : "null").",";
1049
+		$sql .= " date_expedition=".(dol_strlen($this->date_expedition) != 0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
1050
+		$sql .= " date_delivery=".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
1051
+		$sql .= " fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address : "null").",";
1052
+		$sql .= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id : "null").",";
1053
+		$sql .= " tracking_number=".(isset($this->tracking_number) ? "'".$this->db->escape($this->tracking_number)."'" : "null").",";
1054
+		$sql .= " fk_statut=".(isset($this->statut) ? $this->statut : "null").",";
1055
+		$sql .= " height=".(($this->trueHeight != '') ? $this->trueHeight : "null").",";
1056
+		$sql .= " width=".(($this->trueWidth != '') ? $this->trueWidth : "null").",";
1057
+		$sql .= " size_units=".(isset($this->size_units) ? $this->size_units : "null").",";
1058
+		$sql .= " size=".(($this->trueDepth != '') ? $this->trueDepth : "null").",";
1059
+		$sql .= " weight_units=".(isset($this->weight_units) ? $this->weight_units : "null").",";
1060
+		$sql .= " weight=".(($this->trueWeight != '') ? $this->trueWeight : "null").",";
1061
+		$sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
1062
+		$sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
1063
+		$sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").",";
1064
+		$sql .= " entity=".$conf->entity;
1065
+
1066
+        $sql .= " WHERE rowid=".$this->id;
1067 1067
 
1068 1068
 		$this->db->begin();
1069 1069
 
1070 1070
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
1071 1071
         $resql = $this->db->query($sql);
1072
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
1072
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
1073 1073
 
1074
-		if (! $error)
1074
+		if (!$error)
1075 1075
 		{
1076
-			if (! $notrigger)
1076
+			if (!$notrigger)
1077 1077
 			{
1078 1078
                 // Call trigger
1079
-                $result=$this->call_trigger('SHIPPING_MODIFY',$user);
1079
+                $result = $this->call_trigger('SHIPPING_MODIFY', $user);
1080 1080
                 if ($result < 0) { $error++; }
1081 1081
                 // End call triggers
1082 1082
 	    	}
@@ -1085,13 +1085,13 @@  discard block
 block discarded – undo
1085 1085
         // Commit or rollback
1086 1086
 		if ($error)
1087 1087
 		{
1088
-			foreach($this->errors as $errmsg)
1088
+			foreach ($this->errors as $errmsg)
1089 1089
 			{
1090 1090
 	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1091
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
1091
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1092 1092
 			}
1093 1093
 			$this->db->rollback();
1094
-			return -1*$error;
1094
+			return -1 * $error;
1095 1095
 		}
1096 1096
 		else
1097 1097
 		{
@@ -1114,14 +1114,14 @@  discard block
 block discarded – undo
1114 1114
 		{
1115 1115
 		require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1116 1116
 		}
1117
-		$error=0;
1118
-		$this->error='';
1117
+		$error = 0;
1118
+		$this->error = '';
1119 1119
 
1120 1120
 		// Add a protection to refuse deleting if shipment has at least one delivery
1121
-		$this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery');	// Get deliveries linked to this shipment
1121
+		$this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment
1122 1122
 		if (count($this->linkedObjectsIds) > 0)
1123 1123
 		{
1124
-			$this->error='ErrorThereIsSomeDeliveries';
1124
+			$this->error = 'ErrorThereIsSomeDeliveries';
1125 1125
 			return -1;
1126 1126
 		}
1127 1127
 
@@ -1135,13 +1135,13 @@  discard block
 block discarded – undo
1135 1135
 
1136 1136
 			// Loop on each product line to add a stock movement
1137 1137
 			$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1138
-			$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1139
-			$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1140
-			$sql.= " WHERE ed.fk_expedition = ".$this->id;
1141
-			$sql.= " AND cd.rowid = ed.fk_origin_line";
1138
+			$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1139
+			$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1140
+			$sql .= " WHERE ed.fk_expedition = ".$this->id;
1141
+			$sql .= " AND cd.rowid = ed.fk_origin_line";
1142 1142
 
1143 1143
 			dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
1144
-			$resql=$this->db->query($sql);
1144
+			$resql = $this->db->query($sql);
1145 1145
 			if ($resql)
1146 1146
 			{
1147 1147
 				$cpt = $this->db->num_rows($resql);
@@ -1157,20 +1157,20 @@  discard block
 block discarded – undo
1157 1157
 					$lotArray = null;
1158 1158
 					if ($conf->productbatch->enabled)
1159 1159
 					{
1160
-						$lotArray = ExpeditionLineBatch::fetchAll($this->db,$obj->expeditiondet_id);
1161
-						if (! is_array($lotArray))
1160
+						$lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id);
1161
+						if (!is_array($lotArray))
1162 1162
 						{
1163
-							$error++;$this->errors[]="Error ".$this->db->lasterror();
1163
+							$error++; $this->errors[] = "Error ".$this->db->lasterror();
1164 1164
 						}
1165 1165
 					}
1166 1166
 					if (empty($lotArray)) {
1167 1167
 						// no lot/serial
1168 1168
 						// We increment stock of product (and sub-products)
1169 1169
 						// We use warehouse selected for each line
1170
-						$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref));  // Price is set to 0, because we don't want to see WAP changed
1170
+						$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref)); // Price is set to 0, because we don't want to see WAP changed
1171 1171
 						if ($result < 0)
1172 1172
 						{
1173
-							$error++;$this->errors=$this->errors + $mouvS->errors;
1173
+							$error++; $this->errors = $this->errors + $mouvS->errors;
1174 1174
 							break;
1175 1175
 						}
1176 1176
 					}
@@ -1178,12 +1178,12 @@  discard block
 block discarded – undo
1178 1178
 					{
1179 1179
 						// We increment stock of batches
1180 1180
 						// We use warehouse selected for each line
1181
-						foreach($lotArray as $lot)
1181
+						foreach ($lotArray as $lot)
1182 1182
 						{
1183
-							$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->dluo_qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);  // Price is set to 0, because we don't want to see WAP changed
1183
+							$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->dluo_qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed
1184 1184
 							if ($result < 0)
1185 1185
 							{
1186
-								$error++;$this->errors=$this->errors + $mouvS->errors;
1186
+								$error++; $this->errors = $this->errors + $mouvS->errors;
1187 1187
 								break;
1188 1188
 							}
1189 1189
 						}
@@ -1193,46 +1193,46 @@  discard block
 block discarded – undo
1193 1193
 			}
1194 1194
 			else
1195 1195
 			{
1196
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
1196
+				$error++; $this->errors[] = "Error ".$this->db->lasterror();
1197 1197
 			}
1198 1198
 		}
1199 1199
 
1200 1200
 		// delete batch expedition line
1201
-		if (! $error && $conf->productbatch->enabled)
1201
+		if (!$error && $conf->productbatch->enabled)
1202 1202
 		{
1203
-			if (ExpeditionLineBatch::deletefromexp($this->db,$this->id) < 0)
1203
+			if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0)
1204 1204
 			{
1205
-				$error++;$this->errors[]="Error ".$this->db->lasterror();
1205
+				$error++; $this->errors[] = "Error ".$this->db->lasterror();
1206 1206
 			}
1207 1207
 		}
1208 1208
 
1209
-		if (! $error)
1209
+		if (!$error)
1210 1210
 		{
1211 1211
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
1212
-			$sql.= " WHERE fk_expedition = ".$this->id;
1212
+			$sql .= " WHERE fk_expedition = ".$this->id;
1213 1213
 
1214
-			if ( $this->db->query($sql) )
1214
+			if ($this->db->query($sql))
1215 1215
 			{
1216 1216
 				// Delete linked object
1217 1217
 				$res = $this->deleteObjectLinked();
1218 1218
 				if ($res < 0) $error++;
1219 1219
 
1220
-				if (! $error)
1220
+				if (!$error)
1221 1221
 				{
1222 1222
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition";
1223
-					$sql.= " WHERE rowid = ".$this->id;
1223
+					$sql .= " WHERE rowid = ".$this->id;
1224 1224
 
1225 1225
 					if ($this->db->query($sql))
1226 1226
 					{
1227 1227
 						// Call trigger
1228
-						$result=$this->call_trigger('SHIPPING_DELETE',$user);
1228
+						$result = $this->call_trigger('SHIPPING_DELETE', $user);
1229 1229
 						if ($result < 0) { $error++; }
1230 1230
 						// End call triggers
1231 1231
 
1232
-						if (! empty($this->origin) && $this->origin_id > 0)
1232
+						if (!empty($this->origin) && $this->origin_id > 0)
1233 1233
 						{
1234 1234
 						    $this->fetch_origin();
1235
-						    $origin=$this->origin;
1235
+						    $origin = $this->origin;
1236 1236
 						    if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS)     // If order source of shipment is "shipment in progress"
1237 1237
 						    {
1238 1238
                                 // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress"
@@ -1245,19 +1245,19 @@  discard block
 block discarded – undo
1245 1245
 						    }
1246 1246
 						}
1247 1247
 
1248
-						if (! $error)
1248
+						if (!$error)
1249 1249
 						{
1250 1250
 							$this->db->commit();
1251 1251
 
1252 1252
 							// We delete PDFs
1253 1253
 							$ref = dol_sanitizeFileName($this->ref);
1254
-							if (! empty($conf->expedition->dir_output))
1254
+							if (!empty($conf->expedition->dir_output))
1255 1255
 							{
1256
-								$dir = $conf->expedition->dir_output . '/sending/' . $ref ;
1257
-								$file = $dir . '/' . $ref . '.pdf';
1256
+								$dir = $conf->expedition->dir_output.'/sending/'.$ref;
1257
+								$file = $dir.'/'.$ref.'.pdf';
1258 1258
 								if (file_exists($file))
1259 1259
 								{
1260
-									if (! dol_delete_file($file))
1260
+									if (!dol_delete_file($file))
1261 1261
 									{
1262 1262
 										return 0;
1263 1263
 									}
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
 								{
1267 1267
 									if (!dol_delete_dir_recursive($dir))
1268 1268
 									{
1269
-										$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
1269
+										$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
1270 1270
 										return 0;
1271 1271
 									}
1272 1272
 								}
@@ -1282,21 +1282,21 @@  discard block
 block discarded – undo
1282 1282
 					}
1283 1283
 					else
1284 1284
 					{
1285
-						$this->error=$this->db->lasterror()." - sql=$sql";
1285
+						$this->error = $this->db->lasterror()." - sql=$sql";
1286 1286
 						$this->db->rollback();
1287 1287
 						return -3;
1288 1288
 					}
1289 1289
 				}
1290 1290
 				else
1291 1291
 				{
1292
-					$this->error=$this->db->lasterror()." - sql=$sql";
1292
+					$this->error = $this->db->lasterror()." - sql=$sql";
1293 1293
 					$this->db->rollback();
1294 1294
 					return -2;
1295 1295
 				}
1296 1296
 			}
1297 1297
 			else
1298 1298
 			{
1299
-				$this->error=$this->db->lasterror()." - sql=$sql";
1299
+				$this->error = $this->db->lasterror()." - sql=$sql";
1300 1300
 				$this->db->rollback();
1301 1301
 				return -1;
1302 1302
 			}
@@ -1320,18 +1320,18 @@  discard block
 block discarded – undo
1320 1320
 		// TODO: recuperer les champs du document associe a part
1321 1321
 
1322 1322
 		$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type";
1323
-		$sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1324
-		$sql.= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
1325
-		$sql.= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc";
1326
-		$sql.= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1327
-		$sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1328
-		$sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
1329
-		$sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
1330
-		$sql.= " ".MAIN_DB_PREFIX."commandedet as cd)";
1331
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
1332
-		$sql.= " WHERE ed.fk_expedition = ".$this->id;
1333
-		$sql.= " AND ed.fk_origin_line = cd.rowid";
1334
-		$sql.= " ORDER BY cd.rang, ed.fk_origin_line";
1323
+		$sql .= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1324
+		$sql .= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
1325
+		$sql .= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc";
1326
+		$sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1327
+		$sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1328
+		$sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
1329
+		$sql .= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
1330
+		$sql .= " ".MAIN_DB_PREFIX."commandedet as cd)";
1331
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
1332
+		$sql .= " WHERE ed.fk_expedition = ".$this->id;
1333
+		$sql .= " AND ed.fk_origin_line = cd.rowid";
1334
+		$sql .= " ORDER BY cd.rang, ed.fk_origin_line";
1335 1335
 
1336 1336
 		dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1337 1337
 		$resql = $this->db->query($sql);
@@ -1355,8 +1355,8 @@  discard block
 block discarded – undo
1355 1355
 				$obj = $this->db->fetch_object($resql);
1356 1356
 
1357 1357
 			    if ($originline == $obj->fk_origin_line) {
1358
-			        $line->entrepot_id       = 0; // entrepod_id in details_entrepot
1359
-				    $line->qty_shipped    	+= $obj->qty_shipped;
1358
+			        $line->entrepot_id = 0; // entrepod_id in details_entrepot
1359
+				    $line->qty_shipped += $obj->qty_shipped;
1360 1360
 				} else {
1361 1361
 				    $line = new ExpeditionLigne($this->db);
1362 1362
 				    $line->entrepot_id    	= $obj->fk_entrepot;
@@ -1369,24 +1369,24 @@  discard block
 block discarded – undo
1369 1369
 				$line->details_entrepot[]     = $detail_entrepot;
1370 1370
 
1371 1371
                 $line->line_id          = $obj->line_id;
1372
-                $line->rowid            = $obj->line_id;    // TODO deprecated
1372
+                $line->rowid            = $obj->line_id; // TODO deprecated
1373 1373
                 $line->id               = $obj->line_id;
1374 1374
 
1375
-                $line->fk_origin     	= 'orderline';
1375
+                $line->fk_origin = 'orderline';
1376 1376
                 $line->fk_origin_line 	= $obj->fk_origin_line;
1377
-                $line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
1377
+                $line->origin_line_id 	= $obj->fk_origin_line; // TODO deprecated
1378 1378
 
1379
-				$line->fk_expedition    = $this->id;                // id of parent
1379
+				$line->fk_expedition    = $this->id; // id of parent
1380 1380
 
1381 1381
 				$line->product_type     = $obj->product_type;
1382 1382
 				$line->fk_product     	= $obj->fk_product;
1383 1383
 				$line->fk_product_type	= $obj->fk_product_type;
1384
-				$line->ref				= $obj->product_ref;		// TODO deprecated
1385
-                $line->product_ref		= $obj->product_ref;
1386
-                $line->product_label	= $obj->product_label;
1387
-				$line->libelle        	= $obj->product_label;		// TODO deprecated
1388
-				$line->product_tobatch  = $obj->product_tobatch;
1389
-				$line->label			= $obj->custom_label;
1384
+				$line->ref = $obj->product_ref; // TODO deprecated
1385
+                $line->product_ref = $obj->product_ref;
1386
+                $line->product_label = $obj->product_label;
1387
+				$line->libelle        	= $obj->product_label; // TODO deprecated
1388
+				$line->product_tobatch = $obj->product_tobatch;
1389
+				$line->label = $obj->custom_label;
1390 1390
 				$line->description    	= $obj->description;
1391 1391
 				$line->qty_asked      	= $obj->qty_asked;
1392 1392
 				$line->weight         	= $obj->weight;
@@ -1394,40 +1394,40 @@  discard block
 block discarded – undo
1394 1394
 				$line->length         	= $obj->length;
1395 1395
 				$line->length_units   	= $obj->length_units;
1396 1396
 				$line->surface        	= $obj->surface;
1397
-				$line->surface_units   	= $obj->surface_units;
1397
+				$line->surface_units = $obj->surface_units;
1398 1398
 				$line->volume         	= $obj->volume;
1399 1399
 				$line->volume_units   	= $obj->volume_units;
1400 1400
 
1401
-				$line->pa_ht 			= $obj->pa_ht;
1401
+				$line->pa_ht = $obj->pa_ht;
1402 1402
 
1403
-				$localtax_array=array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1403
+				$localtax_array = array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1404 1404
 
1405 1405
 				// For invoicing
1406
-				$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array);	// We force type to 0
1407
-				$line->desc	         	= $obj->description;		// We need ->desc because some code into CommonObject use desc (property defined for other elements)
1408
-				$line->qty 				= $line->qty_shipped;
1409
-				$line->total_ht			= $tabprice[0];
1406
+				$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0
1407
+				$line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements)
1408
+				$line->qty = $line->qty_shipped;
1409
+				$line->total_ht = $tabprice[0];
1410 1410
 				$line->total_localtax1 	= $tabprice[9];
1411 1411
 				$line->total_localtax2 	= $tabprice[10];
1412 1412
 				$line->total_ttc	 	= $tabprice[2];
1413 1413
 				$line->total_tva	 	= $tabprice[1];
1414
-				$line->vat_src_code	 	= $obj->vat_src_code;
1415
-				$line->tva_tx 		 	= $obj->tva_tx;
1414
+				$line->vat_src_code = $obj->vat_src_code;
1415
+				$line->tva_tx = $obj->tva_tx;
1416 1416
 				$line->localtax1_tx 	= $obj->localtax1_tx;
1417 1417
 				$line->localtax2_tx 	= $obj->localtax2_tx;
1418
-				$line->price			= $obj->price;
1419
-				$line->subprice			= $obj->subprice;
1420
-				$line->remise_percent	= $obj->remise_percent;
1418
+				$line->price = $obj->price;
1419
+				$line->subprice = $obj->subprice;
1420
+				$line->remise_percent = $obj->remise_percent;
1421 1421
 
1422
-				$this->total_ht+= $tabprice[0];
1423
-				$this->total_tva+= $tabprice[1];
1424
-				$this->total_ttc+= $tabprice[2];
1425
-				$this->total_localtax1+= $tabprice[9];
1426
-				$this->total_localtax2+= $tabprice[10];
1422
+				$this->total_ht += $tabprice[0];
1423
+				$this->total_tva += $tabprice[1];
1424
+				$this->total_ttc += $tabprice[2];
1425
+				$this->total_localtax1 += $tabprice[9];
1426
+				$this->total_localtax2 += $tabprice[10];
1427 1427
 
1428 1428
 				// Multicurrency
1429
-				$this->fk_multicurrency 		= $obj->fk_multicurrency;
1430
-				$this->multicurrency_code 		= $obj->multicurrency_code;
1429
+				$this->fk_multicurrency = $obj->fk_multicurrency;
1430
+				$this->multicurrency_code = $obj->multicurrency_code;
1431 1431
 				$this->multicurrency_subprice 	= $obj->multicurrency_subprice;
1432 1432
 				$this->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
1433 1433
 				$this->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
@@ -1438,11 +1438,11 @@  discard block
 block discarded – undo
1438 1438
 					$line->detail_batch = array();
1439 1439
 				}
1440 1440
 				// Eat-by date
1441
-				if (! empty($conf->productbatch->enabled) && $obj->line_id > 0)
1441
+				if (!empty($conf->productbatch->enabled) && $obj->line_id > 0)
1442 1442
 				{
1443 1443
                     require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
1444 1444
 
1445
-                    $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db,$obj->line_id);
1445
+                    $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db, $obj->line_id);
1446 1446
                     if (is_array($newdetailbatch))
1447 1447
                     {
1448 1448
 	                    if ($originline != $obj->fk_origin_line)
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 				}
1464 1464
 				else
1465 1465
 				{
1466
-				    $line->total_ht			+= $tabprice[0];
1466
+				    $line->total_ht += $tabprice[0];
1467 1467
 				    $line->total_localtax1 	+= $tabprice[9];
1468 1468
 				    $line->total_localtax2 	+= $tabprice[10];
1469 1469
 				    $line->total_ttc	 	+= $tabprice[2];
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
 		}
1479 1479
 		else
1480 1480
 		{
1481
-			$this->error=$this->db->error();
1481
+			$this->error = $this->db->error();
1482 1482
 			return -3;
1483 1483
 		}
1484 1484
 	}
@@ -1494,13 +1494,13 @@  discard block
 block discarded – undo
1494 1494
      *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1495 1495
      *	@return     string          						String with URL
1496 1496
      */
1497
-	function getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
1497
+	function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1498 1498
 	{
1499 1499
 		global $langs;
1500 1500
 
1501
-		$result='';
1502
-        $label = '<u>' . $langs->trans("ShowSending") . '</u>';
1503
-        $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
1501
+		$result = '';
1502
+        $label = '<u>'.$langs->trans("ShowSending").'</u>';
1503
+        $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1504 1504
         $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1505 1505
 
1506 1506
 		$url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id;
@@ -1510,31 +1510,31 @@  discard block
 block discarded – undo
1510 1510
 		if ($option !== 'nolink')
1511 1511
 		{
1512 1512
 			// Add param to save lastsearch_values or not
1513
-			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1514
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1515
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1513
+			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1514
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
1515
+			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
1516 1516
 		}
1517 1517
 
1518
-		$linkclose='';
1518
+		$linkclose = '';
1519 1519
 		if (empty($notooltip))
1520 1520
 		{
1521
-		    if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1521
+		    if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1522 1522
 		    {
1523
-		        $label=$langs->trans("ShowSending");
1524
-		        $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1523
+		        $label = $langs->trans("ShowSending");
1524
+		        $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1525 1525
 		    }
1526
-		    $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1527
-		    $linkclose.=' class="classfortooltip"';
1526
+		    $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1527
+		    $linkclose .= ' class="classfortooltip"';
1528 1528
 		}
1529 1529
 
1530 1530
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1531
-		$linkend='</a>';
1531
+		$linkend = '</a>';
1532 1532
 
1533
-		$picto='sending';
1533
+		$picto = 'sending';
1534 1534
 
1535
-		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1536
-		if ($withpicto && $withpicto != 2) $result.=' ';
1537
-		$result.=$linkstart.$this->ref.$linkend;
1535
+		if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
1536
+		if ($withpicto && $withpicto != 2) $result .= ' ';
1537
+		$result .= $linkstart.$this->ref.$linkend;
1538 1538
 		return $result;
1539 1539
 	}
1540 1540
 
@@ -1544,9 +1544,9 @@  discard block
 block discarded – undo
1544 1544
      *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1545 1545
      *	@return     string      		Libelle
1546 1546
      */
1547
-	function getLibStatut($mode=0)
1547
+	function getLibStatut($mode = 0)
1548 1548
 	{
1549
-		return $this->LibStatut($this->statut,$mode);
1549
+		return $this->LibStatut($this->statut, $mode);
1550 1550
 	}
1551 1551
 
1552 1552
 	/**
@@ -1556,39 +1556,39 @@  discard block
 block discarded – undo
1556 1556
 	 * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
1557 1557
 	 * @return     string				Label of status
1558 1558
 	 */
1559
-	function LibStatut($statut,$mode)
1559
+	function LibStatut($statut, $mode)
1560 1560
 	{
1561 1561
 		global $langs;
1562 1562
 
1563
-		if ($mode==0)
1563
+		if ($mode == 0)
1564 1564
 		{
1565
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1566
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1567
-			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1565
+			if ($statut == 0) return $langs->trans($this->statuts[$statut]);
1566
+			if ($statut == 1)  return $langs->trans($this->statuts[$statut]);
1567
+			if ($statut == 2)  return $langs->trans($this->statuts[$statut]);
1568 1568
 		}
1569
-		if ($mode==1)
1569
+		if ($mode == 1)
1570 1570
 		{
1571
-			if ($statut==0) return $langs->trans('StatusSendingDraftShort');
1572
-			if ($statut==1) return $langs->trans('StatusSendingValidatedShort');
1573
-			if ($statut==2) return $langs->trans('StatusSendingProcessedShort');
1571
+			if ($statut == 0) return $langs->trans('StatusSendingDraftShort');
1572
+			if ($statut == 1) return $langs->trans('StatusSendingValidatedShort');
1573
+			if ($statut == 2) return $langs->trans('StatusSendingProcessedShort');
1574 1574
 		}
1575 1575
 		if ($mode == 3)
1576 1576
 		{
1577
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1578
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1579
-			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6');
1577
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1578
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1579
+			if ($statut == 2) return img_picto($langs->trans('StatusSendingProcessed'), 'statut6');
1580 1580
 		}
1581 1581
 		if ($mode == 4)
1582 1582
 		{
1583
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1584
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1585
-			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6').' '.$langs->trans('StatusSendingProcessed');
1583
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
1584
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]);
1585
+			if ($statut == 2) return img_picto($langs->trans('StatusSendingProcessed'), 'statut6').' '.$langs->trans('StatusSendingProcessed');
1586 1586
 		}
1587 1587
 		if ($mode == 5)
1588 1588
 		{
1589
-			if ($statut==0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1590
-			if ($statut==1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1591
-			if ($statut==2) return $langs->trans('StatusSendingProcessedShort').' '.img_picto($langs->trans('StatusSendingProcessedShort'),'statut6');
1589
+			if ($statut == 0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]), 'statut0');
1590
+			if ($statut == 1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]), 'statut4');
1591
+			if ($statut == 2) return $langs->trans('StatusSendingProcessedShort').' '.img_picto($langs->trans('StatusSendingProcessedShort'), 'statut6');
1592 1592
 		}
1593 1593
 	}
1594 1594
 
@@ -1603,7 +1603,7 @@  discard block
 block discarded – undo
1603 1603
 	{
1604 1604
 		global $langs;
1605 1605
 
1606
-		$now=dol_now();
1606
+		$now = dol_now();
1607 1607
 
1608 1608
 		dol_syslog(get_class($this)."::initAsSpecimen");
1609 1609
 
@@ -1611,8 +1611,8 @@  discard block
 block discarded – undo
1611 1611
 		$num_prods = 0;
1612 1612
 		$prodids = array();
1613 1613
 		$sql = "SELECT rowid";
1614
-		$sql.= " FROM ".MAIN_DB_PREFIX."product";
1615
-		$sql.= " WHERE entity IN (".getEntity('product').")";
1614
+		$sql .= " FROM ".MAIN_DB_PREFIX."product";
1615
+		$sql .= " WHERE entity IN (".getEntity('product').")";
1616 1616
 		$resql = $this->db->query($sql);
1617 1617
 		if ($resql)
1618 1618
 		{
@@ -1626,20 +1626,20 @@  discard block
 block discarded – undo
1626 1626
 			}
1627 1627
 		}
1628 1628
 
1629
-		$order=new Commande($this->db);
1629
+		$order = new Commande($this->db);
1630 1630
 		$order->initAsSpecimen();
1631 1631
 
1632 1632
 		// Initialise parametres
1633
-		$this->id=0;
1633
+		$this->id = 0;
1634 1634
 		$this->ref = 'SPECIMEN';
1635
-		$this->specimen=1;
1635
+		$this->specimen = 1;
1636 1636
 		$this->statut               = 1;
1637 1637
 		$this->livraison_id         = 0;
1638 1638
 		$this->date                 = $now;
1639 1639
 		$this->date_creation        = $now;
1640 1640
 		$this->date_valid           = $now;
1641 1641
 		$this->date_delivery        = $now;
1642
-		$this->date_expedition      = $now + 24*3600;
1642
+		$this->date_expedition      = $now + 24 * 3600;
1643 1643
 
1644 1644
 		$this->entrepot_id          = 0;
1645 1645
 		$this->fk_delivery_address  = 0;
@@ -1651,22 +1651,22 @@  discard block
 block discarded – undo
1651 1651
         $this->origin_id            = 1;
1652 1652
         $this->origin               = 'commande';
1653 1653
 
1654
-        $this->note_private			= 'Private note';
1655
-        $this->note_public			= 'Public note';
1654
+        $this->note_private = 'Private note';
1655
+        $this->note_public = 'Public note';
1656 1656
 
1657 1657
 		$nbp = 5;
1658 1658
 		$xnbp = 0;
1659 1659
 		while ($xnbp < $nbp)
1660 1660
 		{
1661
-			$line=new ExpeditionLigne($this->db);
1662
-			$line->desc=$langs->trans("Description")." ".$xnbp;
1663
-			$line->libelle=$langs->trans("Description")." ".$xnbp;
1664
-			$line->qty=10;
1665
-			$line->qty_asked=5;
1666
-			$line->qty_shipped=4;
1667
-			$line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1668
-
1669
-			$this->lines[]=$line;
1661
+			$line = new ExpeditionLigne($this->db);
1662
+			$line->desc = $langs->trans("Description")." ".$xnbp;
1663
+			$line->libelle = $langs->trans("Description")." ".$xnbp;
1664
+			$line->qty = 10;
1665
+			$line->qty_asked = 5;
1666
+			$line->qty_shipped = 4;
1667
+			$line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1668
+
1669
+			$this->lines[] = $line;
1670 1670
 			$xnbp++;
1671 1671
 		}
1672 1672
 
@@ -1684,11 +1684,11 @@  discard block
 block discarded – undo
1684 1684
 		if ($user->rights->expedition->creer)
1685 1685
 		{
1686 1686
 			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
1687
-			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1688
-			$sql.= " WHERE rowid = ".$this->id;
1687
+			$sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1688
+			$sql .= " WHERE rowid = ".$this->id;
1689 1689
 
1690 1690
 			dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
1691
-			$resql=$this->db->query($sql);
1691
+			$resql = $this->db->query($sql);
1692 1692
 			if ($resql)
1693 1693
 			{
1694 1694
 				$this->date_delivery = $date_livraison;
@@ -1696,7 +1696,7 @@  discard block
 block discarded – undo
1696 1696
 			}
1697 1697
 			else
1698 1698
 			{
1699
-				$this->error=$this->db->error();
1699
+				$this->error = $this->db->error();
1700 1700
 				return -1;
1701 1701
 			}
1702 1702
 		}
@@ -1717,17 +1717,17 @@  discard block
 block discarded – undo
1717 1717
 		$this->meths = array();
1718 1718
 
1719 1719
 		$sql = "SELECT em.rowid, em.code, em.libelle";
1720
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1721
-		$sql.= " WHERE em.active = 1";
1722
-		$sql.= " ORDER BY em.libelle ASC";
1720
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1721
+		$sql .= " WHERE em.active = 1";
1722
+		$sql .= " ORDER BY em.libelle ASC";
1723 1723
 
1724 1724
 		$resql = $this->db->query($sql);
1725 1725
 		if ($resql)
1726 1726
 		{
1727 1727
 			while ($obj = $this->db->fetch_object($resql))
1728 1728
 			{
1729
-				$label=$langs->trans('SendingMethod'.$obj->code);
1730
-				$this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1729
+				$label = $langs->trans('SendingMethod'.$obj->code);
1730
+				$this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->libelle);
1731 1731
 			}
1732 1732
 		}
1733 1733
 	}
@@ -1738,16 +1738,16 @@  discard block
 block discarded – undo
1738 1738
      *  @param  id      $id     only this carrier, all if none
1739 1739
      *  @return void
1740 1740
      */
1741
-    function list_delivery_methods($id='')
1741
+    function list_delivery_methods($id = '')
1742 1742
     {
1743 1743
         global $langs;
1744 1744
 
1745 1745
         $this->listmeths = array();
1746
-        $i=0;
1746
+        $i = 0;
1747 1747
 
1748 1748
         $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1749
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1750
-        if ($id!='') $sql.= " WHERE em.rowid=".$id;
1749
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1750
+        if ($id != '') $sql .= " WHERE em.rowid=".$id;
1751 1751
 
1752 1752
         $resql = $this->db->query($sql);
1753 1753
         if ($resql)
@@ -1756,8 +1756,8 @@  discard block
 block discarded – undo
1756 1756
             {
1757 1757
                 $this->listmeths[$i]['rowid'] = $obj->rowid;
1758 1758
                 $this->listmeths[$i]['code'] = $obj->code;
1759
-                $label=$langs->trans('SendingMethod'.$obj->code);
1760
-                $this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1759
+                $label = $langs->trans('SendingMethod'.$obj->code);
1760
+                $this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->libelle);
1761 1761
                 $this->listmeths[$i]['description'] = $obj->description;
1762 1762
                 $this->listmeths[$i]['tracking'] = $obj->tracking;
1763 1763
                 $this->listmeths[$i]['active'] = $obj->active;
@@ -1773,25 +1773,25 @@  discard block
 block discarded – undo
1773 1773
      *
1774 1774
      *  @return void
1775 1775
      */
1776
-    function update_delivery_method($id='')
1776
+    function update_delivery_method($id = '')
1777 1777
     {
1778
-        if ($id=='')
1778
+        if ($id == '')
1779 1779
         {
1780 1780
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1781
-            $sql.=" VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1781
+            $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1782 1782
             $resql = $this->db->query($sql);
1783 1783
         }
1784 1784
         else
1785 1785
         {
1786 1786
             $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1787
-            $sql.= " code='".$this->db->escape($this->update['code'])."'";
1788
-            $sql.= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1789
-            $sql.= ",description='".$this->db->escape($this->update['description'])."'";
1790
-            $sql.= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1791
-            $sql.= " WHERE rowid=".$id;
1787
+            $sql .= " code='".$this->db->escape($this->update['code'])."'";
1788
+            $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'";
1789
+            $sql .= ",description='".$this->db->escape($this->update['description'])."'";
1790
+            $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'";
1791
+            $sql .= " WHERE rowid=".$id;
1792 1792
             $resql = $this->db->query($sql);
1793 1793
         }
1794
-        if ($resql < 0) dol_print_error($this->db,'');
1794
+        if ($resql < 0) dol_print_error($this->db, '');
1795 1795
     }
1796 1796
 
1797 1797
     /**
@@ -1804,7 +1804,7 @@  discard block
 block discarded – undo
1804 1804
     function activ_delivery_method($id)
1805 1805
     {
1806 1806
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1';
1807
-        $sql.= ' WHERE rowid='.$id;
1807
+        $sql .= ' WHERE rowid='.$id;
1808 1808
 
1809 1809
         $resql = $this->db->query($sql);
1810 1810
 
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
     function disable_delivery_method($id)
1821 1821
     {
1822 1822
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0';
1823
-        $sql.= ' WHERE rowid='.$id;
1823
+        $sql .= ' WHERE rowid='.$id;
1824 1824
 
1825 1825
         $resql = $this->db->query($sql);
1826 1826
 
@@ -1833,13 +1833,13 @@  discard block
 block discarded – undo
1833 1833
 	 * @param	string	$value		Value
1834 1834
 	 * @return	void
1835 1835
 	 */
1836
-	function GetUrlTrackingStatus($value='')
1836
+	function GetUrlTrackingStatus($value = '')
1837 1837
 	{
1838
-		if (! empty($this->shipping_method_id))
1838
+		if (!empty($this->shipping_method_id))
1839 1839
 		{
1840 1840
 			$sql = "SELECT em.code, em.tracking";
1841
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1842
-			$sql.= " WHERE em.rowid = ".$this->shipping_method_id;
1841
+			$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1842
+			$sql .= " WHERE em.rowid = ".$this->shipping_method_id;
1843 1843
 
1844 1844
 			$resql = $this->db->query($sql);
1845 1845
 			if ($resql)
@@ -1854,7 +1854,7 @@  discard block
 block discarded – undo
1854 1854
 		if (!empty($tracking) && !empty($value))
1855 1855
 		{
1856 1856
 			$url = str_replace('{TRACKID}', $value, $tracking);
1857
-			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1857
+			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value ? $value : 'url').'</a>', $url, $url);
1858 1858
 		}
1859 1859
 		else
1860 1860
 		{
@@ -1869,16 +1869,16 @@  discard block
 block discarded – undo
1869 1869
 	 */
1870 1870
 	function setClosed()
1871 1871
 	{
1872
-		global $conf,$langs,$user;
1872
+		global $conf, $langs, $user;
1873 1873
 
1874
-		$error=0;
1874
+		$error = 0;
1875 1875
 
1876 1876
 		$this->db->begin();
1877 1877
 
1878 1878
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut='.self::STATUS_CLOSED;
1879 1879
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
1880 1880
 
1881
-		$resql=$this->db->query($sql);
1881
+		$resql = $this->db->query($sql);
1882 1882
 		if ($resql)
1883 1883
 		{
1884 1884
 			// Set order billed if 100% of order is shipped (qty in shipment lines match qty in order lines)
@@ -1887,17 +1887,17 @@  discard block
 block discarded – undo
1887 1887
 				$order = new Commande($this->db);
1888 1888
 				$order->fetch($this->origin_id);
1889 1889
 
1890
-				$order->loadExpeditions(self::STATUS_CLOSED);		// Fill $order->expeditions = array(orderlineid => qty)
1890
+				$order->loadExpeditions(self::STATUS_CLOSED); // Fill $order->expeditions = array(orderlineid => qty)
1891 1891
 
1892 1892
 				$shipments_match_order = 1;
1893
-				foreach($order->lines as $line)
1893
+				foreach ($order->lines as $line)
1894 1894
 				{
1895 1895
 					$lineid = $line->id;
1896 1896
 					$qty = $line->qty;
1897
-					if (($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty)
1897
+					if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty)
1898 1898
 					{
1899 1899
 						$shipments_match_order = 0;
1900
-						$text='Qty for order line id '.$lineid.' is '.$qty.'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->expeditions[$lineid].', so we can t close order';
1900
+						$text = 'Qty for order line id '.$lineid.' is '.$qty.'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->expeditions[$lineid].', so we can t close order';
1901 1901
 						dol_syslog($text);
1902 1902
 						break;
1903 1903
 					}
@@ -1909,11 +1909,11 @@  discard block
 block discarded – undo
1909 1909
 				}
1910 1910
 			}
1911 1911
 
1912
-			$this->statut=self::STATUS_CLOSED;
1912
+			$this->statut = self::STATUS_CLOSED;
1913 1913
 
1914 1914
 
1915 1915
 			// If stock increment is done on closing
1916
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
1916
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
1917 1917
 			{
1918 1918
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
1919 1919
 
@@ -1922,16 +1922,16 @@  discard block
 block discarded – undo
1922 1922
 				// Loop on each product line to add a stock movement
1923 1923
 				// TODO possibilite d'expedier a partir d'une propale ou autre origine ?
1924 1924
 				$sql = "SELECT cd.fk_product, cd.subprice,";
1925
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
1926
-				$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
1927
-				$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1928
-				$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1929
-				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
1930
-				$sql.= " WHERE ed.fk_expedition = ".$this->id;
1931
-				$sql.= " AND cd.rowid = ed.fk_origin_line";
1925
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
1926
+				$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
1927
+				$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
1928
+				$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
1929
+				$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
1930
+				$sql .= " WHERE ed.fk_expedition = ".$this->id;
1931
+				$sql .= " AND cd.rowid = ed.fk_origin_line";
1932 1932
 
1933 1933
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
1934
-				$resql=$this->db->query($sql);
1934
+				$resql = $this->db->query($sql);
1935 1935
 				if ($resql)
1936 1936
 				{
1937 1937
 					$cpt = $this->db->num_rows($resql);
@@ -1957,7 +1957,7 @@  discard block
 block discarded – undo
1957 1957
 							// line without batch detail
1958 1958
 
1959 1959
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
1960
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref));
1960
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref));
1961 1961
 							if ($result < 0) {
1962 1962
 							    $this->error = $mouvS->error;
1963 1963
 							    $this->errors = $mouvS->errors;
@@ -1969,7 +1969,7 @@  discard block
 block discarded – undo
1969 1969
 							// line with batch detail
1970 1970
 
1971 1971
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
1972
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1972
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
1973 1973
 							if ($result < 0) {
1974 1974
 							    $this->error = $mouvS->error;
1975 1975
 							    $this->errors = $mouvS->errors;
@@ -1980,15 +1980,15 @@  discard block
 block discarded – undo
1980 1980
 				}
1981 1981
 				else
1982 1982
 				{
1983
-					$this->error=$this->db->lasterror();
1983
+					$this->error = $this->db->lasterror();
1984 1984
 					$error++;
1985 1985
 				}
1986 1986
 			}
1987 1987
 
1988 1988
 			// Call trigger
1989
-			if (! $error)
1989
+			if (!$error)
1990 1990
 			{
1991
-    			$result=$this->call_trigger('SHIPPING_CLOSED',$user);
1991
+    			$result = $this->call_trigger('SHIPPING_CLOSED', $user);
1992 1992
     			if ($result < 0) {
1993 1993
     			    $error++;
1994 1994
     			}
@@ -2000,7 +2000,7 @@  discard block
 block discarded – undo
2000 2000
             $error++;
2001 2001
 		}
2002 2002
 
2003
-		if (! $error)
2003
+		if (!$error)
2004 2004
 		{
2005 2005
 		    $this->db->commit();
2006 2006
 		    return 1;
@@ -2020,28 +2020,28 @@  discard block
 block discarded – undo
2020 2020
 	function set_billed()
2021 2021
 	{
2022 2022
 	    global $user;
2023
-		$error=0;
2023
+		$error = 0;
2024 2024
 
2025 2025
 		$this->db->begin();
2026 2026
 
2027
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1';    // TODO Update only billed
2027
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed
2028 2028
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
2029 2029
 
2030
-		$resql=$this->db->query($sql);
2030
+		$resql = $this->db->query($sql);
2031 2031
 		if ($resql)
2032 2032
 		{
2033
-			$this->statut=2;
2034
-			$this->billed=1;
2033
+			$this->statut = 2;
2034
+			$this->billed = 1;
2035 2035
 
2036 2036
 			// Call trigger
2037
-			$result=$this->call_trigger('SHIPPING_BILLED',$user);
2037
+			$result = $this->call_trigger('SHIPPING_BILLED', $user);
2038 2038
 			if ($result < 0) {
2039 2039
 				$error++;
2040 2040
 			}
2041 2041
 
2042 2042
 		} else {
2043 2043
 			$error++;
2044
-			$this->errors[]=$this->db->lasterror;
2044
+			$this->errors[] = $this->db->lasterror;
2045 2045
 		}
2046 2046
 
2047 2047
 		if (empty($error)) {
@@ -2062,23 +2062,23 @@  discard block
 block discarded – undo
2062 2062
 	 */
2063 2063
 	function reOpen()
2064 2064
 	{
2065
-		global $conf,$langs,$user;
2065
+		global $conf, $langs, $user;
2066 2066
 
2067
-		$error=0;
2067
+		$error = 0;
2068 2068
 
2069 2069
 		$this->db->begin();
2070 2070
 
2071 2071
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1';
2072 2072
 		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
2073 2073
 
2074
-		$resql=$this->db->query($sql);
2074
+		$resql = $this->db->query($sql);
2075 2075
 		if ($resql)
2076 2076
 		{
2077
-			$this->statut=1;
2078
-			$this->billed=0;
2077
+			$this->statut = 1;
2078
+			$this->billed = 0;
2079 2079
 
2080 2080
 			// If stock increment is done on closing
2081
-			if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2081
+			if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2082 2082
 			{
2083 2083
 				require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2084 2084
 
@@ -2087,16 +2087,16 @@  discard block
 block discarded – undo
2087 2087
 				// Loop on each product line to add a stock movement
2088 2088
 				// TODO possibilite d'expedier a partir d'une propale ou autre origine
2089 2089
 				$sql = "SELECT cd.fk_product, cd.subprice,";
2090
-				$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
2091
-				$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2092
-				$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2093
-				$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2094
-				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2095
-				$sql.= " WHERE ed.fk_expedition = ".$this->id;
2096
-				$sql.= " AND cd.rowid = ed.fk_origin_line";
2090
+				$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2091
+				$sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2092
+				$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
2093
+				$sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed";
2094
+				$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2095
+				$sql .= " WHERE ed.fk_expedition = ".$this->id;
2096
+				$sql .= " AND cd.rowid = ed.fk_origin_line";
2097 2097
 
2098 2098
 				dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2099
-				$resql=$this->db->query($sql);
2099
+				$resql = $this->db->query($sql);
2100 2100
 				if ($resql)
2101 2101
 				{
2102 2102
 					$cpt = $this->db->num_rows($resql);
@@ -2123,7 +2123,7 @@  discard block
 block discarded – undo
2123 2123
 							// line without batch detail
2124 2124
 
2125 2125
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2126
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref));
2126
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref));
2127 2127
 							if ($result < 0) {
2128 2128
 							    $this->error = $mouvS->error;
2129 2129
 							    $this->errors = $mouvS->errors;
@@ -2135,7 +2135,7 @@  discard block
 block discarded – undo
2135 2135
 							// line with batch detail
2136 2136
 
2137 2137
 							// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2138
-							$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2138
+							$result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2139 2139
 							if ($result < 0) {
2140 2140
 							    $this->error = $mouvS->error;
2141 2141
 							    $this->errors = $mouvS->errors;
@@ -2146,15 +2146,15 @@  discard block
 block discarded – undo
2146 2146
 				}
2147 2147
 				else
2148 2148
 				{
2149
-					$this->error=$this->db->lasterror();
2149
+					$this->error = $this->db->lasterror();
2150 2150
 					$error++;
2151 2151
 				}
2152 2152
 			}
2153 2153
 
2154
-			if (! $error)
2154
+			if (!$error)
2155 2155
 			{
2156 2156
     			// Call trigger
2157
-    			$result=$this->call_trigger('SHIPPING_REOPEN',$user);
2157
+    			$result = $this->call_trigger('SHIPPING_REOPEN', $user);
2158 2158
     			if ($result < 0) {
2159 2159
     				$error++;
2160 2160
     			}
@@ -2162,10 +2162,10 @@  discard block
 block discarded – undo
2162 2162
 
2163 2163
 		} else {
2164 2164
 			$error++;
2165
-			$this->errors[]=$this->db->lasterror();
2165
+			$this->errors[] = $this->db->lasterror();
2166 2166
 		}
2167 2167
 
2168
-		if (! $error)
2168
+		if (!$error)
2169 2169
 		{
2170 2170
 			$this->db->commit();
2171 2171
 			return 1;
@@ -2187,19 +2187,19 @@  discard block
 block discarded – undo
2187 2187
 	 *  @param      int			$hideref        Hide ref
2188 2188
 	 *  @return     int         				0 if KO, 1 if OK
2189 2189
 	 */
2190
-	public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0)
2190
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2191 2191
 	{
2192
-		global $conf,$langs;
2192
+		global $conf, $langs;
2193 2193
 
2194 2194
 		$langs->load("sendings");
2195 2195
 
2196
-		if (! dol_strlen($modele)) {
2196
+		if (!dol_strlen($modele)) {
2197 2197
 
2198 2198
 			$modele = 'rouget';
2199 2199
 
2200 2200
 			if ($this->modelpdf) {
2201 2201
 				$modele = $this->modelpdf;
2202
-			} elseif (! empty($conf->global->EXPEDITION_ADDON_PDF)) {
2202
+			} elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) {
2203 2203
 				$modele = $conf->global->EXPEDITION_ADDON_PDF;
2204 2204
 			}
2205 2205
 		}
@@ -2252,14 +2252,14 @@  discard block
 block discarded – undo
2252 2252
 
2253 2253
 	// Invoicing
2254 2254
 	var $remise_percent;
2255
-	var $total_ht;			// Total net of tax
2256
-	var $total_ttc;			// Total with tax
2257
-	var $total_tva;			// Total VAT
2258
-	var $total_localtax1;   // Total Local tax 1
2259
-	var $total_localtax2;   // Total Local tax 2
2255
+	var $total_ht; // Total net of tax
2256
+	var $total_ttc; // Total with tax
2257
+	var $total_tva; // Total VAT
2258
+	var $total_localtax1; // Total Local tax 1
2259
+	var $total_localtax2; // Total Local tax 2
2260 2260
 
2261
-	public $element='expeditiondet';
2262
-	public $table_element='expeditiondet';
2261
+	public $element = 'expeditiondet';
2262
+	public $table_element = 'expeditiondet';
2263 2263
 
2264 2264
 	public $fk_origin_line;
2265 2265
 
@@ -2287,7 +2287,7 @@  discard block
 block discarded – undo
2287 2287
      */
2288 2288
 	function __construct($db)
2289 2289
 	{
2290
-		$this->db=$db;
2290
+		$this->db = $db;
2291 2291
 	}
2292 2292
 
2293 2293
 }
Please login to merge, or discard this patch.
Braces   +249 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,9 +33,15 @@  discard block
 block discarded – undo
33 33
 
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
36
-if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
37
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38
-if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
36
+if (! empty($conf->propal->enabled)) {
37
+	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38
+}
39
+if (! empty($conf->commande->enabled)) {
40
+	require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
41
+}
42
+if (! empty($conf->productbatch->enabled)) {
43
+	require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
44
+}
39 45
 
40 46
 
41 47
 /**
@@ -162,14 +168,12 @@  discard block
 block discarded – undo
162 168
 			if ( $numref != "")
163 169
 			{
164 170
 				return $numref;
165
-			}
166
-			else
171
+			} else
167 172
 			{
168 173
 				dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
169 174
 				return "";
170 175
 			}
171
-        }
172
-	    else
176
+        } else
173 177
 	    {
174 178
 		    print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
175 179
 		    return "";
@@ -195,7 +199,9 @@  discard block
 block discarded – undo
195 199
 		// Clean parameters
196 200
 		$this->brouillon = 1;
197 201
 		$this->tracking_number = dol_sanitizeFileName($this->tracking_number);
198
-		if (empty($this->fk_project)) $this->fk_project = 0;
202
+		if (empty($this->fk_project)) {
203
+			$this->fk_project = 0;
204
+		}
199 205
 
200 206
 		$this->user = $user;
201 207
 
@@ -276,8 +282,7 @@  discard block
 block discarded – undo
276 282
 						{
277 283
 							$error++;
278 284
 						}
279
-					}
280
-					else
285
+					} else
281 286
 					{	// with batch management
282 287
 						if (! $this->create_line_batch($this->lines[$i],$this->lines[$i]->array_options) > 0)
283 288
 						{
@@ -302,16 +307,19 @@  discard block
 block discarded – undo
302 307
 				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
303 308
 				if (empty($reshook))
304 309
 				{
305
-					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
310
+					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
311
+						// For avoid conflicts if trigger used
306 312
 					{
307 313
 						$result=$this->insertExtraFields();
314
+					}
308 315
 						if ($result < 0)
309 316
 						{
310 317
 							$error++;
311 318
 						}
312 319
 					}
320
+				} else if ($reshook < 0) {
321
+					$error++;
313 322
 				}
314
-				else if ($reshook < 0) $error++;
315 323
 
316 324
 				if (! $error && ! $notrigger)
317 325
 				{
@@ -324,8 +332,7 @@  discard block
 block discarded – undo
324 332
 					{
325 333
 						$this->db->commit();
326 334
 						return $this->id;
327
-					}
328
-					else
335
+					} else
329 336
 					{
330 337
 						foreach($this->errors as $errmsg)
331 338
 						{
@@ -336,24 +343,21 @@  discard block
 block discarded – undo
336 343
 						return -1*$error;
337 344
 					}
338 345
 
339
-				}
340
-				else
346
+				} else
341 347
 				{
342 348
 					$error++;
343 349
 					$this->error=$this->db->lasterror()." - sql=$sql";
344 350
 					$this->db->rollback();
345 351
 					return -3;
346 352
 				}
347
-			}
348
-			else
353
+			} else
349 354
 			{
350 355
 				$error++;
351 356
 				$this->error=$this->db->lasterror()." - sql=$sql";
352 357
 				$this->db->rollback();
353 358
 				return -2;
354 359
 			}
355
-		}
356
-		else
360
+		} else
357 361
 		{
358 362
 			$error++;
359 363
 			$this->error=$this->db->error()." - sql=$sql";
@@ -394,15 +398,16 @@  discard block
 block discarded – undo
394 398
 		if ($resql)
395 399
 		{
396 400
 		    $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
397
-		}
398
-		else
401
+		} else
399 402
 		{
400 403
 			$error++;
401 404
 		}
402 405
 
403
-		if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
406
+		if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) {
407
+			// For avoid conflicts if trigger used
404 408
 		{
405 409
 			$expeditionline = new ExpeditionLigne($this->db);
410
+		}
406 411
 			$expeditionline->array_options=$array_options;
407 412
 			$expeditionline->id= $this->db->last_insert_id(MAIN_DB_PREFIX.$expeditionline->table_element);
408 413
 			$result=$expeditionline->insertExtraFields();
@@ -413,8 +418,11 @@  discard block
 block discarded – undo
413 418
 			}
414 419
 		}
415 420
 
416
-		if (! $error) return $line_id;
417
-		else return -1;
421
+		if (! $error) {
422
+			return $line_id;
423
+		} else {
424
+			return -1;
425
+		}
418 426
 	}
419 427
 
420 428
 
@@ -445,24 +453,28 @@  discard block
 block discarded – undo
445 453
 			if (($line_id = $this->create_line($stockLocation,$line_ext->origin_line_id,$qty,$array_options)) < 0)
446 454
 			{
447 455
 				$error++;
448
-			}
449
-			else
456
+			} else
450 457
 			{
451 458
 				// create shipment batch lines for stockLocation
452 459
 				foreach ($tab as $detbatch)
453 460
 				{
454 461
 					if ($detbatch->entrepot_id == $stockLocation){
455
-						if (! ($detbatch->create($line_id) >0))		// Create an expeditionlinebatch
462
+						if (! ($detbatch->create($line_id) >0)) {
463
+							// Create an expeditionlinebatch
456 464
 						{
457 465
 							$error++;
458 466
 						}
467
+						}
459 468
 					}
460 469
 				}
461 470
 			}
462 471
 		}
463 472
 
464
-		if (! $error) return 1;
465
-		else return -1;
473
+		if (! $error) {
474
+			return 1;
475
+		} else {
476
+			return -1;
477
+		}
466 478
 	}
467 479
 
468 480
 	/**
@@ -479,7 +491,9 @@  discard block
 block discarded – undo
479 491
 		global $conf;
480 492
 
481 493
 		// Check parameters
482
-		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
494
+		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) {
495
+			return -1;
496
+		}
483 497
 
484 498
 		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
485 499
 		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
@@ -493,10 +507,18 @@  discard block
 block discarded – undo
493 507
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
494 508
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
495 509
 		$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
496
-		if ($id)   	  $sql.= " AND e.rowid=".$id;
497
-        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
498
-        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
499
-        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
510
+		if ($id) {
511
+			$sql.= " AND e.rowid=".$id;
512
+		}
513
+        if ($ref) {
514
+        	$sql.= " AND e.ref='".$this->db->escape($ref)."'";
515
+        }
516
+        if ($ref_ext) {
517
+        	$sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
518
+        }
519
+        if ($ref_int) {
520
+        	$sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
521
+        }
500 522
 
501 523
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
502 524
 		$result = $this->db->query($sql);
@@ -551,7 +573,9 @@  discard block
 block discarded – undo
551 573
 
552 574
 				$this->db->free($result);
553 575
 
554
-				if ($this->statut == 0) $this->brouillon = 1;
576
+				if ($this->statut == 0) {
577
+					$this->brouillon = 1;
578
+				}
555 579
 
556 580
 				$file = $conf->expedition->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'shipment') . "/" . $this->id.".pdf";
557 581
 				$this->pdf_filename = $file;
@@ -581,15 +605,13 @@  discard block
 block discarded – undo
581 605
 				}
582 606
 
583 607
 				return 1;
584
-			}
585
-			else
608
+			} else
586 609
 			{
587 610
 				dol_syslog(get_class($this).'::Fetch no expedition found', LOG_ERR);
588 611
 				$this->error='Delivery with id '.$id.' not found';
589 612
 				return 0;
590 613
 			}
591
-		}
592
-		else
614
+		} else
593 615
 		{
594 616
 			$this->error=$this->db->error();
595 617
 			return -1;
@@ -638,11 +660,12 @@  discard block
 block discarded – undo
638 660
 		$result=$soc->set_as_client();
639 661
 
640 662
 		// Define new ref
641
-		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
663
+		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) {
664
+			// empty should not happened, but when it occurs, the test save life
642 665
 		{
643 666
 			$numref = $this->getNextNumRef($soc);
644 667
 		}
645
-		else
668
+		} else
646 669
 		{
647 670
 			$numref = "EXP".$this->id;
648 671
 		}
@@ -695,12 +718,13 @@  discard block
 block discarded – undo
695 718
 					if (empty($obj->edbrowid))
696 719
 					{
697 720
 						$qty = $obj->qty;
698
-					}
699
-					else
721
+					} else
700 722
 					{
701 723
 						$qty = $obj->edbqty;
702 724
 					}
703
-					if ($qty <= 0) continue;
725
+					if ($qty <= 0) {
726
+						continue;
727
+					}
704 728
 					dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
705 729
 
706 730
 					//var_dump($this->lines[$i]);
@@ -719,8 +743,7 @@  discard block
 block discarded – undo
719 743
 							$this->errors = array_merge($this->errors, $mouvS->errors);
720 744
 							break;
721 745
 						}
722
-					}
723
-					else
746
+					} else
724 747
 					{
725 748
 						// line with batch detail
726 749
 
@@ -735,8 +758,7 @@  discard block
 block discarded – undo
735 758
 						}
736 759
 					}
737 760
 				}
738
-			}
739
-			else
761
+			} else
740 762
 			{
741 763
 				$this->db->rollback();
742 764
 				$this->error=$this->db->error();
@@ -807,8 +829,7 @@  discard block
 block discarded – undo
807 829
 		{
808 830
 			$this->db->commit();
809 831
 			return 1;
810
-		}
811
-		else
832
+		} else
812 833
 		{
813 834
 			foreach($this->errors as $errmsg)
814 835
 			{
@@ -842,16 +863,17 @@  discard block
 block discarded – undo
842 863
 				if ($result > 0)
843 864
 				{
844 865
 					return $result;
845
-				}
846
-				else
866
+				} else
847 867
 				{
848 868
 					$this->error=$delivery->error;
849 869
 					return $result;
850 870
 				}
871
+			} else {
872
+				return 0;
851 873
 			}
852
-			else return 0;
874
+		} else {
875
+			return 0;
853 876
 		}
854
-		else return 0;
855 877
 	}
856 878
 
857 879
 	/**
@@ -899,9 +921,9 @@  discard block
 block discarded – undo
899 921
 				if ($entrepot_id > 0) {
900 922
 					$product->load_stock('warehouseopen');
901 923
 					$product_stock = $product->stock_warehouse[$entrepot_id]->real;
924
+				} else {
925
+									$product_stock = $product->stock_reel;
902 926
 				}
903
-				else
904
-					$product_stock = $product->stock_reel;
905 927
 
906 928
 				$product_type=$product->type;
907 929
 				if ($product_type == 0 && $product_stock < $qty)
@@ -922,8 +944,10 @@  discard block
 block discarded – undo
922 944
 		}
923 945
 
924 946
 		// extrafields
925
-		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
947
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) {
948
+			// For avoid conflicts if trigger used
926 949
 			$line->array_options = $array_options;
950
+		}
927 951
 
928 952
 		$this->lines[$num] = $line;
929 953
 	}
@@ -987,8 +1011,10 @@  discard block
 block discarded – undo
987 1011
 			$line->detail_batch=$tab;
988 1012
 
989 1013
 			// extrafields
990
-			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
1014
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) {
1015
+				// For avoid conflicts if trigger used
991 1016
 				$line->array_options = $array_options;
1017
+			}
992 1018
 
993 1019
 			//var_dump($line);
994 1020
 			$this->lines[$num] = $line;
@@ -1010,25 +1036,63 @@  discard block
 block discarded – undo
1010 1036
 
1011 1037
 		// Clean parameters
1012 1038
 
1013
-		if (isset($this->ref)) $this->ref=trim($this->ref);
1014
-		if (isset($this->entity)) $this->entity=trim($this->entity);
1015
-		if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
1016
-		if (isset($this->socid)) $this->socid=trim($this->socid);
1017
-		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
1018
-		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
1019
-		if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
1020
-		if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
1021
-		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
1022
-		if (isset($this->statut)) $this->statut=(int) $this->statut;
1023
-		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
1024
-		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
1025
-		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
1026
-		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
1027
-		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
1028
-		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
1029
-		if (isset($this->note_private)) $this->note=trim($this->note_private);
1030
-		if (isset($this->note_public)) $this->note=trim($this->note_public);
1031
-		if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
1039
+		if (isset($this->ref)) {
1040
+			$this->ref=trim($this->ref);
1041
+		}
1042
+		if (isset($this->entity)) {
1043
+			$this->entity=trim($this->entity);
1044
+		}
1045
+		if (isset($this->ref_customer)) {
1046
+			$this->ref_customer=trim($this->ref_customer);
1047
+		}
1048
+		if (isset($this->socid)) {
1049
+			$this->socid=trim($this->socid);
1050
+		}
1051
+		if (isset($this->fk_user_author)) {
1052
+			$this->fk_user_author=trim($this->fk_user_author);
1053
+		}
1054
+		if (isset($this->fk_user_valid)) {
1055
+			$this->fk_user_valid=trim($this->fk_user_valid);
1056
+		}
1057
+		if (isset($this->fk_delivery_address)) {
1058
+			$this->fk_delivery_address=trim($this->fk_delivery_address);
1059
+		}
1060
+		if (isset($this->shipping_method_id)) {
1061
+			$this->shipping_method_id=trim($this->shipping_method_id);
1062
+		}
1063
+		if (isset($this->tracking_number)) {
1064
+			$this->tracking_number=trim($this->tracking_number);
1065
+		}
1066
+		if (isset($this->statut)) {
1067
+			$this->statut=(int) $this->statut;
1068
+		}
1069
+		if (isset($this->trueDepth)) {
1070
+			$this->trueDepth=trim($this->trueDepth);
1071
+		}
1072
+		if (isset($this->trueWidth)) {
1073
+			$this->trueWidth=trim($this->trueWidth);
1074
+		}
1075
+		if (isset($this->trueHeight)) {
1076
+			$this->trueHeight=trim($this->trueHeight);
1077
+		}
1078
+		if (isset($this->size_units)) {
1079
+			$this->size_units=trim($this->size_units);
1080
+		}
1081
+		if (isset($this->weight_units)) {
1082
+			$this->weight_units=trim($this->weight_units);
1083
+		}
1084
+		if (isset($this->trueWeight)) {
1085
+			$this->weight=trim($this->trueWeight);
1086
+		}
1087
+		if (isset($this->note_private)) {
1088
+			$this->note=trim($this->note_private);
1089
+		}
1090
+		if (isset($this->note_public)) {
1091
+			$this->note=trim($this->note_public);
1092
+		}
1093
+		if (isset($this->modelpdf)) {
1094
+			$this->modelpdf=trim($this->modelpdf);
1095
+		}
1032 1096
 
1033 1097
 
1034 1098
 
@@ -1092,8 +1156,7 @@  discard block
 block discarded – undo
1092 1156
 			}
1093 1157
 			$this->db->rollback();
1094 1158
 			return -1*$error;
1095
-		}
1096
-		else
1159
+		} else
1097 1160
 		{
1098 1161
 			$this->db->commit();
1099 1162
 			return 1;
@@ -1173,8 +1236,7 @@  discard block
 block discarded – undo
1173 1236
 							$error++;$this->errors=$this->errors + $mouvS->errors;
1174 1237
 							break;
1175 1238
 						}
1176
-					}
1177
-					else
1239
+					} else
1178 1240
 					{
1179 1241
 						// We increment stock of batches
1180 1242
 						// We use warehouse selected for each line
@@ -1187,11 +1249,13 @@  discard block
 block discarded – undo
1187 1249
 								break;
1188 1250
 							}
1189 1251
 						}
1190
-						if ($error) break; // break for loop incase of error
1252
+						if ($error) {
1253
+							break;
1254
+						}
1255
+						// break for loop incase of error
1191 1256
 					}
1192 1257
 				}
1193
-			}
1194
-			else
1258
+			} else
1195 1259
 			{
1196 1260
 				$error++;$this->errors[]="Error ".$this->db->lasterror();
1197 1261
 			}
@@ -1215,7 +1279,9 @@  discard block
 block discarded – undo
1215 1279
 			{
1216 1280
 				// Delete linked object
1217 1281
 				$res = $this->deleteObjectLinked();
1218
-				if ($res < 0) $error++;
1282
+				if ($res < 0) {
1283
+					$error++;
1284
+				}
1219 1285
 
1220 1286
 				if (! $error)
1221 1287
 				{
@@ -1233,10 +1299,12 @@  discard block
 block discarded – undo
1233 1299
 						{
1234 1300
 						    $this->fetch_origin();
1235 1301
 						    $origin=$this->origin;
1236
-						    if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS)     // If order source of shipment is "shipment in progress"
1302
+						    if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) {
1303
+						    	// If order source of shipment is "shipment in progress"
1237 1304
 						    {
1238 1305
                                 // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress"
1239 1306
 						        $this->$origin->loadExpeditions();
1307
+						    }
1240 1308
 						        //var_dump($this->$origin->expeditions);exit;
1241 1309
 						        if (count($this->$origin->expeditions) <= 0)
1242 1310
 						        {
@@ -1273,35 +1341,30 @@  discard block
 block discarded – undo
1273 1341
 							}
1274 1342
 
1275 1343
 							return 1;
1276
-						}
1277
-						else
1344
+						} else
1278 1345
 						{
1279 1346
 							$this->db->rollback();
1280 1347
 							return -1;
1281 1348
 						}
1282
-					}
1283
-					else
1349
+					} else
1284 1350
 					{
1285 1351
 						$this->error=$this->db->lasterror()." - sql=$sql";
1286 1352
 						$this->db->rollback();
1287 1353
 						return -3;
1288 1354
 					}
1289
-				}
1290
-				else
1355
+				} else
1291 1356
 				{
1292 1357
 					$this->error=$this->db->lasterror()." - sql=$sql";
1293 1358
 					$this->db->rollback();
1294 1359
 					return -2;
1295 1360
 				}
1296
-			}
1297
-			else
1361
+			} else
1298 1362
 			{
1299 1363
 				$this->error=$this->db->lasterror()." - sql=$sql";
1300 1364
 				$this->db->rollback();
1301 1365
 				return -1;
1302 1366
 			}
1303
-		}
1304
-		else
1367
+		} else
1305 1368
 		{
1306 1369
 			$this->db->rollback();
1307 1370
 			return -1;
@@ -1448,8 +1511,7 @@  discard block
 block discarded – undo
1448 1511
 	                    if ($originline != $obj->fk_origin_line)
1449 1512
 	                    {
1450 1513
 	                        $line->detail_batch = $newdetailbatch;
1451
-	                    }
1452
-	                    else
1514
+	                    } else
1453 1515
 						{
1454 1516
 	                        $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1455 1517
 	                    }
@@ -1460,8 +1522,7 @@  discard block
 block discarded – undo
1460 1522
 				{
1461 1523
 				    $this->lines[$lineindex] = $line;
1462 1524
 				    $lineindex++;
1463
-				}
1464
-				else
1525
+				} else
1465 1526
 				{
1466 1527
 				    $line->total_ht			+= $tabprice[0];
1467 1528
 				    $line->total_localtax1 	+= $tabprice[9];
@@ -1475,8 +1536,7 @@  discard block
 block discarded – undo
1475 1536
 			}
1476 1537
 			$this->db->free($resql);
1477 1538
 			return 1;
1478
-		}
1479
-		else
1539
+		} else
1480 1540
 		{
1481 1541
 			$this->error=$this->db->error();
1482 1542
 			return -3;
@@ -1505,14 +1565,20 @@  discard block
 block discarded – undo
1505 1565
 
1506 1566
 		$url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id;
1507 1567
 
1508
-		if ($short) return $url;
1568
+		if ($short) {
1569
+			return $url;
1570
+		}
1509 1571
 
1510 1572
 		if ($option !== 'nolink')
1511 1573
 		{
1512 1574
 			// Add param to save lastsearch_values or not
1513 1575
 			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1514
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1515
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1576
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
1577
+				$add_save_lastsearch_values=1;
1578
+			}
1579
+			if ($add_save_lastsearch_values) {
1580
+				$url.='&save_lastsearch_values=1';
1581
+			}
1516 1582
 		}
1517 1583
 
1518 1584
 		$linkclose='';
@@ -1532,8 +1598,12 @@  discard block
 block discarded – undo
1532 1598
 
1533 1599
 		$picto='sending';
1534 1600
 
1535
-		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1536
-		if ($withpicto && $withpicto != 2) $result.=' ';
1601
+		if ($withpicto) {
1602
+			$result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
1603
+		}
1604
+		if ($withpicto && $withpicto != 2) {
1605
+			$result.=' ';
1606
+		}
1537 1607
 		$result.=$linkstart.$this->ref.$linkend;
1538 1608
 		return $result;
1539 1609
 	}
@@ -1562,33 +1632,63 @@  discard block
 block discarded – undo
1562 1632
 
1563 1633
 		if ($mode==0)
1564 1634
 		{
1565
-			if ($statut==0) return $langs->trans($this->statuts[$statut]);
1566
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1567
-			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1635
+			if ($statut==0) {
1636
+				return $langs->trans($this->statuts[$statut]);
1637
+			}
1638
+			if ($statut==1) {
1639
+				return $langs->trans($this->statuts[$statut]);
1640
+			}
1641
+			if ($statut==2) {
1642
+				return $langs->trans($this->statuts[$statut]);
1643
+			}
1568 1644
 		}
1569 1645
 		if ($mode==1)
1570 1646
 		{
1571
-			if ($statut==0) return $langs->trans('StatusSendingDraftShort');
1572
-			if ($statut==1) return $langs->trans('StatusSendingValidatedShort');
1573
-			if ($statut==2) return $langs->trans('StatusSendingProcessedShort');
1647
+			if ($statut==0) {
1648
+				return $langs->trans('StatusSendingDraftShort');
1649
+			}
1650
+			if ($statut==1) {
1651
+				return $langs->trans('StatusSendingValidatedShort');
1652
+			}
1653
+			if ($statut==2) {
1654
+				return $langs->trans('StatusSendingProcessedShort');
1655
+			}
1574 1656
 		}
1575 1657
 		if ($mode == 3)
1576 1658
 		{
1577
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1578
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1579
-			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6');
1659
+			if ($statut==0) {
1660
+				return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1661
+			}
1662
+			if ($statut==1) {
1663
+				return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1664
+			}
1665
+			if ($statut==2) {
1666
+				return img_picto($langs->trans('StatusSendingProcessed'),'statut6');
1667
+			}
1580 1668
 		}
1581 1669
 		if ($mode == 4)
1582 1670
 		{
1583
-			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1584
-			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1585
-			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6').' '.$langs->trans('StatusSendingProcessed');
1671
+			if ($statut==0) {
1672
+				return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1673
+			}
1674
+			if ($statut==1) {
1675
+				return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1676
+			}
1677
+			if ($statut==2) {
1678
+				return img_picto($langs->trans('StatusSendingProcessed'),'statut6').' '.$langs->trans('StatusSendingProcessed');
1679
+			}
1586 1680
 		}
1587 1681
 		if ($mode == 5)
1588 1682
 		{
1589
-			if ($statut==0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1590
-			if ($statut==1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1591
-			if ($statut==2) return $langs->trans('StatusSendingProcessedShort').' '.img_picto($langs->trans('StatusSendingProcessedShort'),'statut6');
1683
+			if ($statut==0) {
1684
+				return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1685
+			}
1686
+			if ($statut==1) {
1687
+				return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1688
+			}
1689
+			if ($statut==2) {
1690
+				return $langs->trans('StatusSendingProcessedShort').' '.img_picto($langs->trans('StatusSendingProcessedShort'),'statut6');
1691
+			}
1592 1692
 		}
1593 1693
 	}
1594 1694
 
@@ -1693,14 +1793,12 @@  discard block
 block discarded – undo
1693 1793
 			{
1694 1794
 				$this->date_delivery = $date_livraison;
1695 1795
 				return 1;
1696
-			}
1697
-			else
1796
+			} else
1698 1797
 			{
1699 1798
 				$this->error=$this->db->error();
1700 1799
 				return -1;
1701 1800
 			}
1702
-		}
1703
-		else
1801
+		} else
1704 1802
 		{
1705 1803
 			return -2;
1706 1804
 		}
@@ -1747,7 +1845,9 @@  discard block
 block discarded – undo
1747 1845
 
1748 1846
         $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1749 1847
         $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1750
-        if ($id!='') $sql.= " WHERE em.rowid=".$id;
1848
+        if ($id!='') {
1849
+        	$sql.= " WHERE em.rowid=".$id;
1850
+        }
1751 1851
 
1752 1852
         $resql = $this->db->query($sql);
1753 1853
         if ($resql)
@@ -1780,8 +1880,7 @@  discard block
 block discarded – undo
1780 1880
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)";
1781 1881
             $sql.=" VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')";
1782 1882
             $resql = $this->db->query($sql);
1783
-        }
1784
-        else
1883
+        } else
1785 1884
         {
1786 1885
             $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET";
1787 1886
             $sql.= " code='".$this->db->escape($this->update['code'])."'";
@@ -1791,7 +1890,9 @@  discard block
 block discarded – undo
1791 1890
             $sql.= " WHERE rowid=".$id;
1792 1891
             $resql = $this->db->query($sql);
1793 1892
         }
1794
-        if ($resql < 0) dol_print_error($this->db,'');
1893
+        if ($resql < 0) {
1894
+        	dol_print_error($this->db,'');
1895
+        }
1795 1896
     }
1796 1897
 
1797 1898
     /**
@@ -1855,8 +1956,7 @@  discard block
 block discarded – undo
1855 1956
 		{
1856 1957
 			$url = str_replace('{TRACKID}', $value, $tracking);
1857 1958
 			$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1858
-		}
1859
-		else
1959
+		} else
1860 1960
 		{
1861 1961
 			$this->tracking_url = $value;
1862 1962
 		}
@@ -1941,12 +2041,13 @@  discard block
 block discarded – undo
1941 2041
 						if (empty($obj->edbrowid))
1942 2042
 						{
1943 2043
 							$qty = $obj->qty;
1944
-						}
1945
-						else
2044
+						} else
1946 2045
 						{
1947 2046
 							$qty = $obj->edbqty;
1948 2047
 						}
1949
-						if ($qty <= 0) continue;
2048
+						if ($qty <= 0) {
2049
+							continue;
2050
+						}
1950 2051
 						dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
1951 2052
 
1952 2053
 						$mouvS = new MouvementStock($this->db);
@@ -1963,8 +2064,7 @@  discard block
 block discarded – undo
1963 2064
 							    $this->errors = $mouvS->errors;
1964 2065
 								$error++; break;
1965 2066
 							}
1966
-						}
1967
-						else
2067
+						} else
1968 2068
 						{
1969 2069
 							// line with batch detail
1970 2070
 
@@ -1977,8 +2077,7 @@  discard block
 block discarded – undo
1977 2077
 							}
1978 2078
 						}
1979 2079
 					}
1980
-				}
1981
-				else
2080
+				} else
1982 2081
 				{
1983 2082
 					$this->error=$this->db->lasterror();
1984 2083
 					$error++;
@@ -1993,8 +2092,7 @@  discard block
 block discarded – undo
1993 2092
     			    $error++;
1994 2093
     			}
1995 2094
 			}
1996
-		}
1997
-		else
2095
+		} else
1998 2096
 		{
1999 2097
 			dol_print_error($this->db);
2000 2098
             $error++;
@@ -2004,8 +2102,7 @@  discard block
 block discarded – undo
2004 2102
 		{
2005 2103
 		    $this->db->commit();
2006 2104
 		    return 1;
2007
-		}
2008
-		else
2105
+		} else
2009 2106
 		{
2010 2107
 		    $this->db->rollback();
2011 2108
 		    return -1;
@@ -2047,8 +2144,7 @@  discard block
 block discarded – undo
2047 2144
 		if (empty($error)) {
2048 2145
 			$this->db->commit();
2049 2146
 			return 1;
2050
-		}
2051
-		else
2147
+		} else
2052 2148
 		{
2053 2149
 			$this->db->rollback();
2054 2150
 			return -1;
@@ -2106,12 +2202,13 @@  discard block
 block discarded – undo
2106 2202
 						if (empty($obj->edbrowid))
2107 2203
 						{
2108 2204
 							$qty = $obj->qty;
2109
-						}
2110
-						else
2205
+						} else
2111 2206
 						{
2112 2207
 							$qty = $obj->edbqty;
2113 2208
 						}
2114
-						if ($qty <= 0) continue;
2209
+						if ($qty <= 0) {
2210
+							continue;
2211
+						}
2115 2212
 						dol_syslog(get_class($this)."::reopen expedition movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
2116 2213
 
2117 2214
 						//var_dump($this->lines[$i]);
@@ -2129,8 +2226,7 @@  discard block
 block discarded – undo
2129 2226
 							    $this->errors = $mouvS->errors;
2130 2227
 								$error++; break;
2131 2228
 							}
2132
-						}
2133
-						else
2229
+						} else
2134 2230
 						{
2135 2231
 							// line with batch detail
2136 2232
 
@@ -2143,8 +2239,7 @@  discard block
 block discarded – undo
2143 2239
 							}
2144 2240
 						}
2145 2241
 					}
2146
-				}
2147
-				else
2242
+				} else
2148 2243
 				{
2149 2244
 					$this->error=$this->db->lasterror();
2150 2245
 					$error++;
@@ -2169,8 +2264,7 @@  discard block
 block discarded – undo
2169 2264
 		{
2170 2265
 			$this->db->commit();
2171 2266
 			return 1;
2172
-		}
2173
-		else
2267
+		} else
2174 2268
 		{
2175 2269
 			$this->db->rollback();
2176 2270
 			return -1;
Please login to merge, or discard this patch.
htdocs/fourn/class/api_supplier_invoices.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -277,7 +277,7 @@
 block discarded – undo
277 277
     /**
278 278
      * Clean sensible object datas
279 279
      *
280
-     * @param   Object  $object    Object to clean
280
+     * @param   FactureFournisseur  $object    Object to clean
281 281
      * @return  array              Array of cleaned object properties
282 282
      */
283 283
     function _cleanObjectDatas($object) {
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
      */
64 64
     function get($id)
65 65
     {
66
-		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->lire) {
66
+		if (!DolibarrApiAccess::$user->rights->fournisseur->facture->lire) {
67 67
 			throw new RestException(401);
68 68
 		}
69 69
 
70 70
         $result = $this->invoice->fetch($id);
71
-        if( ! $result ) {
71
+        if (!$result) {
72 72
             throw new RestException(404, 'Supplier invoice not found');
73 73
         }
74 74
 
75
-		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
75
+		if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
76 76
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
77 77
 		}
78 78
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      *
96 96
 	 * @throws RestException
97 97
      */
98
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
98
+    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '') {
99 99
         global $db, $conf;
100 100
 
101 101
         $obj_ret = array();
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
 
106 106
         // If the internal user must only see his customers, force searching by him
107 107
         $search_sale = 0;
108
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
108
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
109 109
 
110 110
         $sql = "SELECT t.rowid";
111 111
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
112
-        $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
112
+        $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
113 113
 
114
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
114
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
115 115
 
116
-        $sql.= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
117
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
118
-        if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
119
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
116
+        $sql .= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
117
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
118
+        if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
119
+        if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
120 120
 
121 121
 		// Filter by status
122
-        if ($status == 'draft')     $sql.= " AND t.fk_statut IN (0)";
123
-        if ($status == 'unpaid')    $sql.= " AND t.fk_statut IN (1)";
124
-        if ($status == 'paid')      $sql.= " AND t.fk_statut IN (2)";
125
-        if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (3)";
122
+        if ($status == 'draft')     $sql .= " AND t.fk_statut IN (0)";
123
+        if ($status == 'unpaid')    $sql .= " AND t.fk_statut IN (1)";
124
+        if ($status == 'paid')      $sql .= " AND t.fk_statut IN (2)";
125
+        if ($status == 'cancelled') $sql .= " AND t.fk_statut IN (3)";
126 126
         // Insert sale filter
127 127
         if ($search_sale > 0)
128 128
         {
@@ -131,23 +131,23 @@  discard block
 block discarded – undo
131 131
         // Add sql filters
132 132
         if ($sqlfilters)
133 133
         {
134
-            if (! DolibarrApi::_checkFilters($sqlfilters))
134
+            if (!DolibarrApi::_checkFilters($sqlfilters))
135 135
             {
136 136
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
137 137
             }
138
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
139
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
138
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
139
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
140 140
         }
141 141
 
142
-        $sql.= $db->order($sortfield, $sortorder);
143
-        if ($limit)	{
142
+        $sql .= $db->order($sortfield, $sortorder);
143
+        if ($limit) {
144 144
             if ($page < 0)
145 145
             {
146 146
                 $page = 0;
147 147
             }
148 148
             $offset = $limit * $page;
149 149
 
150
-            $sql.= $db->plimit($limit + 1, $offset);
150
+            $sql .= $db->plimit($limit + 1, $offset);
151 151
         }
152 152
 
153 153
         $result = $db->query($sql);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             {
161 161
                 $obj = $db->fetch_object($result);
162 162
                 $invoice_static = new FactureFournisseur($db);
163
-                if($invoice_static->fetch($obj->rowid)) {
163
+                if ($invoice_static->fetch($obj->rowid)) {
164 164
                     $obj_ret[] = $this->_cleanObjectDatas($invoice_static);
165 165
                 }
166 166
                 $i++;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         else {
170 170
             throw new RestException(503, 'Error when retrieve supplier invoice list : '.$db->lasterror());
171 171
         }
172
-        if( ! count($obj_ret)) {
172
+        if (!count($obj_ret)) {
173 173
             throw new RestException(404, 'No supplier invoice found');
174 174
         }
175 175
 		return $obj_ret;
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
      */
184 184
     function post($request_data = NULL)
185 185
     {
186
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
186
+        if (!DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
187 187
 			throw new RestException(401, "Insuffisant rights");
188 188
 		}
189 189
         // Check mandatory fields
190 190
         $result = $this->_validate($request_data);
191 191
 
192
-        foreach($request_data as $field => $value) {
192
+        foreach ($request_data as $field => $value) {
193 193
             $this->invoice->$field = $value;
194 194
         }
195
-        if(! array_keys($request_data,'date')) {
195
+        if (!array_keys($request_data, 'date')) {
196 196
             $this->invoice->date = dol_now();
197 197
         }
198 198
         /* We keep lines as an array
@@ -219,26 +219,26 @@  discard block
 block discarded – undo
219 219
      */
220 220
     function put($id, $request_data = NULL)
221 221
     {
222
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
222
+        if (!DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
223 223
 			throw new RestException(401);
224 224
 		}
225 225
 
226 226
         $result = $this->invoice->fetch($id);
227
-        if( ! $result ) {
227
+        if (!$result) {
228 228
             throw new RestException(404, 'Supplier invoice not found');
229 229
         }
230 230
 
231
-		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
231
+		if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
232 232
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
233 233
 		}
234 234
 
235
-        foreach($request_data as $field => $value) {
235
+        foreach ($request_data as $field => $value) {
236 236
             if ($field == 'id') continue;
237 237
             $this->invoice->$field = $value;
238 238
         }
239 239
 
240
-        if($this->invoice->update($id, DolibarrApiAccess::$user))
241
-            return $this->get ($id);
240
+        if ($this->invoice->update($id, DolibarrApiAccess::$user))
241
+            return $this->get($id);
242 242
 
243 243
         return false;
244 244
     }
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
      */
252 252
     function delete($id)
253 253
     {
254
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->supprimer) {
254
+        if (!DolibarrApiAccess::$user->rights->fournisseur->facture->supprimer) {
255 255
 			throw new RestException(401);
256 256
 		}
257 257
         $result = $this->invoice->fetch($id);
258
-        if( ! $result ) {
258
+        if (!$result) {
259 259
             throw new RestException(404, 'Supplier invoice not found');
260 260
         }
261 261
 
262
-		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
262
+		if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
263 263
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
264 264
 		}
265 265
 
266
-        if( $this->invoice->delete(DolibarrApiAccess::$user) < 0)
266
+        if ($this->invoice->delete(DolibarrApiAccess::$user) < 0)
267 267
         {
268 268
             throw new RestException(500);
269 269
         }
@@ -295,17 +295,17 @@  discard block
 block discarded – undo
295 295
      *   "notrigger": 0
296 296
      * }
297 297
      */
298
-    function validate($id, $idwarehouse=0, $notrigger=0)
298
+    function validate($id, $idwarehouse = 0, $notrigger = 0)
299 299
     {
300
-    	if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
300
+    	if (!DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
301 301
     		throw new RestException(401);
302 302
     	}
303 303
     	$result = $this->invoice->fetch($id);
304
-    	if( ! $result ) {
304
+    	if (!$result) {
305 305
     		throw new RestException(404, 'Invoice not found');
306 306
     	}
307 307
 
308
-		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
308
+		if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
309 309
     		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
310 310
     	}
311 311
 
Please login to merge, or discard this patch.
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -28,174 +28,174 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class SupplierInvoices extends DolibarrApi
30 30
 {
31
-    /**
32
-     *
33
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
-     */
35
-    static $FIELDS = array(
36
-        'socid'
37
-    );
38
-
39
-    /**
40
-     * @var FactureFournisseur $invoice {@type FactureFournisseur}
41
-     */
42
-    public $invoice;
43
-
44
-    /**
45
-     * Constructor
46
-     */
47
-    function __construct()
48
-    {
31
+	/**
32
+	 *
33
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
+	 */
35
+	static $FIELDS = array(
36
+		'socid'
37
+	);
38
+
39
+	/**
40
+	 * @var FactureFournisseur $invoice {@type FactureFournisseur}
41
+	 */
42
+	public $invoice;
43
+
44
+	/**
45
+	 * Constructor
46
+	 */
47
+	function __construct()
48
+	{
49 49
 		global $db, $conf;
50 50
 		$this->db = $db;
51
-        $this->invoice = new FactureFournisseur($this->db);
52
-    }
53
-
54
-    /**
55
-     * Get properties of a supplier invoice object
56
-     *
57
-     * Return an array with supplier invoice information
58
-     *
59
-     * @param 	int 	$id ID of supplier invoice
60
-     * @return 	array|mixed data without useless information
61
-     *
62
-     * @throws 	RestException
63
-     */
64
-    function get($id)
65
-    {
51
+		$this->invoice = new FactureFournisseur($this->db);
52
+	}
53
+
54
+	/**
55
+	 * Get properties of a supplier invoice object
56
+	 *
57
+	 * Return an array with supplier invoice information
58
+	 *
59
+	 * @param 	int 	$id ID of supplier invoice
60
+	 * @return 	array|mixed data without useless information
61
+	 *
62
+	 * @throws 	RestException
63
+	 */
64
+	function get($id)
65
+	{
66 66
 		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->lire) {
67 67
 			throw new RestException(401);
68 68
 		}
69 69
 
70
-        $result = $this->invoice->fetch($id);
71
-        if( ! $result ) {
72
-            throw new RestException(404, 'Supplier invoice not found');
73
-        }
70
+		$result = $this->invoice->fetch($id);
71
+		if( ! $result ) {
72
+			throw new RestException(404, 'Supplier invoice not found');
73
+		}
74 74
 
75 75
 		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
76 76
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
77 77
 		}
78 78
 
79 79
 		return $this->_cleanObjectDatas($this->invoice);
80
-    }
81
-
82
-    /**
83
-     * List invoices
84
-     *
85
-     * Get a list of supplier invoices
86
-     *
87
-     * @param string	$sortfield	      Sort field
88
-     * @param string	$sortorder	      Sort order
89
-     * @param int		$limit		      Limit for list
90
-     * @param int		$page		      Page number
91
-     * @param string   	$thirdparty_ids	  Thirdparty ids to filter invoices of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
92
-     * @param string	$status		      Filter by invoice status : draft | unpaid | paid | cancelled
93
-     * @param string    $sqlfilters       Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
94
-     * @return array                      Array of invoice objects
95
-     *
80
+	}
81
+
82
+	/**
83
+	 * List invoices
84
+	 *
85
+	 * Get a list of supplier invoices
86
+	 *
87
+	 * @param string	$sortfield	      Sort field
88
+	 * @param string	$sortorder	      Sort order
89
+	 * @param int		$limit		      Limit for list
90
+	 * @param int		$page		      Page number
91
+	 * @param string   	$thirdparty_ids	  Thirdparty ids to filter invoices of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
92
+	 * @param string	$status		      Filter by invoice status : draft | unpaid | paid | cancelled
93
+	 * @param string    $sqlfilters       Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
94
+	 * @return array                      Array of invoice objects
95
+	 *
96 96
 	 * @throws RestException
97
-     */
98
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
99
-        global $db, $conf;
97
+	 */
98
+	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
99
+		global $db, $conf;
100 100
 
101
-        $obj_ret = array();
101
+		$obj_ret = array();
102 102
 
103
-        // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
104
-        $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
103
+		// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
104
+		$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
105 105
 
106
-        // If the internal user must only see his customers, force searching by him
107
-        $search_sale = 0;
108
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
106
+		// If the internal user must only see his customers, force searching by him
107
+		$search_sale = 0;
108
+		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
109 109
 
110
-        $sql = "SELECT t.rowid";
111
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
112
-        $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
110
+		$sql = "SELECT t.rowid";
111
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
112
+		$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
113 113
 
114
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
114
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
115 115
 
116
-        $sql.= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
117
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
118
-        if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
119
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
116
+		$sql.= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
117
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
118
+		if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
119
+		if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
120 120
 
121 121
 		// Filter by status
122
-        if ($status == 'draft')     $sql.= " AND t.fk_statut IN (0)";
123
-        if ($status == 'unpaid')    $sql.= " AND t.fk_statut IN (1)";
124
-        if ($status == 'paid')      $sql.= " AND t.fk_statut IN (2)";
125
-        if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (3)";
126
-        // Insert sale filter
127
-        if ($search_sale > 0)
128
-        {
129
-            $sql .= " AND sc.fk_user = ".$search_sale;
130
-        }
131
-        // Add sql filters
132
-        if ($sqlfilters)
133
-        {
134
-            if (! DolibarrApi::_checkFilters($sqlfilters))
135
-            {
136
-                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
137
-            }
138
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
139
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
140
-        }
141
-
142
-        $sql.= $db->order($sortfield, $sortorder);
143
-        if ($limit)	{
144
-            if ($page < 0)
145
-            {
146
-                $page = 0;
147
-            }
148
-            $offset = $limit * $page;
149
-
150
-            $sql.= $db->plimit($limit + 1, $offset);
151
-        }
152
-
153
-        $result = $db->query($sql);
154
-        if ($result)
155
-        {
156
-            $i = 0;
157
-            $num = $db->num_rows($result);
158
-            $min = min($num, ($limit <= 0 ? $num : $limit));
159
-            while ($i < $min)
160
-            {
161
-                $obj = $db->fetch_object($result);
162
-                $invoice_static = new FactureFournisseur($db);
163
-                if($invoice_static->fetch($obj->rowid)) {
164
-                    $obj_ret[] = $this->_cleanObjectDatas($invoice_static);
165
-                }
166
-                $i++;
167
-            }
168
-        }
169
-        else {
170
-            throw new RestException(503, 'Error when retrieve supplier invoice list : '.$db->lasterror());
171
-        }
172
-        if( ! count($obj_ret)) {
173
-            throw new RestException(404, 'No supplier invoice found');
174
-        }
122
+		if ($status == 'draft')     $sql.= " AND t.fk_statut IN (0)";
123
+		if ($status == 'unpaid')    $sql.= " AND t.fk_statut IN (1)";
124
+		if ($status == 'paid')      $sql.= " AND t.fk_statut IN (2)";
125
+		if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (3)";
126
+		// Insert sale filter
127
+		if ($search_sale > 0)
128
+		{
129
+			$sql .= " AND sc.fk_user = ".$search_sale;
130
+		}
131
+		// Add sql filters
132
+		if ($sqlfilters)
133
+		{
134
+			if (! DolibarrApi::_checkFilters($sqlfilters))
135
+			{
136
+				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
137
+			}
138
+			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
139
+			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
140
+		}
141
+
142
+		$sql.= $db->order($sortfield, $sortorder);
143
+		if ($limit)	{
144
+			if ($page < 0)
145
+			{
146
+				$page = 0;
147
+			}
148
+			$offset = $limit * $page;
149
+
150
+			$sql.= $db->plimit($limit + 1, $offset);
151
+		}
152
+
153
+		$result = $db->query($sql);
154
+		if ($result)
155
+		{
156
+			$i = 0;
157
+			$num = $db->num_rows($result);
158
+			$min = min($num, ($limit <= 0 ? $num : $limit));
159
+			while ($i < $min)
160
+			{
161
+				$obj = $db->fetch_object($result);
162
+				$invoice_static = new FactureFournisseur($db);
163
+				if($invoice_static->fetch($obj->rowid)) {
164
+					$obj_ret[] = $this->_cleanObjectDatas($invoice_static);
165
+				}
166
+				$i++;
167
+			}
168
+		}
169
+		else {
170
+			throw new RestException(503, 'Error when retrieve supplier invoice list : '.$db->lasterror());
171
+		}
172
+		if( ! count($obj_ret)) {
173
+			throw new RestException(404, 'No supplier invoice found');
174
+		}
175 175
 		return $obj_ret;
176
-    }
177
-
178
-    /**
179
-     * Create supplier invoice object
180
-     *
181
-     * @param array $request_data   Request datas
182
-     * @return int  ID of supplier invoice
183
-     */
184
-    function post($request_data = NULL)
185
-    {
186
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
176
+	}
177
+
178
+	/**
179
+	 * Create supplier invoice object
180
+	 *
181
+	 * @param array $request_data   Request datas
182
+	 * @return int  ID of supplier invoice
183
+	 */
184
+	function post($request_data = NULL)
185
+	{
186
+		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
187 187
 			throw new RestException(401, "Insuffisant rights");
188 188
 		}
189
-        // Check mandatory fields
190
-        $result = $this->_validate($request_data);
191
-
192
-        foreach($request_data as $field => $value) {
193
-            $this->invoice->$field = $value;
194
-        }
195
-        if(! array_keys($request_data,'date')) {
196
-            $this->invoice->date = dol_now();
197
-        }
198
-        /* We keep lines as an array
189
+		// Check mandatory fields
190
+		$result = $this->_validate($request_data);
191
+
192
+		foreach($request_data as $field => $value) {
193
+			$this->invoice->$field = $value;
194
+		}
195
+		if(! array_keys($request_data,'date')) {
196
+			$this->invoice->date = dol_now();
197
+		}
198
+		/* We keep lines as an array
199 199
          if (isset($request_data["lines"])) {
200 200
             $lines = array();
201 201
             foreach ($request_data["lines"] as $line) {
@@ -204,158 +204,158 @@  discard block
 block discarded – undo
204 204
             $this->invoice->lines = $lines;
205 205
         }*/
206 206
 
207
-        if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
208
-            throw new RestException(500, "Error creating order", array_merge(array($this->invoice->error), $this->invoice->errors));
209
-        }
210
-        return $this->invoice->id;
211
-    }
212
-
213
-    /**
214
-     * Update supplier invoice
215
-     *
216
-     * @param int   $id             Id of supplier invoice to update
217
-     * @param array $request_data   Datas
218
-     * @return int
219
-     */
220
-    function put($id, $request_data = NULL)
221
-    {
222
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
207
+		if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
208
+			throw new RestException(500, "Error creating order", array_merge(array($this->invoice->error), $this->invoice->errors));
209
+		}
210
+		return $this->invoice->id;
211
+	}
212
+
213
+	/**
214
+	 * Update supplier invoice
215
+	 *
216
+	 * @param int   $id             Id of supplier invoice to update
217
+	 * @param array $request_data   Datas
218
+	 * @return int
219
+	 */
220
+	function put($id, $request_data = NULL)
221
+	{
222
+		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
223 223
 			throw new RestException(401);
224 224
 		}
225 225
 
226
-        $result = $this->invoice->fetch($id);
227
-        if( ! $result ) {
228
-            throw new RestException(404, 'Supplier invoice not found');
229
-        }
226
+		$result = $this->invoice->fetch($id);
227
+		if( ! $result ) {
228
+			throw new RestException(404, 'Supplier invoice not found');
229
+		}
230 230
 
231 231
 		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
232 232
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
233 233
 		}
234 234
 
235
-        foreach($request_data as $field => $value) {
236
-            if ($field == 'id') continue;
237
-            $this->invoice->$field = $value;
238
-        }
239
-
240
-        if($this->invoice->update($id, DolibarrApiAccess::$user))
241
-            return $this->get ($id);
242
-
243
-        return false;
244
-    }
245
-
246
-    /**
247
-     * Delete supplier invoice
248
-     *
249
-     * @param int   $id Supplier invoice ID
250
-     * @return type
251
-     */
252
-    function delete($id)
253
-    {
254
-        if(! DolibarrApiAccess::$user->rights->fournisseur->facture->supprimer) {
235
+		foreach($request_data as $field => $value) {
236
+			if ($field == 'id') continue;
237
+			$this->invoice->$field = $value;
238
+		}
239
+
240
+		if($this->invoice->update($id, DolibarrApiAccess::$user))
241
+			return $this->get ($id);
242
+
243
+		return false;
244
+	}
245
+
246
+	/**
247
+	 * Delete supplier invoice
248
+	 *
249
+	 * @param int   $id Supplier invoice ID
250
+	 * @return type
251
+	 */
252
+	function delete($id)
253
+	{
254
+		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->supprimer) {
255 255
 			throw new RestException(401);
256 256
 		}
257
-        $result = $this->invoice->fetch($id);
258
-        if( ! $result ) {
259
-            throw new RestException(404, 'Supplier invoice not found');
260
-        }
257
+		$result = $this->invoice->fetch($id);
258
+		if( ! $result ) {
259
+			throw new RestException(404, 'Supplier invoice not found');
260
+		}
261 261
 
262 262
 		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
263 263
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
264 264
 		}
265 265
 
266
-        if( $this->invoice->delete(DolibarrApiAccess::$user) < 0)
267
-        {
268
-            throw new RestException(500);
269
-        }
270
-
271
-         return array(
272
-            'success' => array(
273
-                'code' => 200,
274
-                'message' => 'Supplier invoice deleted'
275
-            )
276
-        );
277
-    }
278
-
279
-
280
-    /**
281
-     * Validate an order
282
-     *
283
-     * @param   int $id             Order ID
284
-     * @param   int $idwarehouse    Warehouse ID
285
-     * @param   int $notrigger      1=Does not execute triggers, 0= execute triggers
286
-     *
287
-     * @url POST    {id}/validate
288
-     *
289
-     * @return  array
290
-     * FIXME An error 403 is returned if the request has an empty body.
291
-     * Error message: "Forbidden: Content type `text/plain` is not supported."
292
-     * Workaround: send this in the body
293
-     * {
294
-     *   "idwarehouse": 0,
295
-     *   "notrigger": 0
296
-     * }
297
-     */
298
-    function validate($id, $idwarehouse=0, $notrigger=0)
299
-    {
300
-    	if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
301
-    		throw new RestException(401);
302
-    	}
303
-    	$result = $this->invoice->fetch($id);
304
-    	if( ! $result ) {
305
-    		throw new RestException(404, 'Invoice not found');
306
-    	}
266
+		if( $this->invoice->delete(DolibarrApiAccess::$user) < 0)
267
+		{
268
+			throw new RestException(500);
269
+		}
270
+
271
+		 return array(
272
+			'success' => array(
273
+				'code' => 200,
274
+				'message' => 'Supplier invoice deleted'
275
+			)
276
+		);
277
+	}
278
+
279
+
280
+	/**
281
+	 * Validate an order
282
+	 *
283
+	 * @param   int $id             Order ID
284
+	 * @param   int $idwarehouse    Warehouse ID
285
+	 * @param   int $notrigger      1=Does not execute triggers, 0= execute triggers
286
+	 *
287
+	 * @url POST    {id}/validate
288
+	 *
289
+	 * @return  array
290
+	 * FIXME An error 403 is returned if the request has an empty body.
291
+	 * Error message: "Forbidden: Content type `text/plain` is not supported."
292
+	 * Workaround: send this in the body
293
+	 * {
294
+	 *   "idwarehouse": 0,
295
+	 *   "notrigger": 0
296
+	 * }
297
+	 */
298
+	function validate($id, $idwarehouse=0, $notrigger=0)
299
+	{
300
+		if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
301
+			throw new RestException(401);
302
+		}
303
+		$result = $this->invoice->fetch($id);
304
+		if( ! $result ) {
305
+			throw new RestException(404, 'Invoice not found');
306
+		}
307 307
 
308 308
 		if( ! DolibarrApi::_checkAccessToResource('fournisseur',$this->invoice->id,'facture_fourn','facture')) {
309
-    		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
310
-    	}
311
-
312
-    	$result = $this->invoice->validate(DolibarrApiAccess::$user, '', $idwarehouse, $notrigger);
313
-    	if ($result == 0) {
314
-    		throw new RestException(500, 'Error nothing done. May be object is already validated');
315
-    	}
316
-    	if ($result < 0) {
317
-    		throw new RestException(500, 'Error when validating Invoice: '.$this->invoice->error);
318
-    	}
319
-
320
-    	return array(
321
-	    	'success' => array(
322
-		    	'code' => 200,
323
-		    	'message' => 'Invoice validated (Ref='.$this->invoice->ref.')'
324
-	    	)
325
-    	);
326
-    }
327
-
328
-    /**
329
-     * Clean sensible object datas
330
-     *
331
-     * @param   Object  $object    Object to clean
332
-     * @return  array              Array of cleaned object properties
333
-     */
334
-    function _cleanObjectDatas($object) {
335
-
336
-        $object = parent::_cleanObjectDatas($object);
337
-
338
-        unset($object->rowid);
339
-
340
-        return $object;
341
-    }
342
-
343
-    /**
344
-     * Validate fields before create or update object
345
-     *
346
-     * @param array $data   Datas to validate
347
-     * @return array
348
-     *
349
-     * @throws RestException
350
-     */
351
-    function _validate($data)
352
-    {
353
-        $invoice = array();
354
-        foreach (SupplierInvoices::$FIELDS as $field) {
355
-            if (!isset($data[$field]))
356
-                throw new RestException(400, "$field field missing");
357
-            $invoice[$field] = $data[$field];
358
-        }
359
-        return $invoice;
360
-    }
309
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
310
+		}
311
+
312
+		$result = $this->invoice->validate(DolibarrApiAccess::$user, '', $idwarehouse, $notrigger);
313
+		if ($result == 0) {
314
+			throw new RestException(500, 'Error nothing done. May be object is already validated');
315
+		}
316
+		if ($result < 0) {
317
+			throw new RestException(500, 'Error when validating Invoice: '.$this->invoice->error);
318
+		}
319
+
320
+		return array(
321
+			'success' => array(
322
+				'code' => 200,
323
+				'message' => 'Invoice validated (Ref='.$this->invoice->ref.')'
324
+			)
325
+		);
326
+	}
327
+
328
+	/**
329
+	 * Clean sensible object datas
330
+	 *
331
+	 * @param   Object  $object    Object to clean
332
+	 * @return  array              Array of cleaned object properties
333
+	 */
334
+	function _cleanObjectDatas($object) {
335
+
336
+		$object = parent::_cleanObjectDatas($object);
337
+
338
+		unset($object->rowid);
339
+
340
+		return $object;
341
+	}
342
+
343
+	/**
344
+	 * Validate fields before create or update object
345
+	 *
346
+	 * @param array $data   Datas to validate
347
+	 * @return array
348
+	 *
349
+	 * @throws RestException
350
+	 */
351
+	function _validate($data)
352
+	{
353
+		$invoice = array();
354
+		foreach (SupplierInvoices::$FIELDS as $field) {
355
+			if (!isset($data[$field]))
356
+				throw new RestException(400, "$field field missing");
357
+			$invoice[$field] = $data[$field];
358
+		}
359
+		return $invoice;
360
+	}
361 361
 }
Please login to merge, or discard this patch.
Braces   +43 added lines, -17 removed lines patch added patch discarded remove patch
@@ -105,24 +105,47 @@  discard block
 block discarded – undo
105 105
 
106 106
         // If the internal user must only see his customers, force searching by him
107 107
         $search_sale = 0;
108
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
108
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
109
+        	$search_sale = DolibarrApiAccess::$user->id;
110
+        }
109 111
 
110 112
         $sql = "SELECT t.rowid";
111
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
113
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
114
+        	$sql .= ", sc.fk_soc, sc.fk_user";
115
+        }
116
+        // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
112 117
         $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
113 118
 
114
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
119
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
120
+        	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
121
+        }
122
+        // We need this table joined to the select in order to filter by sale
115 123
 
116 124
         $sql.= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')';
117
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
118
-        if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
119
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
125
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
126
+        	$sql.= " AND t.fk_soc = sc.fk_soc";
127
+        }
128
+        if ($socids) {
129
+        	$sql.= " AND t.fk_soc IN (".$socids.")";
130
+        }
131
+        if ($search_sale > 0) {
132
+        	$sql.= " AND t.rowid = sc.fk_soc";
133
+        }
134
+        // Join for the needed table to filter by sale
120 135
 
121 136
 		// Filter by status
122
-        if ($status == 'draft')     $sql.= " AND t.fk_statut IN (0)";
123
-        if ($status == 'unpaid')    $sql.= " AND t.fk_statut IN (1)";
124
-        if ($status == 'paid')      $sql.= " AND t.fk_statut IN (2)";
125
-        if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (3)";
137
+        if ($status == 'draft') {
138
+        	$sql.= " AND t.fk_statut IN (0)";
139
+        }
140
+        if ($status == 'unpaid') {
141
+        	$sql.= " AND t.fk_statut IN (1)";
142
+        }
143
+        if ($status == 'paid') {
144
+        	$sql.= " AND t.fk_statut IN (2)";
145
+        }
146
+        if ($status == 'cancelled') {
147
+        	$sql.= " AND t.fk_statut IN (3)";
148
+        }
126 149
         // Insert sale filter
127 150
         if ($search_sale > 0)
128 151
         {
@@ -165,8 +188,7 @@  discard block
 block discarded – undo
165 188
                 }
166 189
                 $i++;
167 190
             }
168
-        }
169
-        else {
191
+        } else {
170 192
             throw new RestException(503, 'Error when retrieve supplier invoice list : '.$db->lasterror());
171 193
         }
172 194
         if( ! count($obj_ret)) {
@@ -233,12 +255,15 @@  discard block
 block discarded – undo
233 255
 		}
234 256
 
235 257
         foreach($request_data as $field => $value) {
236
-            if ($field == 'id') continue;
258
+            if ($field == 'id') {
259
+            	continue;
260
+            }
237 261
             $this->invoice->$field = $value;
238 262
         }
239 263
 
240
-        if($this->invoice->update($id, DolibarrApiAccess::$user))
241
-            return $this->get ($id);
264
+        if($this->invoice->update($id, DolibarrApiAccess::$user)) {
265
+                    return $this->get ($id);
266
+        }
242 267
 
243 268
         return false;
244 269
     }
@@ -352,8 +377,9 @@  discard block
 block discarded – undo
352 377
     {
353 378
         $invoice = array();
354 379
         foreach (SupplierInvoices::$FIELDS as $field) {
355
-            if (!isset($data[$field]))
356
-                throw new RestException(400, "$field field missing");
380
+            if (!isset($data[$field])) {
381
+                            throw new RestException(400, "$field field missing");
382
+            }
357 383
             $invoice[$field] = $data[$field];
358 384
         }
359 385
         return $invoice;
Please login to merge, or discard this patch.
htdocs/core/class/html.formprojet.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -446,7 +446,7 @@
 block discarded – undo
446 446
 	 *    Build a HTML select list of element of same thirdparty to suggest to link them to project
447 447
 	 *
448 448
 	 *    @param	string		$table_element		Table of the element to update
449
-	 *    @param	string		$socid				If of thirdparty to use as filter or 'id1,id2,...'
449
+	 *    @param	integer		$socid				If of thirdparty to use as filter or 'id1,id2,...'
450 450
 	 *    @param	string		$morecss			More CSS
451 451
 	 *    @param    int         $limitonstatus      Add filters to limit length of list to opened status (for example to avoid ERR_RESPONSE_HEADERS_TOO_BIG on project/element.php page). TODO To implement
452 452
 	 *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -94,18 +94,18 @@  discard block
 block discarded – undo
94 94
 			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid);
95 95
 			if ($discard_closed)
96 96
 			{
97
-			    if (class_exists('Form'))
98
-			    {
99
-    			    if (empty($form)) $form=new Form($this->db);
100
-                    $out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
101
-			    }
97
+				if (class_exists('Form'))
98
+				{
99
+					if (empty($form)) $form=new Form($this->db);
100
+					$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
101
+				}
102 102
 			}
103 103
 		}
104 104
 
105 105
 		if (empty($nooutput))
106 106
 		{
107
-		    print $out;
108
-		    return '';
107
+			print $out;
108
+			return '';
109 109
 		}
110 110
 		else return $out;
111 111
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  int     $option_only	       Return only html options lines without the select tag
121 121
 	 * @param  int     $show_empty		   Add an empty line
122 122
 	 * @param  int     $discard_closed     Discard closed projects (0=Keep,1=hide completely,2=Disable)
123
-     * @param  int     $forcefocus		   Force focus on field (works with javascript only)
124
-     * @param  int     $disabled           Disabled
123
+	 * @param  int     $forcefocus		   Force focus on field (works with javascript only)
124
+	 * @param  int     $disabled           Disabled
125 125
 	 * @param  int     $mode               0 for HTML mode and 1 for array return (to be used by json_encode for example)
126 126
 	 * @param  string  $filterkey          Key to filter
127 127
 	 * @param  int     $nooutput           No print output. Return it only.
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 		if (empty($htmlid)) $htmlid = $htmlname;
139 139
 
140 140
 		$out='';
141
-        $outarray=array();
141
+		$outarray=array();
142 142
 
143 143
 		$hideunselectables = false;
144 144
 		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
159 159
 		if ($socid > 0)
160 160
 		{
161
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
162
-		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
163
-		    {
164
-		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
165
-		    }
161
+			if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
162
+			else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
163
+			{
164
+				$sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
165
+			}
166 166
 		}
167 167
 		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
168 168
 		$sql.= " ORDER BY p.ref ASC";
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 			if (! empty($conf->use_javascript_ajax))
177 177
 			{
178 178
 				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
179
-	           	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
180
-            	$out.=$comboenhancement;
181
-            	$morecss='minwidth100 maxwidth300';
179
+			   	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
180
+				$out.=$comboenhancement;
181
+				$morecss='minwidth100 maxwidth300';
182 182
 			}
183 183
 
184 184
 			if (empty($option_only)) {
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 						$labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
214 214
 						if ($obj->name)
215 215
 						{
216
-						    $labeltoshow.=' - '.$obj->name;
217
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
216
+							$labeltoshow.=' - '.$obj->name;
217
+							if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
218 218
 						}
219 219
 
220 220
 						$disabled=0;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 				if (empty($option_only)) $out.= '</select>';
278 278
 				if (empty($nooutput))
279 279
 				{
280
-				    print $out;
281
-				    return '';
280
+					print $out;
281
+					return '';
282 282
 				}
283 283
 				else return $out;
284 284
 			} else {
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 *	@param	int		$option_only	Return only html options lines without the select tag
303 303
 	 *	@param	string	$show_empty		Add an empty line ('1' or string to show for empty line)
304 304
 	 *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
305
-     *  @param	int		$forcefocus		Force focus on field (works with javascript only)
306
-     *  @param	int		$disabled		Disabled
305
+	 *  @param	int		$forcefocus		Force focus on field (works with javascript only)
306
+	 *  @param	int		$disabled		Disabled
307 307
 	 *  @param	string	$morecss        More css added to the select component
308 308
 	 *	@return int         			Nbr of project if OK, <0 if KO
309 309
 	 */
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 			if (! empty($conf->use_javascript_ajax))
346 346
 			{
347 347
 				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
348
-	           	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
349
-            	$out.=$comboenhancement;
350
-            	$morecss='minwidth200 maxwidth500';
348
+			   	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
349
+				$out.=$comboenhancement;
350
+				$morecss='minwidth200 maxwidth500';
351 351
 			}
352 352
 
353 353
 			if (empty($option_only)) {
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 				break;
485 485
 			case "commande_fourn":
486 486
 			case "commande_fournisseur":
487
-			    $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
487
+				$sql = "SELECT t.rowid, t.ref, t.ref_supplier";
488 488
 				break;
489 489
 			case "facture_rec":
490 490
 				$sql = "SELECT t.rowid, t.titre as ref";
@@ -501,10 +501,10 @@  discard block
 block discarded – undo
501 501
 				break;*/
502 502
 				return '';
503 503
 			case "commande":
504
-		    case "contrat":
504
+			case "contrat":
505 505
 			case "fichinter":
506
-			    $sql = "SELECT t.rowid, t.ref";
507
-			    break;
506
+				$sql = "SELECT t.rowid, t.ref";
507
+				break;
508 508
 			case 'stock_mouvement':
509 509
 				$sql = 'SELECT t.rowid, t.label as ref';
510 510
 				$projectkey='fk_origin';
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
 		$sql.= " WHERE ".$projectkey." is null";
521 521
 		if (! empty($socid) && $linkedtothirdparty)
522 522
 		{
523
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
524
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
523
+			if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
524
+			else $sql.= " AND t.fk_soc IN (".$socid.")";
525 525
 		}
526 526
 		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
527 527
 		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
Please login to merge, or discard this patch.
Braces   +136 added lines, -73 removed lines patch added patch discarded remove patch
@@ -88,15 +88,16 @@  discard block
 block discarded – undo
88 88
 			));
89 89
 
90 90
 			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
91
-		}
92
-		else
91
+		} else
93 92
 		{
94 93
 			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid);
95 94
 			if ($discard_closed)
96 95
 			{
97 96
 			    if (class_exists('Form'))
98 97
 			    {
99
-    			    if (empty($form)) $form=new Form($this->db);
98
+    			    if (empty($form)) {
99
+    			    	$form=new Form($this->db);
100
+    			    }
100 101
                     $out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
101 102
 			    }
102 103
 			}
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 		{
107 108
 		    print $out;
108 109
 		    return '';
110
+		} else {
111
+			return $out;
109 112
 		}
110
-		else return $out;
111 113
 	}
112 114
 
113 115
 	/**
@@ -135,13 +137,17 @@  discard block
 block discarded – undo
135 137
 
136 138
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
137 139
 
138
-		if (empty($htmlid)) $htmlid = $htmlname;
140
+		if (empty($htmlid)) {
141
+			$htmlid = $htmlname;
142
+		}
139 143
 
140 144
 		$out='';
141 145
         $outarray=array();
142 146
 
143 147
 		$hideunselectables = false;
144
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
148
+		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
149
+			$hideunselectables = true;
150
+		}
145 151
 
146 152
 		$projectsListId = false;
147 153
 		if (empty($user->rights->projet->all->lire))
@@ -154,17 +160,26 @@  discard block
 block discarded – undo
154 160
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
155 161
 		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
156 162
 		$sql.= " WHERE p.entity IN (".getEntity('project').")";
157
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
158
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
163
+		if ($projectsListId !== false) {
164
+			$sql.= " AND p.rowid IN (".$projectsListId.")";
165
+		}
166
+		if ($socid == 0) {
167
+			$sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
168
+		}
159 169
 		if ($socid > 0)
160 170
 		{
161
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
162
-		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
171
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
172
+		    	$sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
173
+		    } else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') {
174
+		    	// PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
163 175
 		    {
164 176
 		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
165 177
 		    }
178
+		    }
179
+		}
180
+		if (!empty($filterkey)) {
181
+			$sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
166 182
 		}
167
-		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
168 183
 		$sql.= " ORDER BY p.ref ASC";
169 184
 
170 185
 		$resql=$this->db->query($sql);
@@ -198,12 +213,13 @@  discard block
 block discarded – undo
198 213
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
199 214
 					{
200 215
 						// Do nothing
201
-					}
202
-					else
216
+					} else
203 217
 					{
204
-						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) // We discard closed except if selected
218
+						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) {
219
+							// We discard closed except if selected
205 220
 						{
206 221
 							$i++;
222
+						}
207 223
 							continue;
208 224
 						}
209 225
 
@@ -214,7 +230,9 @@  discard block
 block discarded – undo
214 230
 						if ($obj->name)
215 231
 						{
216 232
 						    $labeltoshow.=' - '.$obj->name;
217
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
233
+						    if ($obj->name_alias) {
234
+						    	$labeltoshow.=' ('.$obj->name_alias.')';
235
+						    }
218 236
 						}
219 237
 
220 238
 						$disabled=0;
@@ -222,13 +240,13 @@  discard block
 block discarded – undo
222 240
 						{
223 241
 							$disabled=1;
224 242
 							$labeltoshow.=' - '.$langs->trans("Draft");
225
-						}
226
-						else if ($obj->fk_statut == 2)
243
+						} else if ($obj->fk_statut == 2)
227 244
 						{
228
-							if ($discard_close == 2) $disabled=1;
245
+							if ($discard_close == 2) {
246
+								$disabled=1;
247
+							}
229 248
 							$labeltoshow.=' - '.$langs->trans("Closed");
230
-						}
231
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
249
+						} else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
232 250
 						{
233 251
 							$disabled=1;
234 252
 							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -239,17 +257,17 @@  discard block
 block discarded – undo
239 257
 							$out.= '<option value="'.$obj->rowid.'" selected';
240 258
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
241 259
 							$out.= '>'.$labeltoshow.'</option>';
242
-						}
243
-						else
260
+						} else
244 261
 						{
245 262
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
246 263
 							{
247 264
 								$resultat='';
248
-							}
249
-							else
265
+							} else
250 266
 							{
251 267
 								$resultat='<option value="'.$obj->rowid.'"';
252
-								if ($disabled) $resultat.=' disabled';
268
+								if ($disabled) {
269
+									$resultat.=' disabled';
270
+								}
253 271
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
254 272
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
255 273
 								$resultat.='>';
@@ -274,18 +292,20 @@  discard block
 block discarded – undo
274 292
 			$this->db->free($resql);
275 293
 
276 294
 			if (!$mode) {
277
-				if (empty($option_only)) $out.= '</select>';
295
+				if (empty($option_only)) {
296
+					$out.= '</select>';
297
+				}
278 298
 				if (empty($nooutput))
279 299
 				{
280 300
 				    print $out;
281 301
 				    return '';
302
+				} else {
303
+					return $out;
282 304
 				}
283
-				else return $out;
284 305
 			} else {
285 306
 				return $outarray;
286 307
 			}
287
-		}
288
-		else
308
+		} else
289 309
 		{
290 310
 			dol_print_error($this->db);
291 311
 			return -1;
@@ -316,7 +336,9 @@  discard block
 block discarded – undo
316 336
 		$out='';
317 337
 
318 338
 		$hideunselectables = false;
319
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
339
+		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
340
+			$hideunselectables = true;
341
+		}
320 342
 
321 343
 		$projectsListId = false;
322 344
 		if (empty($user->rights->projet->all->lire))
@@ -333,9 +355,15 @@  discard block
 block discarded – undo
333 355
 		$sql.= ', '.MAIN_DB_PREFIX.'projet_task as t';
334 356
 		$sql.= " WHERE p.entity = ".$conf->entity;
335 357
 		$sql.= " AND t.fk_projet = p.rowid";
336
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
337
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
338
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
358
+		if ($projectsListId !== false) {
359
+			$sql.= " AND p.rowid IN (".$projectsListId.")";
360
+		}
361
+		if ($socid == 0) {
362
+			$sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
363
+		}
364
+		if ($socid > 0) {
365
+			$sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
366
+		}
339 367
 		$sql.= " ORDER BY p.ref, t.ref ASC";
340 368
 
341 369
 		$resql=$this->db->query($sql);
@@ -355,8 +383,11 @@  discard block
 block discarded – undo
355 383
 			}
356 384
 			if (! empty($show_empty)) {
357 385
 				$out.= '<option value="0" class="optiongrey">';
358
-				if (! is_numeric($show_empty)) $out.=$show_empty;
359
-				else $out.='&nbsp;';
386
+				if (! is_numeric($show_empty)) {
387
+					$out.=$show_empty;
388
+				} else {
389
+					$out.='&nbsp;';
390
+				}
360 391
 				$out.= '</option>';
361 392
 			}
362 393
 			$num = $this->db->num_rows($resql);
@@ -370,8 +401,7 @@  discard block
 block discarded – undo
370 401
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($user->rights->societe->lire))
371 402
 					{
372 403
 						// Do nothing
373
-					}
374
-					else
404
+					} else
375 405
 					{
376 406
 						if ($discard_closed == 1 && $obj->fk_statut == 2)
377 407
 						{
@@ -384,20 +414,22 @@  discard block
 block discarded – undo
384 414
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
385 415
 						$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
386 416
 
387
-						if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
417
+						if ($obj->name) {
418
+							$labeltoshow.=' ('.$obj->name.')';
419
+						}
388 420
 
389 421
 						$disabled=0;
390 422
 						if ($obj->fk_statut == 0)
391 423
 						{
392 424
 							$disabled=1;
393 425
 							$labeltoshow.=' - '.$langs->trans("Draft");
394
-						}
395
-						else if ($obj->fk_statut == 2)
426
+						} else if ($obj->fk_statut == 2)
396 427
 						{
397
-							if ($discard_closed == 2) $disabled=1;
428
+							if ($discard_closed == 2) {
429
+								$disabled=1;
430
+							}
398 431
 							$labeltoshow.=' - '.$langs->trans("Closed");
399
-						}
400
-						else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
432
+						} else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
401 433
 						{
402 434
 							$disabled=1;
403 435
 							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -410,17 +442,17 @@  discard block
 block discarded – undo
410 442
 							$out.= '<option value="'.$obj->rowid.'" selected';
411 443
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
412 444
 							$out.= '>'.$labeltoshow.'</option>';
413
-						}
414
-						else
445
+						} else
415 446
 						{
416 447
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
417 448
 							{
418 449
 								$resultat='';
419
-							}
420
-							else
450
+							} else
421 451
 							{
422 452
 								$resultat='<option value="'.$obj->rowid.'"';
423
-								if ($disabled) $resultat.=' disabled';
453
+								if ($disabled) {
454
+									$resultat.=' disabled';
455
+								}
424 456
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
425 457
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
426 458
 								$resultat.='>';
@@ -441,8 +473,7 @@  discard block
 block discarded – undo
441 473
 
442 474
 			$this->db->free($resql);
443 475
 			return $num;
444
-		}
445
-		else
476
+		} else
446 477
 		{
447 478
 			dol_print_error($this->db);
448 479
 			return -1;
@@ -463,10 +494,15 @@  discard block
 block discarded – undo
463 494
 	{
464 495
 		global $conf, $langs;
465 496
 
466
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
497
+		if ($table_element == 'projet_task') {
498
+			return '';
499
+		}
500
+		// Special cas of element we never link to a project (already always done)
467 501
 
468 502
 		$linkedtothirdparty=false;
469
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','chargesociales'))) $linkedtothirdparty=true;
503
+		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','chargesociales'))) {
504
+			$linkedtothirdparty=true;
505
+		}
470 506
 
471 507
 		$sqlfilter='';
472 508
 		$projectkey="fk_projet";
@@ -514,18 +550,31 @@  discard block
 block discarded – undo
514 550
 				$sql = "SELECT t.rowid, t.ref";
515 551
 				break;
516 552
 		}
517
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
553
+		if ($linkedtothirdparty) {
554
+			$sql.=", s.nom as name";
555
+		}
518 556
 		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
519
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
557
+		if ($linkedtothirdparty) {
558
+			$sql.=", ".MAIN_DB_PREFIX."societe as s";
559
+		}
520 560
 		$sql.= " WHERE ".$projectkey." is null";
521 561
 		if (! empty($socid) && $linkedtothirdparty)
522 562
 		{
523
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
524
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
563
+		    if (is_numeric($socid)) {
564
+		    	$sql.= " AND t.fk_soc=".$socid;
565
+		    } else {
566
+		    	$sql.= " AND t.fk_soc IN (".$socid.")";
567
+		    }
568
+		}
569
+		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) {
570
+			$sql.= ' AND t.entity IN ('.getEntity('project').')';
571
+		}
572
+		if ($linkedtothirdparty) {
573
+			$sql.=" AND s.rowid = t.fk_soc";
574
+		}
575
+		if ($sqlfilter) {
576
+			$sql.= " AND ".$sqlfilter;
525 577
 		}
526
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
527
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
528
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
529 578
 		$sql.= " ORDER BY ref DESC";
530 579
 
531 580
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
@@ -542,8 +591,12 @@  discard block
 block discarded – undo
542 591
 				{
543 592
 					$obj = $this->db->fetch_object($resql);
544 593
 					$ref=$obj->ref?$obj->ref:$obj->rowid;
545
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
546
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
594
+					if (! empty($obj->ref_supplier)) {
595
+						$ref.=' ('.$obj->ref_supplier.')';
596
+					}
597
+					if (! empty($obj->name)) {
598
+						$ref.=' - '.$obj->name;
599
+					}
547 600
 					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
548 601
 					$i++;
549 602
 				}
@@ -558,8 +611,7 @@  discard block
 block discarded – undo
558 611
 			$this->db->free($resql);
559 612
 
560 613
 			return $sellist;
561
-		}
562
-		else
614
+		} else
563 615
 		{
564 616
 			dol_print_error($this->db);
565 617
 			$this->error=$this->db->lasterror();
@@ -599,25 +651,37 @@  discard block
 block discarded – undo
599 651
 			if ($num > 0)
600 652
 			{
601 653
 				$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
602
-				if ($showempty) $sellist.= '<option value="-1">&nbsp;</option>';    // Without &nbsp, strange move of screen when switching value
603
-				if ($showallnone) $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>--'.$langs->trans("OnlyOpportunitiesShort").'--</option>';
604
-				if ($showallnone) $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>--'.$langs->trans("OpenedOpportunitiesShort").'--</option>';
605
-				if ($showallnone) $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>--'.$langs->trans("NotAnOpportunityShort").'--</option>';
654
+				if ($showempty) {
655
+					$sellist.= '<option value="-1">&nbsp;</option>';
656
+				}
657
+				// Without &nbsp, strange move of screen when switching value
658
+				if ($showallnone) {
659
+					$sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>--'.$langs->trans("OnlyOpportunitiesShort").'--</option>';
660
+				}
661
+				if ($showallnone) {
662
+					$sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>--'.$langs->trans("OpenedOpportunitiesShort").'--</option>';
663
+				}
664
+				if ($showallnone) {
665
+					$sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>--'.$langs->trans("NotAnOpportunityShort").'--</option>';
666
+				}
606 667
 				while ($i < $num)
607 668
 				{
608 669
 					$obj = $this->db->fetch_object($resql);
609 670
 
610 671
 					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
611
-					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
672
+					if ($obj->rowid == $preselected) {
673
+						$sellist .= ' selected="selected"';
674
+					}
612 675
 					$sellist .= '>';
613 676
 					if ($useshortlabel)
614 677
 					{
615 678
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatusShort".$obj->code) != "OppStatusShort".$obj->code ? $langs->transnoentitiesnoconv("OppStatusShort".$obj->code) : $obj->label);
616
-					}
617
-					else
679
+					} else
618 680
 					{
619 681
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
620
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
682
+						if ($showpercent) {
683
+							$finallabel.= ' ('.$obj->percent.'%)';
684
+						}
621 685
 					}
622 686
 					$sellist .= $finallabel;
623 687
 					$sellist .='</option>';
@@ -634,8 +698,7 @@  discard block
 block discarded – undo
634 698
 			$this->db->free($resql);
635 699
 
636 700
 			return $sellist;
637
-		}
638
-		else
701
+		} else
639 702
 		{
640 703
 			$this->error=$this->db->lasterror();
641 704
 			$this->errors[]=$this->db->lasterror();
Please login to merge, or discard this patch.
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -63,41 +63,41 @@  discard block
 block discarded – undo
63 63
 	 *	@param  int     $htmlid         Html id to use instead of htmlname
64 64
 	 *	@return string           		Return html content
65 65
 	 */
66
-	function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
66
+	function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '')
67 67
 	{
68
-		global $langs,$conf,$form;
68
+		global $langs, $conf, $form;
69 69
 
70
-		$out='';
70
+		$out = '';
71 71
 
72
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
72
+		if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
73 73
 		{
74
-			$placeholder='';
74
+			$placeholder = '';
75 75
 
76 76
 			if ($selected && empty($selected_input_value))
77 77
 			{
78 78
 				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
79 79
 				$project = new Project($this->db);
80 80
 				$project->fetch($selected);
81
-				$selected_input_value=$project->ref;
81
+				$selected_input_value = $project->ref;
82 82
 			}
83
-			$urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
84
-			$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
83
+			$urloption = 'socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
84
+			$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
85 85
 //				'update' => array(
86 86
 //					'projectid' => 'id'
87 87
 //				)
88 88
 			));
89 89
 
90
-			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
90
+			$out .= '<input type="text" class="minwidth200'.($morecss ? ' '.$morecss : '').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
91 91
 		}
92 92
 		else
93 93
 		{
94
-			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid);
94
+			$out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid);
95 95
 			if ($discard_closed)
96 96
 			{
97 97
 			    if (class_exists('Form'))
98 98
 			    {
99
-    			    if (empty($form)) $form=new Form($this->db);
100
-                    $out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
99
+    			    if (empty($form)) $form = new Form($this->db);
100
+                    $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
101 101
 			    }
102 102
 			}
103 103
 		}
@@ -129,63 +129,63 @@  discard block
 block discarded – undo
129 129
 	 * @param  int     $htmlid             Html id to use instead of htmlname
130 130
 	 * @return int         			       Nb of project if OK, <0 if KO
131 131
 	 */
132
-	function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='')
132
+	function select_projects_list($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '')
133 133
 	{
134
-		global $user,$conf,$langs;
134
+		global $user, $conf, $langs;
135 135
 
136 136
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
137 137
 
138 138
 		if (empty($htmlid)) $htmlid = $htmlname;
139 139
 
140
-		$out='';
141
-        $outarray=array();
140
+		$out = '';
141
+        $outarray = array();
142 142
 
143 143
 		$hideunselectables = false;
144
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
144
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
145 145
 
146 146
 		$projectsListId = false;
147 147
 		if (empty($user->rights->projet->all->lire))
148 148
 		{
149
-			$projectstatic=new Project($this->db);
150
-			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
149
+			$projectstatic = new Project($this->db);
150
+			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
151 151
 		}
152 152
 
153 153
 		// Search all projects
154 154
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
155
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
156
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
157
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
158
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
155
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
156
+		$sql .= " WHERE p.entity IN (".getEntity('project').")";
157
+		if ($projectsListId !== false) $sql .= " AND p.rowid IN (".$projectsListId.")";
158
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
159 159
 		if ($socid > 0)
160 160
 		{
161
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
161
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
162 162
 		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
163 163
 		    {
164
-		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
164
+		        $sql .= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
165 165
 		    }
166 166
 		}
167 167
 		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
168
-		$sql.= " ORDER BY p.ref ASC";
168
+		$sql .= " ORDER BY p.ref ASC";
169 169
 
170
-		$resql=$this->db->query($sql);
170
+		$resql = $this->db->query($sql);
171 171
 		if ($resql)
172 172
 		{
173
-			$morecss='maxwidth500';
173
+			$morecss = 'maxwidth500';
174 174
 
175 175
 			// Use select2 selector
176
-			if (! empty($conf->use_javascript_ajax))
176
+			if (!empty($conf->use_javascript_ajax))
177 177
 			{
178
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
178
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
179 179
 	           	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
180
-            	$out.=$comboenhancement;
181
-            	$morecss='minwidth100 maxwidth300';
180
+            	$out .= $comboenhancement;
181
+            	$morecss = 'minwidth100 maxwidth300';
182 182
 			}
183 183
 
184 184
 			if (empty($option_only)) {
185
-				$out.= '<select class="flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlid.'" name="'.$htmlname.'">';
185
+				$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlid.'" name="'.$htmlname.'">';
186 186
 			}
187 187
 			if (!empty($show_empty)) {
188
-				$out.= '<option value="0">&nbsp;</option>';
188
+				$out .= '<option value="0">&nbsp;</option>';
189 189
 			}
190 190
 			$num = $this->db->num_rows($resql);
191 191
 			$i = 0;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 				{
196 196
 					$obj = $this->db->fetch_object($resql);
197 197
 					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
198
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
198
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
199 199
 					{
200 200
 						// Do nothing
201 201
 					}
@@ -207,56 +207,56 @@  discard block
 block discarded – undo
207 207
 							continue;
208 208
 						}
209 209
 
210
-						$labeltoshow=dol_trunc($obj->ref,18);
210
+						$labeltoshow = dol_trunc($obj->ref, 18);
211 211
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
212 212
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
213
-						$labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
213
+						$labeltoshow .= ', '.dol_trunc($obj->title, $maxlength);
214 214
 						if ($obj->name)
215 215
 						{
216
-						    $labeltoshow.=' - '.$obj->name;
217
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
216
+						    $labeltoshow .= ' - '.$obj->name;
217
+						    if ($obj->name_alias) $labeltoshow .= ' ('.$obj->name_alias.')';
218 218
 						}
219 219
 
220
-						$disabled=0;
220
+						$disabled = 0;
221 221
 						if ($obj->fk_statut == 0)
222 222
 						{
223
-							$disabled=1;
224
-							$labeltoshow.=' - '.$langs->trans("Draft");
223
+							$disabled = 1;
224
+							$labeltoshow .= ' - '.$langs->trans("Draft");
225 225
 						}
226 226
 						else if ($obj->fk_statut == 2)
227 227
 						{
228
-							if ($discard_close == 2) $disabled=1;
229
-							$labeltoshow.=' - '.$langs->trans("Closed");
228
+							if ($discard_close == 2) $disabled = 1;
229
+							$labeltoshow .= ' - '.$langs->trans("Closed");
230 230
 						}
231
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
231
+						else if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
232 232
 						{
233
-							$disabled=1;
234
-							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
233
+							$disabled = 1;
234
+							$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
235 235
 						}
236 236
 
237 237
 						if (!empty($selected) && $selected == $obj->rowid)
238 238
 						{
239
-							$out.= '<option value="'.$obj->rowid.'" selected';
239
+							$out .= '<option value="'.$obj->rowid.'" selected';
240 240
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
241
-							$out.= '>'.$labeltoshow.'</option>';
241
+							$out .= '>'.$labeltoshow.'</option>';
242 242
 						}
243 243
 						else
244 244
 						{
245 245
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
246 246
 							{
247
-								$resultat='';
247
+								$resultat = '';
248 248
 							}
249 249
 							else
250 250
 							{
251
-								$resultat='<option value="'.$obj->rowid.'"';
252
-								if ($disabled) $resultat.=' disabled';
251
+								$resultat = '<option value="'.$obj->rowid.'"';
252
+								if ($disabled) $resultat .= ' disabled';
253 253
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
254 254
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
255
-								$resultat.='>';
256
-								$resultat.=$labeltoshow;
257
-								$resultat.='</option>';
255
+								$resultat .= '>';
256
+								$resultat .= $labeltoshow;
257
+								$resultat .= '</option>';
258 258
 							}
259
-							$out.= $resultat;
259
+							$out .= $resultat;
260 260
 
261 261
 							$outarray[] = array(
262 262
 								'key' => (int) $obj->rowid,
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 			$this->db->free($resql);
275 275
 
276 276
 			if (!$mode) {
277
-				if (empty($option_only)) $out.= '</select>';
277
+				if (empty($option_only)) $out .= '</select>';
278 278
 				if (empty($nooutput))
279 279
 				{
280 280
 				    print $out;
@@ -307,57 +307,57 @@  discard block
 block discarded – undo
307 307
 	 *  @param	string	$morecss        More css added to the select component
308 308
 	 *	@return int         			Nbr of project if OK, <0 if KO
309 309
 	 */
310
-	function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500')
310
+	function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500')
311 311
 	{
312
-		global $user,$conf,$langs;
312
+		global $user, $conf, $langs;
313 313
 
314 314
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
315 315
 
316
-		$out='';
316
+		$out = '';
317 317
 
318 318
 		$hideunselectables = false;
319
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
319
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
320 320
 
321 321
 		$projectsListId = false;
322 322
 		if (empty($user->rights->projet->all->lire))
323 323
 		{
324
-			$projectstatic=new Project($this->db);
325
-			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
324
+			$projectstatic = new Project($this->db);
325
+			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
326 326
 		}
327 327
 
328 328
 		// Search all projects
329 329
 		$sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,';
330
-		$sql.= ' s.nom as name';
331
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
332
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
333
-		$sql.= ', '.MAIN_DB_PREFIX.'projet_task as t';
334
-		$sql.= " WHERE p.entity = ".$conf->entity;
335
-		$sql.= " AND t.fk_projet = p.rowid";
336
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
337
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
338
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
339
-		$sql.= " ORDER BY p.ref, t.ref ASC";
340
-
341
-		$resql=$this->db->query($sql);
330
+		$sql .= ' s.nom as name';
331
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
332
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
333
+		$sql .= ', '.MAIN_DB_PREFIX.'projet_task as t';
334
+		$sql .= " WHERE p.entity = ".$conf->entity;
335
+		$sql .= " AND t.fk_projet = p.rowid";
336
+		if ($projectsListId !== false) $sql .= " AND p.rowid IN (".$projectsListId.")";
337
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
338
+		if ($socid > 0)  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
339
+		$sql .= " ORDER BY p.ref, t.ref ASC";
340
+
341
+		$resql = $this->db->query($sql);
342 342
 		if ($resql)
343 343
 		{
344 344
 			// Use select2 selector
345
-			if (! empty($conf->use_javascript_ajax))
345
+			if (!empty($conf->use_javascript_ajax))
346 346
 			{
347
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
347
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
348 348
 	           	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
349
-            	$out.=$comboenhancement;
350
-            	$morecss='minwidth200 maxwidth500';
349
+            	$out .= $comboenhancement;
350
+            	$morecss = 'minwidth200 maxwidth500';
351 351
 			}
352 352
 
353 353
 			if (empty($option_only)) {
354
-				$out.= '<select class="valignmiddle flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'">';
354
+				$out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">';
355 355
 			}
356
-			if (! empty($show_empty)) {
357
-				$out.= '<option value="0" class="optiongrey">';
358
-				if (! is_numeric($show_empty)) $out.=$show_empty;
359
-				else $out.='&nbsp;';
360
-				$out.= '</option>';
356
+			if (!empty($show_empty)) {
357
+				$out .= '<option value="0" class="optiongrey">';
358
+				if (!is_numeric($show_empty)) $out .= $show_empty;
359
+				else $out .= '&nbsp;';
360
+				$out .= '</option>';
361 361
 			}
362 362
 			$num = $this->db->num_rows($resql);
363 363
 			$i = 0;
@@ -379,62 +379,62 @@  discard block
 block discarded – undo
379 379
 							continue;
380 380
 						}
381 381
 
382
-						$labeltoshow=dol_trunc($obj->ref,18);     // Project ref
382
+						$labeltoshow = dol_trunc($obj->ref, 18); // Project ref
383 383
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
384 384
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
385
-						$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
385
+						$labeltoshow .= ' '.dol_trunc($obj->title, $maxlength);
386 386
 
387
-						if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
387
+						if ($obj->name) $labeltoshow .= ' ('.$obj->name.')';
388 388
 
389
-						$disabled=0;
389
+						$disabled = 0;
390 390
 						if ($obj->fk_statut == 0)
391 391
 						{
392
-							$disabled=1;
393
-							$labeltoshow.=' - '.$langs->trans("Draft");
392
+							$disabled = 1;
393
+							$labeltoshow .= ' - '.$langs->trans("Draft");
394 394
 						}
395 395
 						else if ($obj->fk_statut == 2)
396 396
 						{
397
-							if ($discard_closed == 2) $disabled=1;
398
-							$labeltoshow.=' - '.$langs->trans("Closed");
397
+							if ($discard_closed == 2) $disabled = 1;
398
+							$labeltoshow .= ' - '.$langs->trans("Closed");
399 399
 						}
400
-						else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
400
+						else if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
401 401
 						{
402
-							$disabled=1;
403
-							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
402
+							$disabled = 1;
403
+							$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
404 404
 						}
405 405
 						// Label for task
406
-						$labeltoshow.=' - '.$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength);
406
+						$labeltoshow .= ' - '.$obj->tref.' '.dol_trunc($obj->tlabel, $maxlength);
407 407
 
408 408
 						if (!empty($selected) && $selected == $obj->rowid)
409 409
 						{
410
-							$out.= '<option value="'.$obj->rowid.'" selected';
410
+							$out .= '<option value="'.$obj->rowid.'" selected';
411 411
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
412
-							$out.= '>'.$labeltoshow.'</option>';
412
+							$out .= '>'.$labeltoshow.'</option>';
413 413
 						}
414 414
 						else
415 415
 						{
416 416
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
417 417
 							{
418
-								$resultat='';
418
+								$resultat = '';
419 419
 							}
420 420
 							else
421 421
 							{
422
-								$resultat='<option value="'.$obj->rowid.'"';
423
-								if ($disabled) $resultat.=' disabled';
422
+								$resultat = '<option value="'.$obj->rowid.'"';
423
+								if ($disabled) $resultat .= ' disabled';
424 424
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
425 425
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
426
-								$resultat.='>';
427
-								$resultat.=$labeltoshow;
428
-								$resultat.='</option>';
426
+								$resultat .= '>';
427
+								$resultat .= $labeltoshow;
428
+								$resultat .= '</option>';
429 429
 							}
430
-							$out.= $resultat;
430
+							$out .= $resultat;
431 431
 						}
432 432
 					}
433 433
 					$i++;
434 434
 				}
435 435
 			}
436 436
 			if (empty($option_only)) {
437
-				$out.= '</select>';
437
+				$out .= '</select>';
438 438
 			}
439 439
 
440 440
 			print $out;
@@ -459,17 +459,17 @@  discard block
 block discarded – undo
459 459
 	 *    @param    int         $limitonstatus      Add filters to limit length of list to opened status (for example to avoid ERR_RESPONSE_HEADERS_TOO_BIG on project/element.php page). TODO To implement
460 460
 	 *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
461 461
 	 */
462
-	function select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2)
462
+	function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2)
463 463
 	{
464 464
 		global $conf, $langs;
465 465
 
466
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
466
+		if ($table_element == 'projet_task') return ''; // Special cas of element we never link to a project (already always done)
467 467
 
468
-		$linkedtothirdparty=false;
469
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','chargesociales'))) $linkedtothirdparty=true;
468
+		$linkedtothirdparty = false;
469
+		if (!in_array($table_element, array('don', 'expensereport_det', 'expensereport', 'loan', 'stock_mouvement', 'chargesociales'))) $linkedtothirdparty = true;
470 470
 
471
-		$sqlfilter='';
472
-		$projectkey="fk_projet";
471
+		$sqlfilter = '';
472
+		$projectkey = "fk_projet";
473 473
 		//print $table_element;
474 474
 		switch ($table_element)
475 475
 		{
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 				break;
492 492
 			case "actioncomm":
493 493
 				$sql = "SELECT t.id as rowid, t.label as ref";
494
-				$projectkey="fk_project";
494
+				$projectkey = "fk_project";
495 495
 				break;
496 496
 			case "expensereport":
497 497
 				return '';
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 			    break;
508 508
 			case 'stock_mouvement':
509 509
 				$sql = 'SELECT t.rowid, t.label as ref';
510
-				$projectkey='fk_origin';
510
+				$projectkey = 'fk_origin';
511 511
 				break;
512 512
 			case "payment_various":
513 513
 				$sql = "SELECT t.rowid, t.num_payment as ref";
@@ -517,40 +517,40 @@  discard block
 block discarded – undo
517 517
 				$sql = "SELECT t.rowid, t.ref";
518 518
 				break;
519 519
 		}
520
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
521
-		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
522
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
523
-		$sql.= " WHERE ".$projectkey." is null";
524
-		if (! empty($socid) && $linkedtothirdparty)
520
+		if ($linkedtothirdparty) $sql .= ", s.nom as name";
521
+		$sql .= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
522
+		if ($linkedtothirdparty) $sql .= ", ".MAIN_DB_PREFIX."societe as s";
523
+		$sql .= " WHERE ".$projectkey." is null";
524
+		if (!empty($socid) && $linkedtothirdparty)
525 525
 		{
526
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
527
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
526
+		    if (is_numeric($socid)) $sql .= " AND t.fk_soc=".$socid;
527
+		    else $sql .= " AND t.fk_soc IN (".$socid.")";
528 528
 		}
529
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
530
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
531
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
532
-		$sql.= " ORDER BY ref DESC";
529
+		if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) $sql .= ' AND t.entity IN ('.getEntity('project').')';
530
+		if ($linkedtothirdparty) $sql .= " AND s.rowid = t.fk_soc";
531
+		if ($sqlfilter) $sql .= " AND ".$sqlfilter;
532
+		$sql .= " ORDER BY ref DESC";
533 533
 
534 534
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
535
-		$resql=$this->db->query($sql);
535
+		$resql = $this->db->query($sql);
536 536
 		if ($resql)
537 537
 		{
538 538
 			$num = $this->db->num_rows($resql);
539 539
 			$i = 0;
540 540
 			if ($num > 0)
541 541
 			{
542
-				$sellist = '<select class="flat elementselect css'.$table_element.($morecss?' '.$morecss:'').'" name="elementselect">';
543
-				$sellist .='<option value="-1"></option>';
542
+				$sellist = '<select class="flat elementselect css'.$table_element.($morecss ? ' '.$morecss : '').'" name="elementselect">';
543
+				$sellist .= '<option value="-1"></option>';
544 544
 				while ($i < $num)
545 545
 				{
546 546
 					$obj = $this->db->fetch_object($resql);
547
-					$ref=$obj->ref?$obj->ref:$obj->rowid;
548
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
549
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
550
-					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
547
+					$ref = $obj->ref ? $obj->ref : $obj->rowid;
548
+					if (!empty($obj->ref_supplier)) $ref .= ' ('.$obj->ref_supplier.')';
549
+					if (!empty($obj->name)) $ref .= ' - '.$obj->name;
550
+					$sellist .= '<option value="'.$obj->rowid.'">'.$ref.'</option>';
551 551
 					$i++;
552 552
 				}
553
-				$sellist .='</select>';
553
+				$sellist .= '</select>';
554 554
 			}
555 555
 			/*else
556 556
 			{
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 		else
566 566
 		{
567 567
 			dol_print_error($this->db);
568
-			$this->error=$this->db->lasterror();
569
-			$this->errors[]=$this->db->lasterror();
570
-			dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
568
+			$this->error = $this->db->lasterror();
569
+			$this->errors[] = $this->db->lasterror();
570
+			dol_syslog(get_class($this)."::select_element ".$this->error, LOG_ERR);
571 571
 			return -1;
572 572
 		}
573 573
 	}
@@ -585,32 +585,32 @@  discard block
 block discarded – undo
585 585
 	 *    @param   string      $morecss            Add more css
586 586
 	 *    @return  int|string                      The HTML select list of element or '' if nothing or -1 if KO
587 587
 	 */
588
-	function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='')
588
+	function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '')
589 589
 	{
590 590
 		global $conf, $langs;
591 591
 
592 592
 		$sql = "SELECT rowid, code, label, percent";
593
-		$sql.= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
594
-		$sql.= " WHERE active = 1";
595
-		$sql.= " ORDER BY position";
593
+		$sql .= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
594
+		$sql .= " WHERE active = 1";
595
+		$sql .= " ORDER BY position";
596 596
 
597
-		$resql=$this->db->query($sql);
597
+		$resql = $this->db->query($sql);
598 598
 		if ($resql)
599 599
 		{
600 600
 			$num = $this->db->num_rows($resql);
601 601
 			$i = 0;
602 602
 			if ($num > 0)
603 603
 			{
604
-				$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
605
-				if ($showempty) $sellist.= '<option value="-1">&nbsp;</option>';    // Without &nbsp, strange move of screen when switching value
606
-				if ($showallnone) $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>--'.$langs->trans("OnlyOpportunitiesShort").'--</option>';
607
-				if ($showallnone) $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>--'.$langs->trans("OpenedOpportunitiesShort").'--</option>';
608
-				if ($showallnone) $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>--'.$langs->trans("NotAnOpportunityShort").'--</option>';
604
+				$sellist = '<select class="flat oppstatus'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
605
+				if ($showempty) $sellist .= '<option value="-1">&nbsp;</option>'; // Without &nbsp, strange move of screen when switching value
606
+				if ($showallnone) $sellist .= '<option value="all"'.($preselected == 'all' ? ' selected="selected"' : '').'>--'.$langs->trans("OnlyOpportunitiesShort").'--</option>';
607
+				if ($showallnone) $sellist .= '<option value="openedopp"'.($preselected == 'openedopp' ? ' selected="selected"' : '').'>--'.$langs->trans("OpenedOpportunitiesShort").'--</option>';
608
+				if ($showallnone) $sellist .= '<option value="none"'.($preselected == 'none' ? ' selected="selected"' : '').'>--'.$langs->trans("NotAnOpportunityShort").'--</option>';
609 609
 				while ($i < $num)
610 610
 				{
611 611
 					$obj = $this->db->fetch_object($resql);
612 612
 
613
-					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
613
+					$sellist .= '<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
614 614
 					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
615 615
 					$sellist .= '>';
616 616
 					if ($useshortlabel)
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
 					else
621 621
 					{
622 622
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
623
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
623
+						if ($showpercent) $finallabel .= ' ('.$obj->percent.'%)';
624 624
 					}
625 625
 					$sellist .= $finallabel;
626
-					$sellist .='</option>';
626
+					$sellist .= '</option>';
627 627
 					$i++;
628 628
 				}
629
-				$sellist .='</select>';
629
+				$sellist .= '</select>';
630 630
 			}
631 631
 			/*else
632 632
 			{
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
 		}
641 641
 		else
642 642
 		{
643
-			$this->error=$this->db->lasterror();
644
-			$this->errors[]=$this->db->lasterror();
645
-			dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
643
+			$this->error = $this->db->lasterror();
644
+			$this->errors[] = $this->db->lasterror();
645
+			dol_syslog(get_class($this)."::selectOpportunityStatus ".$this->error, LOG_ERR);
646 646
 			return -1;
647 647
 		}
648 648
 	}
Please login to merge, or discard this patch.
htdocs/compta/sociales/class/chargesociales.class.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      *  Retourne le libelle du statut d'une charge (impaye, payee)
378 378
      *
379 379
      *  @param	int		$mode       	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
380
-	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
380
+	 *  @param  integer	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
381 381
      *  @return	string        			Label
382 382
      */
383 383
     function getLibStatut($mode=0,$alreadypaid=-1)
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      *
391 391
      *  @param	int		$statut        	Id statut
392 392
      *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
393
-	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
393
+	 *  @param  integer	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
394 394
      *  @return string        			Label
395 395
      */
396 396
     function LibStatut($statut,$mode=0,$alreadypaid=-1)
Please login to merge, or discard this patch.
Indentation   +518 added lines, -518 removed lines patch added patch discarded remove patch
@@ -32,100 +32,100 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class ChargeSociales extends CommonObject
34 34
 {
35
-    public $element='chargesociales';
36
-    public $table='chargesociales';
37
-    public $table_element='chargesociales';
38
-    public $picto = 'bill';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $table_ref_field = 'ref';
44
-
45
-    var $date_ech;
46
-    var $lib;
47
-    var $type;
48
-    var $type_libelle;
49
-    var $amount;
50
-    var $paye;
51
-    var $periode;
52
-    var $date_creation;
53
-    var $date_modification;
54
-    var $date_validation;
55
-    var $fk_account;
35
+	public $element='chargesociales';
36
+	public $table='chargesociales';
37
+	public $table_element='chargesociales';
38
+	public $picto = 'bill';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $table_ref_field = 'ref';
44
+
45
+	var $date_ech;
46
+	var $lib;
47
+	var $type;
48
+	var $type_libelle;
49
+	var $amount;
50
+	var $paye;
51
+	var $periode;
52
+	var $date_creation;
53
+	var $date_modification;
54
+	var $date_validation;
55
+	var $fk_account;
56 56
 	var $fk_project;
57 57
 
58 58
 
59
-    /**
60
-     * Constructor
61
-     *
62
-     * @param	DoliDB		$db		Database handler
63
-     */
64
-    function __construct($db)
65
-    {
66
-        $this->db = $db;
67
-        return 1;
68
-    }
69
-
70
-    /**
71
-     *  Retrouve et charge une charge sociale
72
-     *
73
-     *  @param	int     $id		Id
74
-     *  @param	string  $ref	Ref
75
-     *  @return	int <0 KO >0 OK
76
-     */
77
-    function fetch($id, $ref='')
78
-    {
79
-        $sql = "SELECT cs.rowid, cs.date_ech";
80
-        $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
81
-        $sql.= ", cs.fk_account, cs.fk_mode_reglement";
82
-        $sql.= ", c.libelle";
83
-        $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
84
-        $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
85
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
86
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
87
-        if ($ref) $sql.= " WHERE cs.rowid = ".$ref;
88
-        else $sql.= " WHERE cs.rowid = ".$id;
89
-
90
-        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
91
-        $resql=$this->db->query($sql);
92
-        if ($resql)
93
-        {
94
-            if ($this->db->num_rows($resql))
95
-            {
96
-                $obj = $this->db->fetch_object($resql);
97
-
98
-                $this->id					= $obj->rowid;
99
-                $this->ref					= $obj->rowid;
100
-                $this->date_ech				= $this->db->jdate($obj->date_ech);
101
-                $this->lib					= $obj->lib;
102
-                $this->type					= $obj->fk_type;
103
-                $this->type_libelle			= $obj->libelle;
104
-                $this->fk_account			= $obj->fk_account;
105
-                $this->mode_reglement_id	= $obj->fk_mode_reglement;
106
-                $this->mode_reglement_code	= $obj->mode_reglement_code;
107
-                $this->mode_reglement		= $obj->mode_reglement_libelle;
108
-                $this->amount				= $obj->amount;
59
+	/**
60
+	 * Constructor
61
+	 *
62
+	 * @param	DoliDB		$db		Database handler
63
+	 */
64
+	function __construct($db)
65
+	{
66
+		$this->db = $db;
67
+		return 1;
68
+	}
69
+
70
+	/**
71
+	 *  Retrouve et charge une charge sociale
72
+	 *
73
+	 *  @param	int     $id		Id
74
+	 *  @param	string  $ref	Ref
75
+	 *  @return	int <0 KO >0 OK
76
+	 */
77
+	function fetch($id, $ref='')
78
+	{
79
+		$sql = "SELECT cs.rowid, cs.date_ech";
80
+		$sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
81
+		$sql.= ", cs.fk_account, cs.fk_mode_reglement";
82
+		$sql.= ", c.libelle";
83
+		$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
84
+		$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
85
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
86
+		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
87
+		if ($ref) $sql.= " WHERE cs.rowid = ".$ref;
88
+		else $sql.= " WHERE cs.rowid = ".$id;
89
+
90
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
91
+		$resql=$this->db->query($sql);
92
+		if ($resql)
93
+		{
94
+			if ($this->db->num_rows($resql))
95
+			{
96
+				$obj = $this->db->fetch_object($resql);
97
+
98
+				$this->id					= $obj->rowid;
99
+				$this->ref					= $obj->rowid;
100
+				$this->date_ech				= $this->db->jdate($obj->date_ech);
101
+				$this->lib					= $obj->lib;
102
+				$this->type					= $obj->fk_type;
103
+				$this->type_libelle			= $obj->libelle;
104
+				$this->fk_account			= $obj->fk_account;
105
+				$this->mode_reglement_id	= $obj->fk_mode_reglement;
106
+				$this->mode_reglement_code	= $obj->mode_reglement_code;
107
+				$this->mode_reglement		= $obj->mode_reglement_libelle;
108
+				$this->amount				= $obj->amount;
109 109
 				$this->fk_project			= $obj->fk_project;
110
-                $this->paye					= $obj->paye;
111
-                $this->periode				= $this->db->jdate($obj->periode);
112
-                $this->import_key			= $this->import_key;
113
-
114
-                $this->db->free($resql);
115
-
116
-                return 1;
117
-            }
118
-            else
119
-            {
120
-                return 0;
121
-            }
122
-        }
123
-        else
124
-        {
125
-            $this->error=$this->db->lasterror();
126
-            return -1;
127
-        }
128
-    }
110
+				$this->paye					= $obj->paye;
111
+				$this->periode				= $this->db->jdate($obj->periode);
112
+				$this->import_key			= $this->import_key;
113
+
114
+				$this->db->free($resql);
115
+
116
+				return 1;
117
+			}
118
+			else
119
+			{
120
+				return 0;
121
+			}
122
+		}
123
+		else
124
+		{
125
+			$this->error=$this->db->lasterror();
126
+			return -1;
127
+		}
128
+	}
129 129
 
130 130
 	/**
131 131
 	 * Check if a social contribution can be created into database
@@ -136,30 +136,30 @@  discard block
 block discarded – undo
136 136
 	{
137 137
 		$newamount=price2num($this->amount,'MT');
138 138
 
139
-        // Validation parametres
140
-        if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
141
-        {
142
-            return false;
143
-        }
139
+		// Validation parametres
140
+		if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
141
+		{
142
+			return false;
143
+		}
144 144
 
145 145
 
146 146
 		return true;
147 147
 	}
148 148
 
149
-    /**
150
-     *      Create a social contribution into database
151
-     *
152
-     *      @param	User	$user   User making creation
153
-     *      @return int     		<0 if KO, id if OK
154
-     */
155
-    function create($user)
156
-    {
157
-    	global $conf;
149
+	/**
150
+	 *      Create a social contribution into database
151
+	 *
152
+	 *      @param	User	$user   User making creation
153
+	 *      @return int     		<0 if KO, id if OK
154
+	 */
155
+	function create($user)
156
+	{
157
+		global $conf;
158 158
 
159
-        $now=dol_now();
159
+		$now=dol_now();
160 160
 
161
-        // Nettoyage parametres
162
-        $newamount=price2num($this->amount,'MT');
161
+		// Nettoyage parametres
162
+		$newamount=price2num($this->amount,'MT');
163 163
 
164 164
 		if (!$this->check())
165 165
 		{
@@ -167,423 +167,423 @@  discard block
 block discarded – undo
167 167
 			 return -2;
168 168
 		}
169 169
 
170
-        $this->db->begin();
170
+		$this->db->begin();
171 171
 
172
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)";
173
-        $sql.= " VALUES (".$this->type;
174
-        $sql.= ", ".($this->fk_account>0 ? $this->fk_account:'NULL');
175
-        $sql.= ", ".($this->mode_reglement_id>0 ? $this->mode_reglement_id:"NULL");
176
-        $sql.= ", '".$this->db->escape($this->lib)."'";
177
-        $sql.= ", '".$this->db->idate($this->date_ech)."'";
172
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)";
173
+		$sql.= " VALUES (".$this->type;
174
+		$sql.= ", ".($this->fk_account>0 ? $this->fk_account:'NULL');
175
+		$sql.= ", ".($this->mode_reglement_id>0 ? $this->mode_reglement_id:"NULL");
176
+		$sql.= ", '".$this->db->escape($this->lib)."'";
177
+		$sql.= ", '".$this->db->idate($this->date_ech)."'";
178 178
 		$sql.= ", '".$this->db->idate($this->periode)."'";
179
-        $sql.= ", '".price2num($newamount)."'";
179
+		$sql.= ", '".price2num($newamount)."'";
180 180
 		$sql.= ", ".($this->fk_project>0?$this->fk_project:'NULL');
181
-        $sql.= ", ".$conf->entity;
182
-        $sql.= ", ".$user->id;
183
-        $sql.= ", '".$this->db->idate($now)."'";
184
-        $sql.= ")";
185
-
186
-        dol_syslog(get_class($this)."::create", LOG_DEBUG);
187
-        $resql=$this->db->query($sql);
188
-        if ($resql)
189
-        {
190
-            $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
191
-
192
-            //dol_syslog("ChargesSociales::create this->id=".$this->id);
193
-            $this->db->commit();
194
-            return $this->id;
195
-        }
196
-        else
197
-        {
198
-            $this->error=$this->db->error();
199
-            $this->db->rollback();
200
-            return -1;
201
-        }
202
-    }
203
-
204
-
205
-    /**
206
-     *      Delete a social contribution
207
-     *
208
-     *      @param		User    $user   Object user making delete
209
-     *      @return     		int 	<0 if KO, >0 if OK
210
-     */
211
-    function delete($user)
212
-    {
213
-        $error=0;
214
-
215
-        $this->db->begin();
216
-
217
-        // Get bank transaction lines for this social contributions
218
-        include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
219
-        $account=new Account($this->db);
220
-        $lines_url=$account->get_url('',$this->id,'sc');
221
-
222
-        // Delete bank urls
223
-        foreach ($lines_url as $line_url)
224
-        {
225
-            if (! $error)
226
-            {
227
-                $accountline=new AccountLine($this->db);
228
-                $accountline->fetch($line_url['fk_bank']);
229
-                $result=$accountline->delete_urls($user);
230
-                if ($result < 0)
231
-                {
232
-                    $error++;
233
-                }
234
-            }
235
-        }
236
-
237
-        // Delete payments
238
-        if (! $error)
239
-        {
240
-            $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id;
241
-            dol_syslog(get_class($this)."::delete", LOG_DEBUG);
242
-            $resql=$this->db->query($sql);
243
-            if (! $resql)
244
-            {
245
-                $error++;
246
-                $this->error=$this->db->lasterror();
247
-            }
248
-        }
249
-
250
-        if (! $error)
251
-        {
252
-            $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id;
253
-            dol_syslog(get_class($this)."::delete", LOG_DEBUG);
254
-            $resql=$this->db->query($sql);
255
-            if (! $resql)
256
-            {
257
-                $error++;
258
-                $this->error=$this->db->lasterror();
259
-            }
260
-        }
261
-
262
-        if (! $error)
263
-        {
264
-            $this->db->commit();
265
-            return 1;
266
-        }
267
-        else
268
-        {
269
-            $this->db->rollback();
270
-            return -1;
271
-        }
272
-
273
-    }
274
-
275
-
276
-    /**
277
-     *      Met a jour une charge sociale
278
-     *
279
-     *      @param	User	$user   Utilisateur qui modifie
280
-     *      @return int     		<0 si erreur, >0 si ok
281
-     */
282
-    function update($user)
283
-    {
284
-        $this->db->begin();
285
-
286
-        $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
287
-        $sql.= " SET libelle='".$this->db->escape($this->lib)."'";
288
-        $sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
289
-        $sql.= ", periode='".$this->db->idate($this->periode)."'";
290
-        $sql.= ", amount='".price2num($this->amount,'MT')."'";
181
+		$sql.= ", ".$conf->entity;
182
+		$sql.= ", ".$user->id;
183
+		$sql.= ", '".$this->db->idate($now)."'";
184
+		$sql.= ")";
185
+
186
+		dol_syslog(get_class($this)."::create", LOG_DEBUG);
187
+		$resql=$this->db->query($sql);
188
+		if ($resql)
189
+		{
190
+			$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
191
+
192
+			//dol_syslog("ChargesSociales::create this->id=".$this->id);
193
+			$this->db->commit();
194
+			return $this->id;
195
+		}
196
+		else
197
+		{
198
+			$this->error=$this->db->error();
199
+			$this->db->rollback();
200
+			return -1;
201
+		}
202
+	}
203
+
204
+
205
+	/**
206
+	 *      Delete a social contribution
207
+	 *
208
+	 *      @param		User    $user   Object user making delete
209
+	 *      @return     		int 	<0 if KO, >0 if OK
210
+	 */
211
+	function delete($user)
212
+	{
213
+		$error=0;
214
+
215
+		$this->db->begin();
216
+
217
+		// Get bank transaction lines for this social contributions
218
+		include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
219
+		$account=new Account($this->db);
220
+		$lines_url=$account->get_url('',$this->id,'sc');
221
+
222
+		// Delete bank urls
223
+		foreach ($lines_url as $line_url)
224
+		{
225
+			if (! $error)
226
+			{
227
+				$accountline=new AccountLine($this->db);
228
+				$accountline->fetch($line_url['fk_bank']);
229
+				$result=$accountline->delete_urls($user);
230
+				if ($result < 0)
231
+				{
232
+					$error++;
233
+				}
234
+			}
235
+		}
236
+
237
+		// Delete payments
238
+		if (! $error)
239
+		{
240
+			$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id;
241
+			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
242
+			$resql=$this->db->query($sql);
243
+			if (! $resql)
244
+			{
245
+				$error++;
246
+				$this->error=$this->db->lasterror();
247
+			}
248
+		}
249
+
250
+		if (! $error)
251
+		{
252
+			$sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id;
253
+			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
254
+			$resql=$this->db->query($sql);
255
+			if (! $resql)
256
+			{
257
+				$error++;
258
+				$this->error=$this->db->lasterror();
259
+			}
260
+		}
261
+
262
+		if (! $error)
263
+		{
264
+			$this->db->commit();
265
+			return 1;
266
+		}
267
+		else
268
+		{
269
+			$this->db->rollback();
270
+			return -1;
271
+		}
272
+
273
+	}
274
+
275
+
276
+	/**
277
+	 *      Met a jour une charge sociale
278
+	 *
279
+	 *      @param	User	$user   Utilisateur qui modifie
280
+	 *      @return int     		<0 si erreur, >0 si ok
281
+	 */
282
+	function update($user)
283
+	{
284
+		$this->db->begin();
285
+
286
+		$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
287
+		$sql.= " SET libelle='".$this->db->escape($this->lib)."'";
288
+		$sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
289
+		$sql.= ", periode='".$this->db->idate($this->periode)."'";
290
+		$sql.= ", amount='".price2num($this->amount,'MT')."'";
291 291
 		$sql.= ", fk_projet='".$this->db->escape($this->fk_project)."'";
292
-        $sql.= ", fk_user_modif=".$user->id;
293
-        $sql.= " WHERE rowid=".$this->id;
294
-
295
-        dol_syslog(get_class($this)."::update", LOG_DEBUG);
296
-        $resql=$this->db->query($sql);
297
-        if ($resql)
298
-        {
299
-            $this->db->commit();
300
-            return 1;
301
-        }
302
-        else
303
-        {
304
-            $this->error=$this->db->error();
305
-            $this->db->rollback();
306
-            return -1;
307
-        }
308
-    }
309
-
310
-    /**
311
-     * Calculate amount remaining to pay by year
312
-     *
313
-     * @param	int		$year		Year
314
-     * @return	number
315
-     */
316
-    function solde($year = 0)
317
-    {
318
-    	global $conf;
319
-
320
-        $sql = "SELECT SUM(f.amount) as amount";
321
-        $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
322
-        $sql.= " WHERE f.entity = ".$conf->entity;
323
-        $sql.= " AND paye = 0";
324
-
325
-        if ($year) {
326
-            $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
327
-        }
328
-
329
-        $result = $this->db->query($sql);
330
-        if ($result)
331
-        {
332
-            if ($this->db->num_rows($result))
333
-            {
334
-                $obj = $this->db->fetch_object($result);
335
-                $this->db->free($result);
336
-                return $obj->amount;
337
-            }
338
-            else
339
-            {
340
-                return 0;
341
-            }
342
-
343
-        }
344
-        else
345
-        {
346
-            print $this->db->error();
347
-            return -1;
348
-        }
349
-    }
350
-
351
-    /**
352
-     *    Tag social contribution as payed completely
353
-     *
354
-     *    @param	User	$user       Object user making change
355
-     *    @return	int					<0 if KO, >0 if OK
356
-     */
357
-    function set_paid($user)
358
-    {
359
-        $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
360
-        $sql.= " paye = 1";
361
-        $sql.= " WHERE rowid = ".$this->id;
362
-        $return = $this->db->query($sql);
363
-        if ($return) return 1;
364
-        else return -1;
365
-    }
366
-    /**
367
-     *    Remove tag payed on social contribution
368
-     *
369
-     *    @param	User	$user       Object user making change
370
-     *    @return	int					<0 if KO, >0 if OK
371
-     */
372
-    function set_unpaid($user)
373
-    {
374
-        $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
375
-        $sql.= " paye = 0";
376
-        $sql.= " WHERE rowid = ".$this->id;
377
-        $return = $this->db->query($sql);
378
-        if ($return) return 1;
379
-        else return -1;
380
-    }
381
-
382
-    /**
383
-     *  Retourne le libelle du statut d'une charge (impaye, payee)
384
-     *
385
-     *  @param	int		$mode       	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
292
+		$sql.= ", fk_user_modif=".$user->id;
293
+		$sql.= " WHERE rowid=".$this->id;
294
+
295
+		dol_syslog(get_class($this)."::update", LOG_DEBUG);
296
+		$resql=$this->db->query($sql);
297
+		if ($resql)
298
+		{
299
+			$this->db->commit();
300
+			return 1;
301
+		}
302
+		else
303
+		{
304
+			$this->error=$this->db->error();
305
+			$this->db->rollback();
306
+			return -1;
307
+		}
308
+	}
309
+
310
+	/**
311
+	 * Calculate amount remaining to pay by year
312
+	 *
313
+	 * @param	int		$year		Year
314
+	 * @return	number
315
+	 */
316
+	function solde($year = 0)
317
+	{
318
+		global $conf;
319
+
320
+		$sql = "SELECT SUM(f.amount) as amount";
321
+		$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
322
+		$sql.= " WHERE f.entity = ".$conf->entity;
323
+		$sql.= " AND paye = 0";
324
+
325
+		if ($year) {
326
+			$sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
327
+		}
328
+
329
+		$result = $this->db->query($sql);
330
+		if ($result)
331
+		{
332
+			if ($this->db->num_rows($result))
333
+			{
334
+				$obj = $this->db->fetch_object($result);
335
+				$this->db->free($result);
336
+				return $obj->amount;
337
+			}
338
+			else
339
+			{
340
+				return 0;
341
+			}
342
+
343
+		}
344
+		else
345
+		{
346
+			print $this->db->error();
347
+			return -1;
348
+		}
349
+	}
350
+
351
+	/**
352
+	 *    Tag social contribution as payed completely
353
+	 *
354
+	 *    @param	User	$user       Object user making change
355
+	 *    @return	int					<0 if KO, >0 if OK
356
+	 */
357
+	function set_paid($user)
358
+	{
359
+		$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
360
+		$sql.= " paye = 1";
361
+		$sql.= " WHERE rowid = ".$this->id;
362
+		$return = $this->db->query($sql);
363
+		if ($return) return 1;
364
+		else return -1;
365
+	}
366
+	/**
367
+	 *    Remove tag payed on social contribution
368
+	 *
369
+	 *    @param	User	$user       Object user making change
370
+	 *    @return	int					<0 if KO, >0 if OK
371
+	 */
372
+	function set_unpaid($user)
373
+	{
374
+		$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
375
+		$sql.= " paye = 0";
376
+		$sql.= " WHERE rowid = ".$this->id;
377
+		$return = $this->db->query($sql);
378
+		if ($return) return 1;
379
+		else return -1;
380
+	}
381
+
382
+	/**
383
+	 *  Retourne le libelle du statut d'une charge (impaye, payee)
384
+	 *
385
+	 *  @param	int		$mode       	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
386 386
 	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
387
-     *  @return	string        			Label
388
-     */
389
-    function getLibStatut($mode=0,$alreadypaid=-1)
390
-    {
391
-        return $this->LibStatut($this->paye,$mode,$alreadypaid);
392
-    }
393
-
394
-    /**
395
-     *  Renvoi le libelle d'un statut donne
396
-     *
397
-     *  @param	int		$statut        	Id statut
398
-     *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
387
+	 *  @return	string        			Label
388
+	 */
389
+	function getLibStatut($mode=0,$alreadypaid=-1)
390
+	{
391
+		return $this->LibStatut($this->paye,$mode,$alreadypaid);
392
+	}
393
+
394
+	/**
395
+	 *  Renvoi le libelle d'un statut donne
396
+	 *
397
+	 *  @param	int		$statut        	Id statut
398
+	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
399 399
 	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
400
-     *  @return string        			Label
401
-     */
402
-    function LibStatut($statut,$mode=0,$alreadypaid=-1)
403
-    {
404
-        global $langs;
405
-        $langs->load('customers');
406
-        $langs->load('bills');
407
-
408
-        if ($mode == 0)
409
-        {
410
-            if ($statut ==  0) return $langs->trans("Unpaid");
411
-            if ($statut ==  1) return $langs->trans("Paid");
412
-        }
413
-        if ($mode == 1)
414
-        {
415
-            if ($statut ==  0) return $langs->trans("Unpaid");
416
-            if ($statut ==  1) return $langs->trans("Paid");
417
-        }
418
-        if ($mode == 2)
419
-        {
420
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
421
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
422
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
423
-        }
424
-        if ($mode == 3)
425
-        {
426
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
427
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
428
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6');
429
-        }
430
-        if ($mode == 4)
431
-        {
432
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
433
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
434
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
435
-        }
436
-        if ($mode == 5)
437
-        {
438
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
439
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
440
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
441
-        }
442
-        if ($mode == 6)
443
-        {
444
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
445
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
446
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
447
-        }
448
-
449
-        return "Error, mode/status not found";
450
-    }
451
-
452
-
453
-    /**
454
-     *  Return clicable name (with picto eventually)
455
-     *
456
-     *	@param	int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
457
-     * 	@param	int		$maxlen			Longueur max libelle
458
-     *	@return	string					Chaine avec URL
459
-     */
460
-    function getNomUrl($withpicto=0,$maxlen=0)
461
-    {
462
-        global $langs;
463
-
464
-        $result='';
465
-
466
-        if (empty($this->ref)) $this->ref=$this->lib;
467
-        $label = $langs->trans("ShowSocialContribution").': '.$this->ref;
468
-
469
-        $link = '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
470
-        $linkend='</a>';
471
-
472
-        if ($withpicto) $result.=($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
473
-        if ($withpicto && $withpicto != 2) $result.=' ';
474
-        if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
475
-        return $result;
476
-    }
477
-
478
-    /**
479
-     * 	Return amount of payments already done
480
-     *
481
-     *	@return		int		Amount of payment already done, <0 if KO
482
-     */
483
-    function getSommePaiement()
484
-    {
485
-        $table='paiementcharge';
486
-        $field='fk_charge';
487
-
488
-        $sql = 'SELECT sum(amount) as amount';
489
-        $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
490
-        $sql.= ' WHERE '.$field.' = '.$this->id;
491
-
492
-        dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
493
-        $resql=$this->db->query($sql);
494
-        if ($resql)
495
-        {
496
-            $amount=0;
497
-
498
-            $obj = $this->db->fetch_object($resql);
499
-            if ($obj) $amount=$obj->amount?$obj->amount:0;
500
-
501
-            $this->db->free($resql);
502
-            return $amount;
503
-        }
504
-        else
505
-        {
506
-            return -1;
507
-        }
508
-    }
509
-
510
-    /**
511
-     * 	Charge les informations d'ordre info dans l'objet entrepot
512
-     *
513
-     *  @param	int		$id     Id of social contribution
514
-     *  @return	int				<0 if KO, >0 if OK
515
-     */
516
-    function info($id)
517
-    {
518
-        $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
519
-        $sql.= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
400
+	 *  @return string        			Label
401
+	 */
402
+	function LibStatut($statut,$mode=0,$alreadypaid=-1)
403
+	{
404
+		global $langs;
405
+		$langs->load('customers');
406
+		$langs->load('bills');
407
+
408
+		if ($mode == 0)
409
+		{
410
+			if ($statut ==  0) return $langs->trans("Unpaid");
411
+			if ($statut ==  1) return $langs->trans("Paid");
412
+		}
413
+		if ($mode == 1)
414
+		{
415
+			if ($statut ==  0) return $langs->trans("Unpaid");
416
+			if ($statut ==  1) return $langs->trans("Paid");
417
+		}
418
+		if ($mode == 2)
419
+		{
420
+			if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
421
+			if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
422
+			if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
423
+		}
424
+		if ($mode == 3)
425
+		{
426
+			if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
427
+			if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
428
+			if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6');
429
+		}
430
+		if ($mode == 4)
431
+		{
432
+			if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
433
+			if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
434
+			if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
435
+		}
436
+		if ($mode == 5)
437
+		{
438
+			if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
439
+			if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
440
+			if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
441
+		}
442
+		if ($mode == 6)
443
+		{
444
+			if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
445
+			if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
446
+			if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
447
+		}
448
+
449
+		return "Error, mode/status not found";
450
+	}
451
+
452
+
453
+	/**
454
+	 *  Return clicable name (with picto eventually)
455
+	 *
456
+	 *	@param	int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
457
+	 * 	@param	int		$maxlen			Longueur max libelle
458
+	 *	@return	string					Chaine avec URL
459
+	 */
460
+	function getNomUrl($withpicto=0,$maxlen=0)
461
+	{
462
+		global $langs;
463
+
464
+		$result='';
465
+
466
+		if (empty($this->ref)) $this->ref=$this->lib;
467
+		$label = $langs->trans("ShowSocialContribution").': '.$this->ref;
468
+
469
+		$link = '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
470
+		$linkend='</a>';
471
+
472
+		if ($withpicto) $result.=($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
473
+		if ($withpicto && $withpicto != 2) $result.=' ';
474
+		if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
475
+		return $result;
476
+	}
477
+
478
+	/**
479
+	 * 	Return amount of payments already done
480
+	 *
481
+	 *	@return		int		Amount of payment already done, <0 if KO
482
+	 */
483
+	function getSommePaiement()
484
+	{
485
+		$table='paiementcharge';
486
+		$field='fk_charge';
487
+
488
+		$sql = 'SELECT sum(amount) as amount';
489
+		$sql.= ' FROM '.MAIN_DB_PREFIX.$table;
490
+		$sql.= ' WHERE '.$field.' = '.$this->id;
491
+
492
+		dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
493
+		$resql=$this->db->query($sql);
494
+		if ($resql)
495
+		{
496
+			$amount=0;
497
+
498
+			$obj = $this->db->fetch_object($resql);
499
+			if ($obj) $amount=$obj->amount?$obj->amount:0;
500
+
501
+			$this->db->free($resql);
502
+			return $amount;
503
+		}
504
+		else
505
+		{
506
+			return -1;
507
+		}
508
+	}
509
+
510
+	/**
511
+	 * 	Charge les informations d'ordre info dans l'objet entrepot
512
+	 *
513
+	 *  @param	int		$id     Id of social contribution
514
+	 *  @return	int				<0 if KO, >0 if OK
515
+	 */
516
+	function info($id)
517
+	{
518
+		$sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
519
+		$sql.= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
520 520
 		$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
521
-        $sql.= " WHERE e.rowid = ".$id;
522
-
523
-        dol_syslog(get_class($this)."::info", LOG_DEBUG);
524
-        $result=$this->db->query($sql);
525
-        if ($result)
526
-        {
527
-            if ($this->db->num_rows($result))
528
-            {
529
-                $obj = $this->db->fetch_object($result);
530
-
531
-                $this->id = $obj->rowid;
532
-
533
-                if ($obj->fk_user_author) {
534
-                    $cuser = new User($this->db);
535
-                    $cuser->fetch($obj->fk_user_author);
536
-                    $this->user_creation = $cuser;
537
-                }
538
-
539
-                if ($obj->fk_user_modif) {
540
-                    $muser = new User($this->db);
541
-                    $muser->fetch($obj->fk_user_modif);
542
-                    $this->user_modification = $muser;
543
-                }
544
-
545
-                if ($obj->fk_user_valid) {
546
-                    $vuser = new User($this->db);
547
-                    $vuser->fetch($obj->fk_user_valid);
548
-                    $this->user_validation = $vuser;
549
-                }
550
-
551
-                $this->date_creation     = $this->db->jdate($obj->datec);
552
-                $this->date_modification = $this->db->jdate($obj->datem);
553
-                $this->date_validation   = $this->db->jdate($obj->datev);
554
-                $this->import_key        = $obj->import_key;
555
-            }
556
-
557
-            $this->db->free($result);
558
-
559
-        }
560
-        else
561
-        {
562
-            dol_print_error($this->db);
563
-        }
564
-    }
565
-
566
-    /**
567
-     *  Initialise an instance with random values.
568
-     *  Used to build previews or test instances.
569
-     *	id must be 0 if object instance is a specimen.
570
-     *
571
-     *  @return	void
572
-     */
573
-    function initAsSpecimen()
574
-    {
575
-        // Initialize parameters
576
-        $this->id=0;
577
-        $this->ref = 'SPECIMEN';
578
-        $this->specimen=1;
579
-        $this->paye = 0;
580
-        $this->date = time();
581
-        $this->date_ech=$this->date+3600*24*30;
582
-        $this->periode=$this->date+3600*24*30;
583
-        $this->amount=100;
584
-        $this->lib = 0;
585
-        $this->type = 1;
586
-        $this->type_libelle = 'Social contribution label';
587
-    }
521
+		$sql.= " WHERE e.rowid = ".$id;
522
+
523
+		dol_syslog(get_class($this)."::info", LOG_DEBUG);
524
+		$result=$this->db->query($sql);
525
+		if ($result)
526
+		{
527
+			if ($this->db->num_rows($result))
528
+			{
529
+				$obj = $this->db->fetch_object($result);
530
+
531
+				$this->id = $obj->rowid;
532
+
533
+				if ($obj->fk_user_author) {
534
+					$cuser = new User($this->db);
535
+					$cuser->fetch($obj->fk_user_author);
536
+					$this->user_creation = $cuser;
537
+				}
538
+
539
+				if ($obj->fk_user_modif) {
540
+					$muser = new User($this->db);
541
+					$muser->fetch($obj->fk_user_modif);
542
+					$this->user_modification = $muser;
543
+				}
544
+
545
+				if ($obj->fk_user_valid) {
546
+					$vuser = new User($this->db);
547
+					$vuser->fetch($obj->fk_user_valid);
548
+					$this->user_validation = $vuser;
549
+				}
550
+
551
+				$this->date_creation     = $this->db->jdate($obj->datec);
552
+				$this->date_modification = $this->db->jdate($obj->datem);
553
+				$this->date_validation   = $this->db->jdate($obj->datev);
554
+				$this->import_key        = $obj->import_key;
555
+			}
556
+
557
+			$this->db->free($result);
558
+
559
+		}
560
+		else
561
+		{
562
+			dol_print_error($this->db);
563
+		}
564
+	}
565
+
566
+	/**
567
+	 *  Initialise an instance with random values.
568
+	 *  Used to build previews or test instances.
569
+	 *	id must be 0 if object instance is a specimen.
570
+	 *
571
+	 *  @return	void
572
+	 */
573
+	function initAsSpecimen()
574
+	{
575
+		// Initialize parameters
576
+		$this->id=0;
577
+		$this->ref = 'SPECIMEN';
578
+		$this->specimen=1;
579
+		$this->paye = 0;
580
+		$this->date = time();
581
+		$this->date_ech=$this->date+3600*24*30;
582
+		$this->periode=$this->date+3600*24*30;
583
+		$this->amount=100;
584
+		$this->lib = 0;
585
+		$this->type = 1;
586
+		$this->type_libelle = 'Social contribution label';
587
+	}
588 588
 }
589 589
 
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class ChargeSociales extends CommonObject
34 34
 {
35
-    public $element='chargesociales';
36
-    public $table='chargesociales';
37
-    public $table_element='chargesociales';
35
+    public $element = 'chargesociales';
36
+    public $table = 'chargesociales';
37
+    public $table_element = 'chargesociales';
38 38
     public $picto = 'bill';
39 39
 
40 40
     /**
@@ -74,42 +74,42 @@  discard block
 block discarded – undo
74 74
      *  @param	string  $ref	Ref
75 75
      *  @return	int <0 KO >0 OK
76 76
      */
77
-    function fetch($id, $ref='')
77
+    function fetch($id, $ref = '')
78 78
     {
79 79
         $sql = "SELECT cs.rowid, cs.date_ech";
80
-        $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
81
-        $sql.= ", cs.fk_account, cs.fk_mode_reglement";
82
-        $sql.= ", c.libelle";
83
-        $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
84
-        $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
85
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
86
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
87
-        if ($ref) $sql.= " WHERE cs.rowid = ".$ref;
88
-        else $sql.= " WHERE cs.rowid = ".$id;
80
+        $sql .= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
81
+        $sql .= ", cs.fk_account, cs.fk_mode_reglement";
82
+        $sql .= ", c.libelle";
83
+        $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
84
+        $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
85
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
86
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN ('.getEntity('c_paiement').')';
87
+        if ($ref) $sql .= " WHERE cs.rowid = ".$ref;
88
+        else $sql .= " WHERE cs.rowid = ".$id;
89 89
 
90 90
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
91
-        $resql=$this->db->query($sql);
91
+        $resql = $this->db->query($sql);
92 92
         if ($resql)
93 93
         {
94 94
             if ($this->db->num_rows($resql))
95 95
             {
96 96
                 $obj = $this->db->fetch_object($resql);
97 97
 
98
-                $this->id					= $obj->rowid;
98
+                $this->id = $obj->rowid;
99 99
                 $this->ref					= $obj->rowid;
100
-                $this->date_ech				= $this->db->jdate($obj->date_ech);
100
+                $this->date_ech = $this->db->jdate($obj->date_ech);
101 101
                 $this->lib					= $obj->lib;
102
-                $this->type					= $obj->fk_type;
103
-                $this->type_libelle			= $obj->libelle;
104
-                $this->fk_account			= $obj->fk_account;
105
-                $this->mode_reglement_id	= $obj->fk_mode_reglement;
106
-                $this->mode_reglement_code	= $obj->mode_reglement_code;
107
-                $this->mode_reglement		= $obj->mode_reglement_libelle;
108
-                $this->amount				= $obj->amount;
109
-				$this->fk_project			= $obj->fk_project;
110
-                $this->paye					= $obj->paye;
111
-                $this->periode				= $this->db->jdate($obj->periode);
112
-                $this->import_key			= $this->import_key;
102
+                $this->type = $obj->fk_type;
103
+                $this->type_libelle = $obj->libelle;
104
+                $this->fk_account = $obj->fk_account;
105
+                $this->mode_reglement_id = $obj->fk_mode_reglement;
106
+                $this->mode_reglement_code = $obj->mode_reglement_code;
107
+                $this->mode_reglement = $obj->mode_reglement_libelle;
108
+                $this->amount = $obj->amount;
109
+				$this->fk_project = $obj->fk_project;
110
+                $this->paye = $obj->paye;
111
+                $this->periode = $this->db->jdate($obj->periode);
112
+                $this->import_key = $this->import_key;
113 113
 
114 114
                 $this->db->free($resql);
115 115
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         }
123 123
         else
124 124
         {
125
-            $this->error=$this->db->lasterror();
125
+            $this->error = $this->db->lasterror();
126 126
             return -1;
127 127
         }
128 128
     }
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	function check()
136 136
 	{
137
-		$newamount=price2num($this->amount,'MT');
137
+		$newamount = price2num($this->amount, 'MT');
138 138
 
139 139
         // Validation parametres
140
-        if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
140
+        if (!$newamount > 0 || empty($this->date_ech) || empty($this->periode))
141 141
         {
142 142
             return false;
143 143
         }
@@ -156,38 +156,38 @@  discard block
 block discarded – undo
156 156
     {
157 157
     	global $conf;
158 158
 
159
-        $now=dol_now();
159
+        $now = dol_now();
160 160
 
161 161
         // Nettoyage parametres
162
-        $newamount=price2num($this->amount,'MT');
162
+        $newamount = price2num($this->amount, 'MT');
163 163
 
164 164
 		if (!$this->check())
165 165
 		{
166
-			 $this->error="ErrorBadParameter";
166
+			 $this->error = "ErrorBadParameter";
167 167
 			 return -2;
168 168
 		}
169 169
 
170 170
         $this->db->begin();
171 171
 
172 172
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)";
173
-        $sql.= " VALUES (".$this->type;
174
-        $sql.= ", ".($this->fk_account>0 ? $this->fk_account:'NULL');
175
-        $sql.= ", ".($this->mode_reglement_id>0 ? $this->mode_reglement_id:"NULL");
176
-        $sql.= ", '".$this->db->escape($this->lib)."'";
177
-        $sql.= ", '".$this->db->idate($this->date_ech)."'";
178
-		$sql.= ", '".$this->db->idate($this->periode)."'";
179
-        $sql.= ", '".price2num($newamount)."'";
180
-		$sql.= ", ".($this->fk_project>0?$this->fk_project:'NULL');
181
-        $sql.= ", ".$conf->entity;
182
-        $sql.= ", ".$user->id;
183
-        $sql.= ", '".$this->db->idate($now)."'";
184
-        $sql.= ")";
173
+        $sql .= " VALUES (".$this->type;
174
+        $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL');
175
+        $sql .= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : "NULL");
176
+        $sql .= ", '".$this->db->escape($this->lib)."'";
177
+        $sql .= ", '".$this->db->idate($this->date_ech)."'";
178
+		$sql .= ", '".$this->db->idate($this->periode)."'";
179
+        $sql .= ", '".price2num($newamount)."'";
180
+		$sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 'NULL');
181
+        $sql .= ", ".$conf->entity;
182
+        $sql .= ", ".$user->id;
183
+        $sql .= ", '".$this->db->idate($now)."'";
184
+        $sql .= ")";
185 185
 
186 186
         dol_syslog(get_class($this)."::create", LOG_DEBUG);
187
-        $resql=$this->db->query($sql);
187
+        $resql = $this->db->query($sql);
188 188
         if ($resql)
189 189
         {
190
-            $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
190
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
191 191
 
192 192
             //dol_syslog("ChargesSociales::create this->id=".$this->id);
193 193
             $this->db->commit();
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         }
196 196
         else
197 197
         {
198
-            $this->error=$this->db->error();
198
+            $this->error = $this->db->error();
199 199
             $this->db->rollback();
200 200
             return -1;
201 201
         }
@@ -210,23 +210,23 @@  discard block
 block discarded – undo
210 210
      */
211 211
     function delete($user)
212 212
     {
213
-        $error=0;
213
+        $error = 0;
214 214
 
215 215
         $this->db->begin();
216 216
 
217 217
         // Get bank transaction lines for this social contributions
218 218
         include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
219
-        $account=new Account($this->db);
220
-        $lines_url=$account->get_url('',$this->id,'sc');
219
+        $account = new Account($this->db);
220
+        $lines_url = $account->get_url('', $this->id, 'sc');
221 221
 
222 222
         // Delete bank urls
223 223
         foreach ($lines_url as $line_url)
224 224
         {
225
-            if (! $error)
225
+            if (!$error)
226 226
             {
227
-                $accountline=new AccountLine($this->db);
227
+                $accountline = new AccountLine($this->db);
228 228
                 $accountline->fetch($line_url['fk_bank']);
229
-                $result=$accountline->delete_urls($user);
229
+                $result = $accountline->delete_urls($user);
230 230
                 if ($result < 0)
231 231
                 {
232 232
                     $error++;
@@ -235,31 +235,31 @@  discard block
 block discarded – undo
235 235
         }
236 236
 
237 237
         // Delete payments
238
-        if (! $error)
238
+        if (!$error)
239 239
         {
240 240
             $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id;
241 241
             dol_syslog(get_class($this)."::delete", LOG_DEBUG);
242
-            $resql=$this->db->query($sql);
243
-            if (! $resql)
242
+            $resql = $this->db->query($sql);
243
+            if (!$resql)
244 244
             {
245 245
                 $error++;
246
-                $this->error=$this->db->lasterror();
246
+                $this->error = $this->db->lasterror();
247 247
             }
248 248
         }
249 249
 
250
-        if (! $error)
250
+        if (!$error)
251 251
         {
252 252
             $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id;
253 253
             dol_syslog(get_class($this)."::delete", LOG_DEBUG);
254
-            $resql=$this->db->query($sql);
255
-            if (! $resql)
254
+            $resql = $this->db->query($sql);
255
+            if (!$resql)
256 256
             {
257 257
                 $error++;
258
-                $this->error=$this->db->lasterror();
258
+                $this->error = $this->db->lasterror();
259 259
             }
260 260
         }
261 261
 
262
-        if (! $error)
262
+        if (!$error)
263 263
         {
264 264
             $this->db->commit();
265 265
             return 1;
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
         $this->db->begin();
285 285
 
286 286
         $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
287
-        $sql.= " SET libelle='".$this->db->escape($this->lib)."'";
288
-        $sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
289
-        $sql.= ", periode='".$this->db->idate($this->periode)."'";
290
-        $sql.= ", amount='".price2num($this->amount,'MT')."'";
291
-		$sql.= ", fk_projet='".$this->db->escape($this->fk_project)."'";
292
-        $sql.= ", fk_user_modif=".$user->id;
293
-        $sql.= " WHERE rowid=".$this->id;
287
+        $sql .= " SET libelle='".$this->db->escape($this->lib)."'";
288
+        $sql .= ", date_ech='".$this->db->idate($this->date_ech)."'";
289
+        $sql .= ", periode='".$this->db->idate($this->periode)."'";
290
+        $sql .= ", amount='".price2num($this->amount, 'MT')."'";
291
+		$sql .= ", fk_projet='".$this->db->escape($this->fk_project)."'";
292
+        $sql .= ", fk_user_modif=".$user->id;
293
+        $sql .= " WHERE rowid=".$this->id;
294 294
 
295 295
         dol_syslog(get_class($this)."::update", LOG_DEBUG);
296
-        $resql=$this->db->query($sql);
296
+        $resql = $this->db->query($sql);
297 297
         if ($resql)
298 298
         {
299 299
             $this->db->commit();
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         }
302 302
         else
303 303
         {
304
-            $this->error=$this->db->error();
304
+            $this->error = $this->db->error();
305 305
             $this->db->rollback();
306 306
             return -1;
307 307
         }
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
     	global $conf;
319 319
 
320 320
         $sql = "SELECT SUM(f.amount) as amount";
321
-        $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
322
-        $sql.= " WHERE f.entity = ".$conf->entity;
323
-        $sql.= " AND paye = 0";
321
+        $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
322
+        $sql .= " WHERE f.entity = ".$conf->entity;
323
+        $sql .= " AND paye = 0";
324 324
 
325 325
         if ($year) {
326 326
             $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
     function set_paid($user)
358 358
     {
359 359
         $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
360
-        $sql.= " paye = 1";
361
-        $sql.= " WHERE rowid = ".$this->id;
360
+        $sql .= " paye = 1";
361
+        $sql .= " WHERE rowid = ".$this->id;
362 362
         $return = $this->db->query($sql);
363 363
         if ($return) return 1;
364 364
         else return -1;
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
     function set_unpaid($user)
373 373
     {
374 374
         $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
375
-        $sql.= " paye = 0";
376
-        $sql.= " WHERE rowid = ".$this->id;
375
+        $sql .= " paye = 0";
376
+        $sql .= " WHERE rowid = ".$this->id;
377 377
         $return = $this->db->query($sql);
378 378
         if ($return) return 1;
379 379
         else return -1;
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
 	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
387 387
      *  @return	string        			Label
388 388
      */
389
-    function getLibStatut($mode=0,$alreadypaid=-1)
389
+    function getLibStatut($mode = 0, $alreadypaid = -1)
390 390
     {
391
-        return $this->LibStatut($this->paye,$mode,$alreadypaid);
391
+        return $this->LibStatut($this->paye, $mode, $alreadypaid);
392 392
     }
393 393
 
394 394
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	 *  @param  double	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
400 400
      *  @return string        			Label
401 401
      */
402
-    function LibStatut($statut,$mode=0,$alreadypaid=-1)
402
+    function LibStatut($statut, $mode = 0, $alreadypaid = -1)
403 403
     {
404 404
         global $langs;
405 405
         $langs->load('customers');
@@ -407,43 +407,43 @@  discard block
 block discarded – undo
407 407
 
408 408
         if ($mode == 0)
409 409
         {
410
-            if ($statut ==  0) return $langs->trans("Unpaid");
411
-            if ($statut ==  1) return $langs->trans("Paid");
410
+            if ($statut == 0) return $langs->trans("Unpaid");
411
+            if ($statut == 1) return $langs->trans("Paid");
412 412
         }
413 413
         if ($mode == 1)
414 414
         {
415
-            if ($statut ==  0) return $langs->trans("Unpaid");
416
-            if ($statut ==  1) return $langs->trans("Paid");
415
+            if ($statut == 0) return $langs->trans("Unpaid");
416
+            if ($statut == 1) return $langs->trans("Paid");
417 417
         }
418 418
         if ($mode == 2)
419 419
         {
420
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
421
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
422
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
420
+            if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
421
+            if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
422
+            if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
423 423
         }
424 424
         if ($mode == 3)
425 425
         {
426
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
427
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
428
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6');
426
+            if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
427
+            if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
428
+            if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
429 429
         }
430 430
         if ($mode == 4)
431 431
         {
432
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
433
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
434
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
432
+            if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
433
+            if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
434
+            if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
435 435
         }
436 436
         if ($mode == 5)
437 437
         {
438
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
439
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
440
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
438
+            if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
439
+            if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
440
+            if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
441 441
         }
442 442
         if ($mode == 6)
443 443
         {
444
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
445
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
446
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
444
+            if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
445
+            if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
446
+            if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
447 447
         }
448 448
 
449 449
         return "Error, mode/status not found";
@@ -457,21 +457,21 @@  discard block
 block discarded – undo
457 457
      * 	@param	int		$maxlen			Longueur max libelle
458 458
      *	@return	string					Chaine avec URL
459 459
      */
460
-    function getNomUrl($withpicto=0,$maxlen=0)
460
+    function getNomUrl($withpicto = 0, $maxlen = 0)
461 461
     {
462 462
         global $langs;
463 463
 
464
-        $result='';
464
+        $result = '';
465 465
 
466
-        if (empty($this->ref)) $this->ref=$this->lib;
466
+        if (empty($this->ref)) $this->ref = $this->lib;
467 467
         $label = $langs->trans("ShowSocialContribution").': '.$this->ref;
468 468
 
469 469
         $link = '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
470
-        $linkend='</a>';
470
+        $linkend = '</a>';
471 471
 
472
-        if ($withpicto) $result.=($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
473
-        if ($withpicto && $withpicto != 2) $result.=' ';
474
-        if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
472
+        if ($withpicto) $result .= ($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
473
+        if ($withpicto && $withpicto != 2) $result .= ' ';
474
+        if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
475 475
         return $result;
476 476
     }
477 477
 
@@ -482,21 +482,21 @@  discard block
 block discarded – undo
482 482
      */
483 483
     function getSommePaiement()
484 484
     {
485
-        $table='paiementcharge';
486
-        $field='fk_charge';
485
+        $table = 'paiementcharge';
486
+        $field = 'fk_charge';
487 487
 
488 488
         $sql = 'SELECT sum(amount) as amount';
489
-        $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
490
-        $sql.= ' WHERE '.$field.' = '.$this->id;
489
+        $sql .= ' FROM '.MAIN_DB_PREFIX.$table;
490
+        $sql .= ' WHERE '.$field.' = '.$this->id;
491 491
 
492 492
         dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
493
-        $resql=$this->db->query($sql);
493
+        $resql = $this->db->query($sql);
494 494
         if ($resql)
495 495
         {
496
-            $amount=0;
496
+            $amount = 0;
497 497
 
498 498
             $obj = $this->db->fetch_object($resql);
499
-            if ($obj) $amount=$obj->amount?$obj->amount:0;
499
+            if ($obj) $amount = $obj->amount ? $obj->amount : 0;
500 500
 
501 501
             $this->db->free($resql);
502 502
             return $amount;
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
     function info($id)
517 517
     {
518 518
         $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
519
-        $sql.= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
520
-		$sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
521
-        $sql.= " WHERE e.rowid = ".$id;
519
+        $sql .= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
520
+		$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
521
+        $sql .= " WHERE e.rowid = ".$id;
522 522
 
523 523
         dol_syslog(get_class($this)."::info", LOG_DEBUG);
524
-        $result=$this->db->query($sql);
524
+        $result = $this->db->query($sql);
525 525
         if ($result)
526 526
         {
527 527
             if ($this->db->num_rows($result))
@@ -573,14 +573,14 @@  discard block
 block discarded – undo
573 573
     function initAsSpecimen()
574 574
     {
575 575
         // Initialize parameters
576
-        $this->id=0;
576
+        $this->id = 0;
577 577
         $this->ref = 'SPECIMEN';
578
-        $this->specimen=1;
578
+        $this->specimen = 1;
579 579
         $this->paye = 0;
580 580
         $this->date = time();
581
-        $this->date_ech=$this->date+3600*24*30;
582
-        $this->periode=$this->date+3600*24*30;
583
-        $this->amount=100;
581
+        $this->date_ech = $this->date + 3600 * 24 * 30;
582
+        $this->periode = $this->date + 3600 * 24 * 30;
583
+        $this->amount = 100;
584 584
         $this->lib = 0;
585 585
         $this->type = 1;
586 586
         $this->type_libelle = 'Social contribution label';
Please login to merge, or discard this patch.
Braces   +96 added lines, -48 removed lines patch added patch discarded remove patch
@@ -84,8 +84,11 @@  discard block
 block discarded – undo
84 84
         $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
85 85
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
86 86
         $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
87
-        if ($ref) $sql.= " WHERE cs.rowid = ".$ref;
88
-        else $sql.= " WHERE cs.rowid = ".$id;
87
+        if ($ref) {
88
+        	$sql.= " WHERE cs.rowid = ".$ref;
89
+        } else {
90
+        	$sql.= " WHERE cs.rowid = ".$id;
91
+        }
89 92
 
90 93
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
91 94
         $resql=$this->db->query($sql);
@@ -114,13 +117,11 @@  discard block
 block discarded – undo
114 117
                 $this->db->free($resql);
115 118
 
116 119
                 return 1;
117
-            }
118
-            else
120
+            } else
119 121
             {
120 122
                 return 0;
121 123
             }
122
-        }
123
-        else
124
+        } else
124 125
         {
125 126
             $this->error=$this->db->lasterror();
126 127
             return -1;
@@ -192,8 +193,7 @@  discard block
 block discarded – undo
192 193
             //dol_syslog("ChargesSociales::create this->id=".$this->id);
193 194
             $this->db->commit();
194 195
             return $this->id;
195
-        }
196
-        else
196
+        } else
197 197
         {
198 198
             $this->error=$this->db->error();
199 199
             $this->db->rollback();
@@ -263,8 +263,7 @@  discard block
 block discarded – undo
263 263
         {
264 264
             $this->db->commit();
265 265
             return 1;
266
-        }
267
-        else
266
+        } else
268 267
         {
269 268
             $this->db->rollback();
270 269
             return -1;
@@ -298,8 +297,7 @@  discard block
 block discarded – undo
298 297
         {
299 298
             $this->db->commit();
300 299
             return 1;
301
-        }
302
-        else
300
+        } else
303 301
         {
304 302
             $this->error=$this->db->error();
305 303
             $this->db->rollback();
@@ -334,14 +332,12 @@  discard block
 block discarded – undo
334 332
                 $obj = $this->db->fetch_object($result);
335 333
                 $this->db->free($result);
336 334
                 return $obj->amount;
337
-            }
338
-            else
335
+            } else
339 336
             {
340 337
                 return 0;
341 338
             }
342 339
 
343
-        }
344
-        else
340
+        } else
345 341
         {
346 342
             print $this->db->error();
347 343
             return -1;
@@ -360,8 +356,11 @@  discard block
 block discarded – undo
360 356
         $sql.= " paye = 1";
361 357
         $sql.= " WHERE rowid = ".$this->id;
362 358
         $return = $this->db->query($sql);
363
-        if ($return) return 1;
364
-        else return -1;
359
+        if ($return) {
360
+        	return 1;
361
+        } else {
362
+        	return -1;
363
+        }
365 364
     }
366 365
     /**
367 366
      *    Remove tag payed on social contribution
@@ -375,8 +374,11 @@  discard block
 block discarded – undo
375 374
         $sql.= " paye = 0";
376 375
         $sql.= " WHERE rowid = ".$this->id;
377 376
         $return = $this->db->query($sql);
378
-        if ($return) return 1;
379
-        else return -1;
377
+        if ($return) {
378
+        	return 1;
379
+        } else {
380
+        	return -1;
381
+        }
380 382
     }
381 383
 
382 384
     /**
@@ -407,43 +409,81 @@  discard block
 block discarded – undo
407 409
 
408 410
         if ($mode == 0)
409 411
         {
410
-            if ($statut ==  0) return $langs->trans("Unpaid");
411
-            if ($statut ==  1) return $langs->trans("Paid");
412
+            if ($statut ==  0) {
413
+            	return $langs->trans("Unpaid");
414
+            }
415
+            if ($statut ==  1) {
416
+            	return $langs->trans("Paid");
417
+            }
412 418
         }
413 419
         if ($mode == 1)
414 420
         {
415
-            if ($statut ==  0) return $langs->trans("Unpaid");
416
-            if ($statut ==  1) return $langs->trans("Paid");
421
+            if ($statut ==  0) {
422
+            	return $langs->trans("Unpaid");
423
+            }
424
+            if ($statut ==  1) {
425
+            	return $langs->trans("Paid");
426
+            }
417 427
         }
418 428
         if ($mode == 2)
419 429
         {
420
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
421
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
422
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
430
+            if ($statut ==  0 && $alreadypaid <= 0) {
431
+            	return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
432
+            }
433
+            if ($statut ==  0 && $alreadypaid > 0) {
434
+            	return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
435
+            }
436
+            if ($statut ==  1) {
437
+            	return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
438
+            }
423 439
         }
424 440
         if ($mode == 3)
425 441
         {
426
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
427
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
428
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6');
442
+            if ($statut ==  0 && $alreadypaid <= 0) {
443
+            	return img_picto($langs->trans("Unpaid"), 'statut1');
444
+            }
445
+            if ($statut ==  0 && $alreadypaid > 0) {
446
+            	return img_picto($langs->trans("BillStatusStarted"), 'statut3');
447
+            }
448
+            if ($statut ==  1) {
449
+            	return img_picto($langs->trans("Paid"), 'statut6');
450
+            }
429 451
         }
430 452
         if ($mode == 4)
431 453
         {
432
-            if ($statut ==  0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
433
-            if ($statut ==  0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
434
-            if ($statut ==  1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
454
+            if ($statut ==  0 && $alreadypaid <= 0) {
455
+            	return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
456
+            }
457
+            if ($statut ==  0 && $alreadypaid > 0) {
458
+            	return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
459
+            }
460
+            if ($statut ==  1) {
461
+            	return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
462
+            }
435 463
         }
436 464
         if ($mode == 5)
437 465
         {
438
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
439
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
440
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
466
+            if ($statut ==  0 && $alreadypaid <= 0) {
467
+            	return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
468
+            }
469
+            if ($statut ==  0 && $alreadypaid > 0) {
470
+            	return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
471
+            }
472
+            if ($statut ==  1) {
473
+            	return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
474
+            }
441 475
         }
442 476
         if ($mode == 6)
443 477
         {
444
-            if ($statut ==  0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
445
-            if ($statut ==  0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
446
-            if ($statut ==  1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
478
+            if ($statut ==  0 && $alreadypaid <= 0) {
479
+            	return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
480
+            }
481
+            if ($statut ==  0 && $alreadypaid > 0) {
482
+            	return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
483
+            }
484
+            if ($statut ==  1) {
485
+            	return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
486
+            }
447 487
         }
448 488
 
449 489
         return "Error, mode/status not found";
@@ -463,15 +503,23 @@  discard block
 block discarded – undo
463 503
 
464 504
         $result='';
465 505
 
466
-        if (empty($this->ref)) $this->ref=$this->lib;
506
+        if (empty($this->ref)) {
507
+        	$this->ref=$this->lib;
508
+        }
467 509
         $label = $langs->trans("ShowSocialContribution").': '.$this->ref;
468 510
 
469 511
         $link = '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
470 512
         $linkend='</a>';
471 513
 
472
-        if ($withpicto) $result.=($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
473
-        if ($withpicto && $withpicto != 2) $result.=' ';
474
-        if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
514
+        if ($withpicto) {
515
+        	$result.=($link.img_object($label, 'bill', 'class="classfortooltip"').$linkend.' ');
516
+        }
517
+        if ($withpicto && $withpicto != 2) {
518
+        	$result.=' ';
519
+        }
520
+        if ($withpicto != 2) {
521
+        	$result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
522
+        }
475 523
         return $result;
476 524
     }
477 525
 
@@ -496,12 +544,13 @@  discard block
 block discarded – undo
496 544
             $amount=0;
497 545
 
498 546
             $obj = $this->db->fetch_object($resql);
499
-            if ($obj) $amount=$obj->amount?$obj->amount:0;
547
+            if ($obj) {
548
+            	$amount=$obj->amount?$obj->amount:0;
549
+            }
500 550
 
501 551
             $this->db->free($resql);
502 552
             return $amount;
503
-        }
504
-        else
553
+        } else
505 554
         {
506 555
             return -1;
507 556
         }
@@ -556,8 +605,7 @@  discard block
 block discarded – undo
556 605
 
557 606
             $this->db->free($result);
558 607
 
559
-        }
560
-        else
608
+        } else
561 609
         {
562 610
             dol_print_error($this->db);
563 611
         }
Please login to merge, or discard this patch.
htdocs/core/class/html.formactions.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -250,7 +250,7 @@
 block discarded – undo
250 250
     /**
251 251
      *  Output html select list of type of event
252 252
      *
253
-     *  @param	array|string	$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
253
+     *  @param	string	$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
254 254
      *  @param  string		    $htmlname       Name of select field
255 255
      *  @param	string		    $excludetype	A type to exclude ('systemauto', 'system', '')
256 256
      *  @param	integer		    $onlyautoornot	1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type, -1=Keep details and add a combined line "All manual"
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -29,50 +29,50 @@  discard block
 block discarded – undo
29 29
  */
30 30
 class FormActions
31 31
 {
32
-    var $db;
33
-    var $error;
32
+	var $db;
33
+	var $error;
34 34
 
35 35
 
36
-    /**
36
+	/**
37 37
 	 *	Constructor
38 38
 	 *
39 39
 	 *  @param		DoliDB		$db      Database handler
40
-     */
41
-    function __construct($db)
42
-    {
43
-        $this->db = $db;
44
-        return 1;
45
-    }
46
-
47
-
48
-    /**
49
-     *  Show list of action status
50
-     *
51
-     * 	@param	string	$formname		Name of form where select is included
52
-     * 	@param	string	$selected		Preselected value (-1..100)
53
-     * 	@param	int		$canedit		1=can edit, 0=read only
54
-     *  @param  string	$htmlname   	Name of html prefix for html fields (selectX and valX)
55
-     *  @param	integer	$showempty		Show an empty line if select is used
56
-     *  @param	integer	$onlyselect		0=Standard, 1=Hide percent of completion and force usage of a select list, 2=Same than 1 and add "Incomplete (Todo+Running)
57
-     *  @param  string  $morecss        More css on select field
58
-     * 	@return	void
59
-     */
60
-    function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
61
-    {
62
-        global $langs,$conf;
63
-
64
-        $listofstatus = array(
65
-            '-1' => $langs->trans("ActionNotApplicable"),
66
-            '0' => $langs->trans("ActionsToDoShort"),
67
-            '50' => $langs->trans("ActionRunningShort"),
68
-            '100' => $langs->trans("ActionDoneShort")
69
-        );
40
+	 */
41
+	function __construct($db)
42
+	{
43
+		$this->db = $db;
44
+		return 1;
45
+	}
46
+
47
+
48
+	/**
49
+	 *  Show list of action status
50
+	 *
51
+	 * 	@param	string	$formname		Name of form where select is included
52
+	 * 	@param	string	$selected		Preselected value (-1..100)
53
+	 * 	@param	int		$canedit		1=can edit, 0=read only
54
+	 *  @param  string	$htmlname   	Name of html prefix for html fields (selectX and valX)
55
+	 *  @param	integer	$showempty		Show an empty line if select is used
56
+	 *  @param	integer	$onlyselect		0=Standard, 1=Hide percent of completion and force usage of a select list, 2=Same than 1 and add "Incomplete (Todo+Running)
57
+	 *  @param  string  $morecss        More css on select field
58
+	 * 	@return	void
59
+	 */
60
+	function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
61
+	{
62
+		global $langs,$conf;
63
+
64
+		$listofstatus = array(
65
+			'-1' => $langs->trans("ActionNotApplicable"),
66
+			'0' => $langs->trans("ActionsToDoShort"),
67
+			'50' => $langs->trans("ActionRunningShort"),
68
+			'100' => $langs->trans("ActionDoneShort")
69
+		);
70 70
 		// +ActionUncomplete
71 71
 
72
-        if (! empty($conf->use_javascript_ajax))
73
-        {
74
-            print "\n";
75
-            print "<script type=\"text/javascript\">
72
+		if (! empty($conf->use_javascript_ajax))
73
+		{
74
+			print "\n";
75
+			print "<script type=\"text/javascript\">
76 76
                 var htmlname = '".$htmlname."';
77 77
 
78 78
                 $(document).ready(function () {
@@ -116,218 +116,218 @@  discard block
 block discarded – undo
116 116
                     }
117 117
                 }
118 118
                 </script>\n";
119
-        }
120
-        if (! empty($conf->use_javascript_ajax) || $onlyselect)
121
-        {
122
-        	//var_dump($selected);
123
-        	if ($selected == 'done') $selected='100';
124
-            print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
125
-            if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
126
-            foreach($listofstatus as $key => $val)
127
-            {
128
-                print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
129
-                if ($key == '50' && $onlyselect == 2)
130
-                {
131
-                	print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
132
-                }
133
-            }
134
-            print '</select>';
135
-            if ($selected == 0 || $selected == 100) $canedit=0;
136
-
137
-            if (empty($onlyselect))
138
-            {
139
-	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
140
-    	        print '<span class="hideonsmartphone hideifna">%</span>';
141
-            }
142
-        }
143
-        else
119
+		}
120
+		if (! empty($conf->use_javascript_ajax) || $onlyselect)
121
+		{
122
+			//var_dump($selected);
123
+			if ($selected == 'done') $selected='100';
124
+			print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
125
+			if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
126
+			foreach($listofstatus as $key => $val)
127
+			{
128
+				print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
129
+				if ($key == '50' && $onlyselect == 2)
130
+				{
131
+					print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
132
+				}
133
+			}
134
+			print '</select>';
135
+			if ($selected == 0 || $selected == 100) $canedit=0;
136
+
137
+			if (empty($onlyselect))
138
+			{
139
+				print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
140
+				print '<span class="hideonsmartphone hideifna">%</span>';
141
+			}
142
+		}
143
+		else
144 144
 		{
145
-            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
146
-        }
147
-    }
148
-
149
-
150
-    /**
151
-     *  Show list of actions for element
152
-     *
153
-     *  @param	Object	$object					Object
154
-     *  @param  string	$typeelement			'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
155
-     *	@param	int		$socid					Socid of user
156
-     *  @param	int		$forceshowtitle			Show title even if there is no actions to show
157
-     *  @param  string  $morecss        		More css on table
158
-     *  @param	int		$max					Max number of record
159
-     *  @param	string	$moreparambacktopage	More param for the backtopage
160
-     *  @param	string	$morehtmlright			More html text on right of title line
161
-     *	@return	int								<0 if KO, >=0 if OK
162
-     */
163
-    function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
164
-    {
165
-        global $langs,$conf,$user;
166
-        global $bc;
167
-
168
-        require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
169
-
170
-        $sortfield='a.datep';
171
-        $sortorder='DESC';
172
-
173
-        $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
145
+			print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
146
+		}
147
+	}
148
+
149
+
150
+	/**
151
+	 *  Show list of actions for element
152
+	 *
153
+	 *  @param	Object	$object					Object
154
+	 *  @param  string	$typeelement			'invoice','propal','order','invoice_supplier','order_supplier','fichinter'
155
+	 *	@param	int		$socid					Socid of user
156
+	 *  @param	int		$forceshowtitle			Show title even if there is no actions to show
157
+	 *  @param  string  $morecss        		More css on table
158
+	 *  @param	int		$max					Max number of record
159
+	 *  @param	string	$moreparambacktopage	More param for the backtopage
160
+	 *  @param	string	$morehtmlright			More html text on right of title line
161
+	 *	@return	int								<0 if KO, >=0 if OK
162
+	 */
163
+	function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
164
+	{
165
+		global $langs,$conf,$user;
166
+		global $bc;
167
+
168
+		require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
169
+
170
+		$sortfield='a.datep';
171
+		$sortorder='DESC';
172
+
173
+		$listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
174 174
 		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
175 175
 
176
-        $num = count($listofactions);
177
-        if ($num || $forceshowtitle)
178
-        {
179
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
180
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
181
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
182
-        	elseif ($typeelement == 'supplier_payment')  $title=$langs->trans('ActionsOnSupplierPayment');
183
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
184
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
185
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
186
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
187
-            elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
188
-            elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
189
-            elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
190
-            elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
191
-            else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
192
-
193
-            $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
194
-
195
-        	$buttontoaddnewevent = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.'&socid='.$object->socid.'&projectid='.$object->fk_project.'&backtopage='.urlencode($urlbacktopage).'">';
196
-        	$buttontoaddnewevent.= $langs->trans("AddEvent");
197
-        	$buttontoaddnewevent.= '</a>';
198
-
199
-        	print '<!-- formactions->showactions -->'."\n";
200
-        	print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $buttontoaddnewevent);
201
-
202
-        	$page=0; $param='';
203
-
204
-        	$total = 0;
205
-
206
-        	print '<div class="div-table-responsive-no-min">';
207
-        	print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
208
-        	print '<tr class="liste_titre">';
209
-        	print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
210
-        	print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
211
-        	print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
212
-        	print getTitleFieldOfList('Action', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
213
-        	print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
214
-        	print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
215
-        	print '</tr>';
216
-        	print "\n";
217
-
218
-        	$userstatic = new User($this->db);
219
-
220
-        	if (count($listofactions))
221
-        	{
222
-	        	$cursorevent = 0;
223
-	        	foreach($listofactions as $action)
224
-	        	{
225
-	        		if ($max && $cursorevent >= $max) break;
226
-
227
-	        		$ref=$action->getNomUrl(1,-1);
228
-	        		$label=$action->getNomUrl(0,38);
229
-
230
-	        		print '<tr class="oddeven">';
176
+		$num = count($listofactions);
177
+		if ($num || $forceshowtitle)
178
+		{
179
+			if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
180
+			elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
181
+			elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
182
+			elseif ($typeelement == 'supplier_payment')  $title=$langs->trans('ActionsOnSupplierPayment');
183
+			elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
184
+			elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
185
+			elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
186
+			elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
187
+			elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
188
+			elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
189
+			elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
190
+			elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
191
+			else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
192
+
193
+			$urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
194
+
195
+			$buttontoaddnewevent = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.'&socid='.$object->socid.'&projectid='.$object->fk_project.'&backtopage='.urlencode($urlbacktopage).'">';
196
+			$buttontoaddnewevent.= $langs->trans("AddEvent");
197
+			$buttontoaddnewevent.= '</a>';
198
+
199
+			print '<!-- formactions->showactions -->'."\n";
200
+			print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $buttontoaddnewevent);
201
+
202
+			$page=0; $param='';
203
+
204
+			$total = 0;
205
+
206
+			print '<div class="div-table-responsive-no-min">';
207
+			print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
208
+			print '<tr class="liste_titre">';
209
+			print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
210
+			print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
211
+			print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
212
+			print getTitleFieldOfList('Action', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
213
+			print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
214
+			print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
215
+			print '</tr>';
216
+			print "\n";
217
+
218
+			$userstatic = new User($this->db);
219
+
220
+			if (count($listofactions))
221
+			{
222
+				$cursorevent = 0;
223
+				foreach($listofactions as $action)
224
+				{
225
+					if ($max && $cursorevent >= $max) break;
226
+
227
+					$ref=$action->getNomUrl(1,-1);
228
+					$label=$action->getNomUrl(0,38);
229
+
230
+					print '<tr class="oddeven">';
231 231
 					print '<td>'.$ref.'</td>';
232
-	        		print '<td>';
233
-	        		if (! empty($action->userownerid))
234
-	        		{
235
-	        			$userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
236
-	        			print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
237
-	        		}
238
-	        		print '</td>';
239 232
 					print '<td>';
240
-	        		if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
241
-	        		{
242
-	        		    if ($action->type_picto) print img_picto('', $action->type_picto);
243
-	        		    else {
244
-	        		        if ($action->type_code == 'AC_RDV')   print img_picto('', 'object_group').' ';
245
-	        		        if ($action->type_code == 'AC_TEL')   print img_picto('', 'object_phoning').' ';
246
-	        		        if ($action->type_code == 'AC_FAX')   print img_picto('', 'object_phoning_fax').' ';
247
-	        		        if ($action->type_code == 'AC_EMAIL') print img_picto('', 'object_email').' ';
248
-	        		    }
249
-	        		}
250
-	        		print $action->type;
251
-	        		print '</td>';
252
-	        		print '<td>'.$label.'</td>';
253
-	        		print '<td align="center">'.dol_print_date($action->datep,'dayhour');
254
-	        		if ($action->datef)
255
-	        		{
256
-		        		$tmpa=dol_getdate($action->datep);
257
-		        		$tmpb=dol_getdate($action->datef);
258
-		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
259
-		        		{
260
-		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef,'hour');
261
-		        		}
262
-		        		else print '-'.dol_print_date($action->datef,'dayhour');
263
-	        		}
264
-	        		print '</td>';
265
-	        		print '<td align="right">';
266
-	        		if (! empty($action->author->id))
267
-	        		{
268
-	        			print $action->getLibStatut(3);
269
-	        		}
270
-	        		print '</td>';
271
-	        		print '</tr>';
272
-
273
-	        		$cursorevent++;
274
-	        	}
275
-        	}
276
-        	else
277
-        	{
278
-        		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
279
-        	}
280
-
281
-        	if ($max && $num > $max)
282
-        	{
283
-        		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
284
-        	}
285
-
286
-        	print '</table>';
287
-        	print '</div>';
288
-        }
289
-
290
-        return $num;
291
-    }
292
-
293
-
294
-    /**
295
-     *  Output html select list of type of event
296
-     *
297
-     *  @param	array|string	$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
298
-     *  @param  string		    $htmlname       Name of select field
299
-     *  @param	string		    $excludetype	A type to exclude ('systemauto', 'system', '')
300
-     *  @param	integer		    $onlyautoornot	1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type, -1=Keep details and add a combined line "All manual"
301
-     *  @param	int		        $hideinfohelp	1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
302
-     *  @param  int		        $multiselect    1=Allow multiselect of action type
303
-     *  @param  int             $nooutput       1=No output
304
-     * 	@return	string
305
-     */
306
-    function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
307
-    {
308
-        global $langs,$user,$form,$conf;
309
-
310
-        if (! is_object($form)) $form=new Form($db);
311
-
312
-        require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
313
-        require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
314
-        $caction=new CActionComm($this->db);
315
-
316
-       	// Suggest a list with manual events or all auto events
317
-       	$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
318
-       	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
319
-       	//asort($arraylist);
320
-
321
-       	if ($selected == 'manual') $selected='AC_OTH';
322
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
323
-
324
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
325
-
326
-       	$out='';
233
+					if (! empty($action->userownerid))
234
+					{
235
+						$userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
236
+						print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
237
+					}
238
+					print '</td>';
239
+					print '<td>';
240
+					if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
241
+					{
242
+						if ($action->type_picto) print img_picto('', $action->type_picto);
243
+						else {
244
+							if ($action->type_code == 'AC_RDV')   print img_picto('', 'object_group').' ';
245
+							if ($action->type_code == 'AC_TEL')   print img_picto('', 'object_phoning').' ';
246
+							if ($action->type_code == 'AC_FAX')   print img_picto('', 'object_phoning_fax').' ';
247
+							if ($action->type_code == 'AC_EMAIL') print img_picto('', 'object_email').' ';
248
+						}
249
+					}
250
+					print $action->type;
251
+					print '</td>';
252
+					print '<td>'.$label.'</td>';
253
+					print '<td align="center">'.dol_print_date($action->datep,'dayhour');
254
+					if ($action->datef)
255
+					{
256
+						$tmpa=dol_getdate($action->datep);
257
+						$tmpb=dol_getdate($action->datef);
258
+						if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
259
+						{
260
+							if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef,'hour');
261
+						}
262
+						else print '-'.dol_print_date($action->datef,'dayhour');
263
+					}
264
+					print '</td>';
265
+					print '<td align="right">';
266
+					if (! empty($action->author->id))
267
+					{
268
+						print $action->getLibStatut(3);
269
+					}
270
+					print '</td>';
271
+					print '</tr>';
272
+
273
+					$cursorevent++;
274
+				}
275
+			}
276
+			else
277
+			{
278
+				print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
279
+			}
280
+
281
+			if ($max && $num > $max)
282
+			{
283
+				print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
284
+			}
285
+
286
+			print '</table>';
287
+			print '</div>';
288
+		}
289
+
290
+		return $num;
291
+	}
292
+
293
+
294
+	/**
295
+	 *  Output html select list of type of event
296
+	 *
297
+	 *  @param	array|string	$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
298
+	 *  @param  string		    $htmlname       Name of select field
299
+	 *  @param	string		    $excludetype	A type to exclude ('systemauto', 'system', '')
300
+	 *  @param	integer		    $onlyautoornot	1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type, -1=Keep details and add a combined line "All manual"
301
+	 *  @param	int		        $hideinfohelp	1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
302
+	 *  @param  int		        $multiselect    1=Allow multiselect of action type
303
+	 *  @param  int             $nooutput       1=No output
304
+	 * 	@return	string
305
+	 */
306
+	function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
307
+	{
308
+		global $langs,$user,$form,$conf;
309
+
310
+		if (! is_object($form)) $form=new Form($db);
311
+
312
+		require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
313
+		require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
314
+		$caction=new CActionComm($this->db);
315
+
316
+	   	// Suggest a list with manual events or all auto events
317
+	   	$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
318
+	   	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
319
+	   	//asort($arraylist);
320
+
321
+	   	if ($selected == 'manual') $selected='AC_OTH';
322
+	   	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
323
+
324
+	   	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
325
+
326
+	   	$out='';
327 327
 
328 328
 		if (! empty($multiselect))
329 329
 		{
330
-	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
330
+			if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
331 331
 			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
332 332
 		}
333 333
 		else
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
 			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
336 336
 		}
337 337
 
338
-        if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
339
-        {
340
-            $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
341
-        }
338
+		if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
339
+		{
340
+			$out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
341
+		}
342 342
 
343
-        if ($nooutput) return $out;
344
-        else print $out;
345
-        return '';
346
-    }
343
+		if ($nooutput) return $out;
344
+		else print $out;
345
+		return '';
346
+	}
347 347
 
348 348
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      *  @param  string  $morecss        More css on select field
58 58
      * 	@return	void
59 59
      */
60
-    function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
60
+    function form_select_status_action($formname, $selected, $canedit = 1, $htmlname = 'complete', $showempty = 0, $onlyselect = 0, $morecss = 'maxwidth100')
61 61
     {
62
-        global $langs,$conf;
62
+        global $langs, $conf;
63 63
 
64 64
         $listofstatus = array(
65 65
             '-1' => $langs->trans("ActionNotApplicable"),
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         );
70 70
 		// +ActionUncomplete
71 71
 
72
-        if (! empty($conf->use_javascript_ajax))
72
+        if (!empty($conf->use_javascript_ajax))
73 73
         {
74 74
             print "\n";
75 75
             print "<script type=\"text/javascript\">
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 function select_status() {
91 91
                     var defaultvalue = $('#select' + htmlname).val();
92 92
                     var percentage = $('input[name=percentage]');
93
-                    var selected = '".(isset($selected)?$selected:'')."';
93
+                    var selected = '".(isset($selected) ? $selected : '')."';
94 94
                     var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
95 95
 
96 96
                     percentage.val(value);
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
                 }
118 118
                 </script>\n";
119 119
         }
120
-        if (! empty($conf->use_javascript_ajax) || $onlyselect)
120
+        if (!empty($conf->use_javascript_ajax) || $onlyselect)
121 121
         {
122 122
         	//var_dump($selected);
123
-        	if ($selected == 'done') $selected='100';
124
-            print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
125
-            if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
126
-            foreach($listofstatus as $key => $val)
123
+        	if ($selected == 'done') $selected = '100';
124
+            print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
125
+            if ($showempty) print '<option value=""'.($selected == '' ? ' selected' : '').'></option>';
126
+            foreach ($listofstatus as $key => $val)
127 127
             {
128 128
                 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
129 129
                 if ($key == '50' && $onlyselect == 2)
@@ -132,17 +132,17 @@  discard block
 block discarded – undo
132 132
                 }
133 133
             }
134 134
             print '</select>';
135
-            if ($selected == 0 || $selected == 100) $canedit=0;
135
+            if ($selected == 0 || $selected == 100) $canedit = 0;
136 136
 
137 137
             if (empty($onlyselect))
138 138
             {
139
-	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
139
+	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
140 140
     	        print '<span class="hideonsmartphone hideifna">%</span>';
141 141
             }
142 142
         }
143 143
         else
144 144
 		{
145
-            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
145
+            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
146 146
         }
147 147
     }
148 148
 
@@ -160,51 +160,51 @@  discard block
 block discarded – undo
160 160
      *  @param	string	$morehtmlright			More html text on right of title line
161 161
      *	@return	int								<0 if KO, >=0 if OK
162 162
      */
163
-    function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
163
+    function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlright = '')
164 164
     {
165
-        global $langs,$conf,$user;
165
+        global $langs, $conf, $user;
166 166
         global $bc;
167 167
 
168 168
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
169 169
 
170
-        $sortfield='a.datep';
171
-        $sortorder='DESC';
170
+        $sortfield = 'a.datep';
171
+        $sortorder = 'DESC';
172 172
 
173
-        $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
174
-		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
173
+        $listofactions = ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
174
+		if (!is_array($listofactions)) dol_print_error($this->db, 'FailedToGetActions');
175 175
 
176 176
         $num = count($listofactions);
177 177
         if ($num || $forceshowtitle)
178 178
         {
179
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
180
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
181
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
182
-        	elseif ($typeelement == 'supplier_payment')  $title=$langs->trans('ActionsOnSupplierPayment');
183
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
184
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
185
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
186
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
187
-            elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
188
-            elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
189
-            elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
190
-            elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
191
-            else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
192
-
193
-            $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
194
-
195
-        	$buttontoaddnewevent = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.'&socid='.$object->socid.'&projectid='.$object->fk_project.'&backtopage='.urlencode($urlbacktopage).'">';
196
-        	$buttontoaddnewevent.= $langs->trans("AddEvent");
197
-        	$buttontoaddnewevent.= '</a>';
179
+        	if ($typeelement == 'invoice')               $title = $langs->trans('ActionsOnBill');
180
+        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title = $langs->trans('ActionsOnBill');
181
+        	elseif ($typeelement == 'propal')            $title = $langs->trans('ActionsOnPropal');
182
+        	elseif ($typeelement == 'supplier_payment')  $title = $langs->trans('ActionsOnSupplierPayment');
183
+        	elseif ($typeelement == 'supplier_proposal') $title = $langs->trans('ActionsOnSupplierProposal');
184
+        	elseif ($typeelement == 'order')             $title = $langs->trans('ActionsOnOrder');
185
+        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title = $langs->trans('ActionsOnOrder');
186
+        	elseif ($typeelement == 'shipping')          $title = $langs->trans('ActionsOnShipping');
187
+            elseif ($typeelement == 'fichinter')         $title = $langs->trans('ActionsOnFicheInter');
188
+            elseif ($typeelement == 'project')           $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
189
+            elseif ($typeelement == 'task')              $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
190
+            elseif ($typeelement == 'member')            $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
191
+            else $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
192
+
193
+            $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
194
+
195
+        	$buttontoaddnewevent = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(), 'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.'&socid='.$object->socid.'&projectid='.$object->fk_project.'&backtopage='.urlencode($urlbacktopage).'">';
196
+        	$buttontoaddnewevent .= $langs->trans("AddEvent");
197
+        	$buttontoaddnewevent .= '</a>';
198 198
 
199 199
         	print '<!-- formactions->showactions -->'."\n";
200 200
         	print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $buttontoaddnewevent);
201 201
 
202
-        	$page=0; $param='';
202
+        	$page = 0; $param = '';
203 203
 
204 204
         	$total = 0;
205 205
 
206 206
         	print '<div class="div-table-responsive-no-min">';
207
-        	print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
207
+        	print '<table class="noborder'.($morecss ? ' '.$morecss : '').'" width="100%">';
208 208
         	print '<tr class="liste_titre">';
209 209
         	print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
210 210
         	print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
         	if (count($listofactions))
221 221
         	{
222 222
 	        	$cursorevent = 0;
223
-	        	foreach($listofactions as $action)
223
+	        	foreach ($listofactions as $action)
224 224
 	        	{
225 225
 	        		if ($max && $cursorevent >= $max) break;
226 226
 
227
-	        		$ref=$action->getNomUrl(1,-1);
228
-	        		$label=$action->getNomUrl(0,38);
227
+	        		$ref = $action->getNomUrl(1, -1);
228
+	        		$label = $action->getNomUrl(0, 38);
229 229
 
230 230
 	        		print '<tr class="oddeven">';
231 231
 					print '<td>'.$ref.'</td>';
232 232
 	        		print '<td>';
233
-	        		if (! empty($action->userownerid))
233
+	        		if (!empty($action->userownerid))
234 234
 	        		{
235
-	        			$userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
235
+	        			$userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
236 236
 	        			print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
237 237
 	        		}
238 238
 	        		print '</td>';
239 239
 					print '<td>';
240
-	        		if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
240
+	        		if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
241 241
 	        		{
242 242
 	        		    if ($action->type_picto) print img_picto('', $action->type_picto);
243 243
 	        		    else {
@@ -250,20 +250,20 @@  discard block
 block discarded – undo
250 250
 	        		print $action->type;
251 251
 	        		print '</td>';
252 252
 	        		print '<td>'.$label.'</td>';
253
-	        		print '<td align="center">'.dol_print_date($action->datep,'dayhour');
253
+	        		print '<td align="center">'.dol_print_date($action->datep, 'dayhour');
254 254
 	        		if ($action->datef)
255 255
 	        		{
256
-		        		$tmpa=dol_getdate($action->datep);
257
-		        		$tmpb=dol_getdate($action->datef);
256
+		        		$tmpa = dol_getdate($action->datep);
257
+		        		$tmpb = dol_getdate($action->datef);
258 258
 		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
259 259
 		        		{
260
-		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef,'hour');
260
+		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour');
261 261
 		        		}
262
-		        		else print '-'.dol_print_date($action->datef,'dayhour');
262
+		        		else print '-'.dol_print_date($action->datef, 'dayhour');
263 263
 	        		}
264 264
 	        		print '</td>';
265 265
 	        		print '<td align="right">';
266
-	        		if (! empty($action->author->id))
266
+	        		if (!empty($action->author->id))
267 267
 	        		{
268 268
 	        			print $action->getLibStatut(3);
269 269
 	        		}
@@ -303,41 +303,41 @@  discard block
 block discarded – undo
303 303
      *  @param  int             $nooutput       1=No output
304 304
      * 	@return	string
305 305
      */
306
-    function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
306
+    function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0)
307 307
     {
308
-        global $langs,$user,$form,$conf;
308
+        global $langs, $user, $form, $conf;
309 309
 
310
-        if (! is_object($form)) $form=new Form($db);
310
+        if (!is_object($form)) $form = new Form($db);
311 311
 
312 312
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
313 313
         require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
314
-        $caction=new CActionComm($this->db);
314
+        $caction = new CActionComm($this->db);
315 315
 
316 316
        	// Suggest a list with manual events or all auto events
317
-       	$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
318
-       	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
317
+       	$arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
318
+       	array_unshift($arraylist, '&nbsp;'); // Add empty line at start
319 319
        	//asort($arraylist);
320 320
 
321
-       	if ($selected == 'manual') $selected='AC_OTH';
322
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
321
+       	if ($selected == 'manual') $selected = 'AC_OTH';
322
+       	if ($selected == 'auto')   $selected = 'AC_OTH_AUTO';
323 323
 
324
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
324
+       	if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
325 325
 
326
-       	$out='';
326
+       	$out = '';
327 327
 
328
-		if (! empty($multiselect))
328
+		if (!empty($multiselect))
329 329
 		{
330 330
 	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
331
-			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
331
+			$out .= $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
332 332
 		}
333 333
 		else
334 334
 		{
335
-			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
335
+			$out .= $form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
336 336
 		}
337 337
 
338 338
         if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
339 339
         {
340
-            $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
340
+            $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
341 341
         }
342 342
 
343 343
         if ($nooutput) return $out;
Please login to merge, or discard this patch.
Braces   +85 added lines, -39 removed lines patch added patch discarded remove patch
@@ -120,9 +120,13 @@  discard block
 block discarded – undo
120 120
         if (! empty($conf->use_javascript_ajax) || $onlyselect)
121 121
         {
122 122
         	//var_dump($selected);
123
-        	if ($selected == 'done') $selected='100';
123
+        	if ($selected == 'done') {
124
+        		$selected='100';
125
+        	}
124 126
             print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
125
-            if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
127
+            if ($showempty) {
128
+            	print '<option value=""'.($selected == ''?' selected':'').'></option>';
129
+            }
126 130
             foreach($listofstatus as $key => $val)
127 131
             {
128 132
                 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
@@ -132,15 +136,16 @@  discard block
 block discarded – undo
132 136
                 }
133 137
             }
134 138
             print '</select>';
135
-            if ($selected == 0 || $selected == 100) $canedit=0;
139
+            if ($selected == 0 || $selected == 100) {
140
+            	$canedit=0;
141
+            }
136 142
 
137 143
             if (empty($onlyselect))
138 144
             {
139 145
 	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
140 146
     	        print '<span class="hideonsmartphone hideifna">%</span>';
141 147
             }
142
-        }
143
-        else
148
+        } else
144 149
 		{
145 150
             print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
146 151
         }
@@ -171,24 +176,40 @@  discard block
 block discarded – undo
171 176
         $sortorder='DESC';
172 177
 
173 178
         $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
174
-		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
179
+		if (! is_array($listofactions)) {
180
+			dol_print_error($this->db,'FailedToGetActions');
181
+		}
175 182
 
176 183
         $num = count($listofactions);
177 184
         if ($num || $forceshowtitle)
178 185
         {
179
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
180
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
181
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
182
-        	elseif ($typeelement == 'supplier_payment')  $title=$langs->trans('ActionsOnSupplierPayment');
183
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
184
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
185
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
186
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
187
-            elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
188
-            elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
189
-            elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
190
-            elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
191
-            else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
186
+        	if ($typeelement == 'invoice') {
187
+        		$title=$langs->trans('ActionsOnBill');
188
+        	} elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') {
189
+        		$title=$langs->trans('ActionsOnBill');
190
+        	} elseif ($typeelement == 'propal') {
191
+        		$title=$langs->trans('ActionsOnPropal');
192
+        	} elseif ($typeelement == 'supplier_payment') {
193
+        		$title=$langs->trans('ActionsOnSupplierPayment');
194
+        	} elseif ($typeelement == 'supplier_proposal') {
195
+        		$title=$langs->trans('ActionsOnSupplierProposal');
196
+        	} elseif ($typeelement == 'order') {
197
+        		$title=$langs->trans('ActionsOnOrder');
198
+        	} elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') {
199
+        		$title=$langs->trans('ActionsOnOrder');
200
+        	} elseif ($typeelement == 'shipping') {
201
+        		$title=$langs->trans('ActionsOnShipping');
202
+        	} elseif ($typeelement == 'fichinter') {
203
+            	$title=$langs->trans('ActionsOnFicheInter');
204
+            } elseif ($typeelement == 'project') {
205
+            	$title=$langs->trans('LatestLinkedEvents', $max?$max:'');
206
+            } elseif ($typeelement == 'task') {
207
+            	$title=$langs->trans('LatestLinkedEvents', $max?$max:'');
208
+            } elseif ($typeelement == 'member') {
209
+            	$title=$langs->trans('LatestLinkedEvents', $max?$max:'');
210
+            } else {
211
+            	$title=$langs->trans("LatestLinkedEvents", $max?$max:'');
212
+            }
192 213
 
193 214
             $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
194 215
 
@@ -222,7 +243,9 @@  discard block
 block discarded – undo
222 243
 	        	$cursorevent = 0;
223 244
 	        	foreach($listofactions as $action)
224 245
 	        	{
225
-	        		if ($max && $cursorevent >= $max) break;
246
+	        		if ($max && $cursorevent >= $max) {
247
+	        			break;
248
+	        		}
226 249
 
227 250
 	        		$ref=$action->getNomUrl(1,-1);
228 251
 	        		$label=$action->getNomUrl(0,38);
@@ -239,12 +262,21 @@  discard block
 block discarded – undo
239 262
 					print '<td>';
240 263
 	        		if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
241 264
 	        		{
242
-	        		    if ($action->type_picto) print img_picto('', $action->type_picto);
243
-	        		    else {
244
-	        		        if ($action->type_code == 'AC_RDV')   print img_picto('', 'object_group').' ';
245
-	        		        if ($action->type_code == 'AC_TEL')   print img_picto('', 'object_phoning').' ';
246
-	        		        if ($action->type_code == 'AC_FAX')   print img_picto('', 'object_phoning_fax').' ';
247
-	        		        if ($action->type_code == 'AC_EMAIL') print img_picto('', 'object_email').' ';
265
+	        		    if ($action->type_picto) {
266
+	        		    	print img_picto('', $action->type_picto);
267
+	        		    } else {
268
+	        		        if ($action->type_code == 'AC_RDV') {
269
+	        		        	print img_picto('', 'object_group').' ';
270
+	        		        }
271
+	        		        if ($action->type_code == 'AC_TEL') {
272
+	        		        	print img_picto('', 'object_phoning').' ';
273
+	        		        }
274
+	        		        if ($action->type_code == 'AC_FAX') {
275
+	        		        	print img_picto('', 'object_phoning_fax').' ';
276
+	        		        }
277
+	        		        if ($action->type_code == 'AC_EMAIL') {
278
+	        		        	print img_picto('', 'object_email').' ';
279
+	        		        }
248 280
 	        		    }
249 281
 	        		}
250 282
 	        		print $action->type;
@@ -257,9 +289,12 @@  discard block
 block discarded – undo
257 289
 		        		$tmpb=dol_getdate($action->datef);
258 290
 		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
259 291
 		        		{
260
-		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef,'hour');
292
+		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) {
293
+		        				print '-'.dol_print_date($action->datef,'hour');
294
+		        			}
295
+		        		} else {
296
+		        			print '-'.dol_print_date($action->datef,'dayhour');
261 297
 		        		}
262
-		        		else print '-'.dol_print_date($action->datef,'dayhour');
263 298
 	        		}
264 299
 	        		print '</td>';
265 300
 	        		print '<td align="right">';
@@ -272,8 +307,7 @@  discard block
 block discarded – undo
272 307
 
273 308
 	        		$cursorevent++;
274 309
 	        	}
275
-        	}
276
-        	else
310
+        	} else
277 311
         	{
278 312
         		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
279 313
         	}
@@ -307,7 +341,9 @@  discard block
 block discarded – undo
307 341
     {
308 342
         global $langs,$user,$form,$conf;
309 343
 
310
-        if (! is_object($form)) $form=new Form($db);
344
+        if (! is_object($form)) {
345
+        	$form=new Form($db);
346
+        }
311 347
 
312 348
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
313 349
         require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
@@ -318,19 +354,26 @@  discard block
 block discarded – undo
318 354
        	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
319 355
        	//asort($arraylist);
320 356
 
321
-       	if ($selected == 'manual') $selected='AC_OTH';
322
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
357
+       	if ($selected == 'manual') {
358
+       		$selected='AC_OTH';
359
+       	}
360
+       	if ($selected == 'auto') {
361
+       		$selected='AC_OTH_AUTO';
362
+       	}
323 363
 
324
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
364
+       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) {
365
+       		unset($arraylist['AC_OTH_AUTO']);
366
+       	}
325 367
 
326 368
        	$out='';
327 369
 
328 370
 		if (! empty($multiselect))
329 371
 		{
330
-	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
372
+	        if (!is_array($selected) && !empty($selected)) {
373
+	        	$selected = explode(',', $selected);
374
+	        }
331 375
 			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
332
-		}
333
-		else
376
+		} else
334 377
 		{
335 378
 			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
336 379
 		}
@@ -340,8 +383,11 @@  discard block
 block discarded – undo
340 383
             $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
341 384
         }
342 385
 
343
-        if ($nooutput) return $out;
344
-        else print $out;
386
+        if ($nooutput) {
387
+        	return $out;
388
+        } else {
389
+        	print $out;
390
+        }
345 391
         return '';
346 392
     }
347 393
 
Please login to merge, or discard this patch.
htdocs/core/modules/commande/mod_commande_marbre.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
 	 * 	Return next free value
97 97
 	 *
98 98
 	 *  @param	Societe		$objsoc     Object thirdparty
99
-	 *  @param  Object		$object		Object we need next value for
99
+	 *  @param  string		$object		Object we need next value for
100 100
 	 *  @return string      			Value if KO, <0 if KO
101 101
 	 */
102 102
 	function getNextValue($objsoc,$object)
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 	var $nom='Marbre';
36 36
 
37 37
 
38
-    /**
39
-     *  Return description of numbering module
40
-     *
41
-     *  @return     string      Text with description
42
-     */
43
-    function info()
44
-    {
45
-    	global $langs;
46
-      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
47
-    }
38
+	/**
39
+	 *  Return description of numbering module
40
+	 *
41
+	 *  @return     string      Text with description
42
+	 */
43
+	function info()
44
+	{
45
+		global $langs;
46
+	  	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
47
+	}
48 48
 
49 49
 
50 50
 	/**
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 		$date=$object->date;
128 128
 		$yymm = strftime("%y%m",$date);
129 129
 
130
-    	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
131
-    	else $num = sprintf("%04s",$max+1);
130
+		if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
131
+		else $num = sprintf("%04s",$max+1);
132 132
 
133 133
 		dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
134 134
 		return $this->prefix.$yymm."-".$num;
Please login to merge, or discard this patch.
Braces   +13 added lines, -6 removed lines patch added patch discarded remove patch
@@ -114,10 +114,12 @@  discard block
 block discarded – undo
114 114
 		if ($resql)
115 115
 		{
116 116
 			$obj = $db->fetch_object($resql);
117
-			if ($obj) $max = intval($obj->max);
118
-			else $max=0;
119
-		}
120
-		else
117
+			if ($obj) {
118
+				$max = intval($obj->max);
119
+			} else {
120
+				$max=0;
121
+			}
122
+		} else
121 123
 		{
122 124
 			dol_syslog("mod_commande_marbre::getNextValue", LOG_DEBUG);
123 125
 			return -1;
@@ -127,8 +129,13 @@  discard block
 block discarded – undo
127 129
 		$date=$object->date;
128 130
 		$yymm = strftime("%y%m",$date);
129 131
 
130
-    	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
131
-    	else $num = sprintf("%04s",$max+1);
132
+    	if ($max >= (pow(10, 4) - 1)) {
133
+    		$num=$max+1;
134
+    	}
135
+    	// If counter > 9999, we do not format on 4 chars, we take number as it is
136
+    	else {
137
+    		$num = sprintf("%04s",$max+1);
138
+    	}
132 139
 
133 140
 		dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
134 141
 		return $this->prefix.$yymm."-".$num;
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
  *  \ingroup    commande
23 23
  *  \brief      File of class to manage customer order numbering rules Marbre
24 24
  */
25
-require_once DOL_DOCUMENT_ROOT .'/core/modules/commande/modules_commande.php';
25
+require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
26 26
 
27 27
 /**
28 28
  *	Class to manage customer order numbering rules Marbre
29 29
  */
30 30
 class mod_commande_marbre extends ModeleNumRefCommandes
31 31
 {
32
-	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
33
-	var $prefix='CO';
34
-	var $error='';
35
-	var $nom='Marbre';
32
+	var $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
33
+	var $prefix = 'CO';
34
+	var $error = '';
35
+	var $nom = 'Marbre';
36 36
 
37 37
 
38 38
     /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     function info()
44 44
     {
45 45
     	global $langs;
46
-      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
46
+      	return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
47 47
     }
48 48
 
49 49
 
@@ -66,26 +66,26 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	function canBeActivated()
68 68
 	{
69
-		global $conf,$langs,$db;
69
+		global $conf, $langs, $db;
70 70
 
71
-		$coyymm=''; $max='';
71
+		$coyymm = ''; $max = '';
72 72
 
73
-		$posindice=8;
73
+		$posindice = 8;
74 74
 		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
75
-		$sql.= " FROM ".MAIN_DB_PREFIX."commande";
76
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
77
-		$sql.= " AND entity = ".$conf->entity;
75
+		$sql .= " FROM ".MAIN_DB_PREFIX."commande";
76
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
77
+		$sql .= " AND entity = ".$conf->entity;
78 78
 
79
-		$resql=$db->query($sql);
79
+		$resql = $db->query($sql);
80 80
 		if ($resql)
81 81
 		{
82 82
 			$row = $db->fetch_row($resql);
83
-			if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
83
+			if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
84 84
 		}
85
-		if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
85
+		if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm))
86 86
 		{
87 87
 			$langs->load("errors");
88
-			$this->error=$langs->trans('ErrorNumRefModel', $max);
88
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
89 89
 			return false;
90 90
 		}
91 91
 
@@ -99,23 +99,23 @@  discard block
 block discarded – undo
99 99
 	 *  @param  Object		$object		Object we need next value for
100 100
 	 *  @return string      			Value if KO, <0 if KO
101 101
 	 */
102
-	function getNextValue($objsoc,$object)
102
+	function getNextValue($objsoc, $object)
103 103
 	{
104
-		global $db,$conf;
104
+		global $db, $conf;
105 105
 
106 106
 		// D'abord on recupere la valeur max
107
-		$posindice=8;
107
+		$posindice = 8;
108 108
 		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
109
-		$sql.= " FROM ".MAIN_DB_PREFIX."commande";
110
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
111
-		$sql.= " AND entity = ".$conf->entity;
109
+		$sql .= " FROM ".MAIN_DB_PREFIX."commande";
110
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
111
+		$sql .= " AND entity = ".$conf->entity;
112 112
 
113
-		$resql=$db->query($sql);
113
+		$resql = $db->query($sql);
114 114
 		if ($resql)
115 115
 		{
116 116
 			$obj = $db->fetch_object($resql);
117 117
 			if ($obj) $max = intval($obj->max);
118
-			else $max=0;
118
+			else $max = 0;
119 119
 		}
120 120
 		else
121 121
 		{
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 		}
125 125
 
126 126
 		//$date=time();
127
-		$date=$object->date;
128
-		$yymm = strftime("%y%m",$date);
127
+		$date = $object->date;
128
+		$yymm = strftime("%y%m", $date);
129 129
 
130
-    	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
131
-    	else $num = sprintf("%04s",$max+1);
130
+    	if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
131
+    	else $num = sprintf("%04s", $max + 1);
132 132
 
133 133
 		dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
134 134
 		return $this->prefix.$yymm."-".$num;
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * 	@param	string		$objforref	Object for number to search
143 143
 	 *  @return string      			Next free value
144 144
 	 */
145
-	function commande_get_num($objsoc,$objforref)
145
+	function commande_get_num($objsoc, $objforref)
146 146
 	{
147
-		return $this->getNextValue($objsoc,$objforref);
147
+		return $this->getNextValue($objsoc, $objforref);
148 148
 	}
149 149
 
150 150
 }
Please login to merge, or discard this patch.