Passed
Push — master ( 8f7a8e...7e4a07 )
by Alxarafe
20:11
created
dolibarr/htdocs/core/modules/security/generate/modules_genpassword.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 abstract class ModeleGenPassword
32 32
 {
33 33
     /**
34
-	 * @var string Error code (or message)
35
-	 */
36
-	public $error='';
34
+     * @var string Error code (or message)
35
+     */
36
+    public $error='';
37 37
 
38 38
     /**
39 39
      * 		Return if a module can be used or not
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
         return $langs->trans("NoExample");
69 69
     }
70 70
 
71
-	/**
72
-	 * 		Build new password
73
-	 *
74
- 	 *      @return     string      Return a new generated password
75
-	 */
71
+    /**
72
+     * 		Build new password
73
+     *
74
+     *      @return     string      Return a new generated password
75
+     */
76 76
     function getNewGeneratedPassword()
77 77
     {
78 78
         global $langs;
79 79
         return $langs->trans("NotAvailable");
80 80
     }
81 81
 
82
-	/**
83
-	 * 		Validate a password
84
-	 *
85
-	 *		@param		string	$password	Password to check
86
- 	 *      @return     int					0 if KO, >0 if OK
87
-	 */
82
+    /**
83
+     * 		Validate a password
84
+     *
85
+     *		@param		string	$password	Password to check
86
+     *      @return     int					0 if KO, >0 if OK
87
+     */
88 88
     function validatePassword($password)
89 89
     {
90 90
         return 1;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
     /**
34 34
 	 * @var string Error code (or message)
35 35
 	 */
36
-	public $error='';
36
+	public $error = '';
37 37
 
38 38
     /**
39 39
      * 		Return if a module can be used or not
Please login to merge, or discard this patch.
htdocs/core/modules/security/generate/modGeneratePassStandard.class.php 3 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -31,108 +31,108 @@
 block discarded – undo
31 31
  */
32 32
 class modGeneratePassStandard extends ModeleGenPassword
33 33
 {
34
-	/**
35
-	 * @var int ID
36
-	 */
37
-	public $id;
34
+    /**
35
+     * @var int ID
36
+     */
37
+    public $id;
38 38
 
39
-	public $length;
39
+    public $length;
40 40
 
41
-	/**
41
+    /**
42 42
      * @var DoliDB Database handler.
43 43
      */
44 44
     public $db;
45 45
 
46
-	public $conf;
47
-	public $lang;
48
-	public $user;
49
-
50
-
51
-	/**
52
-	 *	Constructor
53
-	 *
54
-	 *  @param		DoliDB		$db			Database handler
55
-	 *	@param		Conf		$conf		Handler de conf
56
-	 *	@param		Translate	$langs		Handler de langue
57
-	 *	@param		User		$user		Handler du user connecte
58
-	 */
59
-	function __construct($db, $conf, $langs, $user)
60
-	{
61
-		$this->id = "standard";
62
-		$this->length = 8;
63
-
64
-		$this->db=$db;
65
-		$this->conf=$conf;
66
-		$this->langs=$langs;
67
-		$this->user=$user;
68
-	}
69
-
70
-	/**
71
-	 *		Return description of module
72
-	 *
73
- 	 *      @return     string      Description of module
74
-	 */
75
-	function getDescription()
76
-	{
77
-		global $langs;
78
-		return $langs->trans("PasswordGenerationStandard");
79
-	}
80
-
81
-	/**
82
-	 * 		Return an example of password generated by this module
83
-	 *
84
- 	 *      @return     string      Example of password
85
-	 */
86
-	function getExample()
87
-	{
88
-		return $this->getNewGeneratedPassword();
89
-	}
90
-
91
-	/**
92
-	 * 		Build new password
93
-	 *
94
- 	 *      @return     string      Return a new generated password
95
-	 */
96
-	function getNewGeneratedPassword()
97
-	{
98
-		// start with a blank password
99
-		$password = "";
100
-
101
-		// define possible characters
102
-		$possible = "0123456789bcdfghjkmnpqrstvwxyz";
103
-
104
-		// set up a counter
105
-		$i = 0;
106
-
107
-		// add random characters to $password until $length is reached
108
-		while ($i < $this->length)
109
-		{
110
-
111
-			// pick a random character from the possible ones
112
-			$char = substr($possible, mt_rand(0, dol_strlen($possible)-1), 1);
113
-
114
-			// we don't want this character if it's already in the password
115
-			if (!strstr($password, $char))
116
-			{
117
-				$password .= $char;
118
-				$i++;
119
-			}
120
-		}
121
-
122
-		// done!
123
-		return $password;
124
-	}
125
-
126
-	/**
127
-	 * 		Validate a password
128
-	 *
129
-	 *		@param		string	$password	Password to check
130
- 	 *      @return     int					0 if KO, >0 if OK
131
-	 */
132
-	function validatePassword($password)
133
-	{
134
-		if (dol_strlen($password) < $this->length) return 0;
135
-		return 1;
136
-	}
46
+    public $conf;
47
+    public $lang;
48
+    public $user;
49
+
50
+
51
+    /**
52
+     *	Constructor
53
+     *
54
+     *  @param		DoliDB		$db			Database handler
55
+     *	@param		Conf		$conf		Handler de conf
56
+     *	@param		Translate	$langs		Handler de langue
57
+     *	@param		User		$user		Handler du user connecte
58
+     */
59
+    function __construct($db, $conf, $langs, $user)
60
+    {
61
+        $this->id = "standard";
62
+        $this->length = 8;
63
+
64
+        $this->db=$db;
65
+        $this->conf=$conf;
66
+        $this->langs=$langs;
67
+        $this->user=$user;
68
+    }
69
+
70
+    /**
71
+     *		Return description of module
72
+     *
73
+     *      @return     string      Description of module
74
+     */
75
+    function getDescription()
76
+    {
77
+        global $langs;
78
+        return $langs->trans("PasswordGenerationStandard");
79
+    }
80
+
81
+    /**
82
+     * 		Return an example of password generated by this module
83
+     *
84
+     *      @return     string      Example of password
85
+     */
86
+    function getExample()
87
+    {
88
+        return $this->getNewGeneratedPassword();
89
+    }
90
+
91
+    /**
92
+     * 		Build new password
93
+     *
94
+     *      @return     string      Return a new generated password
95
+     */
96
+    function getNewGeneratedPassword()
97
+    {
98
+        // start with a blank password
99
+        $password = "";
100
+
101
+        // define possible characters
102
+        $possible = "0123456789bcdfghjkmnpqrstvwxyz";
103
+
104
+        // set up a counter
105
+        $i = 0;
106
+
107
+        // add random characters to $password until $length is reached
108
+        while ($i < $this->length)
109
+        {
110
+
111
+            // pick a random character from the possible ones
112
+            $char = substr($possible, mt_rand(0, dol_strlen($possible)-1), 1);
113
+
114
+            // we don't want this character if it's already in the password
115
+            if (!strstr($password, $char))
116
+            {
117
+                $password .= $char;
118
+                $i++;
119
+            }
120
+        }
121
+
122
+        // done!
123
+        return $password;
124
+    }
125
+
126
+    /**
127
+     * 		Validate a password
128
+     *
129
+     *		@param		string	$password	Password to check
130
+     *      @return     int					0 if KO, >0 if OK
131
+     */
132
+    function validatePassword($password)
133
+    {
134
+        if (dol_strlen($password) < $this->length) return 0;
135
+        return 1;
136
+    }
137 137
 }
138 138
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  *		\brief      File to manage password generation according to standard rule
23 23
  */
24 24
 
25
-require_once DOL_DOCUMENT_ROOT .'/core/modules/security/generate/modules_genpassword.php';
25
+require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassword.php';
26 26
 
27 27
 
28 28
 /**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
 		$this->id = "standard";
62 62
 		$this->length = 8;
63 63
 
64
-		$this->db=$db;
65
-		$this->conf=$conf;
66
-		$this->langs=$langs;
67
-		$this->user=$user;
64
+		$this->db = $db;
65
+		$this->conf = $conf;
66
+		$this->langs = $langs;
67
+		$this->user = $user;
68 68
 	}
69 69
 
70 70
 	/**
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		{
110 110
 
111 111
 			// pick a random character from the possible ones
112
-			$char = substr($possible, mt_rand(0, dol_strlen($possible)-1), 1);
112
+			$char = substr($possible, mt_rand(0, dol_strlen($possible) - 1), 1);
113 113
 
114 114
 			// we don't want this character if it's already in the password
115 115
 			if (!strstr($password, $char))
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -131,7 +131,9 @@
 block discarded – undo
131 131
 	 */
132 132
 	function validatePassword($password)
133 133
 	{
134
-		if (dol_strlen($password) < $this->length) return 0;
134
+		if (dol_strlen($password) < $this->length) {
135
+		    return 0;
136
+		}
135 137
 		return 1;
136 138
 	}
137 139
 }
Please login to merge, or discard this patch.
htdocs/core/modules/security/generate/modGeneratePassPerso.class.php 3 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -33,198 +33,198 @@
 block discarded – undo
33 33
  */
34 34
 class modGeneratePassPerso extends ModeleGenPassword
35 35
 {
36
-	/**
37
-	 * @var int ID
38
-	 */
39
-	public $id;
40
-
41
-	public $length;
42
-	public $length2; // didn't overright display
43
-	public $NbMaj;
44
-	public $NbNum;
45
-	public $NbSpe;
46
-	public $NbRepeat;
47
-	public $WithoutAmbi;
48
-
49
-	/**
36
+    /**
37
+     * @var int ID
38
+     */
39
+    public $id;
40
+
41
+    public $length;
42
+    public $length2; // didn't overright display
43
+    public $NbMaj;
44
+    public $NbNum;
45
+    public $NbSpe;
46
+    public $NbRepeat;
47
+    public $WithoutAmbi;
48
+
49
+    /**
50 50
      * @var DoliDB Database handler.
51 51
      */
52 52
     public $db;
53 53
 
54
-	public $conf;
55
-	public $lang;
56
-	public $user;
57
-
58
-	public $Maj;
59
-	public $Min;
60
-	public $Nb;
61
-	public $Spe;
62
-	public $Ambi;
63
-	public $All;
64
-
65
-	/**
66
-	 *	Constructor
67
-	 *
68
-	 *  @param		DoliDB		$db			Database handler
69
-	 *	@param		Conf		$conf		Handler de conf
70
-	 *	@param		Translate	$langs		Handler de langue
71
-	 *	@param		User		$user		Handler du user connecte
72
-	 */
73
-	function __construct($db, $conf, $langs, $user)
74
-	{
75
-		$this->id = "Perso";
76
-		$this->length = $langs->trans("SetupPerso");
77
-
78
-		$this->db=$db;
79
-		$this->conf=$conf;
80
-		$this->langs=$langs;
81
-		$this->user=$user;
82
-
83
-		if (empty($conf->global->USER_PASSWORD_PATTERN)) {
84
-			// default value (8carac, 1maj, 1digit, 1spe,  3 repeat, no ambi at auto generation.
85
-			dolibarr_set_const($db, "USER_PASSWORD_PATTERN", '8;1;1;1;3;1','chaine',0,'',$conf->entity);
86
-		}
87
-
88
-		$this->Maj = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
89
-		$this->Min = strtolower($this->Maj);
90
-		$this->Nb = "0123456789";
91
-		$this->Spe = "!@#$%&*()_-+={}[]\\|:;'/";
92
-		$this->Ambi = array("1","I","l","|","O","0");
93
-
94
-		$tabConf = explode(";",$conf->global->USER_PASSWORD_PATTERN);
95
-		$this->length2 = $tabConf[0];
96
-		$this->NbMaj = $tabConf[1];
97
-		$this->NbNum = $tabConf[2];
98
-		$this->NbSpe = $tabConf[3];
99
-		$this->NbRepeat = $tabConf[4];
100
-		$this->WithoutAmbi = $tabConf[5];
101
-
102
-		if ($this->WithoutAmbi)
103
-		{
104
-			$this->Maj = str_replace($this->Ambi,"",$this->Maj);
105
-			$this->Min = str_replace($this->Ambi,"",$this->Min);
106
-			$this->Nb  = str_replace($this->Ambi,"",$this->Nb);
107
-			$this->Spe = str_replace($this->Ambi,"",$this->Spe);
108
-		}
109
-
110
-		$pattern = $this->Min . (! empty($this->NbMaj)?$this->Maj:'') . (! empty($this->NbNum)?$this->Nb:'') . (! empty($this->NbSpe)?$this->Spe:'');
111
-		$this->All = str_shuffle($pattern);
112
-
113
-		//$this->All = str_shuffle($this->Maj. $this->Min. $this->Nb. $this->Spe);
114
-		//$this->All = $this->Maj. $this->Min. $this->Nb. $this->Spe;
115
-		//$this->All =  $this->Spe;
116
-	}
117
-
118
-	/**
119
-	 *		Return description of module
120
-	 *
121
-	 *      @return     string      Description of text
122
-	 */
123
-	function getDescription()
124
-	{
125
-		global $langs;
126
-		return $langs->trans("PasswordGenerationPerso");
127
-	}
128
-
129
-	/**
130
-	 * 		Return an example of password generated by this module
131
-	 *
132
-	 *      @return     string      Example of password
133
-	 */
134
-	function getExample()
135
-	{
136
-		return $this->getNewGeneratedPassword();
137
-	}
138
-
139
-	/**
140
-	 * 		Build new password
141
-	 *
142
-	 *      @return     string      Return a new generated password
143
-	 */
144
-	function getNewGeneratedPassword()
145
-	{
146
-		$pass = "";
147
-		for($i=0; $i<$this->NbMaj; $i++){ // Y
148
-			$pass .= $this->Maj[mt_rand(0,strlen($this->Maj) - 1)];
149
-		}
150
-
151
-		for($i=0; $i<$this->NbNum; $i++){ // X
152
-			$pass .= $this->Nb[mt_rand(0,strlen($this->Nb) - 1)];
153
-		}
154
-
155
-		for($i=0; $i<$this->NbSpe; $i++){ // @
156
-			$pass .= $this->Spe[mt_rand(0,strlen($this->Spe) - 1)];
157
-		}
158
-
159
-		for($i=strlen($pass);$i<$this->length2; $i++){ // y
160
-			$pass .= $this->All[mt_rand(0,strlen($this->All) -1)];
161
-		}
162
-
163
-		$pass = str_shuffle($pass);
164
-
165
-		if ($this->validatePassword($pass))
166
-		{
167
-			return $pass;
168
-		}
169
-
170
-		return $this->getNewGeneratedPassword();
171
-	}
172
-
173
-	/**
174
-	 * 		Validate a password
175
-	 *
176
-	 *		@param		string	$password	Password to check
177
-	 *      @return     int					0 if KO, >0 if OK
178
-	 */
179
-	function validatePassword($password)
180
-	{
181
-		$password_a = str_split($password);
182
-		$maj = str_split($this->Maj);
183
-		$num = str_split($this->Nb);
184
-		$spe = str_split($this->Spe);
185
-
186
-		if(count(array_intersect($password_a, $maj)) < $this->NbMaj){
187
-			return 0;
188
-		}
189
-
190
-		if(count(array_intersect($password_a, $num)) < $this->NbNum){
191
-			return 0;
192
-		}
193
-
194
-		if(count(array_intersect($password_a, $spe)) < $this->NbSpe){
195
-			return 0;
196
-		}
197
-
198
-		if(!$this->consecutiveInterationSameCharacter($password)){
199
-			return 0;
200
-		}
201
-
202
-		return 1;
203
-	}
204
-
205
-	/**
206
-	 * 		consecutive iterations of the same character
207
-	 *
208
-	 *		@param		string	$password	Password to check
209
-	 *      @return     int					0 if KO, >0 if OK
210
-	 */
54
+    public $conf;
55
+    public $lang;
56
+    public $user;
57
+
58
+    public $Maj;
59
+    public $Min;
60
+    public $Nb;
61
+    public $Spe;
62
+    public $Ambi;
63
+    public $All;
64
+
65
+    /**
66
+     *	Constructor
67
+     *
68
+     *  @param		DoliDB		$db			Database handler
69
+     *	@param		Conf		$conf		Handler de conf
70
+     *	@param		Translate	$langs		Handler de langue
71
+     *	@param		User		$user		Handler du user connecte
72
+     */
73
+    function __construct($db, $conf, $langs, $user)
74
+    {
75
+        $this->id = "Perso";
76
+        $this->length = $langs->trans("SetupPerso");
77
+
78
+        $this->db=$db;
79
+        $this->conf=$conf;
80
+        $this->langs=$langs;
81
+        $this->user=$user;
82
+
83
+        if (empty($conf->global->USER_PASSWORD_PATTERN)) {
84
+            // default value (8carac, 1maj, 1digit, 1spe,  3 repeat, no ambi at auto generation.
85
+            dolibarr_set_const($db, "USER_PASSWORD_PATTERN", '8;1;1;1;3;1','chaine',0,'',$conf->entity);
86
+        }
87
+
88
+        $this->Maj = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
89
+        $this->Min = strtolower($this->Maj);
90
+        $this->Nb = "0123456789";
91
+        $this->Spe = "!@#$%&*()_-+={}[]\\|:;'/";
92
+        $this->Ambi = array("1","I","l","|","O","0");
93
+
94
+        $tabConf = explode(";",$conf->global->USER_PASSWORD_PATTERN);
95
+        $this->length2 = $tabConf[0];
96
+        $this->NbMaj = $tabConf[1];
97
+        $this->NbNum = $tabConf[2];
98
+        $this->NbSpe = $tabConf[3];
99
+        $this->NbRepeat = $tabConf[4];
100
+        $this->WithoutAmbi = $tabConf[5];
101
+
102
+        if ($this->WithoutAmbi)
103
+        {
104
+            $this->Maj = str_replace($this->Ambi,"",$this->Maj);
105
+            $this->Min = str_replace($this->Ambi,"",$this->Min);
106
+            $this->Nb  = str_replace($this->Ambi,"",$this->Nb);
107
+            $this->Spe = str_replace($this->Ambi,"",$this->Spe);
108
+        }
109
+
110
+        $pattern = $this->Min . (! empty($this->NbMaj)?$this->Maj:'') . (! empty($this->NbNum)?$this->Nb:'') . (! empty($this->NbSpe)?$this->Spe:'');
111
+        $this->All = str_shuffle($pattern);
112
+
113
+        //$this->All = str_shuffle($this->Maj. $this->Min. $this->Nb. $this->Spe);
114
+        //$this->All = $this->Maj. $this->Min. $this->Nb. $this->Spe;
115
+        //$this->All =  $this->Spe;
116
+    }
117
+
118
+    /**
119
+     *		Return description of module
120
+     *
121
+     *      @return     string      Description of text
122
+     */
123
+    function getDescription()
124
+    {
125
+        global $langs;
126
+        return $langs->trans("PasswordGenerationPerso");
127
+    }
128
+
129
+    /**
130
+     * 		Return an example of password generated by this module
131
+     *
132
+     *      @return     string      Example of password
133
+     */
134
+    function getExample()
135
+    {
136
+        return $this->getNewGeneratedPassword();
137
+    }
138
+
139
+    /**
140
+     * 		Build new password
141
+     *
142
+     *      @return     string      Return a new generated password
143
+     */
144
+    function getNewGeneratedPassword()
145
+    {
146
+        $pass = "";
147
+        for($i=0; $i<$this->NbMaj; $i++){ // Y
148
+            $pass .= $this->Maj[mt_rand(0,strlen($this->Maj) - 1)];
149
+        }
150
+
151
+        for($i=0; $i<$this->NbNum; $i++){ // X
152
+            $pass .= $this->Nb[mt_rand(0,strlen($this->Nb) - 1)];
153
+        }
154
+
155
+        for($i=0; $i<$this->NbSpe; $i++){ // @
156
+            $pass .= $this->Spe[mt_rand(0,strlen($this->Spe) - 1)];
157
+        }
158
+
159
+        for($i=strlen($pass);$i<$this->length2; $i++){ // y
160
+            $pass .= $this->All[mt_rand(0,strlen($this->All) -1)];
161
+        }
162
+
163
+        $pass = str_shuffle($pass);
164
+
165
+        if ($this->validatePassword($pass))
166
+        {
167
+            return $pass;
168
+        }
169
+
170
+        return $this->getNewGeneratedPassword();
171
+    }
172
+
173
+    /**
174
+     * 		Validate a password
175
+     *
176
+     *		@param		string	$password	Password to check
177
+     *      @return     int					0 if KO, >0 if OK
178
+     */
179
+    function validatePassword($password)
180
+    {
181
+        $password_a = str_split($password);
182
+        $maj = str_split($this->Maj);
183
+        $num = str_split($this->Nb);
184
+        $spe = str_split($this->Spe);
185
+
186
+        if(count(array_intersect($password_a, $maj)) < $this->NbMaj){
187
+            return 0;
188
+        }
189
+
190
+        if(count(array_intersect($password_a, $num)) < $this->NbNum){
191
+            return 0;
192
+        }
193
+
194
+        if(count(array_intersect($password_a, $spe)) < $this->NbSpe){
195
+            return 0;
196
+        }
197
+
198
+        if(!$this->consecutiveInterationSameCharacter($password)){
199
+            return 0;
200
+        }
201
+
202
+        return 1;
203
+    }
204
+
205
+    /**
206
+     * 		consecutive iterations of the same character
207
+     *
208
+     *		@param		string	$password	Password to check
209
+     *      @return     int					0 if KO, >0 if OK
210
+     */
211 211
     function consecutiveInterationSameCharacter($password)
212 212
     {
213
-		$last = "";
214
-		$count = 0;
215
-		$char = str_split($password);
216
-		foreach($char as $c){
217
-			if($c != $last){
218
-				$last = $c;
219
-				$count = 0;
220
-			}else{
221
-				$count++;
222
-			}
223
-
224
-			if($count >= $this->NbRepeat) {
225
-				return 0;
226
-			}
227
-		}
228
-		return 1;
229
-	}
213
+        $last = "";
214
+        $count = 0;
215
+        $char = str_split($password);
216
+        foreach($char as $c){
217
+            if($c != $last){
218
+                $last = $c;
219
+                $count = 0;
220
+            }else{
221
+                $count++;
222
+            }
223
+
224
+            if($count >= $this->NbRepeat) {
225
+                return 0;
226
+            }
227
+        }
228
+        return 1;
229
+    }
230 230
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *      \brief      File to manage no password generation.
25 25
  */
26 26
 
27
-require_once DOL_DOCUMENT_ROOT .'/core/modules/security/generate/modules_genpassword.php';
27
+require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassword.php';
28 28
 
29 29
 
30 30
 /**
@@ -75,23 +75,23 @@  discard block
 block discarded – undo
75 75
 		$this->id = "Perso";
76 76
 		$this->length = $langs->trans("SetupPerso");
77 77
 
78
-		$this->db=$db;
79
-		$this->conf=$conf;
80
-		$this->langs=$langs;
81
-		$this->user=$user;
78
+		$this->db = $db;
79
+		$this->conf = $conf;
80
+		$this->langs = $langs;
81
+		$this->user = $user;
82 82
 
83 83
 		if (empty($conf->global->USER_PASSWORD_PATTERN)) {
84 84
 			// default value (8carac, 1maj, 1digit, 1spe,  3 repeat, no ambi at auto generation.
85
-			dolibarr_set_const($db, "USER_PASSWORD_PATTERN", '8;1;1;1;3;1','chaine',0,'',$conf->entity);
85
+			dolibarr_set_const($db, "USER_PASSWORD_PATTERN", '8;1;1;1;3;1', 'chaine', 0, '', $conf->entity);
86 86
 		}
87 87
 
88 88
 		$this->Maj = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
89 89
 		$this->Min = strtolower($this->Maj);
90 90
 		$this->Nb = "0123456789";
91 91
 		$this->Spe = "!@#$%&*()_-+={}[]\\|:;'/";
92
-		$this->Ambi = array("1","I","l","|","O","0");
92
+		$this->Ambi = array("1", "I", "l", "|", "O", "0");
93 93
 
94
-		$tabConf = explode(";",$conf->global->USER_PASSWORD_PATTERN);
94
+		$tabConf = explode(";", $conf->global->USER_PASSWORD_PATTERN);
95 95
 		$this->length2 = $tabConf[0];
96 96
 		$this->NbMaj = $tabConf[1];
97 97
 		$this->NbNum = $tabConf[2];
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 
102 102
 		if ($this->WithoutAmbi)
103 103
 		{
104
-			$this->Maj = str_replace($this->Ambi,"",$this->Maj);
105
-			$this->Min = str_replace($this->Ambi,"",$this->Min);
106
-			$this->Nb  = str_replace($this->Ambi,"",$this->Nb);
107
-			$this->Spe = str_replace($this->Ambi,"",$this->Spe);
104
+			$this->Maj = str_replace($this->Ambi, "", $this->Maj);
105
+			$this->Min = str_replace($this->Ambi, "", $this->Min);
106
+			$this->Nb  = str_replace($this->Ambi, "", $this->Nb);
107
+			$this->Spe = str_replace($this->Ambi, "", $this->Spe);
108 108
 		}
109 109
 
110
-		$pattern = $this->Min . (! empty($this->NbMaj)?$this->Maj:'') . (! empty($this->NbNum)?$this->Nb:'') . (! empty($this->NbSpe)?$this->Spe:'');
110
+		$pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj : '').(!empty($this->NbNum) ? $this->Nb : '').(!empty($this->NbSpe) ? $this->Spe : '');
111 111
 		$this->All = str_shuffle($pattern);
112 112
 
113 113
 		//$this->All = str_shuffle($this->Maj. $this->Min. $this->Nb. $this->Spe);
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
 	function getNewGeneratedPassword()
145 145
 	{
146 146
 		$pass = "";
147
-		for($i=0; $i<$this->NbMaj; $i++){ // Y
148
-			$pass .= $this->Maj[mt_rand(0,strlen($this->Maj) - 1)];
147
+		for ($i = 0; $i < $this->NbMaj; $i++) { // Y
148
+			$pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
149 149
 		}
150 150
 
151
-		for($i=0; $i<$this->NbNum; $i++){ // X
152
-			$pass .= $this->Nb[mt_rand(0,strlen($this->Nb) - 1)];
151
+		for ($i = 0; $i < $this->NbNum; $i++) { // X
152
+			$pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
153 153
 		}
154 154
 
155
-		for($i=0; $i<$this->NbSpe; $i++){ // @
156
-			$pass .= $this->Spe[mt_rand(0,strlen($this->Spe) - 1)];
155
+		for ($i = 0; $i < $this->NbSpe; $i++) { // @
156
+			$pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
157 157
 		}
158 158
 
159
-		for($i=strlen($pass);$i<$this->length2; $i++){ // y
160
-			$pass .= $this->All[mt_rand(0,strlen($this->All) -1)];
159
+		for ($i = strlen($pass); $i < $this->length2; $i++) { // y
160
+			$pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
161 161
 		}
162 162
 
163 163
 		$pass = str_shuffle($pass);
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
 		$num = str_split($this->Nb);
184 184
 		$spe = str_split($this->Spe);
185 185
 
186
-		if(count(array_intersect($password_a, $maj)) < $this->NbMaj){
186
+		if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
187 187
 			return 0;
188 188
 		}
189 189
 
190
-		if(count(array_intersect($password_a, $num)) < $this->NbNum){
190
+		if (count(array_intersect($password_a, $num)) < $this->NbNum) {
191 191
 			return 0;
192 192
 		}
193 193
 
194
-		if(count(array_intersect($password_a, $spe)) < $this->NbSpe){
194
+		if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
195 195
 			return 0;
196 196
 		}
197 197
 
198
-		if(!$this->consecutiveInterationSameCharacter($password)){
198
+		if (!$this->consecutiveInterationSameCharacter($password)) {
199 199
 			return 0;
200 200
 		}
201 201
 
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
 		$last = "";
214 214
 		$count = 0;
215 215
 		$char = str_split($password);
216
-		foreach($char as $c){
217
-			if($c != $last){
216
+		foreach ($char as $c) {
217
+			if ($c != $last) {
218 218
 				$last = $c;
219 219
 				$count = 0;
220
-			}else{
220
+			} else {
221 221
 				$count++;
222 222
 			}
223 223
 
224
-			if($count >= $this->NbRepeat) {
224
+			if ($count >= $this->NbRepeat) {
225 225
 				return 0;
226 226
 			}
227 227
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -217,7 +217,7 @@
 block discarded – undo
217 217
 			if($c != $last){
218 218
 				$last = $c;
219 219
 				$count = 0;
220
-			}else{
220
+			} else{
221 221
 				$count++;
222 222
 			}
223 223
 
Please login to merge, or discard this patch.
htdocs/core/modules/security/generate/modGeneratePassNone.class.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -31,82 +31,82 @@
 block discarded – undo
31 31
  */
32 32
 class modGeneratePassNone extends ModeleGenPassword
33 33
 {
34
-	/**
35
-	 * @var int ID
36
-	 */
37
-	public $id;
34
+    /**
35
+     * @var int ID
36
+     */
37
+    public $id;
38 38
 
39
-	public $length;
39
+    public $length;
40 40
 
41
-	/**
41
+    /**
42 42
      * @var DoliDB Database handler.
43 43
      */
44 44
     public $db;
45 45
 
46
-	public $conf;
47
-	public $lang;
48
-	public $user;
46
+    public $conf;
47
+    public $lang;
48
+    public $user;
49 49
 
50 50
 
51
-	/**
52
-	 *	Constructor
53
-	 *
54
-	 *  @param		DoliDB		$db			Database handler
55
-	 *	@param		Conf		$conf		Handler de conf
56
-	 *	@param		Translate	$langs		Handler de langue
57
-	 *	@param		User		$user		Handler du user connecte
58
-	 */
59
-	function __construct($db, $conf, $langs, $user)
60
-	{
61
-		$this->id = "none";
62
-		$this->length = 0;
51
+    /**
52
+     *	Constructor
53
+     *
54
+     *  @param		DoliDB		$db			Database handler
55
+     *	@param		Conf		$conf		Handler de conf
56
+     *	@param		Translate	$langs		Handler de langue
57
+     *	@param		User		$user		Handler du user connecte
58
+     */
59
+    function __construct($db, $conf, $langs, $user)
60
+    {
61
+        $this->id = "none";
62
+        $this->length = 0;
63 63
 
64
-		$this->db=$db;
65
-		$this->conf=$conf;
66
-		$this->langs=$langs;
67
-		$this->user=$user;
68
-	}
64
+        $this->db=$db;
65
+        $this->conf=$conf;
66
+        $this->langs=$langs;
67
+        $this->user=$user;
68
+    }
69 69
 
70
-	/**
71
-	 *		Return description of module
72
-	 *
73
- 	 *      @return     string      Description of text
74
-	 */
75
-	function getDescription()
76
-	{
77
-		global $langs;
78
-		return $langs->trans("PasswordGenerationNone");
79
-	}
70
+    /**
71
+     *		Return description of module
72
+     *
73
+     *      @return     string      Description of text
74
+     */
75
+    function getDescription()
76
+    {
77
+        global $langs;
78
+        return $langs->trans("PasswordGenerationNone");
79
+    }
80 80
 
81
-	/**
82
-	 * 		Return an example of password generated by this module
83
-	 *
84
- 	 *      @return     string      Example of password
85
-	 */
86
-	function getExample()
87
-	{
88
-		return $this->langs->trans("None");
89
-	}
81
+    /**
82
+     * 		Return an example of password generated by this module
83
+     *
84
+     *      @return     string      Example of password
85
+     */
86
+    function getExample()
87
+    {
88
+        return $this->langs->trans("None");
89
+    }
90 90
 
91
-	/**
92
-	 * 		Build new password
93
-	 *
94
- 	 *      @return     string      Return a new generated password
95
-	 */
96
-	function getNewGeneratedPassword()
97
-	{
98
-		return "";
99
-	}
91
+    /**
92
+     * 		Build new password
93
+     *
94
+     *      @return     string      Return a new generated password
95
+     */
96
+    function getNewGeneratedPassword()
97
+    {
98
+        return "";
99
+    }
100 100
 
101
-	/**
102
-	 * 		Validate a password
103
-	 *
104
-	 *		@param		string	$password	Password to check
105
- 	 *      @return     int					0 if KO, >0 if OK
106
-	 */
107
-	function validatePassword($password)
108
-	{
109
-		return 1;
110
-	}
101
+    /**
102
+     * 		Validate a password
103
+     *
104
+     *		@param		string	$password	Password to check
105
+     *      @return     int					0 if KO, >0 if OK
106
+     */
107
+    function validatePassword($password)
108
+    {
109
+        return 1;
110
+    }
111 111
 }
112 112
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  *      \brief      File to manage no password generation.
23 23
  */
24 24
 
25
-require_once DOL_DOCUMENT_ROOT .'/core/modules/security/generate/modules_genpassword.php';
25
+require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modules_genpassword.php';
26 26
 
27 27
 
28 28
 /**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
 		$this->id = "none";
62 62
 		$this->length = 0;
63 63
 
64
-		$this->db=$db;
65
-		$this->conf=$conf;
66
-		$this->langs=$langs;
67
-		$this->user=$user;
64
+		$this->db = $db;
65
+		$this->conf = $conf;
66
+		$this->langs = $langs;
67
+		$this->user = $user;
68 68
 	}
69 69
 
70 70
 	/**
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modApi.class.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -33,223 +33,223 @@
 block discarded – undo
33 33
  */
34 34
 class modApi extends DolibarrModules
35 35
 {
36
-	/**
37
-	 *   Constructor. Define names, constants, directories, boxes, permissions
38
-	 *
39
-	 *   @param      DoliDB		$db      Database handler
40
-	 */
41
-	function __construct($db)
42
-	{
36
+    /**
37
+     *   Constructor. Define names, constants, directories, boxes, permissions
38
+     *
39
+     *   @param      DoliDB		$db      Database handler
40
+     */
41
+    function __construct($db)
42
+    {
43 43
         global $langs,$conf;
44 44
 
45 45
         $this->db = $db;
46 46
 
47
-		// Id for module (must be unique).
48
-		// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49
-		$this->numero = 2610;
50
-		// Key text used to identify module (for permissions, menus, etc...)
51
-		$this->rights_class = 'api';
52
-
53
-		// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
54
-		// It is used to group modules in module setup page
55
-		$this->family = "interface";
56
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57
-		$this->name = preg_replace('/^mod/i','',get_class($this));
58
-		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59
-		$this->description = "REST interface";
60
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
61
-		$this->version = 'dolibarr';
62
-		// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
63
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64
-		// Can be enabled / disabled only in the main company with superadmin account
65
-		$this->core_enabled = 1;
66
-		// Name of image file used for this module.
67
-		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68
-		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
-		$this->picto='technic';
70
-
71
-		$this->module_parts = array();
72
-
73
-		// Data directories to create when module is enabled.
74
-		// Example: this->dirs = array("/api/temp");
75
-		$this->dirs = array('/api/temp');
76
-
77
-		// Config pages. Put here list of php page, stored into api/admin directory, to use to setup module.
78
-		$this->config_page_url = array("index.php@api");
79
-
80
-		// Dependencies
81
-		$this->hidden = false;			// A condition to hide module
82
-		$this->depends = array();		// List of modules id that must be enabled if this module is enabled
83
-		$this->requiredby = array();	// List of modules id to disable if this one is disabled
84
-		$this->conflictwith = array();	// List of modules id this module is in conflict with
85
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
86
-		$this->langfiles = array("other");
87
-
88
-		// Constants
89
-		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
90
-		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
91
-		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
92
-		// );
93
-		$this->const = array();
94
-
95
-		// Array to add new pages in new tabs
96
-		// Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->rights->api->read:/api/mynewtab1.php?id=__ID__',  					// To add a new tab identified by code tabname1
47
+        // Id for module (must be unique).
48
+        // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49
+        $this->numero = 2610;
50
+        // Key text used to identify module (for permissions, menus, etc...)
51
+        $this->rights_class = 'api';
52
+
53
+        // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
54
+        // It is used to group modules in module setup page
55
+        $this->family = "interface";
56
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57
+        $this->name = preg_replace('/^mod/i','',get_class($this));
58
+        // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59
+        $this->description = "REST interface";
60
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
61
+        $this->version = 'dolibarr';
62
+        // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
63
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64
+        // Can be enabled / disabled only in the main company with superadmin account
65
+        $this->core_enabled = 1;
66
+        // Name of image file used for this module.
67
+        // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68
+        // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
+        $this->picto='technic';
70
+
71
+        $this->module_parts = array();
72
+
73
+        // Data directories to create when module is enabled.
74
+        // Example: this->dirs = array("/api/temp");
75
+        $this->dirs = array('/api/temp');
76
+
77
+        // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module.
78
+        $this->config_page_url = array("index.php@api");
79
+
80
+        // Dependencies
81
+        $this->hidden = false;			// A condition to hide module
82
+        $this->depends = array();		// List of modules id that must be enabled if this module is enabled
83
+        $this->requiredby = array();	// List of modules id to disable if this one is disabled
84
+        $this->conflictwith = array();	// List of modules id this module is in conflict with
85
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
86
+        $this->langfiles = array("other");
87
+
88
+        // Constants
89
+        // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
90
+        // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
91
+        //                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
92
+        // );
93
+        $this->const = array();
94
+
95
+        // Array to add new pages in new tabs
96
+        // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->rights->api->read:/api/mynewtab1.php?id=__ID__',  					// To add a new tab identified by code tabname1
97 97
         //                              'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@api:$user->rights->othermodule->read:/api/mynewtab2.php?id=__ID__',  	// To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
98 98
         //                              'objecttype:-tabname:NU:conditiontoremove');                                                     										// To remove an existing tab identified by code tabname
99
-		// where objecttype can be
100
-		// 'categories_x'	  to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
101
-		// 'contact'          to add a tab in contact view
102
-		// 'contract'         to add a tab in contract view
103
-		// 'group'            to add a tab in group view
104
-		// 'intervention'     to add a tab in intervention view
105
-		// 'invoice'          to add a tab in customer invoice view
106
-		// 'invoice_supplier' to add a tab in supplier invoice view
107
-		// 'member'           to add a tab in fundation member view
108
-		// 'opensurveypoll'	  to add a tab in opensurvey poll view
109
-		// 'order'            to add a tab in customer order view
110
-		// 'order_supplier'   to add a tab in supplier order view
111
-		// 'payment'		  to add a tab in payment view
112
-		// 'payment_supplier' to add a tab in supplier payment view
113
-		// 'product'          to add a tab in product view
114
-		// 'propal'           to add a tab in propal view
115
-		// 'project'          to add a tab in project view
116
-		// 'stock'            to add a tab in stock view
117
-		// 'thirdparty'       to add a tab in third party view
118
-		// 'user'             to add a tab in user view
99
+        // where objecttype can be
100
+        // 'categories_x'	  to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
101
+        // 'contact'          to add a tab in contact view
102
+        // 'contract'         to add a tab in contract view
103
+        // 'group'            to add a tab in group view
104
+        // 'intervention'     to add a tab in intervention view
105
+        // 'invoice'          to add a tab in customer invoice view
106
+        // 'invoice_supplier' to add a tab in supplier invoice view
107
+        // 'member'           to add a tab in fundation member view
108
+        // 'opensurveypoll'	  to add a tab in opensurvey poll view
109
+        // 'order'            to add a tab in customer order view
110
+        // 'order_supplier'   to add a tab in supplier order view
111
+        // 'payment'		  to add a tab in payment view
112
+        // 'payment_supplier' to add a tab in supplier payment view
113
+        // 'product'          to add a tab in product view
114
+        // 'propal'           to add a tab in propal view
115
+        // 'project'          to add a tab in project view
116
+        // 'stock'            to add a tab in stock view
117
+        // 'thirdparty'       to add a tab in third party view
118
+        // 'user'             to add a tab in user view
119 119
         $this->tabs = array();
120 120
 
121 121
         // Dictionaries
122
-	    if (! isset($conf->api->enabled))
122
+        if (! isset($conf->api->enabled))
123 123
         {
124
-        	$conf->api=new stdClass();
125
-        	$conf->api->enabled=0;
124
+            $conf->api=new stdClass();
125
+            $conf->api->enabled=0;
126 126
         }
127
-		$this->dictionaries=array();
127
+        $this->dictionaries=array();
128 128
 
129 129
         // Boxes
130
-		// Add here list of php file(s) stored in core/boxes that contains class to show a box.
130
+        // Add here list of php file(s) stored in core/boxes that contains class to show a box.
131 131
         $this->boxes = array();			// List of boxes
132
-		// Example:
133
-		//$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
134
-
135
-		// Permissions
136
-		$this->rights = array();		// Permission array used by this module
137
-		$r=0;
138
-
139
-		// Add here list of permission defined by an id, a label, a boolean and two constant strings.
140
-		// Example:
141
-		// $this->rights[$r][0] = $this->numero + $r;	// Permission id (must not be already used)
142
-		// $this->rights[$r][1] = 'Permision label';	// Permission label
143
-		// $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
144
-		// $this->rights[$r][4] = 'level1';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145
-		// $this->rights[$r][5] = 'level2';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
146
-		// $r++;
147
-
148
-
149
-		// Main menu entries
150
-		$this->menu = array();			// List of menus to add
151
-		$r=0;
152
-
153
-		// Add here entries to declare new menus
154
-		//
155
-		// Example to declare a new Top Menu entry and its Left menu entry:
156
-		// $this->menu[$r]=array(	'fk_menu'=>0,			                // Put 0 if this is a top menu
157
-		//							'type'=>'top',			                // This is a Top menu entry
158
-		//							'titre'=>'Api top menu',
159
-		//							'mainmenu'=>'api',
160
-		//							'leftmenu'=>'api',
161
-		//							'url'=>'/api/pagetop.php',
162
-		//							'langs'=>'mylangfile@api',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
163
-		//							'position'=>100,
164
-		//							'enabled'=>'$conf->api->enabled',	// Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled.
165
-		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
166
-		//							'target'=>'',
167
-		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
168
-		// $r++;
169
-		//
170
-		// Example to declare a Left Menu entry into an existing Top menu entry:
171
-		// $this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=xxx',		    // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
172
-		//							'type'=>'left',			                // This is a Left menu entry
173
-		//							'titre'=>'Api left menu',
174
-		//							'mainmenu'=>'xxx',
175
-		//							'leftmenu'=>'api',
176
-		//							'url'=>'/api/pagelevel2.php',
177
-		//							'langs'=>'mylangfile@api',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
178
-		//							'position'=>100,
179
-		//							'enabled'=>'$conf->api->enabled',  // Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
180
-		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
181
-		//							'target'=>'',
182
-		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
183
-		// $r++;
184
-
185
-
186
-		// Exports
187
-		$r=1;
188
-
189
-		// Example:
190
-		// $this->export_code[$r]=$this->rights_class.'_'.$r;
191
-		// $this->export_label[$r]='CustomersInvoicesAndInvoiceLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
132
+        // Example:
133
+        //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
134
+
135
+        // Permissions
136
+        $this->rights = array();		// Permission array used by this module
137
+        $r=0;
138
+
139
+        // Add here list of permission defined by an id, a label, a boolean and two constant strings.
140
+        // Example:
141
+        // $this->rights[$r][0] = $this->numero + $r;	// Permission id (must not be already used)
142
+        // $this->rights[$r][1] = 'Permision label';	// Permission label
143
+        // $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
144
+        // $this->rights[$r][4] = 'level1';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145
+        // $this->rights[$r][5] = 'level2';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
146
+        // $r++;
147
+
148
+
149
+        // Main menu entries
150
+        $this->menu = array();			// List of menus to add
151
+        $r=0;
152
+
153
+        // Add here entries to declare new menus
154
+        //
155
+        // Example to declare a new Top Menu entry and its Left menu entry:
156
+        // $this->menu[$r]=array(	'fk_menu'=>0,			                // Put 0 if this is a top menu
157
+        //							'type'=>'top',			                // This is a Top menu entry
158
+        //							'titre'=>'Api top menu',
159
+        //							'mainmenu'=>'api',
160
+        //							'leftmenu'=>'api',
161
+        //							'url'=>'/api/pagetop.php',
162
+        //							'langs'=>'mylangfile@api',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
163
+        //							'position'=>100,
164
+        //							'enabled'=>'$conf->api->enabled',	// Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled.
165
+        //							'perms'=>'1',			                // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
166
+        //							'target'=>'',
167
+        //							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
168
+        // $r++;
169
+        //
170
+        // Example to declare a Left Menu entry into an existing Top menu entry:
171
+        // $this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=xxx',		    // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
172
+        //							'type'=>'left',			                // This is a Left menu entry
173
+        //							'titre'=>'Api left menu',
174
+        //							'mainmenu'=>'xxx',
175
+        //							'leftmenu'=>'api',
176
+        //							'url'=>'/api/pagelevel2.php',
177
+        //							'langs'=>'mylangfile@api',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
178
+        //							'position'=>100,
179
+        //							'enabled'=>'$conf->api->enabled',  // Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
180
+        //							'perms'=>'1',			                // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
181
+        //							'target'=>'',
182
+        //							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
183
+        // $r++;
184
+
185
+
186
+        // Exports
187
+        $r=1;
188
+
189
+        // Example:
190
+        // $this->export_code[$r]=$this->rights_class.'_'.$r;
191
+        // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
192 192
         // $this->export_enabled[$r]='1';                               // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
193
-		// $this->export_permission[$r]=array(array("facture","facture","export"));
194
-		// $this->export_fields_array[$r]=array(
195
-		//	's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
196
-		//	's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
197
-		//	's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
198
-		//	'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
199
-		//	'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
200
-		//	'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
201
-		//	'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
202
-		//);
203
-		// $this->export_entities_array[$r]=array(
204
-		//	's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
205
-		//	's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
206
-		//	'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",
207
-		//	'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
208
-		//	'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
209
-		//	'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
210
-		//);
211
-		// $this->export_sql_start[$r]='SELECT DISTINCT ';
212
-		// $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
213
-		// $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
214
-		// $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
215
-		// $this->export_sql_order[$r] .=' ORDER BY s.nom';
216
-		// $r++;
217
-	}
218
-
219
-	/**
220
-	 *		Function called when module is enabled.
221
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
222
-	 *		It also creates data directories
223
-	 *
193
+        // $this->export_permission[$r]=array(array("facture","facture","export"));
194
+        // $this->export_fields_array[$r]=array(
195
+        //	's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
196
+        //	's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
197
+        //	's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
198
+        //	'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
199
+        //	'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
200
+        //	'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
201
+        //	'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
202
+        //);
203
+        // $this->export_entities_array[$r]=array(
204
+        //	's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
205
+        //	's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
206
+        //	'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",
207
+        //	'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
208
+        //	'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
209
+        //	'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
210
+        //);
211
+        // $this->export_sql_start[$r]='SELECT DISTINCT ';
212
+        // $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
213
+        // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
214
+        // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
215
+        // $this->export_sql_order[$r] .=' ORDER BY s.nom';
216
+        // $r++;
217
+    }
218
+
219
+    /**
220
+     *		Function called when module is enabled.
221
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
222
+     *		It also creates data directories
223
+     *
224 224
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
225
-	 *      @return     int             	1 if OK, 0 if KO
226
-	 */
227
-	function init($options='')
228
-	{
229
-		$sql = array();
230
-
231
-		$result=$this->_load_tables('/api/sql/');
232
-
233
-		return $this->_init($sql, $options);
234
-	}
235
-
236
-	/**
237
-	 *		Function called when module is disabled.
238
-	 *      Remove from database constants, boxes and permissions from Dolibarr database.
239
-	 *		Data directories are not deleted.
240
-	 *
241
-	 *      @param string $options Options when enabling module ('', 'noboxes')
242
-	 *      @return int 1 if OK, 0 if KO
243
-	 */
244
-	function remove($options = '')
245
-	{
246
-		// Remove old constants with entity fields different of 0
247
-		$sql = array(
248
-			"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_API', 1),
249
-			"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('API_PRODUCTION_MODE', 1)
250
-		);
251
-
252
-		return $this->_remove($sql, $options);
253
-	}
225
+     *      @return     int             	1 if OK, 0 if KO
226
+     */
227
+    function init($options='')
228
+    {
229
+        $sql = array();
230
+
231
+        $result=$this->_load_tables('/api/sql/');
232
+
233
+        return $this->_init($sql, $options);
234
+    }
235
+
236
+    /**
237
+     *		Function called when module is disabled.
238
+     *      Remove from database constants, boxes and permissions from Dolibarr database.
239
+     *		Data directories are not deleted.
240
+     *
241
+     *      @param string $options Options when enabling module ('', 'noboxes')
242
+     *      @return int 1 if OK, 0 if KO
243
+     */
244
+    function remove($options = '')
245
+    {
246
+        // Remove old constants with entity fields different of 0
247
+        $sql = array(
248
+            "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_API', 1),
249
+            "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('API_PRODUCTION_MODE', 1)
250
+        );
251
+
252
+        return $this->_remove($sql, $options);
253
+    }
254 254
 }
255 255
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *  \ingroup    api
26 26
  *  \brief      Description and activation file for module Api
27 27
  */
28
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 29
 
30 30
 
31 31
 /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	function __construct($db)
42 42
 	{
43
-        global $langs,$conf;
43
+        global $langs, $conf;
44 44
 
45 45
         $this->db = $db;
46 46
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		// It is used to group modules in module setup page
55 55
 		$this->family = "interface";
56 56
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57
-		$this->name = preg_replace('/^mod/i','',get_class($this));
57
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
58 58
 		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59 59
 		$this->description = "REST interface";
60 60
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		// Name of image file used for this module.
67 67
 		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68 68
 		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
-		$this->picto='technic';
69
+		$this->picto = 'technic';
70 70
 
71 71
 		$this->module_parts = array();
72 72
 
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 		$this->config_page_url = array("index.php@api");
79 79
 
80 80
 		// Dependencies
81
-		$this->hidden = false;			// A condition to hide module
82
-		$this->depends = array();		// List of modules id that must be enabled if this module is enabled
83
-		$this->requiredby = array();	// List of modules id to disable if this one is disabled
84
-		$this->conflictwith = array();	// List of modules id this module is in conflict with
85
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
81
+		$this->hidden = false; // A condition to hide module
82
+		$this->depends = array(); // List of modules id that must be enabled if this module is enabled
83
+		$this->requiredby = array(); // List of modules id to disable if this one is disabled
84
+		$this->conflictwith = array(); // List of modules id this module is in conflict with
85
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
86 86
 		$this->langfiles = array("other");
87 87
 
88 88
 		// Constants
@@ -119,22 +119,22 @@  discard block
 block discarded – undo
119 119
         $this->tabs = array();
120 120
 
121 121
         // Dictionaries
122
-	    if (! isset($conf->api->enabled))
122
+	    if (!isset($conf->api->enabled))
123 123
         {
124
-        	$conf->api=new stdClass();
125
-        	$conf->api->enabled=0;
124
+        	$conf->api = new stdClass();
125
+        	$conf->api->enabled = 0;
126 126
         }
127
-		$this->dictionaries=array();
127
+		$this->dictionaries = array();
128 128
 
129 129
         // Boxes
130 130
 		// Add here list of php file(s) stored in core/boxes that contains class to show a box.
131
-        $this->boxes = array();			// List of boxes
131
+        $this->boxes = array(); // List of boxes
132 132
 		// Example:
133 133
 		//$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
134 134
 
135 135
 		// Permissions
136
-		$this->rights = array();		// Permission array used by this module
137
-		$r=0;
136
+		$this->rights = array(); // Permission array used by this module
137
+		$r = 0;
138 138
 
139 139
 		// Add here list of permission defined by an id, a label, a boolean and two constant strings.
140 140
 		// Example:
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 
148 148
 
149 149
 		// Main menu entries
150
-		$this->menu = array();			// List of menus to add
151
-		$r=0;
150
+		$this->menu = array(); // List of menus to add
151
+		$r = 0;
152 152
 
153 153
 		// Add here entries to declare new menus
154 154
 		//
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
 
186 186
 		// Exports
187
-		$r=1;
187
+		$r = 1;
188 188
 
189 189
 		// Example:
190 190
 		// $this->export_code[$r]=$this->rights_class.'_'.$r;
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
225 225
 	 *      @return     int             	1 if OK, 0 if KO
226 226
 	 */
227
-	function init($options='')
227
+	function init($options = '')
228 228
 	{
229 229
 		$sql = array();
230 230
 
231
-		$result=$this->_load_tables('/api/sql/');
231
+		$result = $this->_load_tables('/api/sql/');
232 232
 
233 233
 		return $this->_init($sql, $options);
234 234
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/facture/doc/pdf_sponge.modules.php 3 patches
Indentation   +1852 added lines, -1852 removed lines patch added patch discarded remove patch
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class pdf_sponge extends ModelePDFFactures
45 45
 {
46
-     /**
47
-     * @var DoliDb Database handler
48
-     */
46
+        /**
47
+         * @var DoliDb Database handler
48
+         */
49 49
     public $db;
50 50
 
51
-	/**
51
+    /**
52 52
      * @var string model name
53 53
      */
54 54
     public $name;
55 55
 
56
-	/**
56
+    /**
57 57
      * @var string model description (short text)
58 58
      */
59 59
     public $description;
@@ -63,101 +63,101 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public $update_main_doc_field;
65 65
 
66
-	/**
66
+    /**
67 67
      * @var string document type
68 68
      */
69 69
     public $type;
70 70
 
71
-	/**
71
+    /**
72 72
      * @var array Minimum version of PHP required by module.
73
-	 * e.g.: PHP ≥ 5.3 = array(5, 3)
73
+     * e.g.: PHP ≥ 5.3 = array(5, 3)
74 74
      */
75
-	public $phpmin = array(5, 2);
75
+    public $phpmin = array(5, 2);
76 76
 
77
-	/**
77
+    /**
78 78
      * Dolibarr version of the loaded document
79 79
      * @public string
80 80
      */
81
-	public $version = 'development';
81
+    public $version = 'development';
82 82
 
83 83
     public $page_largeur;
84 84
     public $page_hauteur;
85 85
     public $format;
86
-	public $marge_gauche;
87
-	public $marge_droite;
88
-	public $marge_haute;
89
-	public $marge_basse;
90
-
91
-	public $emetteur;	// Objet societe qui emet
92
-
93
-	/**
94
-	 * @var bool Situation invoice type
95
-	 */
96
-	public $situationinvoice;
97
-
98
-	/**
99
-	 * @var float X position for the situation progress column
100
-	 */
101
-	public $posxprogress;
102
-
103
-
104
-	/**
105
-	 *	Constructor
106
-	 *
107
-	 *  @param		DoliDB		$db      Database handler
108
-	 */
109
-	function __construct($db)
110
-	{
111
-		global $conf,$langs,$mysoc;
112
-
113
-		// Translations
114
-		$langs->loadLangs(array("main", "bills"));
115
-
116
-		$this->db = $db;
117
-		$this->name = "sponge";
118
-		$this->description = $langs->trans('PDFSpongeDescription');
119
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
120
-
121
-		// Dimensiont page
122
-		$this->type = 'pdf';
123
-		$formatarray=pdf_getFormat();
124
-		$this->page_largeur = $formatarray['width'];
125
-		$this->page_hauteur = $formatarray['height'];
126
-		$this->format = array($this->page_largeur,$this->page_hauteur);
127
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
128
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
129
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
130
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
131
-
132
-		$this->option_logo = 1;                    // Affiche logo
133
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
134
-		$this->option_modereg = 1;                 // Affiche mode reglement
135
-		$this->option_condreg = 1;                 // Affiche conditions reglement
136
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
137
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
138
-		$this->option_escompte = 1;                // Affiche si il y a eu escompte
139
-		$this->option_credit_note = 1;             // Support credit notes
140
-		$this->option_freetext = 1;				   // Support add of a personalised text
141
-		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
142
-
143
-		$this->franchise=!$mysoc->tva_assuj;
144
-
145
-		// Get source company
146
-		$this->emetteur=$mysoc;
147
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
148
-
149
-		// Define position of columns
150
-		$this->posxdesc=$this->marge_gauche+1; // used for notes ans other stuff
151
-
152
-		//  Use new system for position of columns, view  $this->defineColumnField()
153
-
154
-		$this->tva=array();
155
-		$this->localtax1=array();
156
-		$this->localtax2=array();
157
-		$this->atleastoneratenotnull=0;
158
-		$this->atleastonediscount=0;
159
-		$this->situationinvoice=false;
160
-	}
86
+    public $marge_gauche;
87
+    public $marge_droite;
88
+    public $marge_haute;
89
+    public $marge_basse;
90
+
91
+    public $emetteur;	// Objet societe qui emet
92
+
93
+    /**
94
+     * @var bool Situation invoice type
95
+     */
96
+    public $situationinvoice;
97
+
98
+    /**
99
+     * @var float X position for the situation progress column
100
+     */
101
+    public $posxprogress;
102
+
103
+
104
+    /**
105
+     *	Constructor
106
+     *
107
+     *  @param		DoliDB		$db      Database handler
108
+     */
109
+    function __construct($db)
110
+    {
111
+        global $conf,$langs,$mysoc;
112
+
113
+        // Translations
114
+        $langs->loadLangs(array("main", "bills"));
115
+
116
+        $this->db = $db;
117
+        $this->name = "sponge";
118
+        $this->description = $langs->trans('PDFSpongeDescription');
119
+        $this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
120
+
121
+        // Dimensiont page
122
+        $this->type = 'pdf';
123
+        $formatarray=pdf_getFormat();
124
+        $this->page_largeur = $formatarray['width'];
125
+        $this->page_hauteur = $formatarray['height'];
126
+        $this->format = array($this->page_largeur,$this->page_hauteur);
127
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
128
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
129
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
130
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
131
+
132
+        $this->option_logo = 1;                    // Affiche logo
133
+        $this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
134
+        $this->option_modereg = 1;                 // Affiche mode reglement
135
+        $this->option_condreg = 1;                 // Affiche conditions reglement
136
+        $this->option_codeproduitservice = 1;      // Affiche code produit-service
137
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
138
+        $this->option_escompte = 1;                // Affiche si il y a eu escompte
139
+        $this->option_credit_note = 1;             // Support credit notes
140
+        $this->option_freetext = 1;				   // Support add of a personalised text
141
+        $this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
142
+
143
+        $this->franchise=!$mysoc->tva_assuj;
144
+
145
+        // Get source company
146
+        $this->emetteur=$mysoc;
147
+        if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
148
+
149
+        // Define position of columns
150
+        $this->posxdesc=$this->marge_gauche+1; // used for notes ans other stuff
151
+
152
+        //  Use new system for position of columns, view  $this->defineColumnField()
153
+
154
+        $this->tva=array();
155
+        $this->localtax1=array();
156
+        $this->localtax2=array();
157
+        $this->atleastoneratenotnull=0;
158
+        $this->atleastonediscount=0;
159
+        $this->situationinvoice=false;
160
+    }
161 161
 
162 162
 
163 163
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -171,1682 +171,1682 @@  discard block
 block discarded – undo
171 171
      *  @param		int			$hidedesc			Do not show desc
172 172
      *  @param		int			$hideref			Do not show ref
173 173
      *  @return     int         	    			1=OK, 0=KO
174
-	 */
175
-	public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
176
-	{
177
-	    // phpcs:enable
178
-	    global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
179
-
180
-	    if (! is_object($outputlangs)) $outputlangs=$langs;
181
-	    // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
182
-	    if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
183
-
184
-	    // Translations
185
-	    $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
186
-
187
-	    $nblignes = count($object->lines);
188
-
189
-	    // Loop on each lines to detect if there is at least one image to show
190
-	    $realpatharray=array();
191
-	    $this->atleastonephoto = false;
192
-	    if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
193
-	    {
194
-	        $objphoto = new Product($this->db);
195
-
196
-	        for ($i = 0 ; $i < $nblignes ; $i++)
197
-	        {
198
-	            if (empty($object->lines[$i]->fk_product)) continue;
199
-
200
-	            $objphoto->fetch($object->lines[$i]->fk_product);
201
-	            //var_dump($objphoto->ref);exit;
202
-	            if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
203
-	            {
204
-	                $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
205
-	                $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
206
-	            }
207
-	            else
208
-	            {
209
-	                $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
210
-	                $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
211
-	            }
212
-
213
-	            $arephoto = false;
214
-	            foreach ($pdir as $midir)
215
-	            {
216
-	                if (! $arephoto)
217
-	                {
218
-	                    $dir = $conf->product->dir_output.'/'.$midir;
219
-
220
-	                    foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
221
-	                    {
222
-	                        if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
223
-	                        {
224
-	                            if ($obj['photo_vignette'])
225
-	                            {
226
-	                                $filename= $obj['photo_vignette'];
227
-	                            }
228
-	                            else
229
-	                            {
230
-	                                $filename=$obj['photo'];
231
-	                            }
232
-	                        }
233
-	                        else
234
-	                        {
235
-	                            $filename=$obj['photo'];
236
-	                        }
237
-
238
-	                        $realpath = $dir.$filename;
239
-	                        $arephoto = true;
240
-	                        $this->atleastonephoto = true;
241
-	                    }
242
-	                }
243
-	            }
244
-
245
-	            if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
246
-	        }
247
-	    }
248
-
249
-	    //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
250
-
251
-	    if ($conf->facture->dir_output)
252
-	    {
253
-	        $object->fetch_thirdparty();
254
-
255
-	        $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
256
-	        $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
257
-	        $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
258
-
259
-	        // Definition of $dir and $file
260
-	        if ($object->specimen)
261
-	        {
262
-	            $dir = $conf->facture->dir_output;
263
-	            $file = $dir . "/SPECIMEN.pdf";
264
-	        }
265
-	        else
266
-	        {
267
-	            $objectref = dol_sanitizeFileName($object->ref);
268
-	            $dir = $conf->facture->dir_output . "/" . $objectref;
269
-	            $file = $dir . "/" . $objectref . ".pdf";
270
-	        }
271
-	        if (! file_exists($dir))
272
-	        {
273
-	            if (dol_mkdir($dir) < 0)
274
-	            {
275
-	                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
276
-	                return 0;
277
-	            }
278
-	        }
279
-
280
-	        if (file_exists($dir))
281
-	        {
282
-	            // Add pdfgeneration hook
283
-	            if (! is_object($hookmanager))
284
-	            {
285
-	                include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
286
-	                $hookmanager=new HookManager($this->db);
287
-	            }
288
-	            $hookmanager->initHooks(array('pdfgeneration'));
289
-	            $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
290
-	            global $action;
291
-	            $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
292
-
293
-	            // Set nblignes with the new facture lines content after hook
294
-	            $nblignes = count($object->lines);
295
-	            $nbpayments = count($object->getListOfPayments());
296
-
297
-	            // Create pdf instance
298
-	            $pdf=pdf_getInstance($this->format);
299
-	            $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
300
-	            $pdf->SetAutoPageBreak(1,0);
301
-
302
-	            $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
303
-	            $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
304
-	            $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22);	// Height reserved to output the footer (value include bottom margin)
305
-
306
-	            if (class_exists('TCPDF'))
307
-	            {
308
-	                $pdf->setPrintHeader(false);
309
-	                $pdf->setPrintFooter(false);
310
-	            }
311
-	            $pdf->SetFont(pdf_getPDFFont($outputlangs));
312
-
313
-	            // Set path to the background PDF File
174
+     */
175
+    public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
176
+    {
177
+        // phpcs:enable
178
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
179
+
180
+        if (! is_object($outputlangs)) $outputlangs=$langs;
181
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
182
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
183
+
184
+        // Translations
185
+        $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
186
+
187
+        $nblignes = count($object->lines);
188
+
189
+        // Loop on each lines to detect if there is at least one image to show
190
+        $realpatharray=array();
191
+        $this->atleastonephoto = false;
192
+        if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
193
+        {
194
+            $objphoto = new Product($this->db);
195
+
196
+            for ($i = 0 ; $i < $nblignes ; $i++)
197
+            {
198
+                if (empty($object->lines[$i]->fk_product)) continue;
199
+
200
+                $objphoto->fetch($object->lines[$i]->fk_product);
201
+                //var_dump($objphoto->ref);exit;
202
+                if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
203
+                {
204
+                    $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
205
+                    $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
206
+                }
207
+                else
208
+                {
209
+                    $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
210
+                    $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
211
+                }
212
+
213
+                $arephoto = false;
214
+                foreach ($pdir as $midir)
215
+                {
216
+                    if (! $arephoto)
217
+                    {
218
+                        $dir = $conf->product->dir_output.'/'.$midir;
219
+
220
+                        foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
221
+                        {
222
+                            if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
223
+                            {
224
+                                if ($obj['photo_vignette'])
225
+                                {
226
+                                    $filename= $obj['photo_vignette'];
227
+                                }
228
+                                else
229
+                                {
230
+                                    $filename=$obj['photo'];
231
+                                }
232
+                            }
233
+                            else
234
+                            {
235
+                                $filename=$obj['photo'];
236
+                            }
237
+
238
+                            $realpath = $dir.$filename;
239
+                            $arephoto = true;
240
+                            $this->atleastonephoto = true;
241
+                        }
242
+                    }
243
+                }
244
+
245
+                if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
246
+            }
247
+        }
248
+
249
+        //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
250
+
251
+        if ($conf->facture->dir_output)
252
+        {
253
+            $object->fetch_thirdparty();
254
+
255
+            $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
256
+            $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
257
+            $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
258
+
259
+            // Definition of $dir and $file
260
+            if ($object->specimen)
261
+            {
262
+                $dir = $conf->facture->dir_output;
263
+                $file = $dir . "/SPECIMEN.pdf";
264
+            }
265
+            else
266
+            {
267
+                $objectref = dol_sanitizeFileName($object->ref);
268
+                $dir = $conf->facture->dir_output . "/" . $objectref;
269
+                $file = $dir . "/" . $objectref . ".pdf";
270
+            }
271
+            if (! file_exists($dir))
272
+            {
273
+                if (dol_mkdir($dir) < 0)
274
+                {
275
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
276
+                    return 0;
277
+                }
278
+            }
279
+
280
+            if (file_exists($dir))
281
+            {
282
+                // Add pdfgeneration hook
283
+                if (! is_object($hookmanager))
284
+                {
285
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
286
+                    $hookmanager=new HookManager($this->db);
287
+                }
288
+                $hookmanager->initHooks(array('pdfgeneration'));
289
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
290
+                global $action;
291
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
292
+
293
+                // Set nblignes with the new facture lines content after hook
294
+                $nblignes = count($object->lines);
295
+                $nbpayments = count($object->getListOfPayments());
296
+
297
+                // Create pdf instance
298
+                $pdf=pdf_getInstance($this->format);
299
+                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
300
+                $pdf->SetAutoPageBreak(1,0);
301
+
302
+                $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
303
+                $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
304
+                $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22);	// Height reserved to output the footer (value include bottom margin)
305
+
306
+                if (class_exists('TCPDF'))
307
+                {
308
+                    $pdf->setPrintHeader(false);
309
+                    $pdf->setPrintFooter(false);
310
+                }
311
+                $pdf->SetFont(pdf_getPDFFont($outputlangs));
312
+
313
+                // Set path to the background PDF File
314 314
                 if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
315
-	            {
316
-	                $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
317
-	                $tplidx = $pdf->importPage(1);
318
-	            }
319
-
320
-	            $pdf->Open();
321
-	            $pagenb=0;
322
-	            $pdf->SetDrawColor(128,128,128);
323
-
324
-	            $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
325
-	            $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
326
-	            $pdf->SetCreator("Dolibarr ".DOL_VERSION);
327
-	            $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
328
-	            $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
329
-	            if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
330
-
331
-	            $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
332
-
333
-	            // Does we have at least one line with discount $this->atleastonediscount
334
-	            foreach ($object->lines as $line) {
335
-	               if ($line->remise_percent){
336
-	                    $this->atleastonediscount = true;
337
-	                    break;
338
-	               }
339
-	            }
340
-
341
-
342
-	            // Situation invoice handling
343
-	            if ($object->situation_cycle_ref)
344
-	            {
345
-	                $this->situationinvoice = true;
346
-	            }
347
-
348
-	            // New page
349
-	            $pdf->AddPage();
350
-	            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
351
-	            $pagenb++;
352
-
353
-	            $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
354
-	            $pdf->SetFont('','', $default_font_size - 1);
355
-	            $pdf->MultiCell(0, 3, '');		// Set interline to 3
356
-	            $pdf->SetTextColor(0,0,0);
357
-
358
-	            $tab_top = 90+$top_shift;
359
-	            $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
360
-	            $tab_height = 130-$top_shift;
361
-	            $tab_height_newpage = 150;
362
-	            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift;
363
-
364
-	            // Incoterm
365
-	            $height_incoterms = 0;
366
-	            if ($conf->incoterm->enabled)
367
-	            {
368
-	                $desc_incoterms = $object->getIncotermsForPDF();
369
-	                if ($desc_incoterms)
370
-	                {
371
-						$tab_top -= 2;
372
-
373
-	                    $pdf->SetFont('','', $default_font_size - 1);
374
-	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
375
-	                    $nexY = max($pdf->GetY(),$nexY);
376
-	                    $height_incoterms=$nexY-$tab_top;
377
-
378
-	                    // Rect prend une longueur en 3eme param
379
-	                    $pdf->SetDrawColor(192,192,192);
380
-	                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
381
-
382
-	                    $tab_top = $nexY+6;
383
-	                    $height_incoterms += 4;
384
-	                }
385
-	            }
386
-
387
-	            // Affiche notes
388
-	            $notetoshow=empty($object->note_public)?'':$object->note_public;
389
-	            if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
390
-	            {
391
-	                // Get first sale rep
392
-	                if (is_object($object->thirdparty))
393
-	                {
394
-	                    $salereparray=$object->thirdparty->getSalesRepresentatives($user);
395
-	                    $salerepobj=new User($this->db);
396
-	                    $salerepobj->fetch($salereparray[0]['id']);
397
-	                    if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
398
-	                }
399
-	            }
400
-
401
-	            $pagenb = $pdf->getPage();
402
-	            if ($notetoshow)
403
-	            {
404
-					$tab_top -= 2;
405
-
406
-	                $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
407
-	                $pageposbeforenote = $pagenb;
408
-
409
-	                $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
410
-	                complete_substitutions_array($substitutionarray, $outputlangs, $object);
411
-	                $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
412
-
413
-
414
-	                $pdf->startTransaction();
415
-
416
-	                $pdf->SetFont('','', $default_font_size - 1);
417
-	                $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
418
-	                // Description
419
-	                $pageposafternote=$pdf->getPage();
420
-	                $posyafter = $pdf->GetY();
421
-
422
-	                if($pageposafternote>$pageposbeforenote )
423
-	                {
424
-	                    $pdf->rollbackTransaction(true);
425
-
426
-	                    // prepar pages to receive notes
427
-	                    while ($pagenb < $pageposafternote) {
428
-	                        $pdf->AddPage();
429
-	                        $pagenb++;
430
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
431
-	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
432
-	                        // $this->_pagefoot($pdf,$object,$outputlangs,1);
433
-	                        $pdf->setTopMargin($tab_top_newpage);
434
-	                        // The only function to edit the bottom margin of current page to set it.
435
-	                        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
436
-	                    }
437
-
438
-	                    // back to start
439
-	                    $pdf->setPage($pageposbeforenote);
440
-	                    $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
441
-	                    $pdf->SetFont('','', $default_font_size - 1);
442
-	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
443
-	                    $pageposafternote=$pdf->getPage();
444
-
445
-	                    $posyafter = $pdf->GetY();
446
-
447
-	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
448
-	                    {
449
-	                        $pdf->AddPage('','',true);
450
-	                        $pagenb++;
451
-	                        $pageposafternote++;
452
-	                        $pdf->setPage($pageposafternote);
453
-	                        $pdf->setTopMargin($tab_top_newpage);
454
-	                        // The only function to edit the bottom margin of current page to set it.
455
-	                        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
456
-	                        //$posyafter = $tab_top_newpage;
457
-	                    }
458
-
459
-
460
-	                    // apply note frame to previus pages
461
-	                    $i = $pageposbeforenote;
462
-	                    while ($i < $pageposafternote) {
463
-	                        $pdf->setPage($i);
464
-
465
-
466
-	                        $pdf->SetDrawColor(128,128,128);
467
-	                        // Draw note frame
468
-	                        if($i>$pageposbeforenote){
469
-	                            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
470
-	                            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
471
-	                        }
472
-	                        else{
473
-	                            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
474
-	                            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
475
-	                        }
476
-
477
-	                        // Add footer
478
-	                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
479
-	                        $this->_pagefoot($pdf,$object,$outputlangs,1);
480
-
481
-	                        $i++;
482
-	                    }
483
-
484
-	                    // apply note frame to last page
485
-	                    $pdf->setPage($pageposafternote);
486
-	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
-	                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
-	                    $height_note=$posyafter-$tab_top_newpage;
489
-	                    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
490
-	                }
491
-	                else // No pagebreak
492
-	                {
493
-	                    $pdf->commitTransaction();
494
-	                    $posyafter = $pdf->GetY();
495
-	                    $height_note=$posyafter-$tab_top;
496
-	                    $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
497
-
498
-
499
-	                    if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
500
-	                    {
501
-	                        // not enough space, need to add page
502
-	                        $pdf->AddPage('','',true);
503
-	                        $pagenb++;
504
-	                        $pageposafternote++;
505
-	                        $pdf->setPage($pageposafternote);
506
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
507
-	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
508
-
509
-	                        $posyafter = $tab_top_newpage;
510
-	                    }
511
-	                }
512
-
513
-	                $tab_height = $tab_height - $height_note;
514
-	                $tab_top = $posyafter +6;
515
-	            }
516
-	            else
517
-	            {
518
-	                $height_note=0;
519
-	            }
520
-
521
-	            $iniY = $tab_top + 7;
522
-	            $curY = $tab_top + 7;
523
-	            $nexY = $tab_top + 7;
524
-
525
-	            // Use new auto collum system
526
-	            $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
527
-
528
-	            // Loop on each lines
529
-	            $pageposbeforeprintlines=$pdf->getPage();
530
-	            $pagenb = $pageposbeforeprintlines;
531
-	            for ($i = 0; $i < $nblignes; $i++)
532
-	            {
533
-
534
-	                $curY = $nexY;
535
-	                $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
536
-	                $pdf->SetTextColor(0,0,0);
537
-
538
-	                // Define size of image if we need it
539
-	                $imglinesize=array();
540
-	                if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
541
-
542
-	                $pdf->setTopMargin($tab_top_newpage);
543
-	                $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
544
-	                $pageposbefore=$pdf->getPage();
545
-
546
-	                $showpricebeforepagebreak=1;
547
-	                $posYAfterImage=0;
548
-	                $posYAfterDescription=0;
549
-
550
-	                if($this->getColumnStatus('photo'))
551
-	                {
552
-    	                // We start with Photo of product line
553
-    	                if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
554
-    	                {
555
-    	                    $pdf->AddPage('','',true);
556
-    	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
557
-    	                    $pdf->setPage($pageposbefore+1);
558
-
559
-    	                    $curY = $tab_top_newpage;
560
-    	                    $showpricebeforepagebreak=0;
561
-    	                }
562
-
563
-    	                if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
564
-    	                {
565
-    	                    $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
566
-    	                    // $pdf->Image does not increase value return by getY, so we save it manually
567
-    	                    $posYAfterImage=$curY+$imglinesize['height'];
568
-    	                }
569
-	                }
570
-
571
-	                // Description of product line
572
-	                if ($this->getColumnStatus('desc'))
573
-	                {
574
-    	                $pdf->startTransaction();
575
-    	                pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
576
-    	                $pageposafter=$pdf->getPage();
577
-    	                if ($pageposafter > $pageposbefore)	// There is a pagebreak
578
-    	                {
579
-    	                    $pdf->rollbackTransaction(true);
580
-    	                    $pageposafter=$pageposbefore;
581
-    	                    //print $pageposafter.'-'.$pageposbefore;exit;
582
-    	                    $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
583
-    	                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
584
-    	                    $pageposafter=$pdf->getPage();
585
-    	                    $posyafter=$pdf->GetY();
586
-    	                    //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
587
-    	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
588
-    	                    {
589
-    	                        if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
590
-    	                        {
591
-    	                            $pdf->AddPage('','',true);
592
-    	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
593
-    	                            $pdf->setPage($pageposafter+1);
594
-    	                        }
595
-    	                    }
596
-    	                    else
597
-    	                    {
598
-    	                        // We found a page break
599
-    	                        $showpricebeforepagebreak=0;
600
-    	                    }
601
-    	                }
602
-    	                else	// No pagebreak
603
-    	                {
604
-    	                    $pdf->commitTransaction();
605
-    	                }
606
-    	                $posYAfterDescription=$pdf->GetY();
607
-	                }
608
-
609
-	                $nexY = $pdf->GetY();
610
-	                $pageposafter=$pdf->getPage();
611
-	                $pdf->setPage($pageposbefore);
612
-	                $pdf->setTopMargin($this->marge_haute);
613
-	                $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
614
-
615
-	                // We suppose that a too long description or photo were moved completely on next page
616
-	                if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
617
-	                    $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
618
-	                }
619
-
620
-	                $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
621
-
622
-	                // VAT Rate
623
-	                if ($this->getColumnStatus('vat'))
624
-	                {
625
-	                    $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
626
-	                    $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
627
-	                    $nexY = max($pdf->GetY(),$nexY);
628
-	                }
629
-
630
-	                // Unit price before discount
631
-	                if ($this->getColumnStatus('subprice'))
632
-	                {
633
-	                    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
634
-	                    $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
635
-	                    $nexY = max($pdf->GetY(),$nexY);
636
-	                }
637
-
638
-	                // Quantity
639
-	                // Enough for 6 chars
640
-	                if ($this->getColumnStatus('qty'))
641
-	                {
642
-	                    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
643
-	                    $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
644
-	                    $nexY = max($pdf->GetY(),$nexY);
645
-	                }
646
-
647
-	                // Situation progress
648
-	                if ($this->getColumnStatus('progress'))
649
-	                {
650
-	                    $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
651
-	                    $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
652
-	                    $nexY = max($pdf->GetY(),$nexY);
653
-	                }
654
-
655
-	                // Unit
656
-	                if ($this->getColumnStatus('unit'))
657
-	                {
658
-	                    $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
659
-	                    $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
660
-	                    $nexY = max($pdf->GetY(),$nexY);
661
-	                }
662
-
663
-	                // Discount on line
664
-	                if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent)
665
-	                {
666
-	                    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
667
-	                    $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
668
-	                    $nexY = max($pdf->GetY(),$nexY);
669
-	                }
670
-
671
-	                // Total HT line
672
-	                if ($this->getColumnStatus('totalexcltax'))
673
-	                {
674
-	                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
675
-	                    $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
676
-	                    $nexY = max($pdf->GetY(),$nexY);
677
-	                }
678
-
679
-
680
-	                $parameters=array(
681
-	                    'object' => $object,
682
-	                    'i' => $i,
683
-	                    'pdf' =>& $pdf,
684
-	                    'curY' =>& $curY,
685
-	                    'nexY' =>& $nexY,
686
-	                    'outputlangs' => $outputlangs,
687
-	                    'hidedetails' => $hidedetails
688
-	                );
689
-	                $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
690
-
691
-
692
-
693
-	                $sign=1;
694
-	                if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
695
-	                // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
696
-	                $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
697
-	                if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
698
-	                {
699
-	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
700
-	                    else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
701
-	                } else {
702
-	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
703
-	                    else $tvaligne= $sign * $object->lines[$i]->total_tva;
704
-	                }
705
-
706
-	                $localtax1ligne=$object->lines[$i]->total_localtax1;
707
-	                $localtax2ligne=$object->lines[$i]->total_localtax2;
708
-	                $localtax1_rate=$object->lines[$i]->localtax1_tx;
709
-	                $localtax2_rate=$object->lines[$i]->localtax2_tx;
710
-	                $localtax1_type=$object->lines[$i]->localtax1_type;
711
-	                $localtax2_type=$object->lines[$i]->localtax2_type;
712
-
713
-	                if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
714
-	                if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
715
-	                if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
716
-
717
-	                $vatrate=(string) $object->lines[$i]->tva_tx;
718
-
719
-	                // Retrieve type from database for backward compatibility with old records
720
-	                if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
721
-	                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
722
-	                {
723
-	                    $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
724
-	                    $localtax1_type = $localtaxtmp_array[0];
725
-	                    $localtax2_type = $localtaxtmp_array[2];
726
-	                }
727
-
728
-	                // retrieve global local tax
729
-	                if ($localtax1_type && $localtax1ligne != 0)
730
-	                    $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
731
-	                    if ($localtax2_type && $localtax2ligne != 0)
732
-	                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
733
-
734
-	                        if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
735
-	                        if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
736
-	                        $this->tva[$vatrate] += $tvaligne;
737
-
738
-	                        $nexY = max($nexY,$posYAfterImage);
739
-
740
-	                        // Add line
741
-	                        if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
742
-	                        {
743
-	                            $pdf->setPage($pageposafter);
744
-	                            $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
745
-	                            //$pdf->SetDrawColor(190,190,200);
746
-	                            $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
747
-	                            $pdf->SetLineStyle(array('dash'=>0));
748
-	                        }
749
-
750
-	                        $nexY+=2;    // Passe espace entre les lignes
751
-
752
-	                        // Detect if some page were added automatically and output _tableau for past pages
753
-	                        while ($pagenb < $pageposafter)
754
-	                        {
755
-	                            $pdf->setPage($pagenb);
756
-	                            if ($pagenb == $pageposbeforeprintlines)
757
-	                            {
758
-	                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
759
-	                            }
760
-	                            else
761
-	                            {
762
-	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
763
-	                            }
764
-	                            $this->_pagefoot($pdf,$object,$outputlangs,1);
765
-	                            $pagenb++;
766
-	                            $pdf->setPage($pagenb);
767
-	                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
768
-	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
769
-	                        }
770
-
771
-	                        if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
772
-	                        {
773
-	                            if ($pagenb == $pageposafter)
774
-	                            {
775
-	                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
776
-	                            }
777
-	                            else
778
-	                            {
779
-	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
780
-	                            }
781
-	                            $this->_pagefoot($pdf,$object,$outputlangs,1);
782
-	                            // New page
783
-	                            $pdf->AddPage();
784
-	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
785
-	                            $pagenb++;
786
-	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
787
-	                        }
788
-	            }
789
-
790
-	            // Show square
791
-	            if ($pagenb == $pageposbeforeprintlines)
792
-	            {
793
-	                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
794
-	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
795
-	            }
796
-	            else
797
-	            {
798
-	                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
799
-	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
800
-	            }
801
-
802
-	            // Affiche zone infos
803
-	            $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
804
-
805
-	            // Affiche zone totaux
806
-	            $posy=$this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
807
-
808
-	            // Affiche zone versements
809
-	            if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
810
-	            {
811
-	                $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
812
-	            }
813
-
814
-	            // Pied de page
815
-	            $this->_pagefoot($pdf,$object,$outputlangs);
816
-	            if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
817
-
818
-	            $pdf->Close();
819
-
820
-	            $pdf->Output($file,'F');
821
-
822
-	            // Add pdfgeneration hook
823
-	            $hookmanager->initHooks(array('pdfgeneration'));
824
-	            $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
825
-	            global $action;
826
-	            $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
827
-
828
-	            if (! empty($conf->global->MAIN_UMASK))
829
-	                @chmod($file, octdec($conf->global->MAIN_UMASK));
830
-
831
-	                $this->result = array('fullpath'=>$file);
832
-
833
-	                return 1;   // No error
834
-	        }
835
-	        else
836
-	        {
837
-	            $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
838
-	            return 0;
839
-	        }
840
-	    }
841
-	    else
842
-	    {
843
-	        $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
844
-	        return 0;
845
-	    }
846
-	}
847
-
848
-
849
-	/**
850
-	 *  Show payments table
851
-	 *
315
+                {
316
+                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
317
+                    $tplidx = $pdf->importPage(1);
318
+                }
319
+
320
+                $pdf->Open();
321
+                $pagenb=0;
322
+                $pdf->SetDrawColor(128,128,128);
323
+
324
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
325
+                $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
326
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
327
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
328
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
329
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
330
+
331
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
332
+
333
+                // Does we have at least one line with discount $this->atleastonediscount
334
+                foreach ($object->lines as $line) {
335
+                    if ($line->remise_percent){
336
+                        $this->atleastonediscount = true;
337
+                        break;
338
+                    }
339
+                }
340
+
341
+
342
+                // Situation invoice handling
343
+                if ($object->situation_cycle_ref)
344
+                {
345
+                    $this->situationinvoice = true;
346
+                }
347
+
348
+                // New page
349
+                $pdf->AddPage();
350
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
351
+                $pagenb++;
352
+
353
+                $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
354
+                $pdf->SetFont('','', $default_font_size - 1);
355
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
356
+                $pdf->SetTextColor(0,0,0);
357
+
358
+                $tab_top = 90+$top_shift;
359
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
360
+                $tab_height = 130-$top_shift;
361
+                $tab_height_newpage = 150;
362
+                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift;
363
+
364
+                // Incoterm
365
+                $height_incoterms = 0;
366
+                if ($conf->incoterm->enabled)
367
+                {
368
+                    $desc_incoterms = $object->getIncotermsForPDF();
369
+                    if ($desc_incoterms)
370
+                    {
371
+                        $tab_top -= 2;
372
+
373
+                        $pdf->SetFont('','', $default_font_size - 1);
374
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
375
+                        $nexY = max($pdf->GetY(),$nexY);
376
+                        $height_incoterms=$nexY-$tab_top;
377
+
378
+                        // Rect prend une longueur en 3eme param
379
+                        $pdf->SetDrawColor(192,192,192);
380
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
381
+
382
+                        $tab_top = $nexY+6;
383
+                        $height_incoterms += 4;
384
+                    }
385
+                }
386
+
387
+                // Affiche notes
388
+                $notetoshow=empty($object->note_public)?'':$object->note_public;
389
+                if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
390
+                {
391
+                    // Get first sale rep
392
+                    if (is_object($object->thirdparty))
393
+                    {
394
+                        $salereparray=$object->thirdparty->getSalesRepresentatives($user);
395
+                        $salerepobj=new User($this->db);
396
+                        $salerepobj->fetch($salereparray[0]['id']);
397
+                        if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
398
+                    }
399
+                }
400
+
401
+                $pagenb = $pdf->getPage();
402
+                if ($notetoshow)
403
+                {
404
+                    $tab_top -= 2;
405
+
406
+                    $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
407
+                    $pageposbeforenote = $pagenb;
408
+
409
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
410
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
411
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
412
+
413
+
414
+                    $pdf->startTransaction();
415
+
416
+                    $pdf->SetFont('','', $default_font_size - 1);
417
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
418
+                    // Description
419
+                    $pageposafternote=$pdf->getPage();
420
+                    $posyafter = $pdf->GetY();
421
+
422
+                    if($pageposafternote>$pageposbeforenote )
423
+                    {
424
+                        $pdf->rollbackTransaction(true);
425
+
426
+                        // prepar pages to receive notes
427
+                        while ($pagenb < $pageposafternote) {
428
+                            $pdf->AddPage();
429
+                            $pagenb++;
430
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
431
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
432
+                            // $this->_pagefoot($pdf,$object,$outputlangs,1);
433
+                            $pdf->setTopMargin($tab_top_newpage);
434
+                            // The only function to edit the bottom margin of current page to set it.
435
+                            $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
436
+                        }
437
+
438
+                        // back to start
439
+                        $pdf->setPage($pageposbeforenote);
440
+                        $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
441
+                        $pdf->SetFont('','', $default_font_size - 1);
442
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
443
+                        $pageposafternote=$pdf->getPage();
444
+
445
+                        $posyafter = $pdf->GetY();
446
+
447
+                        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
448
+                        {
449
+                            $pdf->AddPage('','',true);
450
+                            $pagenb++;
451
+                            $pageposafternote++;
452
+                            $pdf->setPage($pageposafternote);
453
+                            $pdf->setTopMargin($tab_top_newpage);
454
+                            // The only function to edit the bottom margin of current page to set it.
455
+                            $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
456
+                            //$posyafter = $tab_top_newpage;
457
+                        }
458
+
459
+
460
+                        // apply note frame to previus pages
461
+                        $i = $pageposbeforenote;
462
+                        while ($i < $pageposafternote) {
463
+                            $pdf->setPage($i);
464
+
465
+
466
+                            $pdf->SetDrawColor(128,128,128);
467
+                            // Draw note frame
468
+                            if($i>$pageposbeforenote){
469
+                                $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
470
+                                $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
471
+                            }
472
+                            else{
473
+                                $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
474
+                                $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
475
+                            }
476
+
477
+                            // Add footer
478
+                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
479
+                            $this->_pagefoot($pdf,$object,$outputlangs,1);
480
+
481
+                            $i++;
482
+                        }
483
+
484
+                        // apply note frame to last page
485
+                        $pdf->setPage($pageposafternote);
486
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
+                        $height_note=$posyafter-$tab_top_newpage;
489
+                        $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
490
+                    }
491
+                    else // No pagebreak
492
+                    {
493
+                        $pdf->commitTransaction();
494
+                        $posyafter = $pdf->GetY();
495
+                        $height_note=$posyafter-$tab_top;
496
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
497
+
498
+
499
+                        if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
500
+                        {
501
+                            // not enough space, need to add page
502
+                            $pdf->AddPage('','',true);
503
+                            $pagenb++;
504
+                            $pageposafternote++;
505
+                            $pdf->setPage($pageposafternote);
506
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
507
+                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
508
+
509
+                            $posyafter = $tab_top_newpage;
510
+                        }
511
+                    }
512
+
513
+                    $tab_height = $tab_height - $height_note;
514
+                    $tab_top = $posyafter +6;
515
+                }
516
+                else
517
+                {
518
+                    $height_note=0;
519
+                }
520
+
521
+                $iniY = $tab_top + 7;
522
+                $curY = $tab_top + 7;
523
+                $nexY = $tab_top + 7;
524
+
525
+                // Use new auto collum system
526
+                $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
527
+
528
+                // Loop on each lines
529
+                $pageposbeforeprintlines=$pdf->getPage();
530
+                $pagenb = $pageposbeforeprintlines;
531
+                for ($i = 0; $i < $nblignes; $i++)
532
+                {
533
+
534
+                    $curY = $nexY;
535
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
536
+                    $pdf->SetTextColor(0,0,0);
537
+
538
+                    // Define size of image if we need it
539
+                    $imglinesize=array();
540
+                    if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
541
+
542
+                    $pdf->setTopMargin($tab_top_newpage);
543
+                    $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
544
+                    $pageposbefore=$pdf->getPage();
545
+
546
+                    $showpricebeforepagebreak=1;
547
+                    $posYAfterImage=0;
548
+                    $posYAfterDescription=0;
549
+
550
+                    if($this->getColumnStatus('photo'))
551
+                    {
552
+                        // We start with Photo of product line
553
+                        if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
554
+                        {
555
+                            $pdf->AddPage('','',true);
556
+                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
557
+                            $pdf->setPage($pageposbefore+1);
558
+
559
+                            $curY = $tab_top_newpage;
560
+                            $showpricebeforepagebreak=0;
561
+                        }
562
+
563
+                        if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
564
+                        {
565
+                            $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
566
+                            // $pdf->Image does not increase value return by getY, so we save it manually
567
+                            $posYAfterImage=$curY+$imglinesize['height'];
568
+                        }
569
+                    }
570
+
571
+                    // Description of product line
572
+                    if ($this->getColumnStatus('desc'))
573
+                    {
574
+                        $pdf->startTransaction();
575
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
576
+                        $pageposafter=$pdf->getPage();
577
+                        if ($pageposafter > $pageposbefore)	// There is a pagebreak
578
+                        {
579
+                            $pdf->rollbackTransaction(true);
580
+                            $pageposafter=$pageposbefore;
581
+                            //print $pageposafter.'-'.$pageposbefore;exit;
582
+                            $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
583
+                            pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
584
+                            $pageposafter=$pdf->getPage();
585
+                            $posyafter=$pdf->GetY();
586
+                            //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
587
+                            if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
588
+                            {
589
+                                if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
590
+                                {
591
+                                    $pdf->AddPage('','',true);
592
+                                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
593
+                                    $pdf->setPage($pageposafter+1);
594
+                                }
595
+                            }
596
+                            else
597
+                            {
598
+                                // We found a page break
599
+                                $showpricebeforepagebreak=0;
600
+                            }
601
+                        }
602
+                        else	// No pagebreak
603
+                        {
604
+                            $pdf->commitTransaction();
605
+                        }
606
+                        $posYAfterDescription=$pdf->GetY();
607
+                    }
608
+
609
+                    $nexY = $pdf->GetY();
610
+                    $pageposafter=$pdf->getPage();
611
+                    $pdf->setPage($pageposbefore);
612
+                    $pdf->setTopMargin($this->marge_haute);
613
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
614
+
615
+                    // We suppose that a too long description or photo were moved completely on next page
616
+                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
617
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
618
+                    }
619
+
620
+                    $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
621
+
622
+                    // VAT Rate
623
+                    if ($this->getColumnStatus('vat'))
624
+                    {
625
+                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
626
+                        $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
627
+                        $nexY = max($pdf->GetY(),$nexY);
628
+                    }
629
+
630
+                    // Unit price before discount
631
+                    if ($this->getColumnStatus('subprice'))
632
+                    {
633
+                        $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
634
+                        $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
635
+                        $nexY = max($pdf->GetY(),$nexY);
636
+                    }
637
+
638
+                    // Quantity
639
+                    // Enough for 6 chars
640
+                    if ($this->getColumnStatus('qty'))
641
+                    {
642
+                        $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
643
+                        $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
644
+                        $nexY = max($pdf->GetY(),$nexY);
645
+                    }
646
+
647
+                    // Situation progress
648
+                    if ($this->getColumnStatus('progress'))
649
+                    {
650
+                        $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
651
+                        $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
652
+                        $nexY = max($pdf->GetY(),$nexY);
653
+                    }
654
+
655
+                    // Unit
656
+                    if ($this->getColumnStatus('unit'))
657
+                    {
658
+                        $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
659
+                        $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
660
+                        $nexY = max($pdf->GetY(),$nexY);
661
+                    }
662
+
663
+                    // Discount on line
664
+                    if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent)
665
+                    {
666
+                        $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
667
+                        $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
668
+                        $nexY = max($pdf->GetY(),$nexY);
669
+                    }
670
+
671
+                    // Total HT line
672
+                    if ($this->getColumnStatus('totalexcltax'))
673
+                    {
674
+                        $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
675
+                        $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
676
+                        $nexY = max($pdf->GetY(),$nexY);
677
+                    }
678
+
679
+
680
+                    $parameters=array(
681
+                        'object' => $object,
682
+                        'i' => $i,
683
+                        'pdf' =>& $pdf,
684
+                        'curY' =>& $curY,
685
+                        'nexY' =>& $nexY,
686
+                        'outputlangs' => $outputlangs,
687
+                        'hidedetails' => $hidedetails
688
+                    );
689
+                    $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
690
+
691
+
692
+
693
+                    $sign=1;
694
+                    if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
695
+                    // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
696
+                    $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
697
+                    if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
698
+                    {
699
+                        if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
700
+                        else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
701
+                    } else {
702
+                        if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
703
+                        else $tvaligne= $sign * $object->lines[$i]->total_tva;
704
+                    }
705
+
706
+                    $localtax1ligne=$object->lines[$i]->total_localtax1;
707
+                    $localtax2ligne=$object->lines[$i]->total_localtax2;
708
+                    $localtax1_rate=$object->lines[$i]->localtax1_tx;
709
+                    $localtax2_rate=$object->lines[$i]->localtax2_tx;
710
+                    $localtax1_type=$object->lines[$i]->localtax1_type;
711
+                    $localtax2_type=$object->lines[$i]->localtax2_type;
712
+
713
+                    if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
714
+                    if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
715
+                    if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
716
+
717
+                    $vatrate=(string) $object->lines[$i]->tva_tx;
718
+
719
+                    // Retrieve type from database for backward compatibility with old records
720
+                    if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
721
+                        && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
722
+                    {
723
+                        $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
724
+                        $localtax1_type = $localtaxtmp_array[0];
725
+                        $localtax2_type = $localtaxtmp_array[2];
726
+                    }
727
+
728
+                    // retrieve global local tax
729
+                    if ($localtax1_type && $localtax1ligne != 0)
730
+                        $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
731
+                        if ($localtax2_type && $localtax2ligne != 0)
732
+                            $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
733
+
734
+                            if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
735
+                            if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
736
+                            $this->tva[$vatrate] += $tvaligne;
737
+
738
+                            $nexY = max($nexY,$posYAfterImage);
739
+
740
+                            // Add line
741
+                            if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
742
+                            {
743
+                                $pdf->setPage($pageposafter);
744
+                                $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
745
+                                //$pdf->SetDrawColor(190,190,200);
746
+                                $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
747
+                                $pdf->SetLineStyle(array('dash'=>0));
748
+                            }
749
+
750
+                            $nexY+=2;    // Passe espace entre les lignes
751
+
752
+                            // Detect if some page were added automatically and output _tableau for past pages
753
+                            while ($pagenb < $pageposafter)
754
+                            {
755
+                                $pdf->setPage($pagenb);
756
+                                if ($pagenb == $pageposbeforeprintlines)
757
+                                {
758
+                                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
759
+                                }
760
+                                else
761
+                                {
762
+                                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
763
+                                }
764
+                                $this->_pagefoot($pdf,$object,$outputlangs,1);
765
+                                $pagenb++;
766
+                                $pdf->setPage($pagenb);
767
+                                $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
768
+                                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
769
+                            }
770
+
771
+                            if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
772
+                            {
773
+                                if ($pagenb == $pageposafter)
774
+                                {
775
+                                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
776
+                                }
777
+                                else
778
+                                {
779
+                                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
780
+                                }
781
+                                $this->_pagefoot($pdf,$object,$outputlangs,1);
782
+                                // New page
783
+                                $pdf->AddPage();
784
+                                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
785
+                                $pagenb++;
786
+                                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
787
+                            }
788
+                }
789
+
790
+                // Show square
791
+                if ($pagenb == $pageposbeforeprintlines)
792
+                {
793
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
794
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
795
+                }
796
+                else
797
+                {
798
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
799
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
800
+                }
801
+
802
+                // Affiche zone infos
803
+                $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
804
+
805
+                // Affiche zone totaux
806
+                $posy=$this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
807
+
808
+                // Affiche zone versements
809
+                if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
810
+                {
811
+                    $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
812
+                }
813
+
814
+                // Pied de page
815
+                $this->_pagefoot($pdf,$object,$outputlangs);
816
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
817
+
818
+                $pdf->Close();
819
+
820
+                $pdf->Output($file,'F');
821
+
822
+                // Add pdfgeneration hook
823
+                $hookmanager->initHooks(array('pdfgeneration'));
824
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
825
+                global $action;
826
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
827
+
828
+                if (! empty($conf->global->MAIN_UMASK))
829
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
830
+
831
+                    $this->result = array('fullpath'=>$file);
832
+
833
+                    return 1;   // No error
834
+            }
835
+            else
836
+            {
837
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
838
+                return 0;
839
+            }
840
+        }
841
+        else
842
+        {
843
+            $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
844
+            return 0;
845
+        }
846
+    }
847
+
848
+
849
+    /**
850
+     *  Show payments table
851
+     *
852 852
      *  @param	PDF			$pdf           Object PDF
853 853
      *  @param  Object		$object         Object invoice
854 854
      *  @param  int			$posy           Position y in PDF
855 855
      *  @param  Translate	$outputlangs    Object langs for output
856 856
      *  @return int             			<0 if KO, >0 if OK
857
-	 */
858
-	function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
859
-	{
860
-		global $conf;
857
+     */
858
+    function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
859
+    {
860
+        global $conf;
861 861
 
862 862
         $sign=1;
863 863
         if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
864 864
 
865 865
         $tab3_posx = 120;
866
-		$tab3_top = $posy + 8;
867
-		$tab3_width = 80;
868
-		$tab3_height = 4;
869
-		if ($this->page_largeur < 210) // To work with US executive format
870
-		{
871
-			$tab3_posx -= 20;
872
-		}
873
-
874
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
875
-
876
-		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
877
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
878
-
879
-		$pdf->SetFont('','', $default_font_size - 3);
880
-		$pdf->SetXY($tab3_posx, $tab3_top - 4);
881
-		$pdf->MultiCell(60, 3, $title, 0, 'L', 0);
882
-
883
-		$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
884
-
885
-		$pdf->SetFont('','', $default_font_size - 4);
886
-		$pdf->SetXY($tab3_posx, $tab3_top);
887
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
888
-		$pdf->SetXY($tab3_posx+21, $tab3_top);
889
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
890
-		$pdf->SetXY($tab3_posx+40, $tab3_top);
891
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
892
-		$pdf->SetXY($tab3_posx+58, $tab3_top);
893
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
894
-
895
-		$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
896
-
897
-		$y=0;
898
-
899
-		$pdf->SetFont('','', $default_font_size - 4);
900
-
901
-
902
-		// Loop on each deposits and credit notes included
903
-		$sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
904
-		$sql.= " re.description, re.fk_facture_source,";
905
-		$sql.= " f.type, f.datef";
906
-		$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
907
-		$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
908
-		$resql=$this->db->query($sql);
909
-		if ($resql)
910
-		{
911
-			$num = $this->db->num_rows($resql);
912
-			$i=0;
913
-			$invoice=new Facture($this->db);
914
-			while ($i < $num)
915
-			{
916
-				$y+=3;
917
-				$obj = $this->db->fetch_object($resql);
918
-
919
-				if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
920
-				elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
921
-				else $text=$outputlangs->trans("UnknownType");
922
-
923
-				$invoice->fetch($obj->fk_facture_source);
924
-
925
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
926
-				$pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
927
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
928
-				$pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
929
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
930
-				$pdf->MultiCell(20, 3, $text, 0, 'L', 0);
931
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
932
-				$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
933
-
934
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
935
-
936
-				$i++;
937
-			}
938
-		}
939
-		else
940
-		{
941
-			$this->error=$this->db->lasterror();
942
-			return -1;
943
-		}
944
-
945
-		// Loop on each payment
946
-		// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
947
-		$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
948
-		$sql.= " cp.code";
949
-		$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
950
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
951
-		$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
952
-		//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
953
-		$sql.= " ORDER BY p.datep";
954
-
955
-		$resql=$this->db->query($sql);
956
-		if ($resql)
957
-		{
958
-			$num = $this->db->num_rows($resql);
959
-			$i=0;
960
-			while ($i < $num) {
961
-				$y+=3;
962
-				$row = $this->db->fetch_object($resql);
963
-
964
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
965
-				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
966
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
967
-				$pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
968
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
969
-				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
970
-
971
-				$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
972
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
973
-				$pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
974
-
975
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
976
-
977
-				$i++;
978
-			}
979
-		}
980
-		else
981
-		{
982
-			$this->error=$this->db->lasterror();
983
-			return -1;
984
-		}
985
-	}
986
-
987
-
988
-	/**
989
-	 *   Show miscellaneous information (payment mode, payment term, ...)
990
-	 *
991
-	 *   @param		PDF			$pdf     		Object PDF
992
-	 *   @param		Object		$object			Object to show
993
-	 *   @param		int			$posy			Y
994
-	 *   @param		Translate	$outputlangs	Langs object
995
-	 *   @return	void
996
-	 */
997
-	private function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
998
-	{
999
-		global $conf;
1000
-
1001
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1002
-
1003
-		$pdf->SetFont('','', $default_font_size - 1);
1004
-
1005
-		// If France, show VAT mention if not applicable
1006
-		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
1007
-		{
1008
-			$pdf->SetFont('','B', $default_font_size - 2);
1009
-			$pdf->SetXY($this->marge_gauche, $posy);
1010
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1011
-
1012
-			$posy=$pdf->GetY()+4;
1013
-		}
1014
-
1015
-		$posxval=52;
1016
-
1017
-		// Show payments conditions
1018
-		if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
1019
-		{
1020
-			$pdf->SetFont('','B', $default_font_size - 2);
1021
-			$pdf->SetXY($this->marge_gauche, $posy);
1022
-			$titre = $outputlangs->transnoentities("PaymentConditions").':';
1023
-			$pdf->MultiCell(43, 4, $titre, 0, 'L');
1024
-
1025
-			$pdf->SetFont('','', $default_font_size - 2);
1026
-			$pdf->SetXY($posxval, $posy);
1027
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
1028
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
1029
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
1030
-
1031
-			$posy=$pdf->GetY()+3;
1032
-		}
1033
-
1034
-		if ($object->type != 2)
1035
-		{
1036
-			// Check a payment mode is defined
1037
-			if (empty($object->mode_reglement_code)
1038
-			&& empty($conf->global->FACTURE_CHQ_NUMBER)
1039
-			&& empty($conf->global->FACTURE_RIB_NUMBER))
1040
-			{
1041
-				$this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1042
-			}
1043
-			// Avoid having any valid PDF with setup that is not complete
1044
-			elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1045
-				|| ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)))
1046
-			{
1047
-				$outputlangs->load("errors");
1048
-
1049
-				$pdf->SetXY($this->marge_gauche, $posy);
1050
-				$pdf->SetTextColor(200,0,0);
1051
-				$pdf->SetFont('','B', $default_font_size - 2);
1052
-				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
1053
-				$pdf->MultiCell(80, 3, $this->error,0,'L',0);
1054
-				$pdf->SetTextColor(0,0,0);
1055
-
1056
-				$posy=$pdf->GetY()+1;
1057
-			}
1058
-
1059
-			// Show payment mode
1060
-			if ($object->mode_reglement_code
1061
-			&& $object->mode_reglement_code != 'CHQ'
1062
-			&& $object->mode_reglement_code != 'VIR')
1063
-			{
1064
-				$pdf->SetFont('','B', $default_font_size - 2);
1065
-				$pdf->SetXY($this->marge_gauche, $posy);
1066
-				$titre = $outputlangs->transnoentities("PaymentMode").':';
1067
-				$pdf->MultiCell(80, 5, $titre, 0, 'L');
1068
-
1069
-				$pdf->SetFont('','', $default_font_size - 2);
1070
-				$pdf->SetXY($posxval, $posy);
1071
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1072
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1073
-
1074
-				$posy=$pdf->GetY()+2;
1075
-			}
1076
-
1077
-			// Show payment mode CHQ
1078
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1079
-			{
1080
-				// Si mode reglement non force ou si force a CHQ
1081
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1082
-				{
1083
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1084
-
1085
-					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1086
-					{
1087
-						$account = new Account($this->db);
1088
-						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1089
-
1090
-						$pdf->SetXY($this->marge_gauche, $posy);
1091
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1092
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1093
-						$posy=$pdf->GetY()+1;
1094
-
1095
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1096
-			            {
1097
-							$pdf->SetXY($this->marge_gauche, $posy);
1098
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1099
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1100
-							$posy=$pdf->GetY()+2;
1101
-			            }
1102
-					}
1103
-					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1104
-					{
1105
-						$pdf->SetXY($this->marge_gauche, $posy);
1106
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1107
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1108
-						$posy=$pdf->GetY()+1;
1109
-
1110
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1111
-			            {
1112
-							$pdf->SetXY($this->marge_gauche, $posy);
1113
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1114
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1115
-							$posy=$pdf->GetY()+2;
1116
-			            }
1117
-					}
1118
-				}
1119
-			}
1120
-
1121
-			// If payment mode not forced or forced to VIR, show payment with BAN
1122
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1123
-			{
1124
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1125
-				{
1126
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1127
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1128
-					$account = new Account($this->db);
1129
-					$account->fetch($bankid);
1130
-
1131
-					$curx=$this->marge_gauche;
1132
-					$cury=$posy;
1133
-
1134
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1135
-
1136
-					$posy+=2;
1137
-				}
1138
-			}
1139
-		}
1140
-
1141
-		return $posy;
1142
-	}
1143
-
1144
-
1145
-	/**
1146
-	 *	Show total to pay
1147
-	 *
1148
-	 *	@param	PDF			$pdf           Object PDF
1149
-	 *	@param  Facture		$object         Object invoice
1150
-	 *	@param  int			$deja_regle     Montant deja regle
1151
-	 *	@param	int			$posy			Position depart
1152
-	 *	@param	Translate	$outputlangs	Objet langs
1153
-	 *	@return int							Position pour suite
1154
-	 */
1155
-	private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1156
-	{
1157
-		global $conf,$mysoc;
866
+        $tab3_top = $posy + 8;
867
+        $tab3_width = 80;
868
+        $tab3_height = 4;
869
+        if ($this->page_largeur < 210) // To work with US executive format
870
+        {
871
+            $tab3_posx -= 20;
872
+        }
873
+
874
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
875
+
876
+        $title=$outputlangs->transnoentities("PaymentsAlreadyDone");
877
+        if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
878
+
879
+        $pdf->SetFont('','', $default_font_size - 3);
880
+        $pdf->SetXY($tab3_posx, $tab3_top - 4);
881
+        $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
882
+
883
+        $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
884
+
885
+        $pdf->SetFont('','', $default_font_size - 4);
886
+        $pdf->SetXY($tab3_posx, $tab3_top);
887
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
888
+        $pdf->SetXY($tab3_posx+21, $tab3_top);
889
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
890
+        $pdf->SetXY($tab3_posx+40, $tab3_top);
891
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
892
+        $pdf->SetXY($tab3_posx+58, $tab3_top);
893
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
894
+
895
+        $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
896
+
897
+        $y=0;
898
+
899
+        $pdf->SetFont('','', $default_font_size - 4);
900
+
901
+
902
+        // Loop on each deposits and credit notes included
903
+        $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
904
+        $sql.= " re.description, re.fk_facture_source,";
905
+        $sql.= " f.type, f.datef";
906
+        $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
907
+        $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
908
+        $resql=$this->db->query($sql);
909
+        if ($resql)
910
+        {
911
+            $num = $this->db->num_rows($resql);
912
+            $i=0;
913
+            $invoice=new Facture($this->db);
914
+            while ($i < $num)
915
+            {
916
+                $y+=3;
917
+                $obj = $this->db->fetch_object($resql);
918
+
919
+                if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
920
+                elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
921
+                else $text=$outputlangs->trans("UnknownType");
922
+
923
+                $invoice->fetch($obj->fk_facture_source);
924
+
925
+                $pdf->SetXY($tab3_posx, $tab3_top+$y);
926
+                $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
927
+                $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
928
+                $pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
929
+                $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
930
+                $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
931
+                $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
932
+                $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
933
+
934
+                $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
935
+
936
+                $i++;
937
+            }
938
+        }
939
+        else
940
+        {
941
+            $this->error=$this->db->lasterror();
942
+            return -1;
943
+        }
944
+
945
+        // Loop on each payment
946
+        // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
947
+        $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
948
+        $sql.= " cp.code";
949
+        $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
950
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
951
+        $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
952
+        //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
953
+        $sql.= " ORDER BY p.datep";
954
+
955
+        $resql=$this->db->query($sql);
956
+        if ($resql)
957
+        {
958
+            $num = $this->db->num_rows($resql);
959
+            $i=0;
960
+            while ($i < $num) {
961
+                $y+=3;
962
+                $row = $this->db->fetch_object($resql);
963
+
964
+                $pdf->SetXY($tab3_posx, $tab3_top+$y);
965
+                $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
966
+                $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
967
+                $pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
968
+                $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
969
+                $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
970
+
971
+                $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
972
+                $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
973
+                $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
974
+
975
+                $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
976
+
977
+                $i++;
978
+            }
979
+        }
980
+        else
981
+        {
982
+            $this->error=$this->db->lasterror();
983
+            return -1;
984
+        }
985
+    }
986
+
987
+
988
+    /**
989
+     *   Show miscellaneous information (payment mode, payment term, ...)
990
+     *
991
+     *   @param		PDF			$pdf     		Object PDF
992
+     *   @param		Object		$object			Object to show
993
+     *   @param		int			$posy			Y
994
+     *   @param		Translate	$outputlangs	Langs object
995
+     *   @return	void
996
+     */
997
+    private function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
998
+    {
999
+        global $conf;
1000
+
1001
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1002
+
1003
+        $pdf->SetFont('','', $default_font_size - 1);
1004
+
1005
+        // If France, show VAT mention if not applicable
1006
+        if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
1007
+        {
1008
+            $pdf->SetFont('','B', $default_font_size - 2);
1009
+            $pdf->SetXY($this->marge_gauche, $posy);
1010
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1011
+
1012
+            $posy=$pdf->GetY()+4;
1013
+        }
1014
+
1015
+        $posxval=52;
1016
+
1017
+        // Show payments conditions
1018
+        if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
1019
+        {
1020
+            $pdf->SetFont('','B', $default_font_size - 2);
1021
+            $pdf->SetXY($this->marge_gauche, $posy);
1022
+            $titre = $outputlangs->transnoentities("PaymentConditions").':';
1023
+            $pdf->MultiCell(43, 4, $titre, 0, 'L');
1024
+
1025
+            $pdf->SetFont('','', $default_font_size - 2);
1026
+            $pdf->SetXY($posxval, $posy);
1027
+            $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
1028
+            $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
1029
+            $pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
1030
+
1031
+            $posy=$pdf->GetY()+3;
1032
+        }
1033
+
1034
+        if ($object->type != 2)
1035
+        {
1036
+            // Check a payment mode is defined
1037
+            if (empty($object->mode_reglement_code)
1038
+            && empty($conf->global->FACTURE_CHQ_NUMBER)
1039
+            && empty($conf->global->FACTURE_RIB_NUMBER))
1040
+            {
1041
+                $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1042
+            }
1043
+            // Avoid having any valid PDF with setup that is not complete
1044
+            elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1045
+                || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)))
1046
+            {
1047
+                $outputlangs->load("errors");
1048
+
1049
+                $pdf->SetXY($this->marge_gauche, $posy);
1050
+                $pdf->SetTextColor(200,0,0);
1051
+                $pdf->SetFont('','B', $default_font_size - 2);
1052
+                $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
1053
+                $pdf->MultiCell(80, 3, $this->error,0,'L',0);
1054
+                $pdf->SetTextColor(0,0,0);
1055
+
1056
+                $posy=$pdf->GetY()+1;
1057
+            }
1058
+
1059
+            // Show payment mode
1060
+            if ($object->mode_reglement_code
1061
+            && $object->mode_reglement_code != 'CHQ'
1062
+            && $object->mode_reglement_code != 'VIR')
1063
+            {
1064
+                $pdf->SetFont('','B', $default_font_size - 2);
1065
+                $pdf->SetXY($this->marge_gauche, $posy);
1066
+                $titre = $outputlangs->transnoentities("PaymentMode").':';
1067
+                $pdf->MultiCell(80, 5, $titre, 0, 'L');
1068
+
1069
+                $pdf->SetFont('','', $default_font_size - 2);
1070
+                $pdf->SetXY($posxval, $posy);
1071
+                $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1072
+                $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1073
+
1074
+                $posy=$pdf->GetY()+2;
1075
+            }
1076
+
1077
+            // Show payment mode CHQ
1078
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1079
+            {
1080
+                // Si mode reglement non force ou si force a CHQ
1081
+                if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1082
+                {
1083
+                    $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1084
+
1085
+                    if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1086
+                    {
1087
+                        $account = new Account($this->db);
1088
+                        $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1089
+
1090
+                        $pdf->SetXY($this->marge_gauche, $posy);
1091
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1092
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1093
+                        $posy=$pdf->GetY()+1;
1094
+
1095
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1096
+                        {
1097
+                            $pdf->SetXY($this->marge_gauche, $posy);
1098
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1099
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1100
+                            $posy=$pdf->GetY()+2;
1101
+                        }
1102
+                    }
1103
+                    if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1104
+                    {
1105
+                        $pdf->SetXY($this->marge_gauche, $posy);
1106
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1107
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1108
+                        $posy=$pdf->GetY()+1;
1109
+
1110
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1111
+                        {
1112
+                            $pdf->SetXY($this->marge_gauche, $posy);
1113
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1114
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1115
+                            $posy=$pdf->GetY()+2;
1116
+                        }
1117
+                    }
1118
+                }
1119
+            }
1120
+
1121
+            // If payment mode not forced or forced to VIR, show payment with BAN
1122
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1123
+            {
1124
+                if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1125
+                {
1126
+                    $bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1127
+                    if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1128
+                    $account = new Account($this->db);
1129
+                    $account->fetch($bankid);
1130
+
1131
+                    $curx=$this->marge_gauche;
1132
+                    $cury=$posy;
1133
+
1134
+                    $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1135
+
1136
+                    $posy+=2;
1137
+                }
1138
+            }
1139
+        }
1140
+
1141
+        return $posy;
1142
+    }
1143
+
1144
+
1145
+    /**
1146
+     *	Show total to pay
1147
+     *
1148
+     *	@param	PDF			$pdf           Object PDF
1149
+     *	@param  Facture		$object         Object invoice
1150
+     *	@param  int			$deja_regle     Montant deja regle
1151
+     *	@param	int			$posy			Position depart
1152
+     *	@param	Translate	$outputlangs	Objet langs
1153
+     *	@return int							Position pour suite
1154
+     */
1155
+    private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1156
+    {
1157
+        global $conf,$mysoc;
1158 1158
 
1159 1159
         $sign=1;
1160 1160
         if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1161 1161
 
1162 1162
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1163 1163
 
1164
-		$tab2_top = $posy;
1165
-		$tab2_hl = 4;
1166
-		$pdf->SetFont('','', $default_font_size - 1);
1167
-
1168
-		// Tableau total
1169
-		$col1x = 120; $col2x = 170;
1170
-		if ($this->page_largeur < 210) // To work with US executive format
1171
-		{
1172
-			$col2x-=20;
1173
-		}
1174
-		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1175
-
1176
-		$useborder=0;
1177
-		$index = 0;
1178
-
1179
-		// Total HT
1180
-		$pdf->SetFillColor(255,255,255);
1181
-		$pdf->SetXY($col1x, $tab2_top + 0);
1182
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1183
-
1184
-		$total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1185
-		$pdf->SetXY($col2x, $tab2_top + 0);
1186
-		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1187
-
1188
-		// Show VAT by rates and total
1189
-		$pdf->SetFillColor(248,248,248);
1190
-
1191
-		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1192
-
1193
-		$this->atleastoneratenotnull=0;
1194
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1195
-		{
1196
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1197
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1198
-			{
1199
-				// Nothing to do
1200
-			}
1201
-			else
1202
-			{
1203
-			    // FIXME amount of vat not supported with multicurrency
1204
-
1205
-				//Local tax 1 before VAT
1206
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1207
-				//{
1208
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1209
-					{
1210
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1211
-
1212
-						foreach( $localtax_rate as $tvakey => $tvaval )
1213
-						{
1214
-							if ($tvakey!=0)    // On affiche pas taux 0
1215
-							{
1216
-								//$this->atleastoneratenotnull++;
1217
-
1218
-								$index++;
1219
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1220
-
1221
-								$tvacompl='';
1222
-								if (preg_match('/\*/',$tvakey))
1223
-								{
1224
-									$tvakey=str_replace('*','',$tvakey);
1225
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1226
-								}
1227
-
1228
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1229
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1230
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1231
-
1232
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1233
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1234
-							}
1235
-						}
1236
-					}
1237
-	      		//}
1238
-				//Local tax 2 before VAT
1239
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1240
-				//{
1241
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1242
-					{
1243
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1244
-
1245
-						foreach( $localtax_rate as $tvakey => $tvaval )
1246
-						{
1247
-							if ($tvakey!=0)    // On affiche pas taux 0
1248
-							{
1249
-								//$this->atleastoneratenotnull++;
1250
-
1251
-
1252
-
1253
-								$index++;
1254
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1255
-
1256
-								$tvacompl='';
1257
-								if (preg_match('/\*/',$tvakey))
1258
-								{
1259
-									$tvakey=str_replace('*','',$tvakey);
1260
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1261
-								}
1262
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1263
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1264
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1265
-
1266
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1267
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1268
-							}
1269
-						}
1270
-					}
1164
+        $tab2_top = $posy;
1165
+        $tab2_hl = 4;
1166
+        $pdf->SetFont('','', $default_font_size - 1);
1167
+
1168
+        // Tableau total
1169
+        $col1x = 120; $col2x = 170;
1170
+        if ($this->page_largeur < 210) // To work with US executive format
1171
+        {
1172
+            $col2x-=20;
1173
+        }
1174
+        $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1175
+
1176
+        $useborder=0;
1177
+        $index = 0;
1178
+
1179
+        // Total HT
1180
+        $pdf->SetFillColor(255,255,255);
1181
+        $pdf->SetXY($col1x, $tab2_top + 0);
1182
+        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1183
+
1184
+        $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1185
+        $pdf->SetXY($col2x, $tab2_top + 0);
1186
+        $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1187
+
1188
+        // Show VAT by rates and total
1189
+        $pdf->SetFillColor(248,248,248);
1190
+
1191
+        $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1192
+
1193
+        $this->atleastoneratenotnull=0;
1194
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1195
+        {
1196
+            $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1197
+            if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1198
+            {
1199
+                // Nothing to do
1200
+            }
1201
+            else
1202
+            {
1203
+                // FIXME amount of vat not supported with multicurrency
1204
+
1205
+                //Local tax 1 before VAT
1206
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1207
+                //{
1208
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1209
+                    {
1210
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1211
+
1212
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1213
+                        {
1214
+                            if ($tvakey!=0)    // On affiche pas taux 0
1215
+                            {
1216
+                                //$this->atleastoneratenotnull++;
1217
+
1218
+                                $index++;
1219
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1220
+
1221
+                                $tvacompl='';
1222
+                                if (preg_match('/\*/',$tvakey))
1223
+                                {
1224
+                                    $tvakey=str_replace('*','',$tvakey);
1225
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1226
+                                }
1227
+
1228
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1229
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1230
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1231
+
1232
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1233
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1234
+                            }
1235
+                        }
1236
+                    }
1237
+                    //}
1238
+                //Local tax 2 before VAT
1239
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1240
+                //{
1241
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1242
+                    {
1243
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1244
+
1245
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1246
+                        {
1247
+                            if ($tvakey!=0)    // On affiche pas taux 0
1248
+                            {
1249
+                                //$this->atleastoneratenotnull++;
1250
+
1251
+
1252
+
1253
+                                $index++;
1254
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1255
+
1256
+                                $tvacompl='';
1257
+                                if (preg_match('/\*/',$tvakey))
1258
+                                {
1259
+                                    $tvakey=str_replace('*','',$tvakey);
1260
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1261
+                                }
1262
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1263
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1264
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1265
+
1266
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1267
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1268
+                            }
1269
+                        }
1270
+                    }
1271 1271
 
1272 1272
                 //}
1273 1273
 
1274
-				// VAT
1275
-				// Situations totals migth be wrong on huge amounts
1276
-				if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1277
-
1278
-					$sum_pdf_tva = 0;
1279
-					foreach($this->tva as $tvakey => $tvaval){
1280
-						$sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1281
-					}
1282
-
1283
-					if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1284
-						$coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1285
-
1286
-						foreach($this->tva as $tvakey => $tvaval) {
1287
-							$this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1288
-						}
1289
-					}
1290
-				}
1291
-
1292
-				foreach($this->tva as $tvakey => $tvaval)
1293
-				{
1294
-					if ($tvakey != 0)    // On affiche pas taux 0
1295
-					{
1296
-						$this->atleastoneratenotnull++;
1297
-
1298
-						$index++;
1299
-						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1300
-
1301
-						$tvacompl='';
1302
-						if (preg_match('/\*/',$tvakey))
1303
-						{
1304
-							$tvakey=str_replace('*','',$tvakey);
1305
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1306
-						}
1307
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1308
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1309
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1310
-
1311
-						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1312
-						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1313
-					}
1314
-				}
1315
-
1316
-				//Local tax 1 after VAT
1317
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1318
-				//{
1319
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1320
-					{
1321
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1322
-
1323
-						foreach( $localtax_rate as $tvakey => $tvaval )
1324
-						{
1325
-							if ($tvakey != 0)    // On affiche pas taux 0
1326
-							{
1327
-								//$this->atleastoneratenotnull++;
1328
-
1329
-								$index++;
1330
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1331
-
1332
-								$tvacompl='';
1333
-								if (preg_match('/\*/',$tvakey))
1334
-								{
1335
-									$tvakey=str_replace('*','',$tvakey);
1336
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1337
-								}
1338
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1339
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1340
-
1341
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1342
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1343
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1344
-							}
1345
-						}
1346
-					}
1347
-	      		//}
1348
-				//Local tax 2 after VAT
1349
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1350
-				//{
1351
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1352
-					{
1353
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1354
-
1355
-						foreach( $localtax_rate as $tvakey => $tvaval )
1356
-						{
1357
-						    // retrieve global local tax
1358
-							if ($tvakey != 0)    // On affiche pas taux 0
1359
-							{
1360
-								//$this->atleastoneratenotnull++;
1361
-
1362
-								$index++;
1363
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1364
-
1365
-								$tvacompl='';
1366
-								if (preg_match('/\*/',$tvakey))
1367
-								{
1368
-									$tvakey=str_replace('*','',$tvakey);
1369
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1370
-								}
1371
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1372
-
1373
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1374
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1375
-
1376
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1377
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1378
-							}
1379
-						}
1380
-					//}
1381
-				}
1382
-
1383
-				// Revenue stamp
1384
-				if (price2num($object->revenuestamp) != 0)
1385
-				{
1386
-					$index++;
1387
-					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1388
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1389
-
1390
-					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391
-					$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1392
-				}
1393
-
1394
-				// Total TTC
1395
-				$index++;
1396
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1397
-				$pdf->SetTextColor(0,0,60);
1398
-				$pdf->SetFillColor(224,224,224);
1399
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1400
-
1401
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1402
-				$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1403
-			}
1404
-		}
1405
-
1406
-		$pdf->SetTextColor(0,0,0);
1407
-
1408
-		$creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1409
-		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1410
-		//print "x".$creditnoteamount."-".$depositsamount;exit;
1411
-		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1412
-		if ($object->paye) $resteapayer=0;
1413
-
1414
-		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1415
-		{
1416
-			// Already paid + Deposits
1417
-			$index++;
1418
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1419
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1420
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1421
-			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1422
-
1423
-			// Credit note
1424
-			if ($creditnoteamount)
1425
-			{
1426
-				$index++;
1427
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1428
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
1429
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1430
-				$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1431
-			}
1432
-
1433
-			// Escompte
1434
-			if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1435
-			{
1436
-				$index++;
1437
-				$pdf->SetFillColor(255,255,255);
1438
-
1439
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1440
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1441
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1442
-				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1443
-
1444
-				$resteapayer=0;
1445
-			}
1446
-
1447
-			$index++;
1448
-			$pdf->SetTextColor(0,0,60);
1449
-			$pdf->SetFillColor(224,224,224);
1450
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1451
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1452
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1453
-			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1454
-
1455
-			$pdf->SetFont('','', $default_font_size - 1);
1456
-			$pdf->SetTextColor(0,0,0);
1457
-		}
1458
-
1459
-		$index++;
1460
-		return ($tab2_top + ($tab2_hl * $index));
1461
-	}
1462
-
1463
-	/**
1464
-	 *   Show table for lines
1465
-	 *
1466
-	 *   @param		PDF			$pdf     		Object PDF
1467
-	 *   @param		string		$tab_top		Top position of table
1468
-	 *   @param		string		$tab_height		Height of table (rectangle)
1469
-	 *   @param		int			$nexY			Y (not used)
1470
-	 *   @param		Translate	$outputlangs	Langs object
1471
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1472
-	 *   @param		int			$hidebottom		Hide bottom bar of array
1473
-	 *   @param		string		$currency		Currency code
1474
-	 *   @return	void
1475
-	 */
1476
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1477
-	{
1478
-		global $conf;
1479
-
1480
-		// Force to disable hidetop and hidebottom
1481
-		$hidebottom=0;
1482
-		if ($hidetop) $hidetop=-1;
1483
-
1484
-		$currency = !empty($currency) ? $currency : $conf->currency;
1485
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1486
-
1487
-		// Amount in (at tab_top - 1)
1488
-		$pdf->SetTextColor(0,0,0);
1489
-		$pdf->SetFont('','', $default_font_size - 2);
1490
-
1491
-		if (empty($hidetop))
1492
-		{
1493
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1494
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1495
-			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1496
-
1497
-			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1498
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1499
-		}
1500
-
1501
-		$pdf->SetDrawColor(128,128,128);
1502
-		$pdf->SetFont('','', $default_font_size - 1);
1503
-
1504
-		// Output Rect
1505
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1506
-
1507
-
1508
-		foreach ($this->cols as $colKey => $colDef)
1509
-		{
1510
-		    if(!$this->getColumnStatus($colKey)) continue;
1511
-
1512
-		    // get title label
1513
-		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1514
-
1515
-		    // Add column separator
1516
-		    if(!empty($colDef['border-left'])){
1517
-		        $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1518
-		    }
1519
-
1520
-		    if (empty($hidetop))
1521
-		    {
1522
-		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1523
-
1524
-		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1525
-		      $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1526
-		    }
1527
-		}
1528
-
1529
-		if (empty($hidetop)){
1530
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1531
-		}
1532
-	}
1533
-
1534
-	/**
1535
-	 *  Show top header of page.
1536
-	 *
1537
-	 *  @param	PDF			$pdf     		Object PDF
1538
-	 *  @param  Object		$object     	Object to show
1539
-	 *  @param  int	    	$showaddress    0=no, 1=yes
1540
-	 *  @param  Translate	$outputlangs	Object lang for output
1541
-	 *  @return	void
1542
-	 */
1543
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1544
-	{
1545
-		global $conf, $langs;
1546
-
1547
-		// Translations
1548
-		$outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1549
-
1550
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1551
-
1552
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1553
-
1554
-		// Show Draft Watermark
1555
-		if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1274
+                // VAT
1275
+                // Situations totals migth be wrong on huge amounts
1276
+                if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1277
+
1278
+                    $sum_pdf_tva = 0;
1279
+                    foreach($this->tva as $tvakey => $tvaval){
1280
+                        $sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1281
+                    }
1282
+
1283
+                    if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1284
+                        $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1285
+
1286
+                        foreach($this->tva as $tvakey => $tvaval) {
1287
+                            $this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1288
+                        }
1289
+                    }
1290
+                }
1291
+
1292
+                foreach($this->tva as $tvakey => $tvaval)
1293
+                {
1294
+                    if ($tvakey != 0)    // On affiche pas taux 0
1295
+                    {
1296
+                        $this->atleastoneratenotnull++;
1297
+
1298
+                        $index++;
1299
+                        $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1300
+
1301
+                        $tvacompl='';
1302
+                        if (preg_match('/\*/',$tvakey))
1303
+                        {
1304
+                            $tvakey=str_replace('*','',$tvakey);
1305
+                            $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1306
+                        }
1307
+                        $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1308
+                        $totalvat.=vatrate($tvakey,1).$tvacompl;
1309
+                        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1310
+
1311
+                        $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1312
+                        $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1313
+                    }
1314
+                }
1315
+
1316
+                //Local tax 1 after VAT
1317
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1318
+                //{
1319
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1320
+                    {
1321
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1322
+
1323
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1324
+                        {
1325
+                            if ($tvakey != 0)    // On affiche pas taux 0
1326
+                            {
1327
+                                //$this->atleastoneratenotnull++;
1328
+
1329
+                                $index++;
1330
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1331
+
1332
+                                $tvacompl='';
1333
+                                if (preg_match('/\*/',$tvakey))
1334
+                                {
1335
+                                    $tvakey=str_replace('*','',$tvakey);
1336
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1337
+                                }
1338
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1339
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1340
+
1341
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1342
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1343
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1344
+                            }
1345
+                        }
1346
+                    }
1347
+                    //}
1348
+                //Local tax 2 after VAT
1349
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1350
+                //{
1351
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1352
+                    {
1353
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1354
+
1355
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1356
+                        {
1357
+                            // retrieve global local tax
1358
+                            if ($tvakey != 0)    // On affiche pas taux 0
1359
+                            {
1360
+                                //$this->atleastoneratenotnull++;
1361
+
1362
+                                $index++;
1363
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1364
+
1365
+                                $tvacompl='';
1366
+                                if (preg_match('/\*/',$tvakey))
1367
+                                {
1368
+                                    $tvakey=str_replace('*','',$tvakey);
1369
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1370
+                                }
1371
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1372
+
1373
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1374
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1375
+
1376
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1377
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1378
+                            }
1379
+                        }
1380
+                    //}
1381
+                }
1382
+
1383
+                // Revenue stamp
1384
+                if (price2num($object->revenuestamp) != 0)
1385
+                {
1386
+                    $index++;
1387
+                    $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1388
+                    $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1389
+
1390
+                    $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391
+                    $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1392
+                }
1393
+
1394
+                // Total TTC
1395
+                $index++;
1396
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1397
+                $pdf->SetTextColor(0,0,60);
1398
+                $pdf->SetFillColor(224,224,224);
1399
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1400
+
1401
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1402
+                $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1403
+            }
1404
+        }
1405
+
1406
+        $pdf->SetTextColor(0,0,0);
1407
+
1408
+        $creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1409
+        $depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1410
+        //print "x".$creditnoteamount."-".$depositsamount;exit;
1411
+        $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1412
+        if ($object->paye) $resteapayer=0;
1413
+
1414
+        if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1556 1415
         {
1557
-		      pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1416
+            // Already paid + Deposits
1417
+            $index++;
1418
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1419
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1420
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1421
+            $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1422
+
1423
+            // Credit note
1424
+            if ($creditnoteamount)
1425
+            {
1426
+                $index++;
1427
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1428
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
1429
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1430
+                $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1431
+            }
1432
+
1433
+            // Escompte
1434
+            if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1435
+            {
1436
+                $index++;
1437
+                $pdf->SetFillColor(255,255,255);
1438
+
1439
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1440
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1441
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1442
+                $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1443
+
1444
+                $resteapayer=0;
1445
+            }
1446
+
1447
+            $index++;
1448
+            $pdf->SetTextColor(0,0,60);
1449
+            $pdf->SetFillColor(224,224,224);
1450
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1451
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1452
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1453
+            $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1454
+
1455
+            $pdf->SetFont('','', $default_font_size - 1);
1456
+            $pdf->SetTextColor(0,0,0);
1558 1457
         }
1559 1458
 
1560
-		$pdf->SetTextColor(0,0,60);
1561
-		$pdf->SetFont('','B', $default_font_size + 3);
1459
+        $index++;
1460
+        return ($tab2_top + ($tab2_hl * $index));
1461
+    }
1462
+
1463
+    /**
1464
+     *   Show table for lines
1465
+     *
1466
+     *   @param		PDF			$pdf     		Object PDF
1467
+     *   @param		string		$tab_top		Top position of table
1468
+     *   @param		string		$tab_height		Height of table (rectangle)
1469
+     *   @param		int			$nexY			Y (not used)
1470
+     *   @param		Translate	$outputlangs	Langs object
1471
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1472
+     *   @param		int			$hidebottom		Hide bottom bar of array
1473
+     *   @param		string		$currency		Currency code
1474
+     *   @return	void
1475
+     */
1476
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1477
+    {
1478
+        global $conf;
1562 1479
 
1563
-		$w = 110;
1480
+        // Force to disable hidetop and hidebottom
1481
+        $hidebottom=0;
1482
+        if ($hidetop) $hidetop=-1;
1564 1483
 
1565
-		$posy=$this->marge_haute;
1484
+        $currency = !empty($currency) ? $currency : $conf->currency;
1485
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1486
+
1487
+        // Amount in (at tab_top - 1)
1488
+        $pdf->SetTextColor(0,0,0);
1489
+        $pdf->SetFont('','', $default_font_size - 2);
1490
+
1491
+        if (empty($hidetop))
1492
+        {
1493
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1494
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1495
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1496
+
1497
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1498
+            if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1499
+        }
1500
+
1501
+        $pdf->SetDrawColor(128,128,128);
1502
+        $pdf->SetFont('','', $default_font_size - 1);
1503
+
1504
+        // Output Rect
1505
+        $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1506
+
1507
+
1508
+        foreach ($this->cols as $colKey => $colDef)
1509
+        {
1510
+            if(!$this->getColumnStatus($colKey)) continue;
1511
+
1512
+            // get title label
1513
+            $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1514
+
1515
+            // Add column separator
1516
+            if(!empty($colDef['border-left'])){
1517
+                $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1518
+            }
1519
+
1520
+            if (empty($hidetop))
1521
+            {
1522
+                $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1523
+
1524
+                $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1525
+                $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1526
+            }
1527
+        }
1528
+
1529
+        if (empty($hidetop)){
1530
+            $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1531
+        }
1532
+    }
1533
+
1534
+    /**
1535
+     *  Show top header of page.
1536
+     *
1537
+     *  @param	PDF			$pdf     		Object PDF
1538
+     *  @param  Object		$object     	Object to show
1539
+     *  @param  int	    	$showaddress    0=no, 1=yes
1540
+     *  @param  Translate	$outputlangs	Object lang for output
1541
+     *  @return	void
1542
+     */
1543
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1544
+    {
1545
+        global $conf, $langs;
1546
+
1547
+        // Translations
1548
+        $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1549
+
1550
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1551
+
1552
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1553
+
1554
+        // Show Draft Watermark
1555
+        if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1556
+        {
1557
+                pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1558
+        }
1559
+
1560
+        $pdf->SetTextColor(0,0,60);
1561
+        $pdf->SetFont('','B', $default_font_size + 3);
1562
+
1563
+        $w = 110;
1564
+
1565
+        $posy=$this->marge_haute;
1566 1566
         $posx=$this->page_largeur-$this->marge_droite-$w;
1567 1567
 
1568
-		$pdf->SetXY($this->marge_gauche,$posy);
1569
-
1570
-		// Logo
1571
-		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1572
-		{
1573
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1574
-			if ($this->emetteur->logo)
1575
-			{
1576
-				if (is_readable($logo))
1577
-				{
1578
-				    $height=pdf_getHeightForLogo($logo);
1579
-					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1580
-				}
1581
-				else
1582
-				{
1583
-					$pdf->SetTextColor(200,0,0);
1584
-					$pdf->SetFont('','B',$default_font_size - 2);
1585
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1586
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1587
-				}
1588
-			}
1589
-			else
1590
-			{
1591
-				$text=$this->emetteur->name;
1592
-				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1593
-			}
1594
-		}
1595
-
1596
-		$pdf->SetFont('','B', $default_font_size + 3);
1597
-		$pdf->SetXY($posx,$posy);
1598
-		$pdf->SetTextColor(0,0,60);
1599
-		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1600
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1601
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1602
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1603
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1604
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1605
-		$pdf->MultiCell($w, 3, $title, '', 'R');
1606
-
1607
-		$pdf->SetFont('','B',$default_font_size);
1608
-
1609
-		$posy+=5;
1610
-		$pdf->SetXY($posx,$posy);
1611
-		$pdf->SetTextColor(0,0,60);
1612
-		$textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1613
-		if ($object->statut == Facture::STATUS_DRAFT)
1614
-		{
1615
-			$pdf->SetTextColor(128,0,0);
1616
-			$textref.=' - '.$outputlangs->transnoentities("NotValidated");
1617
-		}
1618
-		$pdf->MultiCell($w, 4, $textref, '', 'R');
1619
-
1620
-		$posy+=1;
1621
-		$pdf->SetFont('','', $default_font_size - 2);
1622
-
1623
-		if ($object->ref_client)
1624
-		{
1625
-			$posy+=4;
1626
-			$pdf->SetXY($posx,$posy);
1627
-			$pdf->SetTextColor(0,0,60);
1628
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1629
-		}
1630
-
1631
-		$objectidnext=$object->getIdReplacingInvoice('validated');
1632
-		if ($object->type == 0 && $objectidnext)
1633
-		{
1634
-			$objectreplacing=new Facture($this->db);
1635
-			$objectreplacing->fetch($objectidnext);
1636
-
1637
-			$posy+=3;
1638
-			$pdf->SetXY($posx,$posy);
1639
-			$pdf->SetTextColor(0,0,60);
1640
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1641
-		}
1642
-		if ($object->type == 1)
1643
-		{
1644
-			$objectreplaced=new Facture($this->db);
1645
-			$objectreplaced->fetch($object->fk_facture_source);
1646
-
1647
-			$posy+=4;
1648
-			$pdf->SetXY($posx,$posy);
1649
-			$pdf->SetTextColor(0,0,60);
1650
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1651
-		}
1652
-		if ($object->type == 2 && !empty($object->fk_facture_source))
1653
-		{
1654
-			$objectreplaced=new Facture($this->db);
1655
-			$objectreplaced->fetch($object->fk_facture_source);
1656
-
1657
-			$posy+=3;
1658
-			$pdf->SetXY($posx,$posy);
1659
-			$pdf->SetTextColor(0,0,60);
1660
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1661
-		}
1662
-
1663
-		$posy+=4;
1664
-		$pdf->SetXY($posx,$posy);
1665
-		$pdf->SetTextColor(0,0,60);
1666
-		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1667
-
1668
-		if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1669
-		{
1670
-			$posy+=4;
1671
-			$pdf->SetXY($posx,$posy);
1672
-			$pdf->SetTextColor(0,0,60);
1673
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1674
-		}
1675
-
1676
-		if ($object->type != 2)
1677
-		{
1678
-			$posy+=3;
1679
-			$pdf->SetXY($posx,$posy);
1680
-			$pdf->SetTextColor(0,0,60);
1681
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1682
-		}
1683
-
1684
-		if ($object->thirdparty->code_client)
1685
-		{
1686
-			$posy+=3;
1687
-			$pdf->SetXY($posx,$posy);
1688
-			$pdf->SetTextColor(0,0,60);
1689
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1690
-		}
1691
-
1692
-		// Get contact
1693
-		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1694
-		{
1695
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1696
-		    if (count($arrayidcontact) > 0)
1697
-		    {
1698
-		        $usertmp=new User($this->db);
1699
-		        $usertmp->fetch($arrayidcontact[0]);
1568
+        $pdf->SetXY($this->marge_gauche,$posy);
1569
+
1570
+        // Logo
1571
+        if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1572
+        {
1573
+            $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1574
+            if ($this->emetteur->logo)
1575
+            {
1576
+                if (is_readable($logo))
1577
+                {
1578
+                    $height=pdf_getHeightForLogo($logo);
1579
+                    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1580
+                }
1581
+                else
1582
+                {
1583
+                    $pdf->SetTextColor(200,0,0);
1584
+                    $pdf->SetFont('','B',$default_font_size - 2);
1585
+                    $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1586
+                    $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1587
+                }
1588
+            }
1589
+            else
1590
+            {
1591
+                $text=$this->emetteur->name;
1592
+                $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1593
+            }
1594
+        }
1595
+
1596
+        $pdf->SetFont('','B', $default_font_size + 3);
1597
+        $pdf->SetXY($posx,$posy);
1598
+        $pdf->SetTextColor(0,0,60);
1599
+        $title=$outputlangs->transnoentities("PdfInvoiceTitle");
1600
+        if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1601
+        if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1602
+        if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1603
+        if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1604
+        if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1605
+        $pdf->MultiCell($w, 3, $title, '', 'R');
1606
+
1607
+        $pdf->SetFont('','B',$default_font_size);
1608
+
1609
+        $posy+=5;
1610
+        $pdf->SetXY($posx,$posy);
1611
+        $pdf->SetTextColor(0,0,60);
1612
+        $textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1613
+        if ($object->statut == Facture::STATUS_DRAFT)
1614
+        {
1615
+            $pdf->SetTextColor(128,0,0);
1616
+            $textref.=' - '.$outputlangs->transnoentities("NotValidated");
1617
+        }
1618
+        $pdf->MultiCell($w, 4, $textref, '', 'R');
1619
+
1620
+        $posy+=1;
1621
+        $pdf->SetFont('','', $default_font_size - 2);
1622
+
1623
+        if ($object->ref_client)
1624
+        {
1625
+            $posy+=4;
1626
+            $pdf->SetXY($posx,$posy);
1627
+            $pdf->SetTextColor(0,0,60);
1628
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1629
+        }
1630
+
1631
+        $objectidnext=$object->getIdReplacingInvoice('validated');
1632
+        if ($object->type == 0 && $objectidnext)
1633
+        {
1634
+            $objectreplacing=new Facture($this->db);
1635
+            $objectreplacing->fetch($objectidnext);
1636
+
1637
+            $posy+=3;
1638
+            $pdf->SetXY($posx,$posy);
1639
+            $pdf->SetTextColor(0,0,60);
1640
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1641
+        }
1642
+        if ($object->type == 1)
1643
+        {
1644
+            $objectreplaced=new Facture($this->db);
1645
+            $objectreplaced->fetch($object->fk_facture_source);
1646
+
1647
+            $posy+=4;
1648
+            $pdf->SetXY($posx,$posy);
1649
+            $pdf->SetTextColor(0,0,60);
1650
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1651
+        }
1652
+        if ($object->type == 2 && !empty($object->fk_facture_source))
1653
+        {
1654
+            $objectreplaced=new Facture($this->db);
1655
+            $objectreplaced->fetch($object->fk_facture_source);
1656
+
1657
+            $posy+=3;
1658
+            $pdf->SetXY($posx,$posy);
1659
+            $pdf->SetTextColor(0,0,60);
1660
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1661
+        }
1662
+
1663
+        $posy+=4;
1664
+        $pdf->SetXY($posx,$posy);
1665
+        $pdf->SetTextColor(0,0,60);
1666
+        $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1667
+
1668
+        if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1669
+        {
1670
+            $posy+=4;
1671
+            $pdf->SetXY($posx,$posy);
1672
+            $pdf->SetTextColor(0,0,60);
1673
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1674
+        }
1675
+
1676
+        if ($object->type != 2)
1677
+        {
1678
+            $posy+=3;
1679
+            $pdf->SetXY($posx,$posy);
1680
+            $pdf->SetTextColor(0,0,60);
1681
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1682
+        }
1683
+
1684
+        if ($object->thirdparty->code_client)
1685
+        {
1686
+            $posy+=3;
1687
+            $pdf->SetXY($posx,$posy);
1688
+            $pdf->SetTextColor(0,0,60);
1689
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1690
+        }
1691
+
1692
+        // Get contact
1693
+        if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1694
+        {
1695
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1696
+            if (count($arrayidcontact) > 0)
1697
+            {
1698
+                $usertmp=new User($this->db);
1699
+                $usertmp->fetch($arrayidcontact[0]);
1700 1700
                 $posy+=4;
1701 1701
                 $pdf->SetXY($posx,$posy);
1702
-		        $pdf->SetTextColor(0,0,60);
1703
-		        $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1704
-		    }
1705
-		}
1706
-
1707
-		$posy+=1;
1708
-
1709
-		$top_shift = 0;
1710
-		// Show list of linked objects
1711
-		$current_y = $pdf->getY();
1712
-		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1713
-		if ($current_y < $pdf->getY())
1714
-		{
1715
-			$top_shift = $pdf->getY() - $current_y;
1716
-		}
1717
-
1718
-		if ($showaddress)
1719
-		{
1720
-			// Sender properties
1721
-			$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1722
-
1723
-			// Show sender
1724
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1725
-			$posy+=$top_shift;
1726
-			$posx=$this->marge_gauche;
1727
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1728
-
1729
-			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1730
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1731
-
1732
-
1733
-			// Show sender frame
1734
-			$pdf->SetTextColor(0,0,0);
1735
-			$pdf->SetFont('','', $default_font_size - 2);
1736
-			$pdf->SetXY($posx,$posy-5);
1737
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1738
-			$pdf->SetXY($posx,$posy);
1739
-			$pdf->SetFillColor(230,230,230);
1740
-			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1741
-			$pdf->SetTextColor(0,0,60);
1742
-
1743
-			// Show sender name
1744
-			$pdf->SetXY($posx+2,$posy+3);
1745
-			$pdf->SetFont('','B', $default_font_size);
1746
-			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1747
-			$posy=$pdf->getY();
1748
-
1749
-			// Show sender information
1750
-			$pdf->SetXY($posx+2,$posy);
1751
-			$pdf->SetFont('','', $default_font_size - 1);
1752
-			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1753
-
1754
-			// If BILLING contact defined on invoice, we use it
1755
-			$usecontact=false;
1756
-			$arrayidcontact=$object->getIdContact('external','BILLING');
1757
-			if (count($arrayidcontact) > 0)
1758
-			{
1759
-				$usecontact=true;
1760
-				$result=$object->fetch_contact($arrayidcontact[0]);
1761
-			}
1762
-
1763
-			//Recipient name
1764
-			// On peut utiliser le nom de la societe du contact
1765
-			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1766
-				$thirdparty = $object->contact;
1767
-			} else {
1768
-				$thirdparty = $object->thirdparty;
1769
-			}
1770
-
1771
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1772
-
1773
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1774
-
1775
-			// Show recipient
1776
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1777
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1778
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1779
-			$posy+=$top_shift;
1780
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1781
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1782
-
1783
-			// Show recipient frame
1784
-			$pdf->SetTextColor(0,0,0);
1785
-			$pdf->SetFont('','', $default_font_size - 2);
1786
-			$pdf->SetXY($posx+2,$posy-5);
1787
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1788
-			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1789
-
1790
-			// Show recipient name
1791
-			$pdf->SetXY($posx+2,$posy+3);
1792
-			$pdf->SetFont('','B', $default_font_size);
1793
-			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1794
-
1795
-			$posy = $pdf->getY();
1796
-
1797
-			// Show recipient information
1798
-			$pdf->SetFont('','', $default_font_size - 1);
1799
-			$pdf->SetXY($posx+2,$posy);
1800
-			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1801
-		}
1802
-
1803
-		$pdf->SetTextColor(0,0,0);
1804
-		return $top_shift;
1805
-	}
1806
-
1807
-	/**
1808
-	 *   	Show footer of page. Need this->emetteur object
1702
+                $pdf->SetTextColor(0,0,60);
1703
+                $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1704
+            }
1705
+        }
1706
+
1707
+        $posy+=1;
1708
+
1709
+        $top_shift = 0;
1710
+        // Show list of linked objects
1711
+        $current_y = $pdf->getY();
1712
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1713
+        if ($current_y < $pdf->getY())
1714
+        {
1715
+            $top_shift = $pdf->getY() - $current_y;
1716
+        }
1717
+
1718
+        if ($showaddress)
1719
+        {
1720
+            // Sender properties
1721
+            $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1722
+
1723
+            // Show sender
1724
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1725
+            $posy+=$top_shift;
1726
+            $posx=$this->marge_gauche;
1727
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1728
+
1729
+            $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1730
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1731
+
1732
+
1733
+            // Show sender frame
1734
+            $pdf->SetTextColor(0,0,0);
1735
+            $pdf->SetFont('','', $default_font_size - 2);
1736
+            $pdf->SetXY($posx,$posy-5);
1737
+            $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1738
+            $pdf->SetXY($posx,$posy);
1739
+            $pdf->SetFillColor(230,230,230);
1740
+            $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1741
+            $pdf->SetTextColor(0,0,60);
1742
+
1743
+            // Show sender name
1744
+            $pdf->SetXY($posx+2,$posy+3);
1745
+            $pdf->SetFont('','B', $default_font_size);
1746
+            $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1747
+            $posy=$pdf->getY();
1748
+
1749
+            // Show sender information
1750
+            $pdf->SetXY($posx+2,$posy);
1751
+            $pdf->SetFont('','', $default_font_size - 1);
1752
+            $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1753
+
1754
+            // If BILLING contact defined on invoice, we use it
1755
+            $usecontact=false;
1756
+            $arrayidcontact=$object->getIdContact('external','BILLING');
1757
+            if (count($arrayidcontact) > 0)
1758
+            {
1759
+                $usecontact=true;
1760
+                $result=$object->fetch_contact($arrayidcontact[0]);
1761
+            }
1762
+
1763
+            //Recipient name
1764
+            // On peut utiliser le nom de la societe du contact
1765
+            if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1766
+                $thirdparty = $object->contact;
1767
+            } else {
1768
+                $thirdparty = $object->thirdparty;
1769
+            }
1770
+
1771
+            $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1772
+
1773
+            $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1774
+
1775
+            // Show recipient
1776
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1777
+            if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1778
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1779
+            $posy+=$top_shift;
1780
+            $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1781
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1782
+
1783
+            // Show recipient frame
1784
+            $pdf->SetTextColor(0,0,0);
1785
+            $pdf->SetFont('','', $default_font_size - 2);
1786
+            $pdf->SetXY($posx+2,$posy-5);
1787
+            $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1788
+            $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1789
+
1790
+            // Show recipient name
1791
+            $pdf->SetXY($posx+2,$posy+3);
1792
+            $pdf->SetFont('','B', $default_font_size);
1793
+            $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1794
+
1795
+            $posy = $pdf->getY();
1796
+
1797
+            // Show recipient information
1798
+            $pdf->SetFont('','', $default_font_size - 1);
1799
+            $pdf->SetXY($posx+2,$posy);
1800
+            $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1801
+        }
1802
+
1803
+        $pdf->SetTextColor(0,0,0);
1804
+        return $top_shift;
1805
+    }
1806
+
1807
+    /**
1808
+     *   	Show footer of page. Need this->emetteur object
1809
+     *
1810
+     *   	@param	PDF			$pdf     			PDF
1811
+     * 		@param	Object		$object				Object to show
1812
+     *      @param	Translate	$outputlangs		Object lang for output
1813
+     *      @param	int			$hidefreetext		1=Hide free text
1814
+     *      @return	int								Return height of bottom margin including footer text
1815
+     */
1816
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1817
+    {
1818
+        global $conf;
1819
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1820
+        return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1821
+    }
1822
+
1823
+    /**
1824
+     *   	Define Array Column Field
1809 1825
      *
1810
-	 *   	@param	PDF			$pdf     			PDF
1811
-	 * 		@param	Object		$object				Object to show
1812
-	 *      @param	Translate	$outputlangs		Object lang for output
1813
-	 *      @param	int			$hidefreetext		1=Hide free text
1814
-	 *      @return	int								Return height of bottom margin including footer text
1815
-	 */
1816
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1817
-	{
1818
-		global $conf;
1819
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1820
-		return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1821
-	}
1822
-
1823
-	/**
1824
-	 *   	Define Array Column Field
1825
-	 *
1826
-	 *   	@param	object			$object    		common object
1827
-	 *   	@param	outputlangs		$outputlangs    langs
1826
+     *   	@param	object			$object    		common object
1827
+     *   	@param	outputlangs		$outputlangs    langs
1828 1828
      *      @param	int			   $hidedetails		Do not show line details
1829 1829
      *      @param	int			   $hidedesc		Do not show desc
1830 1830
      *      @param	int			   $hideref			Do not show ref
1831
-	 *      @return	null
1832
-	 */
1831
+     *      @return	null
1832
+     */
1833 1833
     function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0)
1834 1834
     {
1835
-	    global $conf, $hookmanager;
1835
+        global $conf, $hookmanager;
1836 1836
 
1837
-	    // Default field style for content
1838
-	    $this->defaultContentsFieldsStyle = array(
1839
-	        'align' => 'R', // R,C,L
1840
-	        'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1841
-	    );
1837
+        // Default field style for content
1838
+        $this->defaultContentsFieldsStyle = array(
1839
+            'align' => 'R', // R,C,L
1840
+            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1841
+        );
1842 1842
 
1843
-	    // Default field style for content
1844
-	    $this->defaultTitlesFieldsStyle = array(
1845
-	        'align' => 'C', // R,C,L
1846
-	        'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1847
-	    );
1843
+        // Default field style for content
1844
+        $this->defaultTitlesFieldsStyle = array(
1845
+            'align' => 'C', // R,C,L
1846
+            'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1847
+        );
1848 1848
 
1849
-	    /*
1849
+        /*
1850 1850
 	     * For exemple
1851 1851
 	    $this->cols['theColKey'] = array(
1852 1852
 	        'rank' => $rank, // int : use for ordering columns
@@ -1864,24 +1864,24 @@  discard block
 block discarded – undo
1864 1864
 	    );
1865 1865
 	    */
1866 1866
 
1867
-	    $rank=0; // do not use negative rank
1868
-	    $this->cols['desc'] = array(
1869
-	        'rank' => $rank,
1870
-	        'width' => false, // only for desc
1871
-	        'status' => true,
1872
-	        'title' => array(
1873
-	            'textkey' => 'Designation', // use lang key is usefull in somme case with module
1874
-	            'align' => 'L',
1875
-	            // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1876
-	            // 'label' => ' ', // the final label
1877
-	            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1878
-	        ),
1879
-	        'content' => array(
1880
-	            'align' => 'L',
1881
-	        ),
1882
-	    );
1867
+        $rank=0; // do not use negative rank
1868
+        $this->cols['desc'] = array(
1869
+            'rank' => $rank,
1870
+            'width' => false, // only for desc
1871
+            'status' => true,
1872
+            'title' => array(
1873
+                'textkey' => 'Designation', // use lang key is usefull in somme case with module
1874
+                'align' => 'L',
1875
+                // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1876
+                // 'label' => ' ', // the final label
1877
+                'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1878
+            ),
1879
+            'content' => array(
1880
+                'align' => 'L',
1881
+            ),
1882
+        );
1883 1883
 
1884
-	    // PHOTO
1884
+        // PHOTO
1885 1885
         $rank = $rank + 10;
1886 1886
         $this->cols['photo'] = array(
1887 1887
             'rank' => $rank,
@@ -1897,126 +1897,126 @@  discard block
 block discarded – undo
1897 1897
             'border-left' => false, // remove left line separator
1898 1898
         );
1899 1899
 
1900
-	    if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto))
1901
-	    {
1902
-	        $this->cols['photo']['status'] = true;
1903
-	    }
1900
+        if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto))
1901
+        {
1902
+            $this->cols['photo']['status'] = true;
1903
+        }
1904 1904
 
1905 1905
 
1906
-	    $rank = $rank + 10;
1907
-	    $this->cols['vat'] = array(
1908
-	        'rank' => $rank,
1909
-	        'status' => false,
1910
-	        'width' => 16, // in mm
1911
-	        'title' => array(
1912
-	            'textkey' => 'VAT'
1913
-	        ),
1914
-	        'border-left' => true, // add left line separator
1915
-	    );
1906
+        $rank = $rank + 10;
1907
+        $this->cols['vat'] = array(
1908
+            'rank' => $rank,
1909
+            'status' => false,
1910
+            'width' => 16, // in mm
1911
+            'title' => array(
1912
+                'textkey' => 'VAT'
1913
+            ),
1914
+            'border-left' => true, // add left line separator
1915
+        );
1916 1916
 
1917
-	    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1918
-	    {
1919
-	        $this->cols['vat']['status'] = true;
1920
-	    }
1917
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1918
+        {
1919
+            $this->cols['vat']['status'] = true;
1920
+        }
1921 1921
 
1922
-	    $rank = $rank + 10;
1923
-	    $this->cols['subprice'] = array(
1924
-	        'rank' => $rank,
1925
-	        'width' => 19, // in mm
1926
-	        'status' => true,
1927
-	        'title' => array(
1928
-	            'textkey' => 'PriceUHT'
1929
-	        ),
1930
-	        'border-left' => true, // add left line separator
1931
-	    );
1922
+        $rank = $rank + 10;
1923
+        $this->cols['subprice'] = array(
1924
+            'rank' => $rank,
1925
+            'width' => 19, // in mm
1926
+            'status' => true,
1927
+            'title' => array(
1928
+                'textkey' => 'PriceUHT'
1929
+            ),
1930
+            'border-left' => true, // add left line separator
1931
+        );
1932 1932
 
1933
-	    $rank = $rank + 10;
1934
-	    $this->cols['qty'] = array(
1935
-	        'rank' => $rank,
1936
-	        'width' => 16, // in mm
1937
-	        'status' => true,
1938
-	        'title' => array(
1939
-	            'textkey' => 'Qty'
1940
-	        ),
1941
-	        'border-left' => true, // add left line separator
1942
-	    );
1933
+        $rank = $rank + 10;
1934
+        $this->cols['qty'] = array(
1935
+            'rank' => $rank,
1936
+            'width' => 16, // in mm
1937
+            'status' => true,
1938
+            'title' => array(
1939
+                'textkey' => 'Qty'
1940
+            ),
1941
+            'border-left' => true, // add left line separator
1942
+        );
1943 1943
 
1944
-	    $rank = $rank + 10;
1945
-	    $this->cols['progress'] = array(
1946
-	        'rank' => $rank,
1947
-	        'width' => 19, // in mm
1948
-	        'status' => false,
1949
-	        'title' => array(
1950
-	            'textkey' => 'Progress'
1951
-	        ),
1952
-	        'border-left' => true, // add left line separator
1953
-	    );
1944
+        $rank = $rank + 10;
1945
+        $this->cols['progress'] = array(
1946
+            'rank' => $rank,
1947
+            'width' => 19, // in mm
1948
+            'status' => false,
1949
+            'title' => array(
1950
+                'textkey' => 'Progress'
1951
+            ),
1952
+            'border-left' => true, // add left line separator
1953
+        );
1954 1954
 
1955
-	    if($this->situationinvoice)
1956
-	    {
1957
-	        $this->cols['progress']['status'] = true;
1958
-	    }
1955
+        if($this->situationinvoice)
1956
+        {
1957
+            $this->cols['progress']['status'] = true;
1958
+        }
1959 1959
 
1960
-	    $rank = $rank + 10;
1961
-	    $this->cols['unit'] = array(
1962
-	        'rank' => $rank,
1963
-	        'width' => 11, // in mm
1964
-	        'status' => false,
1965
-	        'title' => array(
1966
-	            'textkey' => 'Unit'
1967
-	        ),
1968
-	        'border-left' => true, // add left line separator
1969
-	    );
1970
-	    if($conf->global->PRODUCT_USE_UNITS){
1971
-	        $this->cols['unit']['status'] = true;
1972
-	    }
1973
-
1974
-	    $rank = $rank + 10;
1975
-	    $this->cols['discount'] = array(
1976
-	        'rank' => $rank,
1977
-	        'width' => 13, // in mm
1978
-	        'status' => false,
1979
-	        'title' => array(
1980
-	            'textkey' => 'ReductionShort'
1981
-	        ),
1982
-	        'border-left' => true, // add left line separator
1983
-	    );
1984
-	    if ($this->atleastonediscount){
1985
-	        $this->cols['discount']['status'] = true;
1986
-	    }
1987
-
1988
-	    $rank = $rank + 10;
1989
-	    $this->cols['totalexcltax'] = array(
1990
-	        'rank' => $rank,
1991
-	        'width' => 26, // in mm
1992
-	        'status' => true,
1993
-	        'title' => array(
1994
-	            'textkey' => 'TotalHT'
1995
-	        ),
1996
-	        'border-left' => true, // add left line separator
1997
-	    );
1960
+        $rank = $rank + 10;
1961
+        $this->cols['unit'] = array(
1962
+            'rank' => $rank,
1963
+            'width' => 11, // in mm
1964
+            'status' => false,
1965
+            'title' => array(
1966
+                'textkey' => 'Unit'
1967
+            ),
1968
+            'border-left' => true, // add left line separator
1969
+        );
1970
+        if($conf->global->PRODUCT_USE_UNITS){
1971
+            $this->cols['unit']['status'] = true;
1972
+        }
1998 1973
 
1974
+        $rank = $rank + 10;
1975
+        $this->cols['discount'] = array(
1976
+            'rank' => $rank,
1977
+            'width' => 13, // in mm
1978
+            'status' => false,
1979
+            'title' => array(
1980
+                'textkey' => 'ReductionShort'
1981
+            ),
1982
+            'border-left' => true, // add left line separator
1983
+        );
1984
+        if ($this->atleastonediscount){
1985
+            $this->cols['discount']['status'] = true;
1986
+        }
1987
+
1988
+        $rank = $rank + 10;
1989
+        $this->cols['totalexcltax'] = array(
1990
+            'rank' => $rank,
1991
+            'width' => 26, // in mm
1992
+            'status' => true,
1993
+            'title' => array(
1994
+                'textkey' => 'TotalHT'
1995
+            ),
1996
+            'border-left' => true, // add left line separator
1997
+        );
1999 1998
 
2000
-	    $parameters=array(
2001
-	        'object' => $object,
2002
-	        'outputlangs' => $outputlangs,
2003
-	        'hidedetails' => $hidedetails,
2004
-	        'hidedesc' => $hidedesc,
2005
-	        'hideref' => $hideref
2006
-	    );
2007 1999
 
2008
-	    $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
2009
-	    if ($reshook < 0)
2010
-	    {
2011
-	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2012
-	    }
2013
-	    elseif (empty($reshook))
2014
-	    {
2015
-	        $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2016
-	    }
2017
-	    else
2018
-	    {
2019
-	        $this->cols = $hookmanager->resArray;
2020
-	    }
2021
-	}
2000
+        $parameters=array(
2001
+            'object' => $object,
2002
+            'outputlangs' => $outputlangs,
2003
+            'hidedetails' => $hidedetails,
2004
+            'hidedesc' => $hidedesc,
2005
+            'hideref' => $hideref
2006
+        );
2007
+
2008
+        $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
2009
+        if ($reshook < 0)
2010
+        {
2011
+            setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2012
+        }
2013
+        elseif (empty($reshook))
2014
+        {
2015
+            $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2016
+        }
2017
+        else
2018
+        {
2019
+            $this->cols = $hookmanager->resArray;
2020
+        }
2021
+    }
2022 2022
 }
Please login to merge, or discard this patch.
Spacing   +525 added lines, -525 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	public $marge_haute;
89 89
 	public $marge_basse;
90 90
 
91
-	public $emetteur;	// Objet societe qui emet
91
+	public $emetteur; // Objet societe qui emet
92 92
 
93 93
 	/**
94 94
 	 * @var bool Situation invoice type
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	function __construct($db)
110 110
 	{
111
-		global $conf,$langs,$mysoc;
111
+		global $conf, $langs, $mysoc;
112 112
 
113 113
 		// Translations
114 114
 		$langs->loadLangs(array("main", "bills"));
@@ -116,47 +116,47 @@  discard block
 block discarded – undo
116 116
 		$this->db = $db;
117 117
 		$this->name = "sponge";
118 118
 		$this->description = $langs->trans('PDFSpongeDescription');
119
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
119
+		$this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
120 120
 
121 121
 		// Dimensiont page
122 122
 		$this->type = 'pdf';
123
-		$formatarray=pdf_getFormat();
123
+		$formatarray = pdf_getFormat();
124 124
 		$this->page_largeur = $formatarray['width'];
125 125
 		$this->page_hauteur = $formatarray['height'];
126
-		$this->format = array($this->page_largeur,$this->page_hauteur);
127
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
128
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
129
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
130
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
131
-
132
-		$this->option_logo = 1;                    // Affiche logo
133
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
134
-		$this->option_modereg = 1;                 // Affiche mode reglement
135
-		$this->option_condreg = 1;                 // Affiche conditions reglement
136
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
137
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
138
-		$this->option_escompte = 1;                // Affiche si il y a eu escompte
139
-		$this->option_credit_note = 1;             // Support credit notes
140
-		$this->option_freetext = 1;				   // Support add of a personalised text
141
-		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
142
-
143
-		$this->franchise=!$mysoc->tva_assuj;
126
+		$this->format = array($this->page_largeur, $this->page_hauteur);
127
+		$this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
128
+		$this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
129
+		$this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
130
+		$this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
131
+
132
+		$this->option_logo = 1; // Affiche logo
133
+		$this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
134
+		$this->option_modereg = 1; // Affiche mode reglement
135
+		$this->option_condreg = 1; // Affiche conditions reglement
136
+		$this->option_codeproduitservice = 1; // Affiche code produit-service
137
+		$this->option_multilang = 1; // Dispo en plusieurs langues
138
+		$this->option_escompte = 1; // Affiche si il y a eu escompte
139
+		$this->option_credit_note = 1; // Support credit notes
140
+		$this->option_freetext = 1; // Support add of a personalised text
141
+		$this->option_draft_watermark = 1; // Support add of a watermark on drafts
142
+
143
+		$this->franchise = !$mysoc->tva_assuj;
144 144
 
145 145
 		// Get source company
146
-		$this->emetteur=$mysoc;
147
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
146
+		$this->emetteur = $mysoc;
147
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
148 148
 
149 149
 		// Define position of columns
150
-		$this->posxdesc=$this->marge_gauche+1; // used for notes ans other stuff
150
+		$this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
151 151
 
152 152
 		//  Use new system for position of columns, view  $this->defineColumnField()
153 153
 
154
-		$this->tva=array();
155
-		$this->localtax1=array();
156
-		$this->localtax2=array();
157
-		$this->atleastoneratenotnull=0;
158
-		$this->atleastonediscount=0;
159
-		$this->situationinvoice=false;
154
+		$this->tva = array();
155
+		$this->localtax1 = array();
156
+		$this->localtax2 = array();
157
+		$this->atleastoneratenotnull = 0;
158
+		$this->atleastonediscount = 0;
159
+		$this->situationinvoice = false;
160 160
 	}
161 161
 
162 162
 
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
      *  @param		int			$hideref			Do not show ref
173 173
      *  @return     int         	    			1=OK, 0=KO
174 174
 	 */
175
-	public function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
175
+	public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
176 176
 	{
177 177
 	    // phpcs:enable
178
-	    global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
178
+	    global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblignes;
179 179
 
180
-	    if (! is_object($outputlangs)) $outputlangs=$langs;
180
+	    if (!is_object($outputlangs)) $outputlangs = $langs;
181 181
 	    // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
182
-	    if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
182
+	    if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
183 183
 
184 184
 	    // Translations
185 185
 	    $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
@@ -187,52 +187,52 @@  discard block
 block discarded – undo
187 187
 	    $nblignes = count($object->lines);
188 188
 
189 189
 	    // Loop on each lines to detect if there is at least one image to show
190
-	    $realpatharray=array();
190
+	    $realpatharray = array();
191 191
 	    $this->atleastonephoto = false;
192
-	    if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
192
+	    if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
193 193
 	    {
194 194
 	        $objphoto = new Product($this->db);
195 195
 
196
-	        for ($i = 0 ; $i < $nblignes ; $i++)
196
+	        for ($i = 0; $i < $nblignes; $i++)
197 197
 	        {
198 198
 	            if (empty($object->lines[$i]->fk_product)) continue;
199 199
 
200 200
 	            $objphoto->fetch($object->lines[$i]->fk_product);
201 201
 	            //var_dump($objphoto->ref);exit;
202
-	            if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
202
+	            if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
203 203
 	            {
204
-	                $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
205
-	                $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
204
+	                $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
205
+	                $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
206 206
 	            }
207 207
 	            else
208 208
 	            {
209
-	                $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
210
-	                $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
209
+	                $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; // default
210
+	                $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
211 211
 	            }
212 212
 
213 213
 	            $arephoto = false;
214 214
 	            foreach ($pdir as $midir)
215 215
 	            {
216
-	                if (! $arephoto)
216
+	                if (!$arephoto)
217 217
 	                {
218 218
 	                    $dir = $conf->product->dir_output.'/'.$midir;
219 219
 
220
-	                    foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
220
+	                    foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
221 221
 	                    {
222 222
 	                        if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
223 223
 	                        {
224 224
 	                            if ($obj['photo_vignette'])
225 225
 	                            {
226
-	                                $filename= $obj['photo_vignette'];
226
+	                                $filename = $obj['photo_vignette'];
227 227
 	                            }
228 228
 	                            else
229 229
 	                            {
230
-	                                $filename=$obj['photo'];
230
+	                                $filename = $obj['photo'];
231 231
 	                            }
232 232
 	                        }
233 233
 	                        else
234 234
 	                        {
235
-	                            $filename=$obj['photo'];
235
+	                            $filename = $obj['photo'];
236 236
 	                        }
237 237
 
238 238
 	                        $realpath = $dir.$filename;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	                }
243 243
 	            }
244 244
 
245
-	            if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
245
+	            if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
246 246
 	        }
247 247
 	    }
248 248
 
@@ -260,19 +260,19 @@  discard block
 block discarded – undo
260 260
 	        if ($object->specimen)
261 261
 	        {
262 262
 	            $dir = $conf->facture->dir_output;
263
-	            $file = $dir . "/SPECIMEN.pdf";
263
+	            $file = $dir."/SPECIMEN.pdf";
264 264
 	        }
265 265
 	        else
266 266
 	        {
267 267
 	            $objectref = dol_sanitizeFileName($object->ref);
268
-	            $dir = $conf->facture->dir_output . "/" . $objectref;
269
-	            $file = $dir . "/" . $objectref . ".pdf";
268
+	            $dir = $conf->facture->dir_output."/".$objectref;
269
+	            $file = $dir."/".$objectref.".pdf";
270 270
 	        }
271
-	        if (! file_exists($dir))
271
+	        if (!file_exists($dir))
272 272
 	        {
273 273
 	            if (dol_mkdir($dir) < 0)
274 274
 	            {
275
-	                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
275
+	                $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
276 276
 	                return 0;
277 277
 	            }
278 278
 	        }
@@ -280,28 +280,28 @@  discard block
 block discarded – undo
280 280
 	        if (file_exists($dir))
281 281
 	        {
282 282
 	            // Add pdfgeneration hook
283
-	            if (! is_object($hookmanager))
283
+	            if (!is_object($hookmanager))
284 284
 	            {
285 285
 	                include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
286
-	                $hookmanager=new HookManager($this->db);
286
+	                $hookmanager = new HookManager($this->db);
287 287
 	            }
288 288
 	            $hookmanager->initHooks(array('pdfgeneration'));
289
-	            $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
289
+	            $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
290 290
 	            global $action;
291
-	            $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
291
+	            $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
292 292
 
293 293
 	            // Set nblignes with the new facture lines content after hook
294 294
 	            $nblignes = count($object->lines);
295 295
 	            $nbpayments = count($object->getListOfPayments());
296 296
 
297 297
 	            // Create pdf instance
298
-	            $pdf=pdf_getInstance($this->format);
299
-	            $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
300
-	            $pdf->SetAutoPageBreak(1,0);
298
+	            $pdf = pdf_getInstance($this->format);
299
+	            $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
300
+	            $pdf->SetAutoPageBreak(1, 0);
301 301
 
302
-	            $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
303
-	            $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
304
-	            $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)?12:22);	// Height reserved to output the footer (value include bottom margin)
302
+	            $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
303
+	            $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
304
+	            $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
305 305
 
306 306
 	            if (class_exists('TCPDF'))
307 307
 	            {
@@ -311,28 +311,28 @@  discard block
 block discarded – undo
311 311
 	            $pdf->SetFont(pdf_getPDFFont($outputlangs));
312 312
 
313 313
 	            // Set path to the background PDF File
314
-                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
314
+                if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
315 315
 	            {
316 316
 	                $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
317 317
 	                $tplidx = $pdf->importPage(1);
318 318
 	            }
319 319
 
320 320
 	            $pdf->Open();
321
-	            $pagenb=0;
322
-	            $pdf->SetDrawColor(128,128,128);
321
+	            $pagenb = 0;
322
+	            $pdf->SetDrawColor(128, 128, 128);
323 323
 
324 324
 	            $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
325 325
 	            $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
326 326
 	            $pdf->SetCreator("Dolibarr ".DOL_VERSION);
327 327
 	            $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
328 328
 	            $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
329
-	            if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
329
+	            if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
330 330
 
331
-	            $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
331
+	            $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
332 332
 
333 333
 	            // Does we have at least one line with discount $this->atleastonediscount
334 334
 	            foreach ($object->lines as $line) {
335
-	               if ($line->remise_percent){
335
+	               if ($line->remise_percent) {
336 336
 	                    $this->atleastonediscount = true;
337 337
 	                    break;
338 338
 	               }
@@ -347,17 +347,17 @@  discard block
 block discarded – undo
347 347
 
348 348
 	            // New page
349 349
 	            $pdf->AddPage();
350
-	            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
350
+	            if (!empty($tplidx)) $pdf->useTemplate($tplidx);
351 351
 	            $pagenb++;
352 352
 
353 353
 	            $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
354
-	            $pdf->SetFont('','', $default_font_size - 1);
355
-	            $pdf->MultiCell(0, 3, '');		// Set interline to 3
356
-	            $pdf->SetTextColor(0,0,0);
354
+	            $pdf->SetFont('', '', $default_font_size - 1);
355
+	            $pdf->MultiCell(0, 3, ''); // Set interline to 3
356
+	            $pdf->SetTextColor(0, 0, 0);
357 357
 
358
-	            $tab_top = 90+$top_shift;
359
-	            $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
360
-	            $tab_height = 130-$top_shift;
358
+	            $tab_top = 90 + $top_shift;
359
+	            $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
360
+	            $tab_height = 130 - $top_shift;
361 361
 	            $tab_height_newpage = 150;
362 362
 	            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift;
363 363
 
@@ -370,31 +370,31 @@  discard block
 block discarded – undo
370 370
 	                {
371 371
 						$tab_top -= 2;
372 372
 
373
-	                    $pdf->SetFont('','', $default_font_size - 1);
374
-	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
375
-	                    $nexY = max($pdf->GetY(),$nexY);
376
-	                    $height_incoterms=$nexY-$tab_top;
373
+	                    $pdf->SetFont('', '', $default_font_size - 1);
374
+	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
375
+	                    $nexY = max($pdf->GetY(), $nexY);
376
+	                    $height_incoterms = $nexY - $tab_top;
377 377
 
378 378
 	                    // Rect prend une longueur en 3eme param
379
-	                    $pdf->SetDrawColor(192,192,192);
380
-	                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
379
+	                    $pdf->SetDrawColor(192, 192, 192);
380
+	                    $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
381 381
 
382
-	                    $tab_top = $nexY+6;
382
+	                    $tab_top = $nexY + 6;
383 383
 	                    $height_incoterms += 4;
384 384
 	                }
385 385
 	            }
386 386
 
387 387
 	            // Affiche notes
388
-	            $notetoshow=empty($object->note_public)?'':$object->note_public;
389
-	            if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
388
+	            $notetoshow = empty($object->note_public) ? '' : $object->note_public;
389
+	            if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
390 390
 	            {
391 391
 	                // Get first sale rep
392 392
 	                if (is_object($object->thirdparty))
393 393
 	                {
394
-	                    $salereparray=$object->thirdparty->getSalesRepresentatives($user);
395
-	                    $salerepobj=new User($this->db);
394
+	                    $salereparray = $object->thirdparty->getSalesRepresentatives($user);
395
+	                    $salerepobj = new User($this->db);
396 396
 	                    $salerepobj->fetch($salereparray[0]['id']);
397
-	                    if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
397
+	                    if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
398 398
 	                }
399 399
 	            }
400 400
 
@@ -403,23 +403,23 @@  discard block
 block discarded – undo
403 403
 	            {
404 404
 					$tab_top -= 2;
405 405
 
406
-	                $tab_width = $this->page_largeur-$this->marge_gauche-$this->marge_droite;
406
+	                $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
407 407
 	                $pageposbeforenote = $pagenb;
408 408
 
409
-	                $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
409
+	                $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
410 410
 	                complete_substitutions_array($substitutionarray, $outputlangs, $object);
411 411
 	                $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
412 412
 
413 413
 
414 414
 	                $pdf->startTransaction();
415 415
 
416
-	                $pdf->SetFont('','', $default_font_size - 1);
417
-	                $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
416
+	                $pdf->SetFont('', '', $default_font_size - 1);
417
+	                $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
418 418
 	                // Description
419
-	                $pageposafternote=$pdf->getPage();
419
+	                $pageposafternote = $pdf->getPage();
420 420
 	                $posyafter = $pdf->GetY();
421 421
 
422
-	                if($pageposafternote>$pageposbeforenote )
422
+	                if ($pageposafternote > $pageposbeforenote)
423 423
 	                {
424 424
 	                    $pdf->rollbackTransaction(true);
425 425
 
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	                    while ($pagenb < $pageposafternote) {
428 428
 	                        $pdf->AddPage();
429 429
 	                        $pagenb++;
430
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
430
+	                        if (!empty($tplidx)) $pdf->useTemplate($tplidx);
431 431
 	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
432 432
 	                        // $this->_pagefoot($pdf,$object,$outputlangs,1);
433 433
 	                        $pdf->setTopMargin($tab_top_newpage);
@@ -438,15 +438,15 @@  discard block
 block discarded – undo
438 438
 	                    // back to start
439 439
 	                    $pdf->setPage($pageposbeforenote);
440 440
 	                    $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
441
-	                    $pdf->SetFont('','', $default_font_size - 1);
442
-	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
443
-	                    $pageposafternote=$pdf->getPage();
441
+	                    $pdf->SetFont('', '', $default_font_size - 1);
442
+	                    $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
443
+	                    $pageposafternote = $pdf->getPage();
444 444
 
445 445
 	                    $posyafter = $pdf->GetY();
446 446
 
447
-	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
447
+	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))	// There is no space left for total+free text
448 448
 	                    {
449
-	                        $pdf->AddPage('','',true);
449
+	                        $pdf->AddPage('', '', true);
450 450
 	                        $pagenb++;
451 451
 	                        $pageposafternote++;
452 452
 	                        $pdf->setPage($pageposafternote);
@@ -463,47 +463,47 @@  discard block
 block discarded – undo
463 463
 	                        $pdf->setPage($i);
464 464
 
465 465
 
466
-	                        $pdf->SetDrawColor(128,128,128);
466
+	                        $pdf->SetDrawColor(128, 128, 128);
467 467
 	                        // Draw note frame
468
-	                        if($i>$pageposbeforenote){
468
+	                        if ($i > $pageposbeforenote) {
469 469
 	                            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
470
-	                            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
470
+	                            $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
471 471
 	                        }
472
-	                        else{
472
+	                        else {
473 473
 	                            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
474
-	                            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
474
+	                            $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
475 475
 	                        }
476 476
 
477 477
 	                        // Add footer
478
-	                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
479
-	                        $this->_pagefoot($pdf,$object,$outputlangs,1);
478
+	                        $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
479
+	                        $this->_pagefoot($pdf, $object, $outputlangs, 1);
480 480
 
481 481
 	                        $i++;
482 482
 	                    }
483 483
 
484 484
 	                    // apply note frame to last page
485 485
 	                    $pdf->setPage($pageposafternote);
486
-	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
486
+	                    if (!empty($tplidx)) $pdf->useTemplate($tplidx);
487 487
 	                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
-	                    $height_note=$posyafter-$tab_top_newpage;
489
-	                    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
488
+	                    $height_note = $posyafter - $tab_top_newpage;
489
+	                    $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
490 490
 	                }
491 491
 	                else // No pagebreak
492 492
 	                {
493 493
 	                    $pdf->commitTransaction();
494 494
 	                    $posyafter = $pdf->GetY();
495
-	                    $height_note=$posyafter-$tab_top;
496
-	                    $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note+1);
495
+	                    $height_note = $posyafter - $tab_top;
496
+	                    $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
497 497
 
498 498
 
499
-	                    if($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)) )
499
+	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
500 500
 	                    {
501 501
 	                        // not enough space, need to add page
502
-	                        $pdf->AddPage('','',true);
502
+	                        $pdf->AddPage('', '', true);
503 503
 	                        $pagenb++;
504 504
 	                        $pageposafternote++;
505 505
 	                        $pdf->setPage($pageposafternote);
506
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
506
+	                        if (!empty($tplidx)) $pdf->useTemplate($tplidx);
507 507
 	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
508 508
 
509 509
 	                        $posyafter = $tab_top_newpage;
@@ -511,11 +511,11 @@  discard block
 block discarded – undo
511 511
 	                }
512 512
 
513 513
 	                $tab_height = $tab_height - $height_note;
514
-	                $tab_top = $posyafter +6;
514
+	                $tab_top = $posyafter + 6;
515 515
 	            }
516 516
 	            else
517 517
 	            {
518
-	                $height_note=0;
518
+	                $height_note = 0;
519 519
 	            }
520 520
 
521 521
 	            $iniY = $tab_top + 7;
@@ -523,48 +523,48 @@  discard block
 block discarded – undo
523 523
 	            $nexY = $tab_top + 7;
524 524
 
525 525
 	            // Use new auto collum system
526
-	            $this->prepareArrayColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
526
+	            $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
527 527
 
528 528
 	            // Loop on each lines
529
-	            $pageposbeforeprintlines=$pdf->getPage();
529
+	            $pageposbeforeprintlines = $pdf->getPage();
530 530
 	            $pagenb = $pageposbeforeprintlines;
531 531
 	            for ($i = 0; $i < $nblignes; $i++)
532 532
 	            {
533 533
 
534 534
 	                $curY = $nexY;
535
-	                $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
536
-	                $pdf->SetTextColor(0,0,0);
535
+	                $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
536
+	                $pdf->SetTextColor(0, 0, 0);
537 537
 
538 538
 	                // Define size of image if we need it
539
-	                $imglinesize=array();
540
-	                if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
539
+	                $imglinesize = array();
540
+	                if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
541 541
 
542 542
 	                $pdf->setTopMargin($tab_top_newpage);
543
-	                $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
544
-	                $pageposbefore=$pdf->getPage();
543
+	                $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
544
+	                $pageposbefore = $pdf->getPage();
545 545
 
546
-	                $showpricebeforepagebreak=1;
547
-	                $posYAfterImage=0;
548
-	                $posYAfterDescription=0;
546
+	                $showpricebeforepagebreak = 1;
547
+	                $posYAfterImage = 0;
548
+	                $posYAfterDescription = 0;
549 549
 
550
-	                if($this->getColumnStatus('photo'))
550
+	                if ($this->getColumnStatus('photo'))
551 551
 	                {
552 552
     	                // We start with Photo of product line
553
-    	                if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
553
+    	                if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))	// If photo too high, we moved completely on new page
554 554
     	                {
555
-    	                    $pdf->AddPage('','',true);
556
-    	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
557
-    	                    $pdf->setPage($pageposbefore+1);
555
+    	                    $pdf->AddPage('', '', true);
556
+    	                    if (!empty($tplidx)) $pdf->useTemplate($tplidx);
557
+    	                    $pdf->setPage($pageposbefore + 1);
558 558
 
559 559
     	                    $curY = $tab_top_newpage;
560
-    	                    $showpricebeforepagebreak=0;
560
+    	                    $showpricebeforepagebreak = 0;
561 561
     	                }
562 562
 
563 563
     	                if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
564 564
     	                {
565
-    	                    $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
565
+    	                    $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
566 566
     	                    // $pdf->Image does not increase value return by getY, so we save it manually
567
-    	                    $posYAfterImage=$curY+$imglinesize['height'];
567
+    	                    $posYAfterImage = $curY + $imglinesize['height'];
568 568
     	                }
569 569
 	                }
570 570
 
@@ -572,59 +572,59 @@  discard block
 block discarded – undo
572 572
 	                if ($this->getColumnStatus('desc'))
573 573
 	                {
574 574
     	                $pdf->startTransaction();
575
-    	                pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
576
-    	                $pageposafter=$pdf->getPage();
575
+    	                pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
576
+    	                $pageposafter = $pdf->getPage();
577 577
     	                if ($pageposafter > $pageposbefore)	// There is a pagebreak
578 578
     	                {
579 579
     	                    $pdf->rollbackTransaction(true);
580
-    	                    $pageposafter=$pageposbefore;
580
+    	                    $pageposafter = $pageposbefore;
581 581
     	                    //print $pageposafter.'-'.$pageposbefore;exit;
582
-    	                    $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
583
-    	                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
584
-    	                    $pageposafter=$pdf->getPage();
585
-    	                    $posyafter=$pdf->GetY();
582
+    	                    $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
583
+    	                    pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
584
+    	                    $pageposafter = $pdf->getPage();
585
+    	                    $posyafter = $pdf->GetY();
586 586
     	                    //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
587
-    	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
587
+    	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))	// There is no space left for total+free text
588 588
     	                    {
589
-    	                        if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
589
+    	                        if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
590 590
     	                        {
591
-    	                            $pdf->AddPage('','',true);
592
-    	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
593
-    	                            $pdf->setPage($pageposafter+1);
591
+    	                            $pdf->AddPage('', '', true);
592
+    	                            if (!empty($tplidx)) $pdf->useTemplate($tplidx);
593
+    	                            $pdf->setPage($pageposafter + 1);
594 594
     	                        }
595 595
     	                    }
596 596
     	                    else
597 597
     	                    {
598 598
     	                        // We found a page break
599
-    	                        $showpricebeforepagebreak=0;
599
+    	                        $showpricebeforepagebreak = 0;
600 600
     	                    }
601 601
     	                }
602 602
     	                else	// No pagebreak
603 603
     	                {
604 604
     	                    $pdf->commitTransaction();
605 605
     	                }
606
-    	                $posYAfterDescription=$pdf->GetY();
606
+    	                $posYAfterDescription = $pdf->GetY();
607 607
 	                }
608 608
 
609 609
 	                $nexY = $pdf->GetY();
610
-	                $pageposafter=$pdf->getPage();
610
+	                $pageposafter = $pdf->getPage();
611 611
 	                $pdf->setPage($pageposbefore);
612 612
 	                $pdf->setTopMargin($this->marge_haute);
613
-	                $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
613
+	                $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
614 614
 
615 615
 	                // We suppose that a too long description or photo were moved completely on next page
616 616
 	                if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
617 617
 	                    $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
618 618
 	                }
619 619
 
620
-	                $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
620
+	                $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
621 621
 
622 622
 	                // VAT Rate
623 623
 	                if ($this->getColumnStatus('vat'))
624 624
 	                {
625 625
 	                    $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
626 626
 	                    $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
627
-	                    $nexY = max($pdf->GetY(),$nexY);
627
+	                    $nexY = max($pdf->GetY(), $nexY);
628 628
 	                }
629 629
 
630 630
 	                // Unit price before discount
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	                {
633 633
 	                    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
634 634
 	                    $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
635
-	                    $nexY = max($pdf->GetY(),$nexY);
635
+	                    $nexY = max($pdf->GetY(), $nexY);
636 636
 	                }
637 637
 
638 638
 	                // Quantity
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 	                {
642 642
 	                    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
643 643
 	                    $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
644
-	                    $nexY = max($pdf->GetY(),$nexY);
644
+	                    $nexY = max($pdf->GetY(), $nexY);
645 645
 	                }
646 646
 
647 647
 	                // Situation progress
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 	                {
650 650
 	                    $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
651 651
 	                    $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
652
-	                    $nexY = max($pdf->GetY(),$nexY);
652
+	                    $nexY = max($pdf->GetY(), $nexY);
653 653
 	                }
654 654
 
655 655
 	                // Unit
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 	                {
658 658
 	                    $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
659 659
 	                    $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
660
-	                    $nexY = max($pdf->GetY(),$nexY);
660
+	                    $nexY = max($pdf->GetY(), $nexY);
661 661
 	                }
662 662
 
663 663
 	                // Discount on line
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 	                {
666 666
 	                    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
667 667
 	                    $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
668
-	                    $nexY = max($pdf->GetY(),$nexY);
668
+	                    $nexY = max($pdf->GetY(), $nexY);
669 669
 	                }
670 670
 
671 671
 	                // Total HT line
@@ -673,11 +673,11 @@  discard block
 block discarded – undo
673 673
 	                {
674 674
 	                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
675 675
 	                    $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
676
-	                    $nexY = max($pdf->GetY(),$nexY);
676
+	                    $nexY = max($pdf->GetY(), $nexY);
677 677
 	                }
678 678
 
679 679
 
680
-	                $parameters=array(
680
+	                $parameters = array(
681 681
 	                    'object' => $object,
682 682
 	                    'i' => $i,
683 683
 	                    'pdf' =>& $pdf,
@@ -686,12 +686,12 @@  discard block
 block discarded – undo
686 686
 	                    'outputlangs' => $outputlangs,
687 687
 	                    'hidedetails' => $hidedetails
688 688
 	                );
689
-	                $reshook=$hookmanager->executeHooks('printPDFline',$parameters,$this);    // Note that $object may have been modified by hook
689
+	                $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
690 690
 
691 691
 
692 692
 
693
-	                $sign=1;
694
-	                if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
693
+	                $sign = 1;
694
+	                if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
695 695
 	                // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
696 696
 	                $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
697 697
 	                if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
@@ -699,55 +699,55 @@  discard block
 block discarded – undo
699 699
 	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
700 700
 	                    else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
701 701
 	                } else {
702
-	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
703
-	                    else $tvaligne= $sign * $object->lines[$i]->total_tva;
702
+	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
703
+	                    else $tvaligne = $sign * $object->lines[$i]->total_tva;
704 704
 	                }
705 705
 
706
-	                $localtax1ligne=$object->lines[$i]->total_localtax1;
707
-	                $localtax2ligne=$object->lines[$i]->total_localtax2;
708
-	                $localtax1_rate=$object->lines[$i]->localtax1_tx;
709
-	                $localtax2_rate=$object->lines[$i]->localtax2_tx;
710
-	                $localtax1_type=$object->lines[$i]->localtax1_type;
711
-	                $localtax2_type=$object->lines[$i]->localtax2_type;
706
+	                $localtax1ligne = $object->lines[$i]->total_localtax1;
707
+	                $localtax2ligne = $object->lines[$i]->total_localtax2;
708
+	                $localtax1_rate = $object->lines[$i]->localtax1_tx;
709
+	                $localtax2_rate = $object->lines[$i]->localtax2_tx;
710
+	                $localtax1_type = $object->lines[$i]->localtax1_type;
711
+	                $localtax2_type = $object->lines[$i]->localtax2_type;
712 712
 
713
-	                if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
714
-	                if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
715
-	                if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
713
+	                if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
714
+	                if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
715
+	                if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
716 716
 
717
-	                $vatrate=(string) $object->lines[$i]->tva_tx;
717
+	                $vatrate = (string) $object->lines[$i]->tva_tx;
718 718
 
719 719
 	                // Retrieve type from database for backward compatibility with old records
720
-	                if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
721
-	                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
720
+	                if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
721
+	                    && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
722 722
 	                {
723
-	                    $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
723
+	                    $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
724 724
 	                    $localtax1_type = $localtaxtmp_array[0];
725 725
 	                    $localtax2_type = $localtaxtmp_array[2];
726 726
 	                }
727 727
 
728 728
 	                // retrieve global local tax
729 729
 	                if ($localtax1_type && $localtax1ligne != 0)
730
-	                    $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
730
+	                    $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
731 731
 	                    if ($localtax2_type && $localtax2ligne != 0)
732
-	                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
732
+	                        $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
733 733
 
734
-	                        if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
735
-	                        if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
734
+	                        if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
735
+	                        if (!isset($this->tva[$vatrate])) 				$this->tva[$vatrate] = 0;
736 736
 	                        $this->tva[$vatrate] += $tvaligne;
737 737
 
738
-	                        $nexY = max($nexY,$posYAfterImage);
738
+	                        $nexY = max($nexY, $posYAfterImage);
739 739
 
740 740
 	                        // Add line
741
-	                        if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
741
+	                        if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
742 742
 	                        {
743 743
 	                            $pdf->setPage($pageposafter);
744
-	                            $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
744
+	                            $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
745 745
 	                            //$pdf->SetDrawColor(190,190,200);
746
-	                            $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
746
+	                            $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
747 747
 	                            $pdf->SetLineStyle(array('dash'=>0));
748 748
 	                        }
749 749
 
750
-	                        $nexY+=2;    // Passe espace entre les lignes
750
+	                        $nexY += 2; // Passe espace entre les lignes
751 751
 
752 752
 	                        // Detect if some page were added automatically and output _tableau for past pages
753 753
 	                        while ($pagenb < $pageposafter)
@@ -761,14 +761,14 @@  discard block
 block discarded – undo
761 761
 	                            {
762 762
 	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
763 763
 	                            }
764
-	                            $this->_pagefoot($pdf,$object,$outputlangs,1);
764
+	                            $this->_pagefoot($pdf, $object, $outputlangs, 1);
765 765
 	                            $pagenb++;
766 766
 	                            $pdf->setPage($pagenb);
767
-	                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
767
+	                            $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
768 768
 	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
769 769
 	                        }
770 770
 
771
-	                        if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
771
+	                        if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
772 772
 	                        {
773 773
 	                            if ($pagenb == $pageposafter)
774 774
 	                            {
@@ -778,10 +778,10 @@  discard block
 block discarded – undo
778 778
 	                            {
779 779
 	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
780 780
 	                            }
781
-	                            $this->_pagefoot($pdf,$object,$outputlangs,1);
781
+	                            $this->_pagefoot($pdf, $object, $outputlangs, 1);
782 782
 	                            // New page
783 783
 	                            $pdf->AddPage();
784
-	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
784
+	                            if (!empty($tplidx)) $pdf->useTemplate($tplidx);
785 785
 	                            $pagenb++;
786 786
 	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
787 787
 	                        }
@@ -791,56 +791,56 @@  discard block
 block discarded – undo
791 791
 	            if ($pagenb == $pageposbeforeprintlines)
792 792
 	            {
793 793
 	                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
794
-	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
794
+	                $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
795 795
 	            }
796 796
 	            else
797 797
 	            {
798 798
 	                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
799
-	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
799
+	                $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
800 800
 	            }
801 801
 
802 802
 	            // Affiche zone infos
803
-	            $posy=$this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
803
+	            $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
804 804
 
805 805
 	            // Affiche zone totaux
806
-	            $posy=$this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
806
+	            $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
807 807
 
808 808
 	            // Affiche zone versements
809 809
 	            if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
810 810
 	            {
811
-	                $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
811
+	                $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
812 812
 	            }
813 813
 
814 814
 	            // Pied de page
815
-	            $this->_pagefoot($pdf,$object,$outputlangs);
816
-	            if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
815
+	            $this->_pagefoot($pdf, $object, $outputlangs);
816
+	            if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
817 817
 
818 818
 	            $pdf->Close();
819 819
 
820
-	            $pdf->Output($file,'F');
820
+	            $pdf->Output($file, 'F');
821 821
 
822 822
 	            // Add pdfgeneration hook
823 823
 	            $hookmanager->initHooks(array('pdfgeneration'));
824
-	            $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
824
+	            $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
825 825
 	            global $action;
826
-	            $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
826
+	            $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
827 827
 
828
-	            if (! empty($conf->global->MAIN_UMASK))
828
+	            if (!empty($conf->global->MAIN_UMASK))
829 829
 	                @chmod($file, octdec($conf->global->MAIN_UMASK));
830 830
 
831 831
 	                $this->result = array('fullpath'=>$file);
832 832
 
833
-	                return 1;   // No error
833
+	                return 1; // No error
834 834
 	        }
835 835
 	        else
836 836
 	        {
837
-	            $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
837
+	            $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
838 838
 	            return 0;
839 839
 	        }
840 840
 	    }
841 841
 	    else
842 842
 	    {
843
-	        $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
843
+	        $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
844 844
 	        return 0;
845 845
 	    }
846 846
 	}
@@ -859,8 +859,8 @@  discard block
 block discarded – undo
859 859
 	{
860 860
 		global $conf;
861 861
 
862
-        $sign=1;
863
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
862
+        $sign = 1;
863
+        if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
864 864
 
865 865
         $tab3_posx = 120;
866 866
 		$tab3_top = $posy + 8;
@@ -873,113 +873,113 @@  discard block
 block discarded – undo
873 873
 
874 874
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
875 875
 
876
-		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
877
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
876
+		$title = $outputlangs->transnoentities("PaymentsAlreadyDone");
877
+		if ($object->type == 2) $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
878 878
 
879
-		$pdf->SetFont('','', $default_font_size - 3);
879
+		$pdf->SetFont('', '', $default_font_size - 3);
880 880
 		$pdf->SetXY($tab3_posx, $tab3_top - 4);
881 881
 		$pdf->MultiCell(60, 3, $title, 0, 'L', 0);
882 882
 
883
-		$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
883
+		$pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
884 884
 
885
-		$pdf->SetFont('','', $default_font_size - 4);
885
+		$pdf->SetFont('', '', $default_font_size - 4);
886 886
 		$pdf->SetXY($tab3_posx, $tab3_top);
887 887
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
888
-		$pdf->SetXY($tab3_posx+21, $tab3_top);
888
+		$pdf->SetXY($tab3_posx + 21, $tab3_top);
889 889
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
890
-		$pdf->SetXY($tab3_posx+40, $tab3_top);
890
+		$pdf->SetXY($tab3_posx + 40, $tab3_top);
891 891
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
892
-		$pdf->SetXY($tab3_posx+58, $tab3_top);
892
+		$pdf->SetXY($tab3_posx + 58, $tab3_top);
893 893
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
894 894
 
895
-		$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
895
+		$pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
896 896
 
897
-		$y=0;
897
+		$y = 0;
898 898
 
899
-		$pdf->SetFont('','', $default_font_size - 4);
899
+		$pdf->SetFont('', '', $default_font_size - 4);
900 900
 
901 901
 
902 902
 		// Loop on each deposits and credit notes included
903 903
 		$sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
904
-		$sql.= " re.description, re.fk_facture_source,";
905
-		$sql.= " f.type, f.datef";
906
-		$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
907
-		$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
908
-		$resql=$this->db->query($sql);
904
+		$sql .= " re.description, re.fk_facture_source,";
905
+		$sql .= " f.type, f.datef";
906
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
907
+		$sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
908
+		$resql = $this->db->query($sql);
909 909
 		if ($resql)
910 910
 		{
911 911
 			$num = $this->db->num_rows($resql);
912
-			$i=0;
913
-			$invoice=new Facture($this->db);
912
+			$i = 0;
913
+			$invoice = new Facture($this->db);
914 914
 			while ($i < $num)
915 915
 			{
916
-				$y+=3;
916
+				$y += 3;
917 917
 				$obj = $this->db->fetch_object($resql);
918 918
 
919
-				if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
920
-				elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
921
-				else $text=$outputlangs->trans("UnknownType");
919
+				if ($obj->type == 2) $text = $outputlangs->trans("CreditNote");
920
+				elseif ($obj->type == 3) $text = $outputlangs->trans("Deposit");
921
+				else $text = $outputlangs->trans("UnknownType");
922 922
 
923 923
 				$invoice->fetch($obj->fk_facture_source);
924 924
 
925
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
926
-				$pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
927
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
925
+				$pdf->SetXY($tab3_posx, $tab3_top + $y);
926
+				$pdf->MultiCell(20, 3, dol_print_date($obj->datef, 'day', false, $outputlangs, true), 0, 'L', 0);
927
+				$pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
928 928
 				$pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
929
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
929
+				$pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
930 930
 				$pdf->MultiCell(20, 3, $text, 0, 'L', 0);
931
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
931
+				$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
932 932
 				$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
933 933
 
934
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
934
+				$pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
935 935
 
936 936
 				$i++;
937 937
 			}
938 938
 		}
939 939
 		else
940 940
 		{
941
-			$this->error=$this->db->lasterror();
941
+			$this->error = $this->db->lasterror();
942 942
 			return -1;
943 943
 		}
944 944
 
945 945
 		// Loop on each payment
946 946
 		// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
947 947
 		$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
948
-		$sql.= " cp.code";
949
-		$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
950
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
951
-		$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
948
+		$sql .= " cp.code";
949
+		$sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
950
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
951
+		$sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
952 952
 		//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
953
-		$sql.= " ORDER BY p.datep";
953
+		$sql .= " ORDER BY p.datep";
954 954
 
955
-		$resql=$this->db->query($sql);
955
+		$resql = $this->db->query($sql);
956 956
 		if ($resql)
957 957
 		{
958 958
 			$num = $this->db->num_rows($resql);
959
-			$i=0;
959
+			$i = 0;
960 960
 			while ($i < $num) {
961
-				$y+=3;
961
+				$y += 3;
962 962
 				$row = $this->db->fetch_object($resql);
963 963
 
964
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
965
-				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
966
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
964
+				$pdf->SetXY($tab3_posx, $tab3_top + $y);
965
+				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
966
+				$pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
967 967
 				$pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
968
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
969
-				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
968
+				$pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
969
+				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
970 970
 
971 971
 				$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
972
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
972
+				$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
973 973
 				$pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
974 974
 
975
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
975
+				$pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
976 976
 
977 977
 				$i++;
978 978
 			}
979 979
 		}
980 980
 		else
981 981
 		{
982
-			$this->error=$this->db->lasterror();
982
+			$this->error = $this->db->lasterror();
983 983
 			return -1;
984 984
 		}
985 985
 	}
@@ -1000,35 +1000,35 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1002 1002
 
1003
-		$pdf->SetFont('','', $default_font_size - 1);
1003
+		$pdf->SetFont('', '', $default_font_size - 1);
1004 1004
 
1005 1005
 		// If France, show VAT mention if not applicable
1006 1006
 		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
1007 1007
 		{
1008
-			$pdf->SetFont('','B', $default_font_size - 2);
1008
+			$pdf->SetFont('', 'B', $default_font_size - 2);
1009 1009
 			$pdf->SetXY($this->marge_gauche, $posy);
1010 1010
 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1011 1011
 
1012
-			$posy=$pdf->GetY()+4;
1012
+			$posy = $pdf->GetY() + 4;
1013 1013
 		}
1014 1014
 
1015
-		$posxval=52;
1015
+		$posxval = 52;
1016 1016
 
1017 1017
 		// Show payments conditions
1018 1018
 		if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
1019 1019
 		{
1020
-			$pdf->SetFont('','B', $default_font_size - 2);
1020
+			$pdf->SetFont('', 'B', $default_font_size - 2);
1021 1021
 			$pdf->SetXY($this->marge_gauche, $posy);
1022 1022
 			$titre = $outputlangs->transnoentities("PaymentConditions").':';
1023 1023
 			$pdf->MultiCell(43, 4, $titre, 0, 'L');
1024 1024
 
1025
-			$pdf->SetFont('','', $default_font_size - 2);
1025
+			$pdf->SetFont('', '', $default_font_size - 2);
1026 1026
 			$pdf->SetXY($posxval, $posy);
1027
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
1028
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
1029
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
1027
+			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc);
1028
+			$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1029
+			$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1030 1030
 
1031
-			$posy=$pdf->GetY()+3;
1031
+			$posy = $pdf->GetY() + 3;
1032 1032
 		}
1033 1033
 
1034 1034
 		if ($object->type != 2)
@@ -1047,13 +1047,13 @@  discard block
 block discarded – undo
1047 1047
 				$outputlangs->load("errors");
1048 1048
 
1049 1049
 				$pdf->SetXY($this->marge_gauche, $posy);
1050
-				$pdf->SetTextColor(200,0,0);
1051
-				$pdf->SetFont('','B', $default_font_size - 2);
1052
-				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
1053
-				$pdf->MultiCell(80, 3, $this->error,0,'L',0);
1054
-				$pdf->SetTextColor(0,0,0);
1050
+				$pdf->SetTextColor(200, 0, 0);
1051
+				$pdf->SetFont('', 'B', $default_font_size - 2);
1052
+				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1053
+				$pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
1054
+				$pdf->SetTextColor(0, 0, 0);
1055 1055
 
1056
-				$posy=$pdf->GetY()+1;
1056
+				$posy = $pdf->GetY() + 1;
1057 1057
 			}
1058 1058
 
1059 1059
 			// Show payment mode
@@ -1061,26 +1061,26 @@  discard block
 block discarded – undo
1061 1061
 			&& $object->mode_reglement_code != 'CHQ'
1062 1062
 			&& $object->mode_reglement_code != 'VIR')
1063 1063
 			{
1064
-				$pdf->SetFont('','B', $default_font_size - 2);
1064
+				$pdf->SetFont('', 'B', $default_font_size - 2);
1065 1065
 				$pdf->SetXY($this->marge_gauche, $posy);
1066 1066
 				$titre = $outputlangs->transnoentities("PaymentMode").':';
1067 1067
 				$pdf->MultiCell(80, 5, $titre, 0, 'L');
1068 1068
 
1069
-				$pdf->SetFont('','', $default_font_size - 2);
1069
+				$pdf->SetFont('', '', $default_font_size - 2);
1070 1070
 				$pdf->SetXY($posxval, $posy);
1071
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1072
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1071
+				$lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1072
+				$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1073 1073
 
1074
-				$posy=$pdf->GetY()+2;
1074
+				$posy = $pdf->GetY() + 2;
1075 1075
 			}
1076 1076
 
1077 1077
 			// Show payment mode CHQ
1078 1078
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1079 1079
 			{
1080 1080
 				// Si mode reglement non force ou si force a CHQ
1081
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1081
+				if (!empty($conf->global->FACTURE_CHQ_NUMBER))
1082 1082
 				{
1083
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1083
+					$diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1084 1084
 
1085 1085
 					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1086 1086
 					{
@@ -1088,31 +1088,31 @@  discard block
 block discarded – undo
1088 1088
 						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1089 1089
 
1090 1090
 						$pdf->SetXY($this->marge_gauche, $posy);
1091
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1092
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1093
-						$posy=$pdf->GetY()+1;
1091
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1092
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1093
+						$posy = $pdf->GetY() + 1;
1094 1094
 
1095 1095
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1096 1096
 			            {
1097 1097
 							$pdf->SetXY($this->marge_gauche, $posy);
1098
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1098
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1099 1099
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1100
-							$posy=$pdf->GetY()+2;
1100
+							$posy = $pdf->GetY() + 2;
1101 1101
 			            }
1102 1102
 					}
1103 1103
 					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1104 1104
 					{
1105 1105
 						$pdf->SetXY($this->marge_gauche, $posy);
1106
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1107
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1108
-						$posy=$pdf->GetY()+1;
1106
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1107
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1108
+						$posy = $pdf->GetY() + 1;
1109 1109
 
1110 1110
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1111 1111
 			            {
1112 1112
 							$pdf->SetXY($this->marge_gauche, $posy);
1113
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1113
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1114 1114
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1115
-							$posy=$pdf->GetY()+2;
1115
+							$posy = $pdf->GetY() + 2;
1116 1116
 			            }
1117 1117
 					}
1118 1118
 				}
@@ -1121,19 +1121,19 @@  discard block
 block discarded – undo
1121 1121
 			// If payment mode not forced or forced to VIR, show payment with BAN
1122 1122
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1123 1123
 			{
1124
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1124
+				if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER))
1125 1125
 				{
1126
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1127
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1126
+					$bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1127
+					if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1128 1128
 					$account = new Account($this->db);
1129 1129
 					$account->fetch($bankid);
1130 1130
 
1131
-					$curx=$this->marge_gauche;
1132
-					$cury=$posy;
1131
+					$curx = $this->marge_gauche;
1132
+					$cury = $posy;
1133 1133
 
1134
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1134
+					$posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1135 1135
 
1136
-					$posy+=2;
1136
+					$posy += 2;
1137 1137
 				}
1138 1138
 			}
1139 1139
 		}
@@ -1154,47 +1154,47 @@  discard block
 block discarded – undo
1154 1154
 	 */
1155 1155
 	private function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1156 1156
 	{
1157
-		global $conf,$mysoc;
1157
+		global $conf, $mysoc;
1158 1158
 
1159
-        $sign=1;
1160
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1159
+        $sign = 1;
1160
+        if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1161 1161
 
1162 1162
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1163 1163
 
1164 1164
 		$tab2_top = $posy;
1165 1165
 		$tab2_hl = 4;
1166
-		$pdf->SetFont('','', $default_font_size - 1);
1166
+		$pdf->SetFont('', '', $default_font_size - 1);
1167 1167
 
1168 1168
 		// Tableau total
1169 1169
 		$col1x = 120; $col2x = 170;
1170 1170
 		if ($this->page_largeur < 210) // To work with US executive format
1171 1171
 		{
1172
-			$col2x-=20;
1172
+			$col2x -= 20;
1173 1173
 		}
1174 1174
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1175 1175
 
1176
-		$useborder=0;
1176
+		$useborder = 0;
1177 1177
 		$index = 0;
1178 1178
 
1179 1179
 		// Total HT
1180
-		$pdf->SetFillColor(255,255,255);
1180
+		$pdf->SetFillColor(255, 255, 255);
1181 1181
 		$pdf->SetXY($col1x, $tab2_top + 0);
1182
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1182
+		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1183 1183
 
1184 1184
 		$total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1185 1185
 		$pdf->SetXY($col2x, $tab2_top + 0);
1186
-		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1186
+		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1187 1187
 
1188 1188
 		// Show VAT by rates and total
1189
-		$pdf->SetFillColor(248,248,248);
1189
+		$pdf->SetFillColor(248, 248, 248);
1190 1190
 
1191 1191
 		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1192 1192
 
1193
-		$this->atleastoneratenotnull=0;
1193
+		$this->atleastoneratenotnull = 0;
1194 1194
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1195 1195
 		{
1196
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1197
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1196
+			$tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1197
+			if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1198 1198
 			{
1199 1199
 				// Nothing to do
1200 1200
 			}
@@ -1205,29 +1205,29 @@  discard block
 block discarded – undo
1205 1205
 				//Local tax 1 before VAT
1206 1206
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1207 1207
 				//{
1208
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1208
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1209 1209
 					{
1210
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1210
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1211 1211
 
1212
-						foreach( $localtax_rate as $tvakey => $tvaval )
1212
+						foreach ($localtax_rate as $tvakey => $tvaval)
1213 1213
 						{
1214
-							if ($tvakey!=0)    // On affiche pas taux 0
1214
+							if ($tvakey != 0)    // On affiche pas taux 0
1215 1215
 							{
1216 1216
 								//$this->atleastoneratenotnull++;
1217 1217
 
1218 1218
 								$index++;
1219 1219
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1220 1220
 
1221
-								$tvacompl='';
1222
-								if (preg_match('/\*/',$tvakey))
1221
+								$tvacompl = '';
1222
+								if (preg_match('/\*/', $tvakey))
1223 1223
 								{
1224
-									$tvakey=str_replace('*','',$tvakey);
1224
+									$tvakey = str_replace('*', '', $tvakey);
1225 1225
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1226 1226
 								}
1227 1227
 
1228
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1229
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1230
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1228
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1229
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1230
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1231 1231
 
1232 1232
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1233 1233
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1238,13 +1238,13 @@  discard block
 block discarded – undo
1238 1238
 				//Local tax 2 before VAT
1239 1239
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1240 1240
 				//{
1241
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1241
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1242 1242
 					{
1243
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1243
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1244 1244
 
1245
-						foreach( $localtax_rate as $tvakey => $tvaval )
1245
+						foreach ($localtax_rate as $tvakey => $tvaval)
1246 1246
 						{
1247
-							if ($tvakey!=0)    // On affiche pas taux 0
1247
+							if ($tvakey != 0)    // On affiche pas taux 0
1248 1248
 							{
1249 1249
 								//$this->atleastoneratenotnull++;
1250 1250
 
@@ -1253,15 +1253,15 @@  discard block
 block discarded – undo
1253 1253
 								$index++;
1254 1254
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1255 1255
 
1256
-								$tvacompl='';
1257
-								if (preg_match('/\*/',$tvakey))
1256
+								$tvacompl = '';
1257
+								if (preg_match('/\*/', $tvakey))
1258 1258
 								{
1259
-									$tvakey=str_replace('*','',$tvakey);
1259
+									$tvakey = str_replace('*', '', $tvakey);
1260 1260
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1261 1261
 								}
1262
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1263
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1264
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1262
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1263
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1264
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1265 1265
 
1266 1266
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1267 1267
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1276,20 +1276,20 @@  discard block
 block discarded – undo
1276 1276
 				if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1277 1277
 
1278 1278
 					$sum_pdf_tva = 0;
1279
-					foreach($this->tva as $tvakey => $tvaval){
1280
-						$sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1279
+					foreach ($this->tva as $tvakey => $tvaval) {
1280
+						$sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1281 1281
 					}
1282 1282
 
1283
-					if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1283
+					if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1284 1284
 						$coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1285 1285
 
1286
-						foreach($this->tva as $tvakey => $tvaval) {
1287
-							$this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1286
+						foreach ($this->tva as $tvakey => $tvaval) {
1287
+							$this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1288 1288
 						}
1289 1289
 					}
1290 1290
 				}
1291 1291
 
1292
-				foreach($this->tva as $tvakey => $tvaval)
1292
+				foreach ($this->tva as $tvakey => $tvaval)
1293 1293
 				{
1294 1294
 					if ($tvakey != 0)    // On affiche pas taux 0
1295 1295
 					{
@@ -1298,15 +1298,15 @@  discard block
 block discarded – undo
1298 1298
 						$index++;
1299 1299
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1300 1300
 
1301
-						$tvacompl='';
1302
-						if (preg_match('/\*/',$tvakey))
1301
+						$tvacompl = '';
1302
+						if (preg_match('/\*/', $tvakey))
1303 1303
 						{
1304
-							$tvakey=str_replace('*','',$tvakey);
1304
+							$tvakey = str_replace('*', '', $tvakey);
1305 1305
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1306 1306
 						}
1307
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1308
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1309
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1307
+						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1308
+						$totalvat .= vatrate($tvakey, 1).$tvacompl;
1309
+						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1310 1310
 
1311 1311
 						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1312 1312
 						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1316,11 +1316,11 @@  discard block
 block discarded – undo
1316 1316
 				//Local tax 1 after VAT
1317 1317
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1318 1318
 				//{
1319
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1319
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1320 1320
 					{
1321
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1321
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1322 1322
 
1323
-						foreach( $localtax_rate as $tvakey => $tvaval )
1323
+						foreach ($localtax_rate as $tvakey => $tvaval)
1324 1324
 						{
1325 1325
 							if ($tvakey != 0)    // On affiche pas taux 0
1326 1326
 							{
@@ -1329,16 +1329,16 @@  discard block
 block discarded – undo
1329 1329
 								$index++;
1330 1330
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1331 1331
 
1332
-								$tvacompl='';
1333
-								if (preg_match('/\*/',$tvakey))
1332
+								$tvacompl = '';
1333
+								if (preg_match('/\*/', $tvakey))
1334 1334
 								{
1335
-									$tvakey=str_replace('*','',$tvakey);
1335
+									$tvakey = str_replace('*', '', $tvakey);
1336 1336
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1337 1337
 								}
1338
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1339
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1338
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1339
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1340 1340
 
1341
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1341
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1342 1342
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1343 1343
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1344 1344
 							}
@@ -1348,11 +1348,11 @@  discard block
 block discarded – undo
1348 1348
 				//Local tax 2 after VAT
1349 1349
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1350 1350
 				//{
1351
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1351
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1352 1352
 					{
1353
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1353
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1354 1354
 
1355
-						foreach( $localtax_rate as $tvakey => $tvaval )
1355
+						foreach ($localtax_rate as $tvakey => $tvaval)
1356 1356
 						{
1357 1357
 						    // retrieve global local tax
1358 1358
 							if ($tvakey != 0)    // On affiche pas taux 0
@@ -1362,16 +1362,16 @@  discard block
 block discarded – undo
1362 1362
 								$index++;
1363 1363
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1364 1364
 
1365
-								$tvacompl='';
1366
-								if (preg_match('/\*/',$tvakey))
1365
+								$tvacompl = '';
1366
+								if (preg_match('/\*/', $tvakey))
1367 1367
 								{
1368
-									$tvakey=str_replace('*','',$tvakey);
1368
+									$tvakey = str_replace('*', '', $tvakey);
1369 1369
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1370 1370
 								}
1371
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1371
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1372 1372
 
1373
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1374
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1373
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1374
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1375 1375
 
1376 1376
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1377 1377
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
 				{
1386 1386
 					$index++;
1387 1387
 					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1388
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1388
+					$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1389 1389
 
1390 1390
 					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391 1391
 					$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
@@ -1394,29 +1394,29 @@  discard block
 block discarded – undo
1394 1394
 				// Total TTC
1395 1395
 				$index++;
1396 1396
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1397
-				$pdf->SetTextColor(0,0,60);
1398
-				$pdf->SetFillColor(224,224,224);
1399
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1397
+				$pdf->SetTextColor(0, 0, 60);
1398
+				$pdf->SetFillColor(224, 224, 224);
1399
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1400 1400
 
1401 1401
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1402 1402
 				$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1403 1403
 			}
1404 1404
 		}
1405 1405
 
1406
-		$pdf->SetTextColor(0,0,0);
1406
+		$pdf->SetTextColor(0, 0, 0);
1407 1407
 
1408
-		$creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1409
-		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1408
+		$creditnoteamount = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1409
+		$depositsamount = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1410 1410
 		//print "x".$creditnoteamount."-".$depositsamount;exit;
1411 1411
 		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1412
-		if ($object->paye) $resteapayer=0;
1412
+		if ($object->paye) $resteapayer = 0;
1413 1413
 
1414 1414
 		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1415 1415
 		{
1416 1416
 			// Already paid + Deposits
1417 1417
 			$index++;
1418 1418
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1419
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1419
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1420 1420
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1421 1421
 			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1422 1422
 
@@ -1425,7 +1425,7 @@  discard block
 block discarded – undo
1425 1425
 			{
1426 1426
 				$index++;
1427 1427
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1428
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
1428
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
1429 1429
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1430 1430
 				$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1431 1431
 			}
@@ -1434,26 +1434,26 @@  discard block
 block discarded – undo
1434 1434
 			if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1435 1435
 			{
1436 1436
 				$index++;
1437
-				$pdf->SetFillColor(255,255,255);
1437
+				$pdf->SetFillColor(255, 255, 255);
1438 1438
 
1439 1439
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1440
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1440
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1441 1441
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1442 1442
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1443 1443
 
1444
-				$resteapayer=0;
1444
+				$resteapayer = 0;
1445 1445
 			}
1446 1446
 
1447 1447
 			$index++;
1448
-			$pdf->SetTextColor(0,0,60);
1449
-			$pdf->SetFillColor(224,224,224);
1448
+			$pdf->SetTextColor(0, 0, 60);
1449
+			$pdf->SetFillColor(224, 224, 224);
1450 1450
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1451
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1451
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1452 1452
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1453 1453
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1454 1454
 
1455
-			$pdf->SetFont('','', $default_font_size - 1);
1456
-			$pdf->SetTextColor(0,0,0);
1455
+			$pdf->SetFont('', '', $default_font_size - 1);
1456
+			$pdf->SetTextColor(0, 0, 0);
1457 1457
 		}
1458 1458
 
1459 1459
 		$index++;
@@ -1473,61 +1473,61 @@  discard block
 block discarded – undo
1473 1473
 	 *   @param		string		$currency		Currency code
1474 1474
 	 *   @return	void
1475 1475
 	 */
1476
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1476
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1477 1477
 	{
1478 1478
 		global $conf;
1479 1479
 
1480 1480
 		// Force to disable hidetop and hidebottom
1481
-		$hidebottom=0;
1482
-		if ($hidetop) $hidetop=-1;
1481
+		$hidebottom = 0;
1482
+		if ($hidetop) $hidetop = -1;
1483 1483
 
1484 1484
 		$currency = !empty($currency) ? $currency : $conf->currency;
1485 1485
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1486 1486
 
1487 1487
 		// Amount in (at tab_top - 1)
1488
-		$pdf->SetTextColor(0,0,0);
1489
-		$pdf->SetFont('','', $default_font_size - 2);
1488
+		$pdf->SetTextColor(0, 0, 0);
1489
+		$pdf->SetFont('', '', $default_font_size - 2);
1490 1490
 
1491 1491
 		if (empty($hidetop))
1492 1492
 		{
1493
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1494
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1493
+			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1494
+			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1495 1495
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1496 1496
 
1497 1497
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1498
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1498
+			if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1499 1499
 		}
1500 1500
 
1501
-		$pdf->SetDrawColor(128,128,128);
1502
-		$pdf->SetFont('','', $default_font_size - 1);
1501
+		$pdf->SetDrawColor(128, 128, 128);
1502
+		$pdf->SetFont('', '', $default_font_size - 1);
1503 1503
 
1504 1504
 		// Output Rect
1505
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1505
+		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
1506 1506
 
1507 1507
 
1508 1508
 		foreach ($this->cols as $colKey => $colDef)
1509 1509
 		{
1510
-		    if(!$this->getColumnStatus($colKey)) continue;
1510
+		    if (!$this->getColumnStatus($colKey)) continue;
1511 1511
 
1512 1512
 		    // get title label
1513
-		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
1513
+		    $colDef['title']['label'] = !empty($colDef['title']['label']) ? $colDef['title']['label'] : $outputlangs->transnoentities($colDef['title']['textkey']);
1514 1514
 
1515 1515
 		    // Add column separator
1516
-		    if(!empty($colDef['border-left'])){
1516
+		    if (!empty($colDef['border-left'])) {
1517 1517
 		        $pdf->line($colDef['xStartPos'], $tab_top, $colDef['xStartPos'], $tab_top + $tab_height);
1518 1518
 		    }
1519 1519
 
1520 1520
 		    if (empty($hidetop))
1521 1521
 		    {
1522
-		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0] );
1522
+		      $pdf->SetXY($colDef['xStartPos'] + $colDef['title']['padding'][3], $tab_top + $colDef['title']['padding'][0]);
1523 1523
 
1524
-		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] -$colDef['title']['padding'][1];
1525
-		      $pdf->MultiCell($textWidth,2,$colDef['title']['label'],'',$colDef['title']['align']);
1524
+		      $textWidth = $colDef['width'] - $colDef['title']['padding'][3] - $colDef['title']['padding'][1];
1525
+		      $pdf->MultiCell($textWidth, 2, $colDef['title']['label'], '', $colDef['title']['align']);
1526 1526
 		    }
1527 1527
 		}
1528 1528
 
1529
-		if (empty($hidetop)){
1530
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1529
+		if (empty($hidetop)) {
1530
+			$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line prend une position y en 2eme param et 4eme param
1531 1531
 		}
1532 1532
 	}
1533 1533
 
@@ -1549,162 +1549,162 @@  discard block
 block discarded – undo
1549 1549
 
1550 1550
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1551 1551
 
1552
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1552
+		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1553 1553
 
1554 1554
 		// Show Draft Watermark
1555
-		if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1555
+		if ($object->statut == Facture::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK)))
1556 1556
         {
1557
-		      pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1557
+		      pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
1558 1558
         }
1559 1559
 
1560
-		$pdf->SetTextColor(0,0,60);
1561
-		$pdf->SetFont('','B', $default_font_size + 3);
1560
+		$pdf->SetTextColor(0, 0, 60);
1561
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1562 1562
 
1563 1563
 		$w = 110;
1564 1564
 
1565
-		$posy=$this->marge_haute;
1566
-        $posx=$this->page_largeur-$this->marge_droite-$w;
1565
+		$posy = $this->marge_haute;
1566
+        $posx = $this->page_largeur - $this->marge_droite - $w;
1567 1567
 
1568
-		$pdf->SetXY($this->marge_gauche,$posy);
1568
+		$pdf->SetXY($this->marge_gauche, $posy);
1569 1569
 
1570 1570
 		// Logo
1571 1571
 		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1572 1572
 		{
1573
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1573
+			$logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1574 1574
 			if ($this->emetteur->logo)
1575 1575
 			{
1576 1576
 				if (is_readable($logo))
1577 1577
 				{
1578
-				    $height=pdf_getHeightForLogo($logo);
1579
-					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1578
+				    $height = pdf_getHeightForLogo($logo);
1579
+					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1580 1580
 				}
1581 1581
 				else
1582 1582
 				{
1583
-					$pdf->SetTextColor(200,0,0);
1584
-					$pdf->SetFont('','B',$default_font_size - 2);
1585
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1583
+					$pdf->SetTextColor(200, 0, 0);
1584
+					$pdf->SetFont('', 'B', $default_font_size - 2);
1585
+					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1586 1586
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1587 1587
 				}
1588 1588
 			}
1589 1589
 			else
1590 1590
 			{
1591
-				$text=$this->emetteur->name;
1591
+				$text = $this->emetteur->name;
1592 1592
 				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1593 1593
 			}
1594 1594
 		}
1595 1595
 
1596
-		$pdf->SetFont('','B', $default_font_size + 3);
1597
-		$pdf->SetXY($posx,$posy);
1598
-		$pdf->SetTextColor(0,0,60);
1599
-		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1600
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1601
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1602
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1603
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1604
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1596
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1597
+		$pdf->SetXY($posx, $posy);
1598
+		$pdf->SetTextColor(0, 0, 60);
1599
+		$title = $outputlangs->transnoentities("PdfInvoiceTitle");
1600
+		if ($object->type == 1) $title = $outputlangs->transnoentities("InvoiceReplacement");
1601
+		if ($object->type == 2) $title = $outputlangs->transnoentities("InvoiceAvoir");
1602
+		if ($object->type == 3) $title = $outputlangs->transnoentities("InvoiceDeposit");
1603
+		if ($object->type == 4) $title = $outputlangs->transnoentities("InvoiceProForma");
1604
+		if ($this->situationinvoice) $title = $outputlangs->transnoentities("InvoiceSituation");
1605 1605
 		$pdf->MultiCell($w, 3, $title, '', 'R');
1606 1606
 
1607
-		$pdf->SetFont('','B',$default_font_size);
1607
+		$pdf->SetFont('', 'B', $default_font_size);
1608 1608
 
1609
-		$posy+=5;
1610
-		$pdf->SetXY($posx,$posy);
1611
-		$pdf->SetTextColor(0,0,60);
1612
-		$textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1609
+		$posy += 5;
1610
+		$pdf->SetXY($posx, $posy);
1611
+		$pdf->SetTextColor(0, 0, 60);
1612
+		$textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1613 1613
 		if ($object->statut == Facture::STATUS_DRAFT)
1614 1614
 		{
1615
-			$pdf->SetTextColor(128,0,0);
1616
-			$textref.=' - '.$outputlangs->transnoentities("NotValidated");
1615
+			$pdf->SetTextColor(128, 0, 0);
1616
+			$textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1617 1617
 		}
1618 1618
 		$pdf->MultiCell($w, 4, $textref, '', 'R');
1619 1619
 
1620
-		$posy+=1;
1621
-		$pdf->SetFont('','', $default_font_size - 2);
1620
+		$posy += 1;
1621
+		$pdf->SetFont('', '', $default_font_size - 2);
1622 1622
 
1623 1623
 		if ($object->ref_client)
1624 1624
 		{
1625
-			$posy+=4;
1626
-			$pdf->SetXY($posx,$posy);
1627
-			$pdf->SetTextColor(0,0,60);
1628
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1625
+			$posy += 4;
1626
+			$pdf->SetXY($posx, $posy);
1627
+			$pdf->SetTextColor(0, 0, 60);
1628
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1629 1629
 		}
1630 1630
 
1631
-		$objectidnext=$object->getIdReplacingInvoice('validated');
1631
+		$objectidnext = $object->getIdReplacingInvoice('validated');
1632 1632
 		if ($object->type == 0 && $objectidnext)
1633 1633
 		{
1634
-			$objectreplacing=new Facture($this->db);
1634
+			$objectreplacing = new Facture($this->db);
1635 1635
 			$objectreplacing->fetch($objectidnext);
1636 1636
 
1637
-			$posy+=3;
1638
-			$pdf->SetXY($posx,$posy);
1639
-			$pdf->SetTextColor(0,0,60);
1637
+			$posy += 3;
1638
+			$pdf->SetXY($posx, $posy);
1639
+			$pdf->SetTextColor(0, 0, 60);
1640 1640
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1641 1641
 		}
1642 1642
 		if ($object->type == 1)
1643 1643
 		{
1644
-			$objectreplaced=new Facture($this->db);
1644
+			$objectreplaced = new Facture($this->db);
1645 1645
 			$objectreplaced->fetch($object->fk_facture_source);
1646 1646
 
1647
-			$posy+=4;
1648
-			$pdf->SetXY($posx,$posy);
1649
-			$pdf->SetTextColor(0,0,60);
1647
+			$posy += 4;
1648
+			$pdf->SetXY($posx, $posy);
1649
+			$pdf->SetTextColor(0, 0, 60);
1650 1650
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1651 1651
 		}
1652 1652
 		if ($object->type == 2 && !empty($object->fk_facture_source))
1653 1653
 		{
1654
-			$objectreplaced=new Facture($this->db);
1654
+			$objectreplaced = new Facture($this->db);
1655 1655
 			$objectreplaced->fetch($object->fk_facture_source);
1656 1656
 
1657
-			$posy+=3;
1658
-			$pdf->SetXY($posx,$posy);
1659
-			$pdf->SetTextColor(0,0,60);
1657
+			$posy += 3;
1658
+			$pdf->SetXY($posx, $posy);
1659
+			$pdf->SetTextColor(0, 0, 60);
1660 1660
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1661 1661
 		}
1662 1662
 
1663
-		$posy+=4;
1664
-		$pdf->SetXY($posx,$posy);
1665
-		$pdf->SetTextColor(0,0,60);
1666
-		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1663
+		$posy += 4;
1664
+		$pdf->SetXY($posx, $posy);
1665
+		$pdf->SetTextColor(0, 0, 60);
1666
+		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : ".dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
1667 1667
 
1668
-		if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1668
+		if (!empty($conf->global->INVOICE_POINTOFTAX_DATE))
1669 1669
 		{
1670
-			$posy+=4;
1671
-			$pdf->SetXY($posx,$posy);
1672
-			$pdf->SetTextColor(0,0,60);
1673
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1670
+			$posy += 4;
1671
+			$pdf->SetXY($posx, $posy);
1672
+			$pdf->SetTextColor(0, 0, 60);
1673
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
1674 1674
 		}
1675 1675
 
1676 1676
 		if ($object->type != 2)
1677 1677
 		{
1678
-			$posy+=3;
1679
-			$pdf->SetXY($posx,$posy);
1680
-			$pdf->SetTextColor(0,0,60);
1681
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1678
+			$posy += 3;
1679
+			$pdf->SetXY($posx, $posy);
1680
+			$pdf->SetTextColor(0, 0, 60);
1681
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
1682 1682
 		}
1683 1683
 
1684 1684
 		if ($object->thirdparty->code_client)
1685 1685
 		{
1686
-			$posy+=3;
1687
-			$pdf->SetXY($posx,$posy);
1688
-			$pdf->SetTextColor(0,0,60);
1689
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1686
+			$posy += 3;
1687
+			$pdf->SetXY($posx, $posy);
1688
+			$pdf->SetTextColor(0, 0, 60);
1689
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1690 1690
 		}
1691 1691
 
1692 1692
 		// Get contact
1693 1693
 		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1694 1694
 		{
1695
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1695
+		    $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1696 1696
 		    if (count($arrayidcontact) > 0)
1697 1697
 		    {
1698
-		        $usertmp=new User($this->db);
1698
+		        $usertmp = new User($this->db);
1699 1699
 		        $usertmp->fetch($arrayidcontact[0]);
1700
-                $posy+=4;
1701
-                $pdf->SetXY($posx,$posy);
1702
-		        $pdf->SetTextColor(0,0,60);
1700
+                $posy += 4;
1701
+                $pdf->SetXY($posx, $posy);
1702
+		        $pdf->SetTextColor(0, 0, 60);
1703 1703
 		        $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1704 1704
 		    }
1705 1705
 		}
1706 1706
 
1707
-		$posy+=1;
1707
+		$posy += 1;
1708 1708
 
1709 1709
 		$top_shift = 0;
1710 1710
 		// Show list of linked objects
@@ -1721,43 +1721,43 @@  discard block
 block discarded – undo
1721 1721
 			$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1722 1722
 
1723 1723
 			// Show sender
1724
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1725
-			$posy+=$top_shift;
1726
-			$posx=$this->marge_gauche;
1727
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1724
+			$posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1725
+			$posy += $top_shift;
1726
+			$posx = $this->marge_gauche;
1727
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1728 1728
 
1729
-			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1730
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1729
+			$hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1730
+			$widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1731 1731
 
1732 1732
 
1733 1733
 			// Show sender frame
1734
-			$pdf->SetTextColor(0,0,0);
1735
-			$pdf->SetFont('','', $default_font_size - 2);
1736
-			$pdf->SetXY($posx,$posy-5);
1737
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1738
-			$pdf->SetXY($posx,$posy);
1739
-			$pdf->SetFillColor(230,230,230);
1734
+			$pdf->SetTextColor(0, 0, 0);
1735
+			$pdf->SetFont('', '', $default_font_size - 2);
1736
+			$pdf->SetXY($posx, $posy - 5);
1737
+			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1738
+			$pdf->SetXY($posx, $posy);
1739
+			$pdf->SetFillColor(230, 230, 230);
1740 1740
 			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1741
-			$pdf->SetTextColor(0,0,60);
1741
+			$pdf->SetTextColor(0, 0, 60);
1742 1742
 
1743 1743
 			// Show sender name
1744
-			$pdf->SetXY($posx+2,$posy+3);
1745
-			$pdf->SetFont('','B', $default_font_size);
1746
-			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1747
-			$posy=$pdf->getY();
1744
+			$pdf->SetXY($posx + 2, $posy + 3);
1745
+			$pdf->SetFont('', 'B', $default_font_size);
1746
+			$pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1747
+			$posy = $pdf->getY();
1748 1748
 
1749 1749
 			// Show sender information
1750
-			$pdf->SetXY($posx+2,$posy);
1751
-			$pdf->SetFont('','', $default_font_size - 1);
1752
-			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1750
+			$pdf->SetXY($posx + 2, $posy);
1751
+			$pdf->SetFont('', '', $default_font_size - 1);
1752
+			$pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1753 1753
 
1754 1754
 			// If BILLING contact defined on invoice, we use it
1755
-			$usecontact=false;
1756
-			$arrayidcontact=$object->getIdContact('external','BILLING');
1755
+			$usecontact = false;
1756
+			$arrayidcontact = $object->getIdContact('external', 'BILLING');
1757 1757
 			if (count($arrayidcontact) > 0)
1758 1758
 			{
1759
-				$usecontact=true;
1760
-				$result=$object->fetch_contact($arrayidcontact[0]);
1759
+				$usecontact = true;
1760
+				$result = $object->fetch_contact($arrayidcontact[0]);
1761 1761
 			}
1762 1762
 
1763 1763
 			//Recipient name
@@ -1768,39 +1768,39 @@  discard block
 block discarded – undo
1768 1768
 				$thirdparty = $object->thirdparty;
1769 1769
 			}
1770 1770
 
1771
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1771
+			$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1772 1772
 
1773
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1773
+			$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1774 1774
 
1775 1775
 			// Show recipient
1776
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1777
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1778
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1779
-			$posy+=$top_shift;
1780
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1781
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1776
+			$widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1777
+			if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1778
+			$posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1779
+			$posy += $top_shift;
1780
+			$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1781
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1782 1782
 
1783 1783
 			// Show recipient frame
1784
-			$pdf->SetTextColor(0,0,0);
1785
-			$pdf->SetFont('','', $default_font_size - 2);
1786
-			$pdf->SetXY($posx+2,$posy-5);
1787
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1784
+			$pdf->SetTextColor(0, 0, 0);
1785
+			$pdf->SetFont('', '', $default_font_size - 2);
1786
+			$pdf->SetXY($posx + 2, $posy - 5);
1787
+			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1788 1788
 			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1789 1789
 
1790 1790
 			// Show recipient name
1791
-			$pdf->SetXY($posx+2,$posy+3);
1792
-			$pdf->SetFont('','B', $default_font_size);
1791
+			$pdf->SetXY($posx + 2, $posy + 3);
1792
+			$pdf->SetFont('', 'B', $default_font_size);
1793 1793
 			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1794 1794
 
1795 1795
 			$posy = $pdf->getY();
1796 1796
 
1797 1797
 			// Show recipient information
1798
-			$pdf->SetFont('','', $default_font_size - 1);
1799
-			$pdf->SetXY($posx+2,$posy);
1798
+			$pdf->SetFont('', '', $default_font_size - 1);
1799
+			$pdf->SetXY($posx + 2, $posy);
1800 1800
 			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1801 1801
 		}
1802 1802
 
1803
-		$pdf->SetTextColor(0,0,0);
1803
+		$pdf->SetTextColor(0, 0, 0);
1804 1804
 		return $top_shift;
1805 1805
 	}
1806 1806
 
@@ -1813,11 +1813,11 @@  discard block
 block discarded – undo
1813 1813
 	 *      @param	int			$hidefreetext		1=Hide free text
1814 1814
 	 *      @return	int								Return height of bottom margin including footer text
1815 1815
 	 */
1816
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1816
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1817 1817
 	{
1818 1818
 		global $conf;
1819
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1820
-		return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1819
+		$showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1820
+		return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1821 1821
 	}
1822 1822
 
1823 1823
 	/**
@@ -1830,20 +1830,20 @@  discard block
 block discarded – undo
1830 1830
      *      @param	int			   $hideref			Do not show ref
1831 1831
 	 *      @return	null
1832 1832
 	 */
1833
-    function defineColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0)
1833
+    function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1834 1834
     {
1835 1835
 	    global $conf, $hookmanager;
1836 1836
 
1837 1837
 	    // Default field style for content
1838 1838
 	    $this->defaultContentsFieldsStyle = array(
1839 1839
 	        'align' => 'R', // R,C,L
1840
-	        'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1840
+	        'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1841 1841
 	    );
1842 1842
 
1843 1843
 	    // Default field style for content
1844 1844
 	    $this->defaultTitlesFieldsStyle = array(
1845 1845
 	        'align' => 'C', // R,C,L
1846
-	        'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1846
+	        'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1847 1847
 	    );
1848 1848
 
1849 1849
 	    /*
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
 	    );
1865 1865
 	    */
1866 1866
 
1867
-	    $rank=0; // do not use negative rank
1867
+	    $rank = 0; // do not use negative rank
1868 1868
 	    $this->cols['desc'] = array(
1869 1869
 	        'rank' => $rank,
1870 1870
 	        'width' => false, // only for desc
@@ -1874,7 +1874,7 @@  discard block
 block discarded – undo
1874 1874
 	            'align' => 'L',
1875 1875
 	            // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1876 1876
 	            // 'label' => ' ', // the final label
1877
-	            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1877
+	            'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1878 1878
 	        ),
1879 1879
 	        'content' => array(
1880 1880
 	            'align' => 'L',
@@ -1885,19 +1885,19 @@  discard block
 block discarded – undo
1885 1885
         $rank = $rank + 10;
1886 1886
         $this->cols['photo'] = array(
1887 1887
             'rank' => $rank,
1888
-            'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1888
+            'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1889 1889
             'status' => false,
1890 1890
             'title' => array(
1891 1891
                 'textkey' => 'Photo',
1892 1892
                 'label' => ' '
1893 1893
             ),
1894 1894
             'content' => array(
1895
-                'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1895
+                'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1896 1896
             ),
1897 1897
             'border-left' => false, // remove left line separator
1898 1898
         );
1899 1899
 
1900
-	    if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto))
1900
+	    if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto))
1901 1901
 	    {
1902 1902
 	        $this->cols['photo']['status'] = true;
1903 1903
 	    }
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
 	        'border-left' => true, // add left line separator
1953 1953
 	    );
1954 1954
 
1955
-	    if($this->situationinvoice)
1955
+	    if ($this->situationinvoice)
1956 1956
 	    {
1957 1957
 	        $this->cols['progress']['status'] = true;
1958 1958
 	    }
@@ -1967,7 +1967,7 @@  discard block
 block discarded – undo
1967 1967
 	        ),
1968 1968
 	        'border-left' => true, // add left line separator
1969 1969
 	    );
1970
-	    if($conf->global->PRODUCT_USE_UNITS){
1970
+	    if ($conf->global->PRODUCT_USE_UNITS) {
1971 1971
 	        $this->cols['unit']['status'] = true;
1972 1972
 	    }
1973 1973
 
@@ -1981,7 +1981,7 @@  discard block
 block discarded – undo
1981 1981
 	        ),
1982 1982
 	        'border-left' => true, // add left line separator
1983 1983
 	    );
1984
-	    if ($this->atleastonediscount){
1984
+	    if ($this->atleastonediscount) {
1985 1985
 	        $this->cols['discount']['status'] = true;
1986 1986
 	    }
1987 1987
 
@@ -1997,7 +1997,7 @@  discard block
 block discarded – undo
1997 1997
 	    );
1998 1998
 
1999 1999
 
2000
-	    $parameters=array(
2000
+	    $parameters = array(
2001 2001
 	        'object' => $object,
2002 2002
 	        'outputlangs' => $outputlangs,
2003 2003
 	        'hidedetails' => $hidedetails,
@@ -2005,7 +2005,7 @@  discard block
 block discarded – undo
2005 2005
 	        'hideref' => $hideref
2006 2006
 	    );
2007 2007
 
2008
-	    $reshook=$hookmanager->executeHooks('defineColumnField',$parameters,$this);    // Note that $object may have been modified by hook
2008
+	    $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2009 2009
 	    if ($reshook < 0)
2010 2010
 	    {
2011 2011
 	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Please login to merge, or discard this patch.
Braces   +233 added lines, -116 removed lines patch added patch discarded remove patch
@@ -144,7 +144,10 @@  discard block
 block discarded – undo
144 144
 
145 145
 		// Get source company
146 146
 		$this->emetteur=$mysoc;
147
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
147
+		if (empty($this->emetteur->country_code)) {
148
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
149
+		}
150
+		// By default, if was not defined
148 151
 
149 152
 		// Define position of columns
150 153
 		$this->posxdesc=$this->marge_gauche+1; // used for notes ans other stuff
@@ -177,9 +180,13 @@  discard block
 block discarded – undo
177 180
 	    // phpcs:enable
178 181
 	    global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
179 182
 
180
-	    if (! is_object($outputlangs)) $outputlangs=$langs;
183
+	    if (! is_object($outputlangs)) {
184
+	        $outputlangs=$langs;
185
+	    }
181 186
 	    // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
182
-	    if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
187
+	    if (! empty($conf->global->MAIN_USE_FPDF)) {
188
+	        $outputlangs->charset_output='ISO-8859-1';
189
+	    }
183 190
 
184 191
 	    // Translations
185 192
 	    $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
@@ -195,7 +202,9 @@  discard block
 block discarded – undo
195 202
 
196 203
 	        for ($i = 0 ; $i < $nblignes ; $i++)
197 204
 	        {
198
-	            if (empty($object->lines[$i]->fk_product)) continue;
205
+	            if (empty($object->lines[$i]->fk_product)) {
206
+	                continue;
207
+	            }
199 208
 
200 209
 	            $objphoto->fetch($object->lines[$i]->fk_product);
201 210
 	            //var_dump($objphoto->ref);exit;
@@ -203,8 +212,7 @@  discard block
 block discarded – undo
203 212
 	            {
204 213
 	                $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
205 214
 	                $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
206
-	            }
207
-	            else
215
+	            } else
208 216
 	            {
209 217
 	                $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';				// default
210 218
 	                $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";	// alternative
@@ -219,18 +227,18 @@  discard block
 block discarded – undo
219 227
 
220 228
 	                    foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
221 229
 	                    {
222
-	                        if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
230
+	                        if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
231
+	                            // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
223 232
 	                        {
224 233
 	                            if ($obj['photo_vignette'])
225 234
 	                            {
226 235
 	                                $filename= $obj['photo_vignette'];
227
-	                            }
228
-	                            else
236
+	                        }
237
+	                            } else
229 238
 	                            {
230 239
 	                                $filename=$obj['photo'];
231 240
 	                            }
232
-	                        }
233
-	                        else
241
+	                        } else
234 242
 	                        {
235 243
 	                            $filename=$obj['photo'];
236 244
 	                        }
@@ -242,7 +250,9 @@  discard block
 block discarded – undo
242 250
 	                }
243 251
 	            }
244 252
 
245
-	            if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
253
+	            if ($realpath && $arephoto) {
254
+	                $realpatharray[$i]=$realpath;
255
+	            }
246 256
 	        }
247 257
 	    }
248 258
 
@@ -261,8 +271,7 @@  discard block
 block discarded – undo
261 271
 	        {
262 272
 	            $dir = $conf->facture->dir_output;
263 273
 	            $file = $dir . "/SPECIMEN.pdf";
264
-	        }
265
-	        else
274
+	        } else
266 275
 	        {
267 276
 	            $objectref = dol_sanitizeFileName($object->ref);
268 277
 	            $dir = $conf->facture->dir_output . "/" . $objectref;
@@ -326,7 +335,9 @@  discard block
 block discarded – undo
326 335
 	            $pdf->SetCreator("Dolibarr ".DOL_VERSION);
327 336
 	            $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
328 337
 	            $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
329
-	            if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
338
+	            if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
339
+	                $pdf->SetCompression(false);
340
+	            }
330 341
 
331 342
 	            $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
332 343
 
@@ -347,7 +358,9 @@  discard block
 block discarded – undo
347 358
 
348 359
 	            // New page
349 360
 	            $pdf->AddPage();
350
-	            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
361
+	            if (! empty($tplidx)) {
362
+	                $pdf->useTemplate($tplidx);
363
+	            }
351 364
 	            $pagenb++;
352 365
 
353 366
 	            $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
@@ -359,7 +372,9 @@  discard block
 block discarded – undo
359 372
 	            $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
360 373
 	            $tab_height = 130-$top_shift;
361 374
 	            $tab_height_newpage = 150;
362
-	            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift;
375
+	            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
376
+	                $tab_height_newpage -= $top_shift;
377
+	            }
363 378
 
364 379
 	            // Incoterm
365 380
 	            $height_incoterms = 0;
@@ -394,7 +409,9 @@  discard block
 block discarded – undo
394 409
 	                    $salereparray=$object->thirdparty->getSalesRepresentatives($user);
395 410
 	                    $salerepobj=new User($this->db);
396 411
 	                    $salerepobj->fetch($salereparray[0]['id']);
397
-	                    if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
412
+	                    if (! empty($salerepobj->signature)) {
413
+	                        $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
414
+	                    }
398 415
 	                }
399 416
 	            }
400 417
 
@@ -427,8 +444,12 @@  discard block
 block discarded – undo
427 444
 	                    while ($pagenb < $pageposafternote) {
428 445
 	                        $pdf->AddPage();
429 446
 	                        $pagenb++;
430
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
431
-	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
447
+	                        if (! empty($tplidx)) {
448
+	                            $pdf->useTemplate($tplidx);
449
+	                        }
450
+	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
451
+	                            $this->_pagehead($pdf, $object, 0, $outputlangs);
452
+	                        }
432 453
 	                        // $this->_pagefoot($pdf,$object,$outputlangs,1);
433 454
 	                        $pdf->setTopMargin($tab_top_newpage);
434 455
 	                        // The only function to edit the bottom margin of current page to set it.
@@ -444,9 +465,11 @@  discard block
 block discarded – undo
444 465
 
445 466
 	                    $posyafter = $pdf->GetY();
446 467
 
447
-	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20)))	// There is no space left for total+free text
468
+	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+20))) {
469
+	                        // There is no space left for total+free text
448 470
 	                    {
449 471
 	                        $pdf->AddPage('','',true);
472
+	                    }
450 473
 	                        $pagenb++;
451 474
 	                        $pageposafternote++;
452 475
 	                        $pdf->setPage($pageposafternote);
@@ -468,8 +491,7 @@  discard block
 block discarded – undo
468 491
 	                        if($i>$pageposbeforenote){
469 492
 	                            $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
470 493
 	                            $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note + 1);
471
-	                        }
472
-	                        else{
494
+	                        } else{
473 495
 	                            $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
474 496
 	                            $pdf->Rect($this->marge_gauche, $tab_top-1, $tab_width, $height_note + 1);
475 497
 	                        }
@@ -483,12 +505,15 @@  discard block
 block discarded – undo
483 505
 
484 506
 	                    // apply note frame to last page
485 507
 	                    $pdf->setPage($pageposafternote);
486
-	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
-	                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
508
+	                    if (! empty($tplidx)) {
509
+	                        $pdf->useTemplate($tplidx);
510
+	                    }
511
+	                    if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
512
+	                        $this->_pagehead($pdf, $object, 0, $outputlangs);
513
+	                    }
488 514
 	                    $height_note=$posyafter-$tab_top_newpage;
489 515
 	                    $pdf->Rect($this->marge_gauche, $tab_top_newpage-1, $tab_width, $height_note+1);
490
-	                }
491
-	                else // No pagebreak
516
+	                } else // No pagebreak
492 517
 	                {
493 518
 	                    $pdf->commitTransaction();
494 519
 	                    $posyafter = $pdf->GetY();
@@ -503,8 +528,12 @@  discard block
 block discarded – undo
503 528
 	                        $pagenb++;
504 529
 	                        $pageposafternote++;
505 530
 	                        $pdf->setPage($pageposafternote);
506
-	                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
507
-	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
531
+	                        if (! empty($tplidx)) {
532
+	                            $pdf->useTemplate($tplidx);
533
+	                        }
534
+	                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
535
+	                            $this->_pagehead($pdf, $object, 0, $outputlangs);
536
+	                        }
508 537
 
509 538
 	                        $posyafter = $tab_top_newpage;
510 539
 	                    }
@@ -512,8 +541,7 @@  discard block
 block discarded – undo
512 541
 
513 542
 	                $tab_height = $tab_height - $height_note;
514 543
 	                $tab_top = $posyafter +6;
515
-	            }
516
-	            else
544
+	            } else
517 545
 	            {
518 546
 	                $height_note=0;
519 547
 	            }
@@ -537,7 +565,9 @@  discard block
 block discarded – undo
537 565
 
538 566
 	                // Define size of image if we need it
539 567
 	                $imglinesize=array();
540
-	                if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
568
+	                if (! empty($realpatharray[$i])) {
569
+	                    $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
570
+	                }
541 571
 
542 572
 	                $pdf->setTopMargin($tab_top_newpage);
543 573
 	                $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
@@ -550,10 +580,14 @@  discard block
 block discarded – undo
550 580
 	                if($this->getColumnStatus('photo'))
551 581
 	                {
552 582
     	                // We start with Photo of product line
553
-    	                if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
583
+    	                if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) {
584
+    	                    // If photo too high, we moved completely on new page
554 585
     	                {
555 586
     	                    $pdf->AddPage('','',true);
556
-    	                    if (! empty($tplidx)) $pdf->useTemplate($tplidx);
587
+    	                }
588
+    	                    if (! empty($tplidx)) {
589
+    	                        $pdf->useTemplate($tplidx);
590
+    	                    }
557 591
     	                    $pdf->setPage($pageposbefore+1);
558 592
 
559 593
     	                    $curY = $tab_top_newpage;
@@ -574,9 +608,11 @@  discard block
 block discarded – undo
574 608
     	                $pdf->startTransaction();
575 609
     	                pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->getColumnContentWidth('desc'),3,$this->getColumnContentXStart('desc'),$curY,$hideref,$hidedesc);
576 610
     	                $pageposafter=$pdf->getPage();
577
-    	                if ($pageposafter > $pageposbefore)	// There is a pagebreak
611
+    	                if ($pageposafter > $pageposbefore) {
612
+    	                    // There is a pagebreak
578 613
     	                {
579 614
     	                    $pdf->rollbackTransaction(true);
615
+    	                }
580 616
     	                    $pageposafter=$pageposbefore;
581 617
     	                    //print $pageposafter.'-'.$pageposbefore;exit;
582 618
     	                    $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
@@ -584,22 +620,24 @@  discard block
 block discarded – undo
584 620
     	                    $pageposafter=$pdf->getPage();
585 621
     	                    $posyafter=$pdf->GetY();
586 622
     	                    //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
587
-    	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
623
+    	                    if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) {
624
+    	                        // There is no space left for total+free text
588 625
     	                    {
589 626
     	                        if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
590 627
     	                        {
591 628
     	                            $pdf->AddPage('','',true);
592
-    	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
629
+    	                    }
630
+    	                            if (! empty($tplidx)) {
631
+    	                                $pdf->useTemplate($tplidx);
632
+    	                            }
593 633
     	                            $pdf->setPage($pageposafter+1);
594 634
     	                        }
595
-    	                    }
596
-    	                    else
635
+    	                    } else
597 636
     	                    {
598 637
     	                        // We found a page break
599 638
     	                        $showpricebeforepagebreak=0;
600 639
     	                    }
601
-    	                }
602
-    	                else	// No pagebreak
640
+    	                } else	// No pagebreak
603 641
     	                {
604 642
     	                    $pdf->commitTransaction();
605 643
     	                }
@@ -691,16 +729,24 @@  discard block
 block discarded – undo
691 729
 
692 730
 
693 731
 	                $sign=1;
694
-	                if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
732
+	                if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
733
+	                    $sign=-1;
734
+	                }
695 735
 	                // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
696 736
 	                $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
697
-	                if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
737
+	                if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
738
+	                    // Compute progress from previous situation
698 739
 	                {
699 740
 	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
700
-	                    else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
701 741
 	                } else {
702
-	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
703
-	                    else $tvaligne= $sign * $object->lines[$i]->total_tva;
742
+	                        $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
743
+	                    }
744
+	                } else {
745
+	                    if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
746
+	                        $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
747
+	                    } else {
748
+	                        $tvaligne= $sign * $object->lines[$i]->total_tva;
749
+	                    }
704 750
 	                }
705 751
 
706 752
 	                $localtax1ligne=$object->lines[$i]->total_localtax1;
@@ -710,29 +756,43 @@  discard block
 block discarded – undo
710 756
 	                $localtax1_type=$object->lines[$i]->localtax1_type;
711 757
 	                $localtax2_type=$object->lines[$i]->localtax2_type;
712 758
 
713
-	                if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
714
-	                if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
715
-	                if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
759
+	                if ($object->remise_percent) {
760
+	                    $tvaligne-=($tvaligne*$object->remise_percent)/100;
761
+	                }
762
+	                if ($object->remise_percent) {
763
+	                    $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
764
+	                }
765
+	                if ($object->remise_percent) {
766
+	                    $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
767
+	                }
716 768
 
717 769
 	                $vatrate=(string) $object->lines[$i]->tva_tx;
718 770
 
719 771
 	                // Retrieve type from database for backward compatibility with old records
720 772
 	                if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
721
-	                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
773
+	                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) {
774
+	                    // and there is local tax
722 775
 	                {
723 776
 	                    $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
777
+	                }
724 778
 	                    $localtax1_type = $localtaxtmp_array[0];
725 779
 	                    $localtax2_type = $localtaxtmp_array[2];
726 780
 	                }
727 781
 
728 782
 	                // retrieve global local tax
729
-	                if ($localtax1_type && $localtax1ligne != 0)
730
-	                    $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
731
-	                    if ($localtax2_type && $localtax2ligne != 0)
732
-	                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
783
+	                if ($localtax1_type && $localtax1ligne != 0) {
784
+	                	                    $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
785
+	                }
786
+	                    if ($localtax2_type && $localtax2ligne != 0) {
787
+	                    	                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
788
+	                    }
733 789
 
734
-	                        if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
735
-	                        if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
790
+	                        if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
791
+	                            $vatrate.='*';
792
+	                        }
793
+	                        if (! isset($this->tva[$vatrate])) {
794
+	                            $this->tva[$vatrate]=0;
795
+	                        }
736 796
 	                        $this->tva[$vatrate] += $tvaligne;
737 797
 
738 798
 	                        $nexY = max($nexY,$posYAfterImage);
@@ -756,8 +816,7 @@  discard block
 block discarded – undo
756 816
 	                            if ($pagenb == $pageposbeforeprintlines)
757 817
 	                            {
758 818
 	                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
759
-	                            }
760
-	                            else
819
+	                            } else
761 820
 	                            {
762 821
 	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
763 822
 	                            }
@@ -765,7 +824,9 @@  discard block
 block discarded – undo
765 824
 	                            $pagenb++;
766 825
 	                            $pdf->setPage($pagenb);
767 826
 	                            $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
768
-	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
827
+	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
828
+	                                $this->_pagehead($pdf, $object, 0, $outputlangs);
829
+	                            }
769 830
 	                        }
770 831
 
771 832
 	                        if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
@@ -773,17 +834,20 @@  discard block
 block discarded – undo
773 834
 	                            if ($pagenb == $pageposafter)
774 835
 	                            {
775 836
 	                                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
776
-	                            }
777
-	                            else
837
+	                            } else
778 838
 	                            {
779 839
 	                                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
780 840
 	                            }
781 841
 	                            $this->_pagefoot($pdf,$object,$outputlangs,1);
782 842
 	                            // New page
783 843
 	                            $pdf->AddPage();
784
-	                            if (! empty($tplidx)) $pdf->useTemplate($tplidx);
844
+	                            if (! empty($tplidx)) {
845
+	                                $pdf->useTemplate($tplidx);
846
+	                            }
785 847
 	                            $pagenb++;
786
-	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
848
+	                            if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
849
+	                                $this->_pagehead($pdf, $object, 0, $outputlangs);
850
+	                            }
787 851
 	                        }
788 852
 	            }
789 853
 
@@ -792,8 +856,7 @@  discard block
 block discarded – undo
792 856
 	            {
793 857
 	                $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
794 858
 	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
795
-	            }
796
-	            else
859
+	            } else
797 860
 	            {
798 861
 	                $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
799 862
 	                $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
@@ -813,7 +876,9 @@  discard block
 block discarded – undo
813 876
 
814 877
 	            // Pied de page
815 878
 	            $this->_pagefoot($pdf,$object,$outputlangs);
816
-	            if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
879
+	            if (method_exists($pdf,'AliasNbPages')) {
880
+	                $pdf->AliasNbPages();
881
+	            }
817 882
 
818 883
 	            $pdf->Close();
819 884
 
@@ -825,20 +890,19 @@  discard block
 block discarded – undo
825 890
 	            global $action;
826 891
 	            $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
827 892
 
828
-	            if (! empty($conf->global->MAIN_UMASK))
829
-	                @chmod($file, octdec($conf->global->MAIN_UMASK));
893
+	            if (! empty($conf->global->MAIN_UMASK)) {
894
+	            	                @chmod($file, octdec($conf->global->MAIN_UMASK));
895
+	            }
830 896
 
831 897
 	                $this->result = array('fullpath'=>$file);
832 898
 
833 899
 	                return 1;   // No error
834
-	        }
835
-	        else
900
+	        } else
836 901
 	        {
837 902
 	            $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
838 903
 	            return 0;
839 904
 	        }
840
-	    }
841
-	    else
905
+	    } else
842 906
 	    {
843 907
 	        $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
844 908
 	        return 0;
@@ -860,21 +924,27 @@  discard block
 block discarded – undo
860 924
 		global $conf;
861 925
 
862 926
         $sign=1;
863
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
927
+        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
928
+            $sign=-1;
929
+        }
864 930
 
865 931
         $tab3_posx = 120;
866 932
 		$tab3_top = $posy + 8;
867 933
 		$tab3_width = 80;
868 934
 		$tab3_height = 4;
869
-		if ($this->page_largeur < 210) // To work with US executive format
935
+		if ($this->page_largeur < 210) {
936
+		    // To work with US executive format
870 937
 		{
871 938
 			$tab3_posx -= 20;
872 939
 		}
940
+		}
873 941
 
874 942
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
875 943
 
876 944
 		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
877
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
945
+		if ($object->type == 2) {
946
+		    $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
947
+		}
878 948
 
879 949
 		$pdf->SetFont('','', $default_font_size - 3);
880 950
 		$pdf->SetXY($tab3_posx, $tab3_top - 4);
@@ -916,9 +986,13 @@  discard block
 block discarded – undo
916 986
 				$y+=3;
917 987
 				$obj = $this->db->fetch_object($resql);
918 988
 
919
-				if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
920
-				elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
921
-				else $text=$outputlangs->trans("UnknownType");
989
+				if ($obj->type == 2) {
990
+				    $text=$outputlangs->trans("CreditNote");
991
+				} elseif ($obj->type == 3) {
992
+				    $text=$outputlangs->trans("Deposit");
993
+				} else {
994
+				    $text=$outputlangs->trans("UnknownType");
995
+				}
922 996
 
923 997
 				$invoice->fetch($obj->fk_facture_source);
924 998
 
@@ -935,8 +1009,7 @@  discard block
 block discarded – undo
935 1009
 
936 1010
 				$i++;
937 1011
 			}
938
-		}
939
-		else
1012
+		} else
940 1013
 		{
941 1014
 			$this->error=$this->db->lasterror();
942 1015
 			return -1;
@@ -976,8 +1049,7 @@  discard block
 block discarded – undo
976 1049
 
977 1050
 				$i++;
978 1051
 			}
979
-		}
980
-		else
1052
+		} else
981 1053
 		{
982 1054
 			$this->error=$this->db->lasterror();
983 1055
 			return -1;
@@ -1124,7 +1196,10 @@  discard block
 block discarded – undo
1124 1196
 				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1125 1197
 				{
1126 1198
 					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1127
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1199
+					if (! empty($object->fk_bank)) {
1200
+					    $bankid=$object->fk_bank;
1201
+					}
1202
+					// For backward compatibility when object->fk_account is forced with object->fk_bank
1128 1203
 					$account = new Account($this->db);
1129 1204
 					$account->fetch($bankid);
1130 1205
 
@@ -1157,7 +1232,9 @@  discard block
 block discarded – undo
1157 1232
 		global $conf,$mysoc;
1158 1233
 
1159 1234
         $sign=1;
1160
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1235
+        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1236
+            $sign=-1;
1237
+        }
1161 1238
 
1162 1239
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1163 1240
 
@@ -1167,10 +1244,12 @@  discard block
 block discarded – undo
1167 1244
 
1168 1245
 		// Tableau total
1169 1246
 		$col1x = 120; $col2x = 170;
1170
-		if ($this->page_largeur < 210) // To work with US executive format
1247
+		if ($this->page_largeur < 210) {
1248
+		    // To work with US executive format
1171 1249
 		{
1172 1250
 			$col2x-=20;
1173 1251
 		}
1252
+		}
1174 1253
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1175 1254
 
1176 1255
 		$useborder=0;
@@ -1197,8 +1276,7 @@  discard block
 block discarded – undo
1197 1276
 			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1198 1277
 			{
1199 1278
 				// Nothing to do
1200
-			}
1201
-			else
1279
+			} else
1202 1280
 			{
1203 1281
 			    // FIXME amount of vat not supported with multicurrency
1204 1282
 
@@ -1207,15 +1285,19 @@  discard block
 block discarded – undo
1207 1285
 				//{
1208 1286
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1209 1287
 					{
1210
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1288
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1289
+						    continue;
1290
+						}
1211 1291
 
1212 1292
 						foreach( $localtax_rate as $tvakey => $tvaval )
1213 1293
 						{
1214
-							if ($tvakey!=0)    // On affiche pas taux 0
1294
+							if ($tvakey!=0) {
1295
+							    // On affiche pas taux 0
1215 1296
 							{
1216 1297
 								//$this->atleastoneratenotnull++;
1217 1298
 
1218 1299
 								$index++;
1300
+							}
1219 1301
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1220 1302
 
1221 1303
 								$tvacompl='';
@@ -1240,17 +1322,21 @@  discard block
 block discarded – undo
1240 1322
 				//{
1241 1323
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1242 1324
 					{
1243
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1325
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1326
+						    continue;
1327
+						}
1244 1328
 
1245 1329
 						foreach( $localtax_rate as $tvakey => $tvaval )
1246 1330
 						{
1247
-							if ($tvakey!=0)    // On affiche pas taux 0
1331
+							if ($tvakey!=0) {
1332
+							    // On affiche pas taux 0
1248 1333
 							{
1249 1334
 								//$this->atleastoneratenotnull++;
1250 1335
 
1251 1336
 
1252 1337
 
1253 1338
 								$index++;
1339
+							}
1254 1340
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1255 1341
 
1256 1342
 								$tvacompl='';
@@ -1291,9 +1377,11 @@  discard block
 block discarded – undo
1291 1377
 
1292 1378
 				foreach($this->tva as $tvakey => $tvaval)
1293 1379
 				{
1294
-					if ($tvakey != 0)    // On affiche pas taux 0
1380
+					if ($tvakey != 0) {
1381
+					    // On affiche pas taux 0
1295 1382
 					{
1296 1383
 						$this->atleastoneratenotnull++;
1384
+					}
1297 1385
 
1298 1386
 						$index++;
1299 1387
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@@ -1318,15 +1406,19 @@  discard block
 block discarded – undo
1318 1406
 				//{
1319 1407
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1320 1408
 					{
1321
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1409
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1410
+						    continue;
1411
+						}
1322 1412
 
1323 1413
 						foreach( $localtax_rate as $tvakey => $tvaval )
1324 1414
 						{
1325
-							if ($tvakey != 0)    // On affiche pas taux 0
1415
+							if ($tvakey != 0) {
1416
+							    // On affiche pas taux 0
1326 1417
 							{
1327 1418
 								//$this->atleastoneratenotnull++;
1328 1419
 
1329 1420
 								$index++;
1421
+							}
1330 1422
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1331 1423
 
1332 1424
 								$tvacompl='';
@@ -1350,16 +1442,20 @@  discard block
 block discarded – undo
1350 1442
 				//{
1351 1443
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1352 1444
 					{
1353
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1445
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1446
+						    continue;
1447
+						}
1354 1448
 
1355 1449
 						foreach( $localtax_rate as $tvakey => $tvaval )
1356 1450
 						{
1357 1451
 						    // retrieve global local tax
1358
-							if ($tvakey != 0)    // On affiche pas taux 0
1452
+							if ($tvakey != 0) {
1453
+							    // On affiche pas taux 0
1359 1454
 							{
1360 1455
 								//$this->atleastoneratenotnull++;
1361 1456
 
1362 1457
 								$index++;
1458
+							}
1363 1459
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1364 1460
 
1365 1461
 								$tvacompl='';
@@ -1409,7 +1505,9 @@  discard block
 block discarded – undo
1409 1505
 		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1410 1506
 		//print "x".$creditnoteamount."-".$depositsamount;exit;
1411 1507
 		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1412
-		if ($object->paye) $resteapayer=0;
1508
+		if ($object->paye) {
1509
+		    $resteapayer=0;
1510
+		}
1413 1511
 
1414 1512
 		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1415 1513
 		{
@@ -1479,7 +1577,9 @@  discard block
 block discarded – undo
1479 1577
 
1480 1578
 		// Force to disable hidetop and hidebottom
1481 1579
 		$hidebottom=0;
1482
-		if ($hidetop) $hidetop=-1;
1580
+		if ($hidetop) {
1581
+		    $hidetop=-1;
1582
+		}
1483 1583
 
1484 1584
 		$currency = !empty($currency) ? $currency : $conf->currency;
1485 1585
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1495,7 +1595,9 @@  discard block
 block discarded – undo
1495 1595
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1496 1596
 
1497 1597
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1498
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1598
+			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1599
+			    $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1600
+			}
1499 1601
 		}
1500 1602
 
1501 1603
 		$pdf->SetDrawColor(128,128,128);
@@ -1507,7 +1609,9 @@  discard block
 block discarded – undo
1507 1609
 
1508 1610
 		foreach ($this->cols as $colKey => $colDef)
1509 1611
 		{
1510
-		    if(!$this->getColumnStatus($colKey)) continue;
1612
+		    if(!$this->getColumnStatus($colKey)) {
1613
+		        continue;
1614
+		    }
1511 1615
 
1512 1616
 		    // get title label
1513 1617
 		    $colDef['title']['label'] = !empty($colDef['title']['label'])?$colDef['title']['label']:$outputlangs->transnoentities($colDef['title']['textkey']);
@@ -1577,16 +1681,14 @@  discard block
 block discarded – undo
1577 1681
 				{
1578 1682
 				    $height=pdf_getHeightForLogo($logo);
1579 1683
 					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1580
-				}
1581
-				else
1684
+				} else
1582 1685
 				{
1583 1686
 					$pdf->SetTextColor(200,0,0);
1584 1687
 					$pdf->SetFont('','B',$default_font_size - 2);
1585 1688
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1586 1689
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1587 1690
 				}
1588
-			}
1589
-			else
1691
+			} else
1590 1692
 			{
1591 1693
 				$text=$this->emetteur->name;
1592 1694
 				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1597,11 +1699,21 @@  discard block
 block discarded – undo
1597 1699
 		$pdf->SetXY($posx,$posy);
1598 1700
 		$pdf->SetTextColor(0,0,60);
1599 1701
 		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1600
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1601
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1602
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1603
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1604
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1702
+		if ($object->type == 1) {
1703
+		    $title=$outputlangs->transnoentities("InvoiceReplacement");
1704
+		}
1705
+		if ($object->type == 2) {
1706
+		    $title=$outputlangs->transnoentities("InvoiceAvoir");
1707
+		}
1708
+		if ($object->type == 3) {
1709
+		    $title=$outputlangs->transnoentities("InvoiceDeposit");
1710
+		}
1711
+		if ($object->type == 4) {
1712
+		    $title=$outputlangs->transnoentities("InvoiceProForma");
1713
+		}
1714
+		if ($this->situationinvoice) {
1715
+		    $title=$outputlangs->transnoentities("InvoiceSituation");
1716
+		}
1605 1717
 		$pdf->MultiCell($w, 3, $title, '', 'R');
1606 1718
 
1607 1719
 		$pdf->SetFont('','B',$default_font_size);
@@ -1724,7 +1836,9 @@  discard block
 block discarded – undo
1724 1836
 			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1725 1837
 			$posy+=$top_shift;
1726 1838
 			$posx=$this->marge_gauche;
1727
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1839
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1840
+			    $posx=$this->page_largeur-$this->marge_droite-80;
1841
+			}
1728 1842
 
1729 1843
 			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1730 1844
 			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
@@ -1774,11 +1888,16 @@  discard block
 block discarded – undo
1774 1888
 
1775 1889
 			// Show recipient
1776 1890
 			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1777
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1891
+			if ($this->page_largeur < 210) {
1892
+			    $widthrecbox=84;
1893
+			}
1894
+			// To work with US executive format
1778 1895
 			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1779 1896
 			$posy+=$top_shift;
1780 1897
 			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1781
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1898
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1899
+			    $posx=$this->marge_gauche;
1900
+			}
1782 1901
 
1783 1902
 			// Show recipient frame
1784 1903
 			$pdf->SetTextColor(0,0,0);
@@ -2009,12 +2128,10 @@  discard block
 block discarded – undo
2009 2128
 	    if ($reshook < 0)
2010 2129
 	    {
2011 2130
 	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2012
-	    }
2013
-	    elseif (empty($reshook))
2131
+	    } elseif (empty($reshook))
2014 2132
 	    {
2015 2133
 	        $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2016
-	    }
2017
-	    else
2134
+	    } else
2018 2135
 	    {
2019 2136
 	        $this->cols = $hookmanager->resArray;
2020 2137
 	    }
Please login to merge, or discard this patch.
htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php 3 patches
Indentation   +461 added lines, -461 removed lines patch added patch discarded remove patch
@@ -39,487 +39,487 @@
 block discarded – undo
39 39
  */
40 40
 class doc_generic_invoice_odt extends ModelePDFFactures
41 41
 {
42
-	/**
43
-	 * Issuer
44
-	 * @var Company object that emits
45
-	 */
46
-	public $emetteur;
47
-
48
-	/**
49
-   * @var array() Minimum version of PHP required by module.
50
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
51
-   */
52
-	public $phpmin = array(5, 4);
53
-
54
-	/**
42
+    /**
43
+     * Issuer
44
+     * @var Company object that emits
45
+     */
46
+    public $emetteur;
47
+
48
+    /**
49
+     * @var array() Minimum version of PHP required by module.
50
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
51
+     */
52
+    public $phpmin = array(5, 4);
53
+
54
+    /**
55 55
      * Dolibarr version of the loaded document
56 56
      * @public string
57 57
      */
58
-	public $version = 'dolibarr';
58
+    public $version = 'dolibarr';
59 59
 
60 60
 
61
-	/**
62
-	 *	Constructor
63
-	 *
64
-	 *  @param		DoliDB		$db      Database handler
65
-	 */
66
-	function __construct($db)
67
-	{
68
-		global $conf, $langs, $mysoc;
61
+    /**
62
+     *	Constructor
63
+     *
64
+     *  @param		DoliDB		$db      Database handler
65
+     */
66
+    function __construct($db)
67
+    {
68
+        global $conf, $langs, $mysoc;
69 69
 
70
-		// Load translation files required by the page
70
+        // Load translation files required by the page
71 71
         $langs->loadLangs(array("main","companies"));
72 72
 
73
-		$this->db = $db;
74
-		$this->name = "ODT/ODS templates";
75
-		$this->description = $langs->trans("DocumentModelOdt");
76
-		$this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
77
-
78
-		// Dimension page pour format A4
79
-		$this->type = 'odt';
80
-		$this->page_largeur = 0;
81
-		$this->page_hauteur = 0;
82
-		$this->format = array($this->page_largeur,$this->page_hauteur);
83
-		$this->marge_gauche=0;
84
-		$this->marge_droite=0;
85
-		$this->marge_haute=0;
86
-		$this->marge_basse=0;
87
-
88
-		$this->option_logo = 1;                    // Affiche logo
89
-		$this->option_tva = 0;                     // Gere option tva FACTURE_TVAOPTION
90
-		$this->option_modereg = 0;                 // Affiche mode reglement
91
-		$this->option_condreg = 0;                 // Affiche conditions reglement
92
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
93
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
94
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
95
-		$this->option_credit_note = 0;             // Support credit notes
96
-		$this->option_freetext = 1;				   // Support add of a personalised text
97
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
98
-
99
-		// Recupere emetteur
100
-		$this->emetteur=$mysoc;
101
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
102
-	}
103
-
104
-
105
-	/**
106
-	 * Return description of a module
107
-	 *
108
-	 * @param	Translate	$langs      Lang object to use for output
109
-	 * @return	string      			Description
110
-	 */
111
-	function info($langs)
112
-	{
113
-		global $conf, $langs;
114
-
115
-		// Load translation files required by the page
73
+        $this->db = $db;
74
+        $this->name = "ODT/ODS templates";
75
+        $this->description = $langs->trans("DocumentModelOdt");
76
+        $this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
77
+
78
+        // Dimension page pour format A4
79
+        $this->type = 'odt';
80
+        $this->page_largeur = 0;
81
+        $this->page_hauteur = 0;
82
+        $this->format = array($this->page_largeur,$this->page_hauteur);
83
+        $this->marge_gauche=0;
84
+        $this->marge_droite=0;
85
+        $this->marge_haute=0;
86
+        $this->marge_basse=0;
87
+
88
+        $this->option_logo = 1;                    // Affiche logo
89
+        $this->option_tva = 0;                     // Gere option tva FACTURE_TVAOPTION
90
+        $this->option_modereg = 0;                 // Affiche mode reglement
91
+        $this->option_condreg = 0;                 // Affiche conditions reglement
92
+        $this->option_codeproduitservice = 0;      // Affiche code produit-service
93
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
94
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
95
+        $this->option_credit_note = 0;             // Support credit notes
96
+        $this->option_freetext = 1;				   // Support add of a personalised text
97
+        $this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
98
+
99
+        // Recupere emetteur
100
+        $this->emetteur=$mysoc;
101
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
102
+    }
103
+
104
+
105
+    /**
106
+     * Return description of a module
107
+     *
108
+     * @param	Translate	$langs      Lang object to use for output
109
+     * @return	string      			Description
110
+     */
111
+    function info($langs)
112
+    {
113
+        global $conf, $langs;
114
+
115
+        // Load translation files required by the page
116 116
         $langs->loadLangs(array("errors","companies"));
117 117
 
118
-		$form = new Form($this->db);
119
-
120
-		$texte = $this->description.".<br>\n";
121
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
122
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
123
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
124
-		$texte.= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">';
125
-		$texte.= '<table class="nobordernopadding" width="100%">';
126
-
127
-		// List of directories area
128
-		$texte.= '<tr><td valign="middle">';
129
-		$texttitle=$langs->trans("ListOfDirectories");
130
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH)));
131
-		$listoffiles=array();
132
-		foreach($listofdir as $key=>$tmpdir)
133
-		{
134
-			$tmpdir=trim($tmpdir);
135
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
136
-			if (! $tmpdir) {
137
-				unset($listofdir[$key]); continue;
138
-			}
139
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
140
-			else
141
-			{
142
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
143
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
144
-			}
145
-		}
146
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
147
-		// Add list of substitution keys
148
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
149
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
150
-
151
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
152
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
154
-		$texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH;
155
-		$texte.= '</textarea>';
156
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
157
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
158
-		$texte.= '<br></div></div>';
159
-
160
-		// Scan directories
161
-		$nbofiles=count($listoffiles);
162
-		if (! empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH))
163
-		{
164
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
165
-			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
166
-			$texte.=count($listoffiles);
167
-			//$texte.=$nbofiles?'</a>':'';
168
-			$texte.='</b>';
169
-		}
170
-		if ($nbofiles)
171
-		{
172
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
173
-   			foreach($listoffiles as $file)
174
-   			{
118
+        $form = new Form($this->db);
119
+
120
+        $texte = $this->description.".<br>\n";
121
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
122
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
123
+        $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
124
+        $texte.= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">';
125
+        $texte.= '<table class="nobordernopadding" width="100%">';
126
+
127
+        // List of directories area
128
+        $texte.= '<tr><td valign="middle">';
129
+        $texttitle=$langs->trans("ListOfDirectories");
130
+        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH)));
131
+        $listoffiles=array();
132
+        foreach($listofdir as $key=>$tmpdir)
133
+        {
134
+            $tmpdir=trim($tmpdir);
135
+            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
136
+            if (! $tmpdir) {
137
+                unset($listofdir[$key]); continue;
138
+            }
139
+            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
140
+            else
141
+            {
142
+                $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
143
+                if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
144
+            }
145
+        }
146
+        $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
147
+        // Add list of substitution keys
148
+        $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
149
+        $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
150
+
151
+        $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
152
+        $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153
+        $texte.= '<textarea class="flat" cols="60" name="value1">';
154
+        $texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH;
155
+        $texte.= '</textarea>';
156
+        $texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
157
+        $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
158
+        $texte.= '<br></div></div>';
159
+
160
+        // Scan directories
161
+        $nbofiles=count($listoffiles);
162
+        if (! empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH))
163
+        {
164
+            $texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
165
+            //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
166
+            $texte.=count($listoffiles);
167
+            //$texte.=$nbofiles?'</a>':'';
168
+            $texte.='</b>';
169
+        }
170
+        if ($nbofiles)
171
+        {
172
+                $texte.='<div id="div_'.get_class($this).'" class="hidden">';
173
+                foreach($listoffiles as $file)
174
+                {
175 175
                 $texte.=$file['name'].'<br>';
176
-   			}
177
-   			$texte.='<div id="div_'.get_class($this).'">';
178
-		}
176
+                }
177
+                $texte.='<div id="div_'.get_class($this).'">';
178
+        }
179 179
 
180
-		$texte.= '</td>';
180
+        $texte.= '</td>';
181 181
 
182
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
183
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
184
-		$texte.= '</td>';
185
-		$texte.= '</tr>';
182
+        $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
183
+        $texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
184
+        $texte.= '</td>';
185
+        $texte.= '</tr>';
186 186
 
187
-		$texte.= '</table>';
188
-		$texte.= '</form>';
187
+        $texte.= '</table>';
188
+        $texte.= '</form>';
189 189
 
190
-		return $texte;
191
-	}
190
+        return $texte;
191
+    }
192 192
 
193 193
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
194
-	/**
195
-	 *	Function to build a document on disk using the generic odt module.
196
-	 *
197
-	 *	@param		Facture		$object				Object source to build document
198
-	 *	@param		Translate	$outputlangs		Lang output object
199
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
200
-	 *  @param		int			$hidedetails		Do not show line details
201
-	 *  @param		int			$hidedesc			Do not show desc
202
-	 *  @param		int			$hideref			Do not show ref
203
-	 *	@return		int         					1 if OK, <=0 if KO
204
-	 */
205
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
206
-	{
194
+    /**
195
+     *	Function to build a document on disk using the generic odt module.
196
+     *
197
+     *	@param		Facture		$object				Object source to build document
198
+     *	@param		Translate	$outputlangs		Lang output object
199
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
200
+     *  @param		int			$hidedetails		Do not show line details
201
+     *  @param		int			$hidedesc			Do not show desc
202
+     *  @param		int			$hideref			Do not show ref
203
+     *	@return		int         					1 if OK, <=0 if KO
204
+     */
205
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
206
+    {
207 207
         // phpcs:enable
208
-		global $user,$langs,$conf,$mysoc,$hookmanager;
209
-
210
-		if (empty($srctemplatepath))
211
-		{
212
-			dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
213
-			return -1;
214
-		}
215
-
216
-		// Add odtgeneration hook
217
-		if (! is_object($hookmanager))
218
-		{
219
-			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
220
-			$hookmanager=new HookManager($this->db);
221
-		}
222
-		$hookmanager->initHooks(array('odtgeneration'));
223
-		global $action;
224
-
225
-		if (! is_object($outputlangs)) $outputlangs=$langs;
226
-		$sav_charset_output=$outputlangs->charset_output;
227
-		$outputlangs->charset_output='UTF-8';
228
-
229
-		// Load translation files required by the page
230
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
231
-
232
-		if ($conf->facture->dir_output)
233
-		{
234
-			// If $object is id instead of object
235
-			if (! is_object($object))
236
-			{
237
-				$id = $object;
238
-				$object = new Facture($this->db);
239
-				$result=$object->fetch($id);
240
-				if ($result < 0)
241
-				{
242
-					dol_print_error($this->db,$object->error);
243
-					return -1;
244
-				}
245
-			}
246
-
247
-			$dir = $conf->facture->dir_output;
248
-			$objectref = dol_sanitizeFileName($object->ref);
249
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
250
-			$file = $dir . "/" . $objectref . ".odt";
251
-
252
-			if (! file_exists($dir))
253
-			{
254
-				if (dol_mkdir($dir) < 0)
255
-				{
256
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
257
-					return -1;
258
-				}
259
-			}
260
-
261
-			if (file_exists($dir))
262
-			{
263
-				//print "srctemplatepath=".$srctemplatepath;	// Src filename
264
-				$newfile=basename($srctemplatepath);
265
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
266
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
267
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
268
-
269
-				$newfiletmp=$objectref.'_'.$newfiletmp;
270
-
271
-				// Get extension (ods or odt)
272
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
273
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274
-				{
275
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
277
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
-				}
279
-				else
280
-				{
281
-					$filename=$newfiletmp.'.'.$newfileformat;
282
-				}
283
-				$file=$dir.'/'.$filename;
284
-				//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
285
-				//print "newdir=".$dir;
286
-				//print "newfile=".$newfile;
287
-				//print "file=".$file;
288
-				//print "conf->societe->dir_temp=".$conf->societe->dir_temp;
289
-
290
-				dol_mkdir($conf->facture->dir_temp);
291
-
292
-
293
-				// If BILLING contact defined on invoice, we use it
294
-				$usecontact=false;
295
-				$arrayidcontact=$object->getIdContact('external','BILLING');
296
-				if (count($arrayidcontact) > 0)
297
-				{
298
-					$usecontact=true;
299
-					$result=$object->fetch_contact($arrayidcontact[0]);
300
-				}
301
-
302
-				// Recipient name
303
-				$contactobject = null;
304
-				if (! empty($usecontact)) {
305
-					// On peut utiliser le nom de la societe du contact
306
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
307
-						$socobject = $object->contact;
308
-					else {
309
-						$socobject = $object->thirdparty;
310
-						// if we have a BILLING contact and we dont use it as recipient we store the contact object for later use
311
-						$contactobject = $object->contact;
312
-					}
313
-				} else {
314
-					$socobject = $object->thirdparty;
315
-				}
316
-
317
-				// Fetch info for linked propal
318
-				$object->fetchObjectLinked('','','','');
319
-				//print_r($object->linkedObjects['propal']); exit;
320
-
321
-				$propal_object = $object->linkedObjects['propal'][0];
322
-
323
-				// Make substitution
324
-				$substitutionarray=array(
325
-				'__FROM_NAME__' => $this->emetteur->name,
326
-				'__FROM_EMAIL__' => $this->emetteur->email,
327
-				'__TOTAL_TTC__' => $object->total_ttc,
328
-				'__TOTAL_HT__' => $object->total_ht,
329
-				'__TOTAL_VAT__' => $object->total_tva
330
-				);
331
-				complete_substitutions_array($substitutionarray, $langs, $object);
332
-				// Call the ODTSubstitution hook
333
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
334
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
335
-
336
-				// Line of free text
337
-				$newfreetext='';
338
-				$paramfreetext='INVOICE_FREE_TEXT';
339
-				if (! empty($conf->global->$paramfreetext))
340
-				{
341
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
342
-				}
343
-
344
-				// Open and load template
345
-				require_once ODTPHP_PATH.'odf.php';
346
-				try {
347
-					$odfHandler = new odf(
348
-						$srctemplatepath,
349
-						array(
350
-						'PATH_TO_TMP'	  => $conf->facture->dir_temp,
351
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
352
-						'DELIMITER_LEFT'  => '{',
353
-						'DELIMITER_RIGHT' => '}'
354
-						)
355
-					);
356
-				}
357
-				catch (Exception $e)
358
-				{
359
-					$this->error=$e->getMessage();
360
-					dol_syslog($e->getMessage(), LOG_INFO);
361
-					return -1;
362
-				}
363
-				// After construction $odfHandler->contentXml contains content and
364
-				// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
365
-				// [!-- BEGIN lines --]*[!-- END lines --]
366
-				//print html_entity_decode($odfHandler->__toString());
367
-				//print exit;
368
-
369
-
370
-				// Make substitutions into odt of freetext
371
-				try {
372
-					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
373
-				}
374
-				catch (OdfException $e)
375
-				{
376
-					dol_syslog($e->getMessage(), LOG_INFO);
377
-				}
378
-
379
-				// Define substitution array
380
-				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
381
-				$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
382
-				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
383
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
384
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
385
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
386
-				$array_propal=is_object($propal_object)?$this->get_substitutionarray_object($propal_object,$outputlangs,'propal'):array();
387
-				$array_other=$this->get_substitutionarray_other($outputlangs);
388
-				// retrieve contact information for use in object as contact_xxx tags
389
-				$array_thirdparty_contact = array();
390
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
391
-
392
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact);
393
-				complete_substitutions_array($tmparray, $outputlangs, $object);
394
-
395
-				// Call the ODTSubstitution hook
396
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
397
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
398
-
399
-				//var_dump($tmparray); exit;
400
-				foreach($tmparray as $key=>$value)
401
-				{
402
-					try {
403
-						if (preg_match('/logo$/',$key)) // Image
404
-						{
405
-							//var_dump($value);exit;
406
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
407
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
408
-						}
409
-						else    // Text
410
-						{
411
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
412
-						}
413
-					}
414
-					catch (OdfException $e)
415
-					{
208
+        global $user,$langs,$conf,$mysoc,$hookmanager;
209
+
210
+        if (empty($srctemplatepath))
211
+        {
212
+            dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
213
+            return -1;
214
+        }
215
+
216
+        // Add odtgeneration hook
217
+        if (! is_object($hookmanager))
218
+        {
219
+            include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
220
+            $hookmanager=new HookManager($this->db);
221
+        }
222
+        $hookmanager->initHooks(array('odtgeneration'));
223
+        global $action;
224
+
225
+        if (! is_object($outputlangs)) $outputlangs=$langs;
226
+        $sav_charset_output=$outputlangs->charset_output;
227
+        $outputlangs->charset_output='UTF-8';
228
+
229
+        // Load translation files required by the page
230
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
231
+
232
+        if ($conf->facture->dir_output)
233
+        {
234
+            // If $object is id instead of object
235
+            if (! is_object($object))
236
+            {
237
+                $id = $object;
238
+                $object = new Facture($this->db);
239
+                $result=$object->fetch($id);
240
+                if ($result < 0)
241
+                {
242
+                    dol_print_error($this->db,$object->error);
243
+                    return -1;
244
+                }
245
+            }
246
+
247
+            $dir = $conf->facture->dir_output;
248
+            $objectref = dol_sanitizeFileName($object->ref);
249
+            if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
250
+            $file = $dir . "/" . $objectref . ".odt";
251
+
252
+            if (! file_exists($dir))
253
+            {
254
+                if (dol_mkdir($dir) < 0)
255
+                {
256
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
257
+                    return -1;
258
+                }
259
+            }
260
+
261
+            if (file_exists($dir))
262
+            {
263
+                //print "srctemplatepath=".$srctemplatepath;	// Src filename
264
+                $newfile=basename($srctemplatepath);
265
+                $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
266
+                $newfiletmp=preg_replace('/template_/i','',$newfiletmp);
267
+                $newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
268
+
269
+                $newfiletmp=$objectref.'_'.$newfiletmp;
270
+
271
+                // Get extension (ods or odt)
272
+                $newfileformat=substr($newfile, strrpos($newfile, '.')+1);
273
+                if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274
+                {
275
+                    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
+                    if ($format == '1') $format='%Y%m%d%H%M%S';
277
+                    $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
+                }
279
+                else
280
+                {
281
+                    $filename=$newfiletmp.'.'.$newfileformat;
282
+                }
283
+                $file=$dir.'/'.$filename;
284
+                //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
285
+                //print "newdir=".$dir;
286
+                //print "newfile=".$newfile;
287
+                //print "file=".$file;
288
+                //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
289
+
290
+                dol_mkdir($conf->facture->dir_temp);
291
+
292
+
293
+                // If BILLING contact defined on invoice, we use it
294
+                $usecontact=false;
295
+                $arrayidcontact=$object->getIdContact('external','BILLING');
296
+                if (count($arrayidcontact) > 0)
297
+                {
298
+                    $usecontact=true;
299
+                    $result=$object->fetch_contact($arrayidcontact[0]);
300
+                }
301
+
302
+                // Recipient name
303
+                $contactobject = null;
304
+                if (! empty($usecontact)) {
305
+                    // On peut utiliser le nom de la societe du contact
306
+                    if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
307
+                        $socobject = $object->contact;
308
+                    else {
309
+                        $socobject = $object->thirdparty;
310
+                        // if we have a BILLING contact and we dont use it as recipient we store the contact object for later use
311
+                        $contactobject = $object->contact;
312
+                    }
313
+                } else {
314
+                    $socobject = $object->thirdparty;
315
+                }
316
+
317
+                // Fetch info for linked propal
318
+                $object->fetchObjectLinked('','','','');
319
+                //print_r($object->linkedObjects['propal']); exit;
320
+
321
+                $propal_object = $object->linkedObjects['propal'][0];
322
+
323
+                // Make substitution
324
+                $substitutionarray=array(
325
+                '__FROM_NAME__' => $this->emetteur->name,
326
+                '__FROM_EMAIL__' => $this->emetteur->email,
327
+                '__TOTAL_TTC__' => $object->total_ttc,
328
+                '__TOTAL_HT__' => $object->total_ht,
329
+                '__TOTAL_VAT__' => $object->total_tva
330
+                );
331
+                complete_substitutions_array($substitutionarray, $langs, $object);
332
+                // Call the ODTSubstitution hook
333
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
334
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
335
+
336
+                // Line of free text
337
+                $newfreetext='';
338
+                $paramfreetext='INVOICE_FREE_TEXT';
339
+                if (! empty($conf->global->$paramfreetext))
340
+                {
341
+                    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
342
+                }
343
+
344
+                // Open and load template
345
+                require_once ODTPHP_PATH.'odf.php';
346
+                try {
347
+                    $odfHandler = new odf(
348
+                        $srctemplatepath,
349
+                        array(
350
+                        'PATH_TO_TMP'	  => $conf->facture->dir_temp,
351
+                        'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
352
+                        'DELIMITER_LEFT'  => '{',
353
+                        'DELIMITER_RIGHT' => '}'
354
+                        )
355
+                    );
356
+                }
357
+                catch (Exception $e)
358
+                {
359
+                    $this->error=$e->getMessage();
360
+                    dol_syslog($e->getMessage(), LOG_INFO);
361
+                    return -1;
362
+                }
363
+                // After construction $odfHandler->contentXml contains content and
364
+                // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
365
+                // [!-- BEGIN lines --]*[!-- END lines --]
366
+                //print html_entity_decode($odfHandler->__toString());
367
+                //print exit;
368
+
369
+
370
+                // Make substitutions into odt of freetext
371
+                try {
372
+                    $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
373
+                }
374
+                catch (OdfException $e)
375
+                {
376
+                    dol_syslog($e->getMessage(), LOG_INFO);
377
+                }
378
+
379
+                // Define substitution array
380
+                $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
381
+                $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
382
+                $array_objet=$this->get_substitutionarray_object($object,$outputlangs);
383
+                $array_user=$this->get_substitutionarray_user($user,$outputlangs);
384
+                $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
385
+                $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
386
+                $array_propal=is_object($propal_object)?$this->get_substitutionarray_object($propal_object,$outputlangs,'propal'):array();
387
+                $array_other=$this->get_substitutionarray_other($outputlangs);
388
+                // retrieve contact information for use in object as contact_xxx tags
389
+                $array_thirdparty_contact = array();
390
+                if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
391
+
392
+                $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact);
393
+                complete_substitutions_array($tmparray, $outputlangs, $object);
394
+
395
+                // Call the ODTSubstitution hook
396
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
397
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
398
+
399
+                //var_dump($tmparray); exit;
400
+                foreach($tmparray as $key=>$value)
401
+                {
402
+                    try {
403
+                        if (preg_match('/logo$/',$key)) // Image
404
+                        {
405
+                            //var_dump($value);exit;
406
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
407
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
408
+                        }
409
+                        else    // Text
410
+                        {
411
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
412
+                        }
413
+                    }
414
+                    catch (OdfException $e)
415
+                    {
416
+                        dol_syslog($e->getMessage(), LOG_INFO);
417
+                    }
418
+                }
419
+                // Replace tags of lines
420
+                try
421
+                {
422
+                    $foundtagforlines = 1;
423
+                    try {
424
+                        $listlines = $odfHandler->setSegment('lines');
425
+                    }
426
+                    catch(OdfException $e)
427
+                    {
428
+                        // We may arrive here if tags for lines not present into template
429
+                        $foundtagforlines = 0;
416 430
                         dol_syslog($e->getMessage(), LOG_INFO);
417
-					}
418
-				}
419
-				// Replace tags of lines
420
-				try
421
-				{
422
-					$foundtagforlines = 1;
423
-					try {
424
-						$listlines = $odfHandler->setSegment('lines');
425
-					}
426
-					catch(OdfException $e)
427
-					{
428
-						// We may arrive here if tags for lines not present into template
429
-						$foundtagforlines = 0;
430
-						dol_syslog($e->getMessage(), LOG_INFO);
431
-					}
432
-					if ($foundtagforlines)
433
-					{
434
-						foreach ($object->lines as $line)
435
-						{
436
-							$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
437
-							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
438
-							// Call the ODTSubstitutionLine hook
439
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
440
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
441
-							foreach($tmparray as $key => $val)
442
-							{
443
-								try
444
-								{
445
-									$listlines->setVars($key, $val, true, 'UTF-8');
446
-								}
447
-								catch(OdfException $e)
448
-								{
449
-									dol_syslog($e->getMessage(), LOG_INFO);
450
-								}
451
-								catch(SegmentException $e)
452
-								{
453
-									dol_syslog($e->getMessage(), LOG_INFO);
454
-								}
455
-							}
456
-							$listlines->merge();
457
-						}
458
-						$odfHandler->mergeSegment($listlines);
459
-					}
460
-				}
461
-				catch(OdfException $e)
462
-				{
463
-					$this->error=$e->getMessage();
464
-					dol_syslog($this->error, LOG_WARNING);
465
-					return -1;
466
-				}
467
-
468
-				// Replace labels translated
469
-				$tmparray=$outputlangs->get_translations_for_substitutions();
470
-				foreach($tmparray as $key=>$value)
471
-				{
472
-					try {
473
-						$odfHandler->setVars($key, $value, true, 'UTF-8');
474
-					}
475
-					catch(OdfException $e)
476
-					{
431
+                    }
432
+                    if ($foundtagforlines)
433
+                    {
434
+                        foreach ($object->lines as $line)
435
+                        {
436
+                            $tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
437
+                            complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
438
+                            // Call the ODTSubstitutionLine hook
439
+                            $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
440
+                            $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
441
+                            foreach($tmparray as $key => $val)
442
+                            {
443
+                                try
444
+                                {
445
+                                    $listlines->setVars($key, $val, true, 'UTF-8');
446
+                                }
447
+                                catch(OdfException $e)
448
+                                {
449
+                                    dol_syslog($e->getMessage(), LOG_INFO);
450
+                                }
451
+                                catch(SegmentException $e)
452
+                                {
453
+                                    dol_syslog($e->getMessage(), LOG_INFO);
454
+                                }
455
+                            }
456
+                            $listlines->merge();
457
+                        }
458
+                        $odfHandler->mergeSegment($listlines);
459
+                    }
460
+                }
461
+                catch(OdfException $e)
462
+                {
463
+                    $this->error=$e->getMessage();
464
+                    dol_syslog($this->error, LOG_WARNING);
465
+                    return -1;
466
+                }
467
+
468
+                // Replace labels translated
469
+                $tmparray=$outputlangs->get_translations_for_substitutions();
470
+                foreach($tmparray as $key=>$value)
471
+                {
472
+                    try {
473
+                        $odfHandler->setVars($key, $value, true, 'UTF-8');
474
+                    }
475
+                    catch(OdfException $e)
476
+                    {
477 477
                         dol_syslog($e->getMessage(), LOG_INFO);
478
-					}
479
-				}
480
-
481
-				// Call the beforeODTSave hook
482
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
483
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
484
-
485
-				// Write new file
486
-				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487
-					try {
488
-						$odfHandler->exportAsAttachedPDF($file);
489
-					}catch (Exception $e){
490
-						$this->error=$e->getMessage();
478
+                    }
479
+                }
480
+
481
+                // Call the beforeODTSave hook
482
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
483
+                $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
484
+
485
+                // Write new file
486
+                if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487
+                    try {
488
+                        $odfHandler->exportAsAttachedPDF($file);
489
+                    }catch (Exception $e){
490
+                        $this->error=$e->getMessage();
491 491
                         dol_syslog($e->getMessage(), LOG_INFO);
492
-						return -1;
493
-					}
494
-				}
495
-				else {
496
-					try {
497
-						$odfHandler->saveToDisk($file);
498
-					} catch (Exception $e) {
499
-						$this->error=$e->getMessage();
492
+                        return -1;
493
+                    }
494
+                }
495
+                else {
496
+                    try {
497
+                        $odfHandler->saveToDisk($file);
498
+                    } catch (Exception $e) {
499
+                        $this->error=$e->getMessage();
500 500
                         dol_syslog($e->getMessage(), LOG_INFO);
501
-						return -1;
502
-					}
503
-				}
504
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
505
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
506
-
507
-				if (! empty($conf->global->MAIN_UMASK))
508
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
509
-
510
-				$odfHandler=null;	// Destroy object
511
-
512
-				$this->result = array('fullpath'=>$file);
513
-
514
-				return 1;   // Success
515
-			}
516
-			else
517
-			{
518
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519
-				return -1;
520
-			}
521
-		}
522
-
523
-		return -1;
524
-	}
501
+                        return -1;
502
+                    }
503
+                }
504
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
505
+                $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
506
+
507
+                if (! empty($conf->global->MAIN_UMASK))
508
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
509
+
510
+                $odfHandler=null;	// Destroy object
511
+
512
+                $this->result = array('fullpath'=>$file);
513
+
514
+                return 1;   // Success
515
+            }
516
+            else
517
+            {
518
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519
+                return -1;
520
+            }
521
+        }
522
+
523
+        return -1;
524
+    }
525 525
 }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -68,37 +68,37 @@  discard block
 block discarded – undo
68 68
 		global $conf, $langs, $mysoc;
69 69
 
70 70
 		// Load translation files required by the page
71
-        $langs->loadLangs(array("main","companies"));
71
+        $langs->loadLangs(array("main", "companies"));
72 72
 
73 73
 		$this->db = $db;
74 74
 		$this->name = "ODT/ODS templates";
75 75
 		$this->description = $langs->trans("DocumentModelOdt");
76
-		$this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
76
+		$this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
77 77
 
78 78
 		// Dimension page pour format A4
79 79
 		$this->type = 'odt';
80 80
 		$this->page_largeur = 0;
81 81
 		$this->page_hauteur = 0;
82
-		$this->format = array($this->page_largeur,$this->page_hauteur);
83
-		$this->marge_gauche=0;
84
-		$this->marge_droite=0;
85
-		$this->marge_haute=0;
86
-		$this->marge_basse=0;
87
-
88
-		$this->option_logo = 1;                    // Affiche logo
89
-		$this->option_tva = 0;                     // Gere option tva FACTURE_TVAOPTION
90
-		$this->option_modereg = 0;                 // Affiche mode reglement
91
-		$this->option_condreg = 0;                 // Affiche conditions reglement
92
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
93
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
94
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
95
-		$this->option_credit_note = 0;             // Support credit notes
96
-		$this->option_freetext = 1;				   // Support add of a personalised text
97
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
82
+		$this->format = array($this->page_largeur, $this->page_hauteur);
83
+		$this->marge_gauche = 0;
84
+		$this->marge_droite = 0;
85
+		$this->marge_haute = 0;
86
+		$this->marge_basse = 0;
87
+
88
+		$this->option_logo = 1; // Affiche logo
89
+		$this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
90
+		$this->option_modereg = 0; // Affiche mode reglement
91
+		$this->option_condreg = 0; // Affiche conditions reglement
92
+		$this->option_codeproduitservice = 0; // Affiche code produit-service
93
+		$this->option_multilang = 1; // Dispo en plusieurs langues
94
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
95
+		$this->option_credit_note = 0; // Support credit notes
96
+		$this->option_freetext = 1; // Support add of a personalised text
97
+		$this->option_draft_watermark = 0; // Support add of a watermark on drafts
98 98
 
99 99
 		// Recupere emetteur
100
-		$this->emetteur=$mysoc;
101
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
100
+		$this->emetteur = $mysoc;
101
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini
102 102
 	}
103 103
 
104 104
 
@@ -113,79 +113,79 @@  discard block
 block discarded – undo
113 113
 		global $conf, $langs;
114 114
 
115 115
 		// Load translation files required by the page
116
-        $langs->loadLangs(array("errors","companies"));
116
+        $langs->loadLangs(array("errors", "companies"));
117 117
 
118 118
 		$form = new Form($this->db);
119 119
 
120 120
 		$texte = $this->description.".<br>\n";
121
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
122
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
123
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
124
-		$texte.= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">';
125
-		$texte.= '<table class="nobordernopadding" width="100%">';
121
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
122
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
123
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
124
+		$texte .= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">';
125
+		$texte .= '<table class="nobordernopadding" width="100%">';
126 126
 
127 127
 		// List of directories area
128
-		$texte.= '<tr><td valign="middle">';
129
-		$texttitle=$langs->trans("ListOfDirectories");
130
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH)));
131
-		$listoffiles=array();
132
-		foreach($listofdir as $key=>$tmpdir)
128
+		$texte .= '<tr><td valign="middle">';
129
+		$texttitle = $langs->trans("ListOfDirectories");
130
+		$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH)));
131
+		$listoffiles = array();
132
+		foreach ($listofdir as $key=>$tmpdir)
133 133
 		{
134
-			$tmpdir=trim($tmpdir);
135
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
136
-			if (! $tmpdir) {
134
+			$tmpdir = trim($tmpdir);
135
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
136
+			if (!$tmpdir) {
137 137
 				unset($listofdir[$key]); continue;
138 138
 			}
139
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
139
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
140 140
 			else
141 141
 			{
142
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
143
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
142
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
143
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
144 144
 			}
145 145
 		}
146
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
146
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
147 147
 		// Add list of substitution keys
148
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
149
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
150
-
151
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
152
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
154
-		$texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH;
155
-		$texte.= '</textarea>';
156
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
157
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
158
-		$texte.= '<br></div></div>';
148
+		$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
149
+		$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
150
+
151
+		$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
152
+		$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
153
+		$texte .= '<textarea class="flat" cols="60" name="value1">';
154
+		$texte .= $conf->global->FACTURE_ADDON_PDF_ODT_PATH;
155
+		$texte .= '</textarea>';
156
+		$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
157
+		$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
158
+		$texte .= '<br></div></div>';
159 159
 
160 160
 		// Scan directories
161
-		$nbofiles=count($listoffiles);
162
-		if (! empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH))
161
+		$nbofiles = count($listoffiles);
162
+		if (!empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH))
163 163
 		{
164
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
164
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>';
165 165
 			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
166
-			$texte.=count($listoffiles);
166
+			$texte .= count($listoffiles);
167 167
 			//$texte.=$nbofiles?'</a>':'';
168
-			$texte.='</b>';
168
+			$texte .= '</b>';
169 169
 		}
170 170
 		if ($nbofiles)
171 171
 		{
172
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
173
-   			foreach($listoffiles as $file)
172
+   			$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
173
+   			foreach ($listoffiles as $file)
174 174
    			{
175
-                $texte.=$file['name'].'<br>';
175
+                $texte .= $file['name'].'<br>';
176 176
    			}
177
-   			$texte.='<div id="div_'.get_class($this).'">';
177
+   			$texte .= '<div id="div_'.get_class($this).'">';
178 178
 		}
179 179
 
180
-		$texte.= '</td>';
180
+		$texte .= '</td>';
181 181
 
182
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
183
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
184
-		$texte.= '</td>';
185
-		$texte.= '</tr>';
182
+		$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
183
+		$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
184
+		$texte .= '</td>';
185
+		$texte .= '</tr>';
186 186
 
187
-		$texte.= '</table>';
188
-		$texte.= '</form>';
187
+		$texte .= '</table>';
188
+		$texte .= '</form>';
189 189
 
190 190
 		return $texte;
191 191
 	}
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
 	 *  @param		int			$hideref			Do not show ref
203 203
 	 *	@return		int         					1 if OK, <=0 if KO
204 204
 	 */
205
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
205
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
206 206
 	{
207 207
         // phpcs:enable
208
-		global $user,$langs,$conf,$mysoc,$hookmanager;
208
+		global $user, $langs, $conf, $mysoc, $hookmanager;
209 209
 
210 210
 		if (empty($srctemplatepath))
211 211
 		{
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 		}
215 215
 
216 216
 		// Add odtgeneration hook
217
-		if (! is_object($hookmanager))
217
+		if (!is_object($hookmanager))
218 218
 		{
219 219
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
220
-			$hookmanager=new HookManager($this->db);
220
+			$hookmanager = new HookManager($this->db);
221 221
 		}
222 222
 		$hookmanager->initHooks(array('odtgeneration'));
223 223
 		global $action;
224 224
 
225
-		if (! is_object($outputlangs)) $outputlangs=$langs;
226
-		$sav_charset_output=$outputlangs->charset_output;
227
-		$outputlangs->charset_output='UTF-8';
225
+		if (!is_object($outputlangs)) $outputlangs = $langs;
226
+		$sav_charset_output = $outputlangs->charset_output;
227
+		$outputlangs->charset_output = 'UTF-8';
228 228
 
229 229
 		// Load translation files required by the page
230 230
 		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
@@ -232,28 +232,28 @@  discard block
 block discarded – undo
232 232
 		if ($conf->facture->dir_output)
233 233
 		{
234 234
 			// If $object is id instead of object
235
-			if (! is_object($object))
235
+			if (!is_object($object))
236 236
 			{
237 237
 				$id = $object;
238 238
 				$object = new Facture($this->db);
239
-				$result=$object->fetch($id);
239
+				$result = $object->fetch($id);
240 240
 				if ($result < 0)
241 241
 				{
242
-					dol_print_error($this->db,$object->error);
242
+					dol_print_error($this->db, $object->error);
243 243
 					return -1;
244 244
 				}
245 245
 			}
246 246
 
247 247
 			$dir = $conf->facture->dir_output;
248 248
 			$objectref = dol_sanitizeFileName($object->ref);
249
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
250
-			$file = $dir . "/" . $objectref . ".odt";
249
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
250
+			$file = $dir."/".$objectref.".odt";
251 251
 
252
-			if (! file_exists($dir))
252
+			if (!file_exists($dir))
253 253
 			{
254 254
 				if (dol_mkdir($dir) < 0)
255 255
 				{
256
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
256
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
257 257
 					return -1;
258 258
 				}
259 259
 			}
@@ -261,26 +261,26 @@  discard block
 block discarded – undo
261 261
 			if (file_exists($dir))
262 262
 			{
263 263
 				//print "srctemplatepath=".$srctemplatepath;	// Src filename
264
-				$newfile=basename($srctemplatepath);
265
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
266
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
267
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
264
+				$newfile = basename($srctemplatepath);
265
+				$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
266
+				$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
267
+				$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
268 268
 
269
-				$newfiletmp=$objectref.'_'.$newfiletmp;
269
+				$newfiletmp = $objectref.'_'.$newfiletmp;
270 270
 
271 271
 				// Get extension (ods or odt)
272
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
273
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
272
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
273
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
274 274
 				{
275
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
277
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
275
+				    $format = $conf->global->MAIN_DOC_USE_TIMING;
276
+				    if ($format == '1') $format = '%Y%m%d%H%M%S';
277
+					$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
278 278
 				}
279 279
 				else
280 280
 				{
281
-					$filename=$newfiletmp.'.'.$newfileformat;
281
+					$filename = $newfiletmp.'.'.$newfileformat;
282 282
 				}
283
-				$file=$dir.'/'.$filename;
283
+				$file = $dir.'/'.$filename;
284 284
 				//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
285 285
 				//print "newdir=".$dir;
286 286
 				//print "newfile=".$newfile;
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
 
292 292
 
293 293
 				// If BILLING contact defined on invoice, we use it
294
-				$usecontact=false;
295
-				$arrayidcontact=$object->getIdContact('external','BILLING');
294
+				$usecontact = false;
295
+				$arrayidcontact = $object->getIdContact('external', 'BILLING');
296 296
 				if (count($arrayidcontact) > 0)
297 297
 				{
298
-					$usecontact=true;
299
-					$result=$object->fetch_contact($arrayidcontact[0]);
298
+					$usecontact = true;
299
+					$result = $object->fetch_contact($arrayidcontact[0]);
300 300
 				}
301 301
 
302 302
 				// Recipient name
303 303
 				$contactobject = null;
304
-				if (! empty($usecontact)) {
304
+				if (!empty($usecontact)) {
305 305
 					// On peut utiliser le nom de la societe du contact
306
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
306
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
307 307
 						$socobject = $object->contact;
308 308
 					else {
309 309
 						$socobject = $object->thirdparty;
@@ -315,13 +315,13 @@  discard block
 block discarded – undo
315 315
 				}
316 316
 
317 317
 				// Fetch info for linked propal
318
-				$object->fetchObjectLinked('','','','');
318
+				$object->fetchObjectLinked('', '', '', '');
319 319
 				//print_r($object->linkedObjects['propal']); exit;
320 320
 
321 321
 				$propal_object = $object->linkedObjects['propal'][0];
322 322
 
323 323
 				// Make substitution
324
-				$substitutionarray=array(
324
+				$substitutionarray = array(
325 325
 				'__FROM_NAME__' => $this->emetteur->name,
326 326
 				'__FROM_EMAIL__' => $this->emetteur->email,
327 327
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -330,15 +330,15 @@  discard block
 block discarded – undo
330 330
 				);
331 331
 				complete_substitutions_array($substitutionarray, $langs, $object);
332 332
 				// Call the ODTSubstitution hook
333
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
334
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
333
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
334
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
335 335
 
336 336
 				// Line of free text
337
-				$newfreetext='';
338
-				$paramfreetext='INVOICE_FREE_TEXT';
339
-				if (! empty($conf->global->$paramfreetext))
337
+				$newfreetext = '';
338
+				$paramfreetext = 'INVOICE_FREE_TEXT';
339
+				if (!empty($conf->global->$paramfreetext))
340 340
 				{
341
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
341
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
342 342
 				}
343 343
 
344 344
 				// Open and load template
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 						$srctemplatepath,
349 349
 						array(
350 350
 						'PATH_TO_TMP'	  => $conf->facture->dir_temp,
351
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
351
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
352 352
 						'DELIMITER_LEFT'  => '{',
353 353
 						'DELIMITER_RIGHT' => '}'
354 354
 						)
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 				}
357 357
 				catch (Exception $e)
358 358
 				{
359
-					$this->error=$e->getMessage();
359
+					$this->error = $e->getMessage();
360 360
 					dol_syslog($e->getMessage(), LOG_INFO);
361 361
 					return -1;
362 362
 				}
@@ -378,29 +378,29 @@  discard block
 block discarded – undo
378 378
 
379 379
 				// Define substitution array
380 380
 				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
381
-				$array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs);
382
-				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
383
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
384
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
385
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
386
-				$array_propal=is_object($propal_object)?$this->get_substitutionarray_object($propal_object,$outputlangs,'propal'):array();
387
-				$array_other=$this->get_substitutionarray_other($outputlangs);
381
+				$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
382
+				$array_objet = $this->get_substitutionarray_object($object, $outputlangs);
383
+				$array_user = $this->get_substitutionarray_user($user, $outputlangs);
384
+				$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
385
+				$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
386
+				$array_propal = is_object($propal_object) ? $this->get_substitutionarray_object($propal_object, $outputlangs, 'propal') : array();
387
+				$array_other = $this->get_substitutionarray_other($outputlangs);
388 388
 				// retrieve contact information for use in object as contact_xxx tags
389 389
 				$array_thirdparty_contact = array();
390
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
390
+				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
391 391
 
392
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact);
392
+				$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_propal, $array_other, $array_thirdparty_contact);
393 393
 				complete_substitutions_array($tmparray, $outputlangs, $object);
394 394
 
395 395
 				// Call the ODTSubstitution hook
396
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
397
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
396
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
397
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
398 398
 
399 399
 				//var_dump($tmparray); exit;
400
-				foreach($tmparray as $key=>$value)
400
+				foreach ($tmparray as $key=>$value)
401 401
 				{
402 402
 					try {
403
-						if (preg_match('/logo$/',$key)) // Image
403
+						if (preg_match('/logo$/', $key)) // Image
404 404
 						{
405 405
 							//var_dump($value);exit;
406 406
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 					try {
424 424
 						$listlines = $odfHandler->setSegment('lines');
425 425
 					}
426
-					catch(OdfException $e)
426
+					catch (OdfException $e)
427 427
 					{
428 428
 						// We may arrive here if tags for lines not present into template
429 429
 						$foundtagforlines = 0;
@@ -433,22 +433,22 @@  discard block
 block discarded – undo
433 433
 					{
434 434
 						foreach ($object->lines as $line)
435 435
 						{
436
-							$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
436
+							$tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
437 437
 							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
438 438
 							// Call the ODTSubstitutionLine hook
439
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
440
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
441
-							foreach($tmparray as $key => $val)
439
+							$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line);
440
+							$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
441
+							foreach ($tmparray as $key => $val)
442 442
 							{
443 443
 								try
444 444
 								{
445 445
 									$listlines->setVars($key, $val, true, 'UTF-8');
446 446
 								}
447
-								catch(OdfException $e)
447
+								catch (OdfException $e)
448 448
 								{
449 449
 									dol_syslog($e->getMessage(), LOG_INFO);
450 450
 								}
451
-								catch(SegmentException $e)
451
+								catch (SegmentException $e)
452 452
 								{
453 453
 									dol_syslog($e->getMessage(), LOG_INFO);
454 454
 								}
@@ -458,36 +458,36 @@  discard block
 block discarded – undo
458 458
 						$odfHandler->mergeSegment($listlines);
459 459
 					}
460 460
 				}
461
-				catch(OdfException $e)
461
+				catch (OdfException $e)
462 462
 				{
463
-					$this->error=$e->getMessage();
463
+					$this->error = $e->getMessage();
464 464
 					dol_syslog($this->error, LOG_WARNING);
465 465
 					return -1;
466 466
 				}
467 467
 
468 468
 				// Replace labels translated
469
-				$tmparray=$outputlangs->get_translations_for_substitutions();
470
-				foreach($tmparray as $key=>$value)
469
+				$tmparray = $outputlangs->get_translations_for_substitutions();
470
+				foreach ($tmparray as $key=>$value)
471 471
 				{
472 472
 					try {
473 473
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
474 474
 					}
475
-					catch(OdfException $e)
475
+					catch (OdfException $e)
476 476
 					{
477 477
                         dol_syslog($e->getMessage(), LOG_INFO);
478 478
 					}
479 479
 				}
480 480
 
481 481
 				// Call the beforeODTSave hook
482
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
483
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
482
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
483
+				$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
484 484
 
485 485
 				// Write new file
486 486
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487 487
 					try {
488 488
 						$odfHandler->exportAsAttachedPDF($file);
489
-					}catch (Exception $e){
490
-						$this->error=$e->getMessage();
489
+					} catch (Exception $e) {
490
+						$this->error = $e->getMessage();
491 491
                         dol_syslog($e->getMessage(), LOG_INFO);
492 492
 						return -1;
493 493
 					}
@@ -496,26 +496,26 @@  discard block
 block discarded – undo
496 496
 					try {
497 497
 						$odfHandler->saveToDisk($file);
498 498
 					} catch (Exception $e) {
499
-						$this->error=$e->getMessage();
499
+						$this->error = $e->getMessage();
500 500
                         dol_syslog($e->getMessage(), LOG_INFO);
501 501
 						return -1;
502 502
 					}
503 503
 				}
504
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
505
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
504
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
505
+				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
506 506
 
507
-				if (! empty($conf->global->MAIN_UMASK))
507
+				if (!empty($conf->global->MAIN_UMASK))
508 508
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
509 509
 
510
-				$odfHandler=null;	// Destroy object
510
+				$odfHandler = null; // Destroy object
511 511
 
512 512
 				$this->result = array('fullpath'=>$file);
513 513
 
514
-				return 1;   // Success
514
+				return 1; // Success
515 515
 			}
516 516
 			else
517 517
 			{
518
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
518
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
519 519
 				return -1;
520 520
 			}
521 521
 		}
Please login to merge, or discard this patch.
Braces   +46 added lines, -40 removed lines patch added patch discarded remove patch
@@ -98,7 +98,10 @@  discard block
 block discarded – undo
98 98
 
99 99
 		// Recupere emetteur
100 100
 		$this->emetteur=$mysoc;
101
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
101
+		if (! $this->emetteur->country_code) {
102
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
103
+		}
104
+		// Par defaut, si n'etait pas defini
102 105
 	}
103 106
 
104 107
 
@@ -136,11 +139,14 @@  discard block
 block discarded – undo
136 139
 			if (! $tmpdir) {
137 140
 				unset($listofdir[$key]); continue;
138 141
 			}
139
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
140
-			else
142
+			if (! is_dir($tmpdir)) {
143
+			    $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
144
+			} else
141 145
 			{
142 146
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
143
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
147
+				if (count($tmpfiles)) {
148
+				    $listoffiles=array_merge($listoffiles,$tmpfiles);
149
+				}
144 150
 			}
145 151
 		}
146 152
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -222,7 +228,9 @@  discard block
 block discarded – undo
222 228
 		$hookmanager->initHooks(array('odtgeneration'));
223 229
 		global $action;
224 230
 
225
-		if (! is_object($outputlangs)) $outputlangs=$langs;
231
+		if (! is_object($outputlangs)) {
232
+		    $outputlangs=$langs;
233
+		}
226 234
 		$sav_charset_output=$outputlangs->charset_output;
227 235
 		$outputlangs->charset_output='UTF-8';
228 236
 
@@ -246,7 +254,9 @@  discard block
 block discarded – undo
246 254
 
247 255
 			$dir = $conf->facture->dir_output;
248 256
 			$objectref = dol_sanitizeFileName($object->ref);
249
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
257
+			if (! preg_match('/specimen/i',$objectref)) {
258
+			    $dir.= "/" . $objectref;
259
+			}
250 260
 			$file = $dir . "/" . $objectref . ".odt";
251 261
 
252 262
 			if (! file_exists($dir))
@@ -273,10 +283,11 @@  discard block
 block discarded – undo
273 283
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274 284
 				{
275 285
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
286
+				    if ($format == '1') {
287
+				        $format='%Y%m%d%H%M%S';
288
+				    }
277 289
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
-				}
279
-				else
290
+				} else
280 291
 				{
281 292
 					$filename=$newfiletmp.'.'.$newfileformat;
282 293
 				}
@@ -303,9 +314,9 @@  discard block
 block discarded – undo
303 314
 				$contactobject = null;
304 315
 				if (! empty($usecontact)) {
305 316
 					// On peut utiliser le nom de la societe du contact
306
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
307
-						$socobject = $object->contact;
308
-					else {
317
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
318
+											$socobject = $object->contact;
319
+					} else {
309 320
 						$socobject = $object->thirdparty;
310 321
 						// if we have a BILLING contact and we dont use it as recipient we store the contact object for later use
311 322
 						$contactobject = $object->contact;
@@ -353,8 +364,7 @@  discard block
 block discarded – undo
353 364
 						'DELIMITER_RIGHT' => '}'
354 365
 						)
355 366
 					);
356
-				}
357
-				catch (Exception $e)
367
+				} catch (Exception $e)
358 368
 				{
359 369
 					$this->error=$e->getMessage();
360 370
 					dol_syslog($e->getMessage(), LOG_INFO);
@@ -370,8 +380,7 @@  discard block
 block discarded – undo
370 380
 				// Make substitutions into odt of freetext
371 381
 				try {
372 382
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
373
-				}
374
-				catch (OdfException $e)
383
+				} catch (OdfException $e)
375 384
 				{
376 385
 					dol_syslog($e->getMessage(), LOG_INFO);
377 386
 				}
@@ -387,7 +396,9 @@  discard block
 block discarded – undo
387 396
 				$array_other=$this->get_substitutionarray_other($outputlangs);
388 397
 				// retrieve contact information for use in object as contact_xxx tags
389 398
 				$array_thirdparty_contact = array();
390
-				if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
399
+				if ($usecontact && is_object($contactobject)) {
400
+				    $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
401
+				}
391 402
 
392 403
 				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact);
393 404
 				complete_substitutions_array($tmparray, $outputlangs, $object);
@@ -400,18 +411,19 @@  discard block
 block discarded – undo
400 411
 				foreach($tmparray as $key=>$value)
401 412
 				{
402 413
 					try {
403
-						if (preg_match('/logo$/',$key)) // Image
414
+						if (preg_match('/logo$/',$key)) {
415
+						    // Image
404 416
 						{
405 417
 							//var_dump($value);exit;
406 418
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
407
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
408
-						}
409
-						else    // Text
419
+						} else {
420
+							    $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
421
+							}
422
+						} else    // Text
410 423
 						{
411 424
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
412 425
 						}
413
-					}
414
-					catch (OdfException $e)
426
+					} catch (OdfException $e)
415 427
 					{
416 428
                         dol_syslog($e->getMessage(), LOG_INFO);
417 429
 					}
@@ -422,8 +434,7 @@  discard block
 block discarded – undo
422 434
 					$foundtagforlines = 1;
423 435
 					try {
424 436
 						$listlines = $odfHandler->setSegment('lines');
425
-					}
426
-					catch(OdfException $e)
437
+					} catch(OdfException $e)
427 438
 					{
428 439
 						// We may arrive here if tags for lines not present into template
429 440
 						$foundtagforlines = 0;
@@ -443,12 +454,10 @@  discard block
 block discarded – undo
443 454
 								try
444 455
 								{
445 456
 									$listlines->setVars($key, $val, true, 'UTF-8');
446
-								}
447
-								catch(OdfException $e)
457
+								} catch(OdfException $e)
448 458
 								{
449 459
 									dol_syslog($e->getMessage(), LOG_INFO);
450
-								}
451
-								catch(SegmentException $e)
460
+								} catch(SegmentException $e)
452 461
 								{
453 462
 									dol_syslog($e->getMessage(), LOG_INFO);
454 463
 								}
@@ -457,8 +466,7 @@  discard block
 block discarded – undo
457 466
 						}
458 467
 						$odfHandler->mergeSegment($listlines);
459 468
 					}
460
-				}
461
-				catch(OdfException $e)
469
+				} catch(OdfException $e)
462 470
 				{
463 471
 					$this->error=$e->getMessage();
464 472
 					dol_syslog($this->error, LOG_WARNING);
@@ -471,8 +479,7 @@  discard block
 block discarded – undo
471 479
 				{
472 480
 					try {
473 481
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
474
-					}
475
-					catch(OdfException $e)
482
+					} catch(OdfException $e)
476 483
 					{
477 484
                         dol_syslog($e->getMessage(), LOG_INFO);
478 485
 					}
@@ -486,13 +493,12 @@  discard block
 block discarded – undo
486 493
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
487 494
 					try {
488 495
 						$odfHandler->exportAsAttachedPDF($file);
489
-					}catch (Exception $e){
496
+					} catch (Exception $e){
490 497
 						$this->error=$e->getMessage();
491 498
                         dol_syslog($e->getMessage(), LOG_INFO);
492 499
 						return -1;
493 500
 					}
494
-				}
495
-				else {
501
+				} else {
496 502
 					try {
497 503
 						$odfHandler->saveToDisk($file);
498 504
 					} catch (Exception $e) {
@@ -504,16 +510,16 @@  discard block
 block discarded – undo
504 510
 				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
505 511
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
506 512
 
507
-				if (! empty($conf->global->MAIN_UMASK))
508
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
513
+				if (! empty($conf->global->MAIN_UMASK)) {
514
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
515
+				}
509 516
 
510 517
 				$odfHandler=null;	// Destroy object
511 518
 
512 519
 				$this->result = array('fullpath'=>$file);
513 520
 
514 521
 				return 1;   // Success
515
-			}
516
-			else
522
+			} else
517 523
 			{
518 524
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
519 525
 				return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/facture/doc/pdf_crabe.modules.php 3 patches
Indentation   +1683 added lines, -1683 removed lines patch added patch discarded remove patch
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class pdf_crabe extends ModelePDFFactures
45 45
 {
46
-     /**
47
-     * @var DoliDb Database handler
48
-     */
46
+        /**
47
+         * @var DoliDb Database handler
48
+         */
49 49
     public $db;
50 50
 
51
-	/**
51
+    /**
52 52
      * @var string model name
53 53
      */
54 54
     public $name;
55 55
 
56
-	/**
56
+    /**
57 57
      * @var string model description (short text)
58 58
      */
59 59
     public $description;
@@ -63,163 +63,163 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public $update_main_doc_field;
65 65
 
66
-	/**
66
+    /**
67 67
      * @var string document type
68 68
      */
69 69
     public $type;
70 70
 
71
-	/**
71
+    /**
72 72
      * @var array() Minimum version of PHP required by module.
73
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
73
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
74 74
      */
75
-	public $phpmin = array(5, 4);
75
+    public $phpmin = array(5, 4);
76 76
 
77
-	/**
77
+    /**
78 78
      * Dolibarr version of the loaded document
79 79
      * @public string
80 80
      */
81
-	public $version = 'dolibarr';
81
+    public $version = 'dolibarr';
82 82
 
83
-	/**
83
+    /**
84 84
      * @var int page_largeur
85 85
      */
86 86
     public $page_largeur;
87 87
 
88
-	/**
88
+    /**
89 89
      * @var int page_hauteur
90 90
      */
91 91
     public $page_hauteur;
92 92
 
93
-	/**
93
+    /**
94 94
      * @var array format
95 95
      */
96 96
     public $format;
97 97
 
98
-	/**
98
+    /**
99 99
      * @var int marge_gauche
100 100
      */
101
-	public $marge_gauche;
101
+    public $marge_gauche;
102 102
 
103
-	/**
103
+    /**
104 104
      * @var int marge_droite
105 105
      */
106
-	public $marge_droite;
106
+    public $marge_droite;
107 107
 
108
-	/**
108
+    /**
109 109
      * @var int marge_haute
110 110
      */
111
-	public $marge_haute;
111
+    public $marge_haute;
112 112
 
113
-	/**
113
+    /**
114 114
      * @var int marge_basse
115 115
      */
116
-	public $marge_basse;
117
-
118
-	/**
119
-	 * Issuer
120
-	 * @var Company object that emits
121
-	 */
122
-	public $emetteur;
123
-
124
-	/**
125
-	 * @var bool Situation invoice type
126
-	 */
127
-	public $situationinvoice;
128
-
129
-	/**
130
-	 * @var float X position for the situation progress column
131
-	 */
132
-	public $posxprogress;
133
-
134
-
135
-	/**
136
-	 *	Constructor
137
-	 *
138
-	 *  @param		DoliDB		$db      Database handler
139
-	 */
140
-	function __construct($db)
141
-	{
142
-		global $conf, $langs, $mysoc;
143
-
144
-		// Translations
145
-		$langs->loadLangs(array("main", "bills"));
146
-
147
-		$this->db = $db;
148
-		$this->name = "crabe";
149
-		$this->description = $langs->trans('PDFCrabeDescription');
150
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
151
-
152
-		// Dimensiont page
153
-		$this->type = 'pdf';
154
-		$formatarray=pdf_getFormat();
155
-		$this->page_largeur = $formatarray['width'];
156
-		$this->page_hauteur = $formatarray['height'];
157
-		$this->format = array($this->page_largeur,$this->page_hauteur);
158
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
159
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
160
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
161
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
162
-
163
-		$this->option_logo = 1;                    // Affiche logo
164
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
165
-		$this->option_modereg = 1;                 // Affiche mode reglement
166
-		$this->option_condreg = 1;                 // Affiche conditions reglement
167
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
168
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
169
-		$this->option_escompte = 1;                // Affiche si il y a eu escompte
170
-		$this->option_credit_note = 1;             // Support credit notes
171
-		$this->option_freetext = 1;				   // Support add of a personalised text
172
-		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
173
-
174
-		$this->franchise=!$mysoc->tva_assuj;
175
-
176
-		// Get source company
177
-		$this->emetteur=$mysoc;
178
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
179
-
180
-		// Define position of columns
181
-		$this->posxdesc=$this->marge_gauche+1;
182
-		if($conf->global->PRODUCT_USE_UNITS)
183
-		{
184
-			$this->posxtva=101;
185
-			$this->posxup=118;
186
-			$this->posxqty=135;
187
-			$this->posxunit=151;
188
-		}
189
-		else
190
-		{
191
-			$this->posxtva=110;
192
-			$this->posxup=126;
193
-			$this->posxqty=145;
194
-		}
195
-		$this->posxdiscount=162;
196
-		$this->posxprogress=126; // Only displayed for situation invoices
197
-		$this->postotalht=174;
198
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
199
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
200
-		if ($this->page_largeur < 210) // To work with US executive format
201
-		{
202
-		    $this->posxpicture-=20;
203
-		    $this->posxtva-=20;
204
-		    $this->posxup-=20;
205
-		    $this->posxqty-=20;
206
-		    $this->posxunit-=20;
207
-		    $this->posxdiscount-=20;
208
-		    $this->posxprogress-=20;
209
-		    $this->postotalht-=20;
210
-		}
211
-
212
-		$this->tva=array();
213
-		$this->localtax1=array();
214
-		$this->localtax2=array();
215
-		$this->atleastoneratenotnull=0;
216
-		$this->atleastonediscount=0;
217
-		$this->situationinvoice=false;
218
-	}
116
+    public $marge_basse;
117
+
118
+    /**
119
+     * Issuer
120
+     * @var Company object that emits
121
+     */
122
+    public $emetteur;
123
+
124
+    /**
125
+     * @var bool Situation invoice type
126
+     */
127
+    public $situationinvoice;
128
+
129
+    /**
130
+     * @var float X position for the situation progress column
131
+     */
132
+    public $posxprogress;
133
+
134
+
135
+    /**
136
+     *	Constructor
137
+     *
138
+     *  @param		DoliDB		$db      Database handler
139
+     */
140
+    function __construct($db)
141
+    {
142
+        global $conf, $langs, $mysoc;
143
+
144
+        // Translations
145
+        $langs->loadLangs(array("main", "bills"));
146
+
147
+        $this->db = $db;
148
+        $this->name = "crabe";
149
+        $this->description = $langs->trans('PDFCrabeDescription');
150
+        $this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
151
+
152
+        // Dimensiont page
153
+        $this->type = 'pdf';
154
+        $formatarray=pdf_getFormat();
155
+        $this->page_largeur = $formatarray['width'];
156
+        $this->page_hauteur = $formatarray['height'];
157
+        $this->format = array($this->page_largeur,$this->page_hauteur);
158
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
159
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
160
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
161
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
162
+
163
+        $this->option_logo = 1;                    // Affiche logo
164
+        $this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
165
+        $this->option_modereg = 1;                 // Affiche mode reglement
166
+        $this->option_condreg = 1;                 // Affiche conditions reglement
167
+        $this->option_codeproduitservice = 1;      // Affiche code produit-service
168
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
169
+        $this->option_escompte = 1;                // Affiche si il y a eu escompte
170
+        $this->option_credit_note = 1;             // Support credit notes
171
+        $this->option_freetext = 1;				   // Support add of a personalised text
172
+        $this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
173
+
174
+        $this->franchise=!$mysoc->tva_assuj;
175
+
176
+        // Get source company
177
+        $this->emetteur=$mysoc;
178
+        if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
179
+
180
+        // Define position of columns
181
+        $this->posxdesc=$this->marge_gauche+1;
182
+        if($conf->global->PRODUCT_USE_UNITS)
183
+        {
184
+            $this->posxtva=101;
185
+            $this->posxup=118;
186
+            $this->posxqty=135;
187
+            $this->posxunit=151;
188
+        }
189
+        else
190
+        {
191
+            $this->posxtva=110;
192
+            $this->posxup=126;
193
+            $this->posxqty=145;
194
+        }
195
+        $this->posxdiscount=162;
196
+        $this->posxprogress=126; // Only displayed for situation invoices
197
+        $this->postotalht=174;
198
+        if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
199
+        $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
200
+        if ($this->page_largeur < 210) // To work with US executive format
201
+        {
202
+            $this->posxpicture-=20;
203
+            $this->posxtva-=20;
204
+            $this->posxup-=20;
205
+            $this->posxqty-=20;
206
+            $this->posxunit-=20;
207
+            $this->posxdiscount-=20;
208
+            $this->posxprogress-=20;
209
+            $this->postotalht-=20;
210
+        }
211
+
212
+        $this->tva=array();
213
+        $this->localtax1=array();
214
+        $this->localtax2=array();
215
+        $this->atleastoneratenotnull=0;
216
+        $this->atleastonediscount=0;
217
+        $this->situationinvoice=false;
218
+    }
219 219
 
220 220
 
221 221
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
222
-	/**
222
+    /**
223 223
      *  Function to build pdf onto disk
224 224
      *
225 225
      *  @param		Object		$object				Object to generate
@@ -229,104 +229,104 @@  discard block
 block discarded – undo
229 229
      *  @param		int			$hidedesc			Do not show desc
230 230
      *  @param		int			$hideref			Do not show ref
231 231
      *  @return     int         	    			1=OK, 0=KO
232
-	 */
233
-	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
234
-	{
232
+     */
233
+    function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
234
+    {
235 235
         // phpcs:enable
236
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
237
-
238
-		if (! is_object($outputlangs)) $outputlangs=$langs;
239
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
240
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
241
-
242
-		// Load traductions files requiredby by page
243
-		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
244
-
245
-		$nblignes = count($object->lines);
246
-
247
-		// Loop on each lines to detect if there is at least one image to show
248
-		$realpatharray=array();
249
-		if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
250
-		{
251
-			for ($i = 0 ; $i < $nblignes ; $i++)
252
-			{
253
-				if (empty($object->lines[$i]->fk_product)) continue;
254
-
255
-				$objphoto = new Product($this->db);
256
-				$objphoto->fetch($object->lines[$i]->fk_product);
257
-
258
-				$pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
259
-				$dir = $conf->product->dir_output.'/'.$pdir;
260
-
261
-				$realpath='';
262
-				foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
263
-				{
264
-					$filename=$obj['photo'];
265
-					//if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
266
-					$realpath = $dir.$filename;
267
-					break;
268
-				}
269
-
270
-				if ($realpath) $realpatharray[$i]=$realpath;
271
-			}
272
-		}
273
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
274
-
275
-		if ($conf->facture->dir_output)
276
-		{
277
-			$object->fetch_thirdparty();
278
-
279
-			$deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
280
-			$amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
281
-			$amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
282
-
283
-			// Definition of $dir and $file
284
-			if ($object->specimen)
285
-			{
286
-				$dir = $conf->facture->dir_output;
287
-				$file = $dir . "/SPECIMEN.pdf";
288
-			}
289
-			else
290
-			{
291
-				$objectref = dol_sanitizeFileName($object->ref);
292
-				$dir = $conf->facture->dir_output . "/" . $objectref;
293
-				$file = $dir . "/" . $objectref . ".pdf";
294
-			}
295
-			if (! file_exists($dir))
296
-			{
297
-				if (dol_mkdir($dir) < 0)
298
-				{
299
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
300
-					return 0;
301
-				}
302
-			}
303
-
304
-			if (file_exists($dir))
305
-			{
306
-				// Add pdfgeneration hook
307
-				if (! is_object($hookmanager))
308
-				{
309
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
310
-					$hookmanager=new HookManager($this->db);
311
-				}
312
-				$hookmanager->initHooks(array('pdfgeneration'));
313
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
314
-				global $action;
315
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
316
-
317
-				// Set nblignes with the new facture lines content after hook
318
-				$nblignes = count($object->lines);
319
-				$nbpayments = count($object->getListOfPayments());
320
-
321
-				// Create pdf instance
322
-				$pdf=pdf_getInstance($this->format);
236
+        global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
237
+
238
+        if (! is_object($outputlangs)) $outputlangs=$langs;
239
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
240
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
241
+
242
+        // Load traductions files requiredby by page
243
+        $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
244
+
245
+        $nblignes = count($object->lines);
246
+
247
+        // Loop on each lines to detect if there is at least one image to show
248
+        $realpatharray=array();
249
+        if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
250
+        {
251
+            for ($i = 0 ; $i < $nblignes ; $i++)
252
+            {
253
+                if (empty($object->lines[$i]->fk_product)) continue;
254
+
255
+                $objphoto = new Product($this->db);
256
+                $objphoto->fetch($object->lines[$i]->fk_product);
257
+
258
+                $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
259
+                $dir = $conf->product->dir_output.'/'.$pdir;
260
+
261
+                $realpath='';
262
+                foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
263
+                {
264
+                    $filename=$obj['photo'];
265
+                    //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
266
+                    $realpath = $dir.$filename;
267
+                    break;
268
+                }
269
+
270
+                if ($realpath) $realpatharray[$i]=$realpath;
271
+            }
272
+        }
273
+        if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
274
+
275
+        if ($conf->facture->dir_output)
276
+        {
277
+            $object->fetch_thirdparty();
278
+
279
+            $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
280
+            $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
281
+            $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
282
+
283
+            // Definition of $dir and $file
284
+            if ($object->specimen)
285
+            {
286
+                $dir = $conf->facture->dir_output;
287
+                $file = $dir . "/SPECIMEN.pdf";
288
+            }
289
+            else
290
+            {
291
+                $objectref = dol_sanitizeFileName($object->ref);
292
+                $dir = $conf->facture->dir_output . "/" . $objectref;
293
+                $file = $dir . "/" . $objectref . ".pdf";
294
+            }
295
+            if (! file_exists($dir))
296
+            {
297
+                if (dol_mkdir($dir) < 0)
298
+                {
299
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
300
+                    return 0;
301
+                }
302
+            }
303
+
304
+            if (file_exists($dir))
305
+            {
306
+                // Add pdfgeneration hook
307
+                if (! is_object($hookmanager))
308
+                {
309
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
310
+                    $hookmanager=new HookManager($this->db);
311
+                }
312
+                $hookmanager->initHooks(array('pdfgeneration'));
313
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
314
+                global $action;
315
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
316
+
317
+                // Set nblignes with the new facture lines content after hook
318
+                $nblignes = count($object->lines);
319
+                $nbpayments = count($object->getListOfPayments());
320
+
321
+                // Create pdf instance
322
+                $pdf=pdf_getInstance($this->format);
323 323
                 $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
324 324
                 $pdf->SetAutoPageBreak(1,0);
325 325
 
326 326
                 $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
327
-		        $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
328
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
329
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
327
+                $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
328
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
329
+                if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
330 330
 
331 331
                 if (class_exists('TCPDF'))
332 332
                 {
@@ -338,1514 +338,1514 @@  discard block
 block discarded – undo
338 338
                 // Set path to the background PDF File
339 339
                 if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
340 340
                 {
341
-				    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
342
-				    $tplidx = $pdf->importPage(1);
341
+                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
342
+                    $tplidx = $pdf->importPage(1);
343 343
                 }
344 344
 
345
-				$pdf->Open();
346
-				$pagenb=0;
347
-				$pdf->SetDrawColor(128,128,128);
348
-
349
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
350
-				$pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
351
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
352
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
353
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
355
-
356
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
357
-
358
-				// Positionne $this->atleastonediscount si on a au moins une remise
359
-				for ($i = 0 ; $i < $nblignes ; $i++)
360
-				{
361
-					if ($object->lines[$i]->remise_percent)
362
-					{
363
-						$this->atleastonediscount++;
364
-					}
365
-				}
366
-				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))    // retreive space not used by discount
367
-				{
368
-					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
369
-					$this->posxtva+=($this->postotalht - $this->posxdiscount);
370
-					$this->posxup+=($this->postotalht - $this->posxdiscount);
371
-					$this->posxqty+=($this->postotalht - $this->posxdiscount);
372
-					$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
373
-					//$this->postotalht;
374
-				}
375
-
376
-				$progress_width = 0;
377
-				// Situation invoice handling
378
-				if ($object->situation_cycle_ref)
379
-				{
380
-					$this->situationinvoice = true;
381
-					$progress_width = 18;
382
-					$this->posxtva -= $progress_width;
383
-					$this->posxup -= $progress_width;
384
-					$this->posxqty -= $progress_width;
385
-					if(empty($conf->global->PRODUCT_USE_UNITS)) {
386
-						$this->posxprogress += $progress_width;
387
-					}
388
-					/*$this->posxdiscount -= $progress_width;
345
+                $pdf->Open();
346
+                $pagenb=0;
347
+                $pdf->SetDrawColor(128,128,128);
348
+
349
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
350
+                $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
351
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
352
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
353
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
355
+
356
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
357
+
358
+                // Positionne $this->atleastonediscount si on a au moins une remise
359
+                for ($i = 0 ; $i < $nblignes ; $i++)
360
+                {
361
+                    if ($object->lines[$i]->remise_percent)
362
+                    {
363
+                        $this->atleastonediscount++;
364
+                    }
365
+                }
366
+                if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))    // retreive space not used by discount
367
+                {
368
+                    $this->posxpicture+=($this->postotalht - $this->posxdiscount);
369
+                    $this->posxtva+=($this->postotalht - $this->posxdiscount);
370
+                    $this->posxup+=($this->postotalht - $this->posxdiscount);
371
+                    $this->posxqty+=($this->postotalht - $this->posxdiscount);
372
+                    $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
373
+                    //$this->postotalht;
374
+                }
375
+
376
+                $progress_width = 0;
377
+                // Situation invoice handling
378
+                if ($object->situation_cycle_ref)
379
+                {
380
+                    $this->situationinvoice = true;
381
+                    $progress_width = 18;
382
+                    $this->posxtva -= $progress_width;
383
+                    $this->posxup -= $progress_width;
384
+                    $this->posxqty -= $progress_width;
385
+                    if(empty($conf->global->PRODUCT_USE_UNITS)) {
386
+                        $this->posxprogress += $progress_width;
387
+                    }
388
+                    /*$this->posxdiscount -= $progress_width;
389 389
 					$this->posxprogress -= $progress_width;*/
390
-				}
391
-
392
-				// New page
393
-				$pdf->AddPage();
394
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
395
-				$pagenb++;
396
-
397
-				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
398
-				$pdf->SetFont('','', $default_font_size - 1);
399
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
400
-				$pdf->SetTextColor(0,0,0);
401
-
402
-				$tab_top = 90+$top_shift;
403
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
404
-
405
-				// Incoterm
406
-				if ($conf->incoterm->enabled)
407
-				{
408
-					$desc_incoterms = $object->getIncotermsForPDF();
409
-					if ($desc_incoterms)
410
-					{
411
-						$tab_top -= 2;
412
-
413
-						$pdf->SetFont('','', $default_font_size - 1);
414
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
415
-						$nexY = $pdf->GetY();
416
-						$height_incoterms=$nexY-$tab_top;
417
-
418
-						// Rect prend une longueur en 3eme param
419
-						$pdf->SetDrawColor(192,192,192);
420
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
421
-
422
-						$tab_top = $nexY+6;
423
-					}
424
-				}
425
-
426
-				// Affiche notes
427
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
428
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
429
-				{
430
-					// Get first sale rep
431
-					if (is_object($object->thirdparty))
432
-					{
433
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
434
-						$salerepobj=new User($this->db);
435
-						$salerepobj->fetch($salereparray[0]['id']);
436
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
437
-					}
438
-				}
439
-				if ($notetoshow)
440
-				{
441
-					$tab_top -= 2;
442
-
443
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
444
-					complete_substitutions_array($substitutionarray, $outputlangs, $object);
445
-					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
446
-
447
-					$pdf->SetFont('','', $default_font_size - 1);
448
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
449
-					$nexY = $pdf->GetY();
450
-					$height_note=$nexY-$tab_top;
451
-
452
-					// Rect prend une longueur en 3eme param
453
-					$pdf->SetDrawColor(192,192,192);
454
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
455
-
456
-					$tab_top = $nexY+6;
457
-				}
458
-
459
-				$iniY = $tab_top + 7;
460
-				$curY = $tab_top + 7;
461
-				$nexY = $tab_top + 7;
462
-
463
-				// Loop on each lines
464
-				for ($i = 0; $i < $nblignes; $i++)
465
-				{
466
-					$curY = $nexY;
467
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
468
-					$pdf->SetTextColor(0,0,0);
469
-
470
-					// Define size of image if we need it
471
-					$imglinesize=array();
472
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
473
-
474
-					$pdf->setTopMargin($tab_top_newpage);
475
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
476
-					$pageposbefore=$pdf->getPage();
477
-
478
-					$showpricebeforepagebreak=1;
479
-					$posYAfterImage=0;
480
-					$posYAfterDescription=0;
481
-
482
-					// We start with Photo of product line
483
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
484
-					{
485
-						$pdf->AddPage('','',true);
486
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
-						$pdf->setPage($pageposbefore+1);
489
-
490
-						$curY = $tab_top_newpage;
491
-						$showpricebeforepagebreak=0;
492
-					}
493
-
494
-					if (isset($imglinesize['width']) && isset($imglinesize['height']))
495
-					{
496
-						$curX = $this->posxpicture-1;
497
-						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
498
-						// $pdf->Image does not increase value return by getY, so we save it manually
499
-						$posYAfterImage=$curY+$imglinesize['height'];
500
-					}
501
-
502
-					// Description of product line
503
-					$curX = $this->posxdesc-1;
504
-
505
-					$pdf->startTransaction();
506
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
507
-					$pageposafter=$pdf->getPage();
508
-					if ($pageposafter > $pageposbefore)	// There is a pagebreak
509
-					{
510
-						$pdf->rollbackTransaction(true);
511
-						$pageposafter=$pageposbefore;
512
-						//print $pageposafter.'-'.$pageposbefore;exit;
513
-						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
514
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
515
-						$pageposafter=$pdf->getPage();
516
-						$posyafter=$pdf->GetY();
517
-						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
518
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
519
-						{
520
-							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
521
-							{
522
-								$pdf->AddPage('','',true);
523
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
524
-								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
525
-								$pdf->setPage($pageposafter+1);
526
-							}
527
-						}
528
-						else
529
-						{
530
-							// We found a page break
531
-							$showpricebeforepagebreak=0;
532
-						}
533
-					}
534
-					else	// No pagebreak
535
-					{
536
-						$pdf->commitTransaction();
537
-					}
538
-					$posYAfterDescription=$pdf->GetY();
539
-
540
-					$nexY = $pdf->GetY();
541
-					$pageposafter=$pdf->getPage();
542
-					$pdf->setPage($pageposbefore);
543
-					$pdf->setTopMargin($this->marge_haute);
544
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
545
-
546
-					// We suppose that a too long description or photo were moved completely on next page
547
-					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
548
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
549
-					}
550
-
551
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
552
-
553
-					// VAT Rate
554
-					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
555
-					{
556
-						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
557
-						$pdf->SetXY($this->posxtva-5, $curY);
558
-						$pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
559
-					}
560
-
561
-					// Unit price before discount
562
-					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
563
-					$pdf->SetXY($this->posxup, $curY);
564
-					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
565
-
566
-					// Quantity
567
-					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
568
-					$pdf->SetXY($this->posxqty, $curY);
569
-					// Enough for 6 chars
570
-
571
-					if ($this->situationinvoice)
572
-					{
573
-						$pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R');
574
-					}
575
-					else if($conf->global->PRODUCT_USE_UNITS)
576
-					{
577
-						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
578
-					}
579
-					else
580
-					{
581
-						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
582
-					}
583
-
584
-					// Situation progress
585
-					if ($this->situationinvoice)
586
-					{
587
-						$progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
588
-						$pdf->SetXY($this->posxprogress, $curY);
589
-						if($conf->global->PRODUCT_USE_UNITS)
590
-						{
591
-							$pdf->MultiCell($this->posxunit-$this->posxprogress-1, 3, $progress, 0, 'R');
592
-						}
593
-						else if ($this->atleastonediscount)
594
-						{
595
-							$pdf->MultiCell($this->posxdiscount-$this->posxprogress-1, 3, $progress, 0, 'R');
596
-						}
597
-						else
598
-						{
599
-							$pdf->MultiCell($this->postotalht-$this->posxprogress-1, 3, $progress, 0, 'R');
600
-						}
601
-					}
602
-
603
-					// Unit
604
-					if($conf->global->PRODUCT_USE_UNITS)
605
-					{
606
-						$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
607
-						$pdf->SetXY($this->posxunit, $curY);
608
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
609
-					}
610
-
611
-					// Discount on line
612
-					if ($object->lines[$i]->remise_percent)
613
-					{
390
+                }
391
+
392
+                // New page
393
+                $pdf->AddPage();
394
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
395
+                $pagenb++;
396
+
397
+                $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
398
+                $pdf->SetFont('','', $default_font_size - 1);
399
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
400
+                $pdf->SetTextColor(0,0,0);
401
+
402
+                $tab_top = 90+$top_shift;
403
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
404
+
405
+                // Incoterm
406
+                if ($conf->incoterm->enabled)
407
+                {
408
+                    $desc_incoterms = $object->getIncotermsForPDF();
409
+                    if ($desc_incoterms)
410
+                    {
411
+                        $tab_top -= 2;
412
+
413
+                        $pdf->SetFont('','', $default_font_size - 1);
414
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
415
+                        $nexY = $pdf->GetY();
416
+                        $height_incoterms=$nexY-$tab_top;
417
+
418
+                        // Rect prend une longueur en 3eme param
419
+                        $pdf->SetDrawColor(192,192,192);
420
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
421
+
422
+                        $tab_top = $nexY+6;
423
+                    }
424
+                }
425
+
426
+                // Affiche notes
427
+                $notetoshow=empty($object->note_public)?'':$object->note_public;
428
+                if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
429
+                {
430
+                    // Get first sale rep
431
+                    if (is_object($object->thirdparty))
432
+                    {
433
+                        $salereparray=$object->thirdparty->getSalesRepresentatives($user);
434
+                        $salerepobj=new User($this->db);
435
+                        $salerepobj->fetch($salereparray[0]['id']);
436
+                        if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
437
+                    }
438
+                }
439
+                if ($notetoshow)
440
+                {
441
+                    $tab_top -= 2;
442
+
443
+                    $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
444
+                    complete_substitutions_array($substitutionarray, $outputlangs, $object);
445
+                    $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
446
+
447
+                    $pdf->SetFont('','', $default_font_size - 1);
448
+                    $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
449
+                    $nexY = $pdf->GetY();
450
+                    $height_note=$nexY-$tab_top;
451
+
452
+                    // Rect prend une longueur en 3eme param
453
+                    $pdf->SetDrawColor(192,192,192);
454
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
455
+
456
+                    $tab_top = $nexY+6;
457
+                }
458
+
459
+                $iniY = $tab_top + 7;
460
+                $curY = $tab_top + 7;
461
+                $nexY = $tab_top + 7;
462
+
463
+                // Loop on each lines
464
+                for ($i = 0; $i < $nblignes; $i++)
465
+                {
466
+                    $curY = $nexY;
467
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
468
+                    $pdf->SetTextColor(0,0,0);
469
+
470
+                    // Define size of image if we need it
471
+                    $imglinesize=array();
472
+                    if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
473
+
474
+                    $pdf->setTopMargin($tab_top_newpage);
475
+                    $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
476
+                    $pageposbefore=$pdf->getPage();
477
+
478
+                    $showpricebeforepagebreak=1;
479
+                    $posYAfterImage=0;
480
+                    $posYAfterDescription=0;
481
+
482
+                    // We start with Photo of product line
483
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
484
+                    {
485
+                        $pdf->AddPage('','',true);
486
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
+                        $pdf->setPage($pageposbefore+1);
489
+
490
+                        $curY = $tab_top_newpage;
491
+                        $showpricebeforepagebreak=0;
492
+                    }
493
+
494
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']))
495
+                    {
496
+                        $curX = $this->posxpicture-1;
497
+                        $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
498
+                        // $pdf->Image does not increase value return by getY, so we save it manually
499
+                        $posYAfterImage=$curY+$imglinesize['height'];
500
+                    }
501
+
502
+                    // Description of product line
503
+                    $curX = $this->posxdesc-1;
504
+
505
+                    $pdf->startTransaction();
506
+                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
507
+                    $pageposafter=$pdf->getPage();
508
+                    if ($pageposafter > $pageposbefore)	// There is a pagebreak
509
+                    {
510
+                        $pdf->rollbackTransaction(true);
511
+                        $pageposafter=$pageposbefore;
512
+                        //print $pageposafter.'-'.$pageposbefore;exit;
513
+                        $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
514
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
515
+                        $pageposafter=$pdf->getPage();
516
+                        $posyafter=$pdf->GetY();
517
+                        //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
518
+                        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
519
+                        {
520
+                            if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
521
+                            {
522
+                                $pdf->AddPage('','',true);
523
+                                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
524
+                                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
525
+                                $pdf->setPage($pageposafter+1);
526
+                            }
527
+                        }
528
+                        else
529
+                        {
530
+                            // We found a page break
531
+                            $showpricebeforepagebreak=0;
532
+                        }
533
+                    }
534
+                    else	// No pagebreak
535
+                    {
536
+                        $pdf->commitTransaction();
537
+                    }
538
+                    $posYAfterDescription=$pdf->GetY();
539
+
540
+                    $nexY = $pdf->GetY();
541
+                    $pageposafter=$pdf->getPage();
542
+                    $pdf->setPage($pageposbefore);
543
+                    $pdf->setTopMargin($this->marge_haute);
544
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
545
+
546
+                    // We suppose that a too long description or photo were moved completely on next page
547
+                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
548
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
549
+                    }
550
+
551
+                    $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
552
+
553
+                    // VAT Rate
554
+                    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
555
+                    {
556
+                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
557
+                        $pdf->SetXY($this->posxtva-5, $curY);
558
+                        $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
559
+                    }
560
+
561
+                    // Unit price before discount
562
+                    $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
563
+                    $pdf->SetXY($this->posxup, $curY);
564
+                    $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
565
+
566
+                    // Quantity
567
+                    $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
568
+                    $pdf->SetXY($this->posxqty, $curY);
569
+                    // Enough for 6 chars
570
+
571
+                    if ($this->situationinvoice)
572
+                    {
573
+                        $pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R');
574
+                    }
575
+                    else if($conf->global->PRODUCT_USE_UNITS)
576
+                    {
577
+                        $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
578
+                    }
579
+                    else
580
+                    {
581
+                        $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
582
+                    }
583
+
584
+                    // Situation progress
585
+                    if ($this->situationinvoice)
586
+                    {
587
+                        $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
588
+                        $pdf->SetXY($this->posxprogress, $curY);
589
+                        if($conf->global->PRODUCT_USE_UNITS)
590
+                        {
591
+                            $pdf->MultiCell($this->posxunit-$this->posxprogress-1, 3, $progress, 0, 'R');
592
+                        }
593
+                        else if ($this->atleastonediscount)
594
+                        {
595
+                            $pdf->MultiCell($this->posxdiscount-$this->posxprogress-1, 3, $progress, 0, 'R');
596
+                        }
597
+                        else
598
+                        {
599
+                            $pdf->MultiCell($this->postotalht-$this->posxprogress-1, 3, $progress, 0, 'R');
600
+                        }
601
+                    }
602
+
603
+                    // Unit
604
+                    if($conf->global->PRODUCT_USE_UNITS)
605
+                    {
606
+                        $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
607
+                        $pdf->SetXY($this->posxunit, $curY);
608
+                        $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
609
+                    }
610
+
611
+                    // Discount on line
612
+                    if ($object->lines[$i]->remise_percent)
613
+                    {
614 614
                         $pdf->SetXY($this->posxdiscount-2, $curY);
615
-					    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
616
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
617
-					}
618
-
619
-					// Total HT line
620
-					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
621
-					$pdf->SetXY($this->postotalht, $curY);
622
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
623
-
624
-
625
-					$sign=1;
626
-					if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
627
-					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
628
-					$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
629
-					if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
630
-					{
631
-						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
632
-						else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
633
-					} else {
634
-						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
635
-						else $tvaligne= $sign * $object->lines[$i]->total_tva;
636
-					}
637
-
638
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
639
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
640
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
641
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
642
-					$localtax1_type=$object->lines[$i]->localtax1_type;
643
-					$localtax2_type=$object->lines[$i]->localtax2_type;
644
-
645
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
646
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
647
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
648
-
649
-					$vatrate=(string) $object->lines[$i]->tva_tx;
650
-
651
-					// Retrieve type from database for backward compatibility with old records
652
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
653
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
654
-					{
655
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
656
-						$localtax1_type = $localtaxtmp_array[0];
657
-						$localtax2_type = $localtaxtmp_array[2];
658
-					}
659
-
660
-				    // retrieve global local tax
661
-					if ($localtax1_type && $localtax1ligne != 0)
662
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
663
-					if ($localtax2_type && $localtax2ligne != 0)
664
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
665
-
666
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
667
-					if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
668
-					$this->tva[$vatrate] += $tvaligne;
669
-
670
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
671
-
672
-					// Add line
673
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
674
-					{
675
-						$pdf->setPage($pageposafter);
676
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
677
-						//$pdf->SetDrawColor(190,190,200);
678
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
679
-						$pdf->SetLineStyle(array('dash'=>0));
680
-					}
681
-
682
-					$nexY+=2;    // Passe espace entre les lignes
683
-
684
-					// Detect if some page were added automatically and output _tableau for past pages
685
-					while ($pagenb < $pageposafter)
686
-					{
687
-						$pdf->setPage($pagenb);
688
-						if ($pagenb == 1)
689
-						{
690
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
691
-						}
692
-						else
693
-						{
694
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
695
-						}
696
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
697
-						$pagenb++;
698
-						$pdf->setPage($pagenb);
699
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
700
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
701
-					}
702
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
703
-					{
704
-						if ($pagenb == 1)
705
-						{
706
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
707
-						}
708
-						else
709
-						{
710
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
711
-						}
712
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
713
-						// New page
714
-						$pdf->AddPage();
715
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
716
-						$pagenb++;
717
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
718
-					}
719
-				}
720
-
721
-				// Show square
722
-				if ($pagenb == 1)
723
-				{
724
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
725
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
726
-				}
727
-				else
728
-				{
729
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
730
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
731
-				}
732
-
733
-				// Affiche zone infos
734
-				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
735
-
736
-				// Affiche zone totaux
737
-				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
738
-
739
-				// Affiche zone versements
740
-				if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
741
-				{
742
-					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
743
-				}
744
-
745
-				// Pied de page
746
-				$this->_pagefoot($pdf,$object,$outputlangs);
747
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
748
-
749
-				$pdf->Close();
750
-
751
-				$pdf->Output($file,'F');
752
-
753
-				// Add pdfgeneration hook
754
-				$hookmanager->initHooks(array('pdfgeneration'));
755
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
756
-				global $action;
757
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
758
-
759
-				if (! empty($conf->global->MAIN_UMASK))
760
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
761
-
762
-				$this->result = array('fullpath'=>$file);
763
-
764
-				return 1;   // No error
765
-			}
766
-			else
767
-			{
768
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
769
-				return 0;
770
-			}
771
-		}
772
-		else
773
-		{
774
-			$this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
775
-			return 0;
776
-		}
777
-	}
615
+                        $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
616
+                        $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
617
+                    }
618
+
619
+                    // Total HT line
620
+                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
621
+                    $pdf->SetXY($this->postotalht, $curY);
622
+                    $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
623
+
624
+
625
+                    $sign=1;
626
+                    if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
627
+                    // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
628
+                    $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
629
+                    if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
630
+                    {
631
+                        if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
632
+                        else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
633
+                    } else {
634
+                        if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
635
+                        else $tvaligne= $sign * $object->lines[$i]->total_tva;
636
+                    }
637
+
638
+                    $localtax1ligne=$object->lines[$i]->total_localtax1;
639
+                    $localtax2ligne=$object->lines[$i]->total_localtax2;
640
+                    $localtax1_rate=$object->lines[$i]->localtax1_tx;
641
+                    $localtax2_rate=$object->lines[$i]->localtax2_tx;
642
+                    $localtax1_type=$object->lines[$i]->localtax1_type;
643
+                    $localtax2_type=$object->lines[$i]->localtax2_type;
644
+
645
+                    if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
646
+                    if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
647
+                    if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
648
+
649
+                    $vatrate=(string) $object->lines[$i]->tva_tx;
650
+
651
+                    // Retrieve type from database for backward compatibility with old records
652
+                    if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
653
+                    && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
654
+                    {
655
+                        $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
656
+                        $localtax1_type = $localtaxtmp_array[0];
657
+                        $localtax2_type = $localtaxtmp_array[2];
658
+                    }
659
+
660
+                    // retrieve global local tax
661
+                    if ($localtax1_type && $localtax1ligne != 0)
662
+                        $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
663
+                    if ($localtax2_type && $localtax2ligne != 0)
664
+                        $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
665
+
666
+                    if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
667
+                    if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
668
+                    $this->tva[$vatrate] += $tvaligne;
669
+
670
+                    if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
671
+
672
+                    // Add line
673
+                    if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
674
+                    {
675
+                        $pdf->setPage($pageposafter);
676
+                        $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
677
+                        //$pdf->SetDrawColor(190,190,200);
678
+                        $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
679
+                        $pdf->SetLineStyle(array('dash'=>0));
680
+                    }
681
+
682
+                    $nexY+=2;    // Passe espace entre les lignes
683
+
684
+                    // Detect if some page were added automatically and output _tableau for past pages
685
+                    while ($pagenb < $pageposafter)
686
+                    {
687
+                        $pdf->setPage($pagenb);
688
+                        if ($pagenb == 1)
689
+                        {
690
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
691
+                        }
692
+                        else
693
+                        {
694
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
695
+                        }
696
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
697
+                        $pagenb++;
698
+                        $pdf->setPage($pagenb);
699
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
700
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
701
+                    }
702
+                    if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
703
+                    {
704
+                        if ($pagenb == 1)
705
+                        {
706
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
707
+                        }
708
+                        else
709
+                        {
710
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
711
+                        }
712
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
713
+                        // New page
714
+                        $pdf->AddPage();
715
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
716
+                        $pagenb++;
717
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
718
+                    }
719
+                }
720
+
721
+                // Show square
722
+                if ($pagenb == 1)
723
+                {
724
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
725
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
726
+                }
727
+                else
728
+                {
729
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
730
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
731
+                }
732
+
733
+                // Affiche zone infos
734
+                $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
735
+
736
+                // Affiche zone totaux
737
+                $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
738
+
739
+                // Affiche zone versements
740
+                if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
741
+                {
742
+                    $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
743
+                }
744
+
745
+                // Pied de page
746
+                $this->_pagefoot($pdf,$object,$outputlangs);
747
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
748
+
749
+                $pdf->Close();
750
+
751
+                $pdf->Output($file,'F');
752
+
753
+                // Add pdfgeneration hook
754
+                $hookmanager->initHooks(array('pdfgeneration'));
755
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
756
+                global $action;
757
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
758
+
759
+                if (! empty($conf->global->MAIN_UMASK))
760
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
761
+
762
+                $this->result = array('fullpath'=>$file);
763
+
764
+                return 1;   // No error
765
+            }
766
+            else
767
+            {
768
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
769
+                return 0;
770
+            }
771
+        }
772
+        else
773
+        {
774
+            $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
775
+            return 0;
776
+        }
777
+    }
778 778
 
779 779
 
780 780
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
781
-	/**
782
-	 *  Show payments table
783
-	 *
781
+    /**
782
+     *  Show payments table
783
+     *
784 784
      *  @param	PDF			$pdf           Object PDF
785 785
      *  @param  Object		$object         Object invoice
786 786
      *  @param  int			$posy           Position y in PDF
787 787
      *  @param  Translate	$outputlangs    Object langs for output
788 788
      *  @return int             			<0 if KO, >0 if OK
789
-	 */
790
-	function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
791
-	{
789
+     */
790
+    function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
791
+    {
792 792
         // phpcs:enable
793
-		global $conf;
793
+        global $conf;
794 794
 
795 795
         $sign=1;
796 796
         if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
797 797
 
798 798
         $tab3_posx = 120;
799
-		$tab3_top = $posy + 8;
800
-		$tab3_width = 80;
801
-		$tab3_height = 4;
802
-		if ($this->page_largeur < 210) // To work with US executive format
803
-		{
804
-			$tab3_posx -= 20;
805
-		}
806
-
807
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
808
-
809
-		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
810
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
811
-
812
-		$pdf->SetFont('','', $default_font_size - 3);
813
-		$pdf->SetXY($tab3_posx, $tab3_top - 4);
814
-		$pdf->MultiCell(60, 3, $title, 0, 'L', 0);
815
-
816
-		$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
817
-
818
-		$pdf->SetFont('','', $default_font_size - 4);
819
-		$pdf->SetXY($tab3_posx, $tab3_top);
820
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
821
-		$pdf->SetXY($tab3_posx+21, $tab3_top);
822
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
823
-		$pdf->SetXY($tab3_posx+40, $tab3_top);
824
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
825
-		$pdf->SetXY($tab3_posx+58, $tab3_top);
826
-		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
827
-
828
-		$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
829
-
830
-		$y=0;
831
-
832
-		$pdf->SetFont('','', $default_font_size - 4);
833
-
834
-
835
-		// Loop on each discount available (deposits and credit notes and excess of payment included)
836
-		$sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
837
-		$sql.= " re.description, re.fk_facture_source,";
838
-		$sql.= " f.type, f.datef";
839
-		$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
840
-		$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
841
-		$resql=$this->db->query($sql);
842
-		if ($resql)
843
-		{
844
-			$num = $this->db->num_rows($resql);
845
-			$i=0;
846
-			$invoice=new Facture($this->db);
847
-			while ($i < $num)
848
-			{
849
-				$y+=3;
850
-				$obj = $this->db->fetch_object($resql);
851
-
852
-				if ($obj->type == 2) $text=$outputlangs->transnoentities("CreditNote");
853
-				elseif ($obj->type == 3) $text=$outputlangs->transnoentities("Deposit");
854
-				elseif ($obj->type == 0) $text=$outputlangs->transnoentities("ExcessReceived");
855
-				else $text=$outputlangs->transnoentities("UnknownType");
856
-
857
-				$invoice->fetch($obj->fk_facture_source);
858
-
859
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
860
-				$pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
861
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
862
-				$pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
863
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
864
-				$pdf->MultiCell(20, 3, $text, 0, 'L', 0);
865
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
866
-				$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
867
-
868
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
869
-
870
-				$i++;
871
-			}
872
-		}
873
-		else
874
-		{
875
-			$this->error=$this->db->lasterror();
876
-			return -1;
877
-		}
878
-
879
-		// Loop on each payment
880
-		// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
881
-		$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
882
-		$sql.= " cp.code";
883
-		$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
884
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
885
-		$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
886
-		//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
887
-		$sql.= " ORDER BY p.datep";
888
-
889
-		$resql=$this->db->query($sql);
890
-		if ($resql)
891
-		{
892
-			$num = $this->db->num_rows($resql);
893
-			$i=0;
894
-			while ($i < $num) {
895
-				$y+=3;
896
-				$row = $this->db->fetch_object($resql);
897
-
898
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
899
-				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
900
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
901
-				$pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
902
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
903
-				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
904
-
905
-				$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
906
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
907
-				$pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
908
-
909
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
910
-
911
-				$i++;
912
-			}
913
-		}
914
-		else
915
-		{
916
-			$this->error=$this->db->lasterror();
917
-			return -1;
918
-		}
919
-	}
799
+        $tab3_top = $posy + 8;
800
+        $tab3_width = 80;
801
+        $tab3_height = 4;
802
+        if ($this->page_largeur < 210) // To work with US executive format
803
+        {
804
+            $tab3_posx -= 20;
805
+        }
806
+
807
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
808
+
809
+        $title=$outputlangs->transnoentities("PaymentsAlreadyDone");
810
+        if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
811
+
812
+        $pdf->SetFont('','', $default_font_size - 3);
813
+        $pdf->SetXY($tab3_posx, $tab3_top - 4);
814
+        $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
815
+
816
+        $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
817
+
818
+        $pdf->SetFont('','', $default_font_size - 4);
819
+        $pdf->SetXY($tab3_posx, $tab3_top);
820
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
821
+        $pdf->SetXY($tab3_posx+21, $tab3_top);
822
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
823
+        $pdf->SetXY($tab3_posx+40, $tab3_top);
824
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
825
+        $pdf->SetXY($tab3_posx+58, $tab3_top);
826
+        $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
827
+
828
+        $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
829
+
830
+        $y=0;
831
+
832
+        $pdf->SetFont('','', $default_font_size - 4);
833
+
834
+
835
+        // Loop on each discount available (deposits and credit notes and excess of payment included)
836
+        $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
837
+        $sql.= " re.description, re.fk_facture_source,";
838
+        $sql.= " f.type, f.datef";
839
+        $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
840
+        $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
841
+        $resql=$this->db->query($sql);
842
+        if ($resql)
843
+        {
844
+            $num = $this->db->num_rows($resql);
845
+            $i=0;
846
+            $invoice=new Facture($this->db);
847
+            while ($i < $num)
848
+            {
849
+                $y+=3;
850
+                $obj = $this->db->fetch_object($resql);
851
+
852
+                if ($obj->type == 2) $text=$outputlangs->transnoentities("CreditNote");
853
+                elseif ($obj->type == 3) $text=$outputlangs->transnoentities("Deposit");
854
+                elseif ($obj->type == 0) $text=$outputlangs->transnoentities("ExcessReceived");
855
+                else $text=$outputlangs->transnoentities("UnknownType");
856
+
857
+                $invoice->fetch($obj->fk_facture_source);
858
+
859
+                $pdf->SetXY($tab3_posx, $tab3_top+$y);
860
+                $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
861
+                $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
862
+                $pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
863
+                $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
864
+                $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
865
+                $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
866
+                $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
867
+
868
+                $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
869
+
870
+                $i++;
871
+            }
872
+        }
873
+        else
874
+        {
875
+            $this->error=$this->db->lasterror();
876
+            return -1;
877
+        }
878
+
879
+        // Loop on each payment
880
+        // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
881
+        $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
882
+        $sql.= " cp.code";
883
+        $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
884
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
885
+        $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
886
+        //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
887
+        $sql.= " ORDER BY p.datep";
888
+
889
+        $resql=$this->db->query($sql);
890
+        if ($resql)
891
+        {
892
+            $num = $this->db->num_rows($resql);
893
+            $i=0;
894
+            while ($i < $num) {
895
+                $y+=3;
896
+                $row = $this->db->fetch_object($resql);
897
+
898
+                $pdf->SetXY($tab3_posx, $tab3_top+$y);
899
+                $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
900
+                $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
901
+                $pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
902
+                $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
903
+                $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
904
+
905
+                $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
906
+                $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
907
+                $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
908
+
909
+                $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
910
+
911
+                $i++;
912
+            }
913
+        }
914
+        else
915
+        {
916
+            $this->error=$this->db->lasterror();
917
+            return -1;
918
+        }
919
+    }
920 920
 
921 921
 
922 922
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
923
-	/**
924
-	 *   Show miscellaneous information (payment mode, payment term, ...)
925
-	 *
926
-	 *   @param		PDF			$pdf     		Object PDF
927
-	 *   @param		Object		$object			Object to show
928
-	 *   @param		int			$posy			Y
929
-	 *   @param		Translate	$outputlangs	Langs object
930
-	 *   @return	void
931
-	 */
932
-	function _tableau_info(&$pdf, $object, $posy, $outputlangs)
933
-	{
923
+    /**
924
+     *   Show miscellaneous information (payment mode, payment term, ...)
925
+     *
926
+     *   @param		PDF			$pdf     		Object PDF
927
+     *   @param		Object		$object			Object to show
928
+     *   @param		int			$posy			Y
929
+     *   @param		Translate	$outputlangs	Langs object
930
+     *   @return	void
931
+     */
932
+    function _tableau_info(&$pdf, $object, $posy, $outputlangs)
933
+    {
934 934
         // phpcs:enable
935
-		global $conf;
936
-
937
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
938
-
939
-		$pdf->SetFont('','', $default_font_size - 1);
940
-
941
-		// If France, show VAT mention if not applicable
942
-		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
943
-		{
944
-			$pdf->SetFont('','B', $default_font_size - 2);
945
-			$pdf->SetXY($this->marge_gauche, $posy);
946
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
947
-
948
-			$posy=$pdf->GetY()+4;
949
-		}
950
-
951
-		$posxval=52;
952
-
953
-		// Show payments conditions
954
-		if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
955
-		{
956
-			$pdf->SetFont('','B', $default_font_size - 2);
957
-			$pdf->SetXY($this->marge_gauche, $posy);
958
-			$titre = $outputlangs->transnoentities("PaymentConditions").':';
959
-			$pdf->MultiCell(43, 4, $titre, 0, 'L');
960
-
961
-			$pdf->SetFont('','', $default_font_size - 2);
962
-			$pdf->SetXY($posxval, $posy);
963
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
964
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
965
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
966
-
967
-			$posy=$pdf->GetY()+3;
968
-		}
969
-
970
-		if ($object->type != 2)
971
-		{
972
-			// Check a payment mode is defined
973
-			if (empty($object->mode_reglement_code)
974
-			&& empty($conf->global->FACTURE_CHQ_NUMBER)
975
-			&& empty($conf->global->FACTURE_RIB_NUMBER))
976
-			{
977
-				$this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
978
-			}
979
-			// Avoid having any valid PDF with setup that is not complete
980
-			elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
981
-				|| ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)))
982
-			{
983
-				$outputlangs->load("errors");
984
-
985
-				$pdf->SetXY($this->marge_gauche, $posy);
986
-				$pdf->SetTextColor(200,0,0);
987
-				$pdf->SetFont('','B', $default_font_size - 2);
988
-				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
989
-				$pdf->MultiCell(80, 3, $this->error,0,'L',0);
990
-				$pdf->SetTextColor(0,0,0);
991
-
992
-				$posy=$pdf->GetY()+1;
993
-			}
994
-
995
-			// Show payment mode
996
-			if ($object->mode_reglement_code
997
-			&& $object->mode_reglement_code != 'CHQ'
998
-			&& $object->mode_reglement_code != 'VIR')
999
-			{
1000
-				$pdf->SetFont('','B', $default_font_size - 2);
1001
-				$pdf->SetXY($this->marge_gauche, $posy);
1002
-				$titre = $outputlangs->transnoentities("PaymentMode").':';
1003
-				$pdf->MultiCell(80, 5, $titre, 0, 'L');
1004
-
1005
-				$pdf->SetFont('','', $default_font_size - 2);
1006
-				$pdf->SetXY($posxval, $posy);
1007
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1008
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1009
-
1010
-				$posy=$pdf->GetY()+2;
1011
-			}
1012
-
1013
-			// Show payment mode CHQ
1014
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1015
-			{
1016
-				// Si mode reglement non force ou si force a CHQ
1017
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1018
-				{
1019
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1020
-
1021
-					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1022
-					{
1023
-						$account = new Account($this->db);
1024
-						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1025
-
1026
-						$pdf->SetXY($this->marge_gauche, $posy);
1027
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1028
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1029
-						$posy=$pdf->GetY()+1;
1030
-
1031
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1032
-			            {
1033
-							$pdf->SetXY($this->marge_gauche, $posy);
1034
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1035
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1036
-							$posy=$pdf->GetY()+2;
1037
-			            }
1038
-					}
1039
-					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1040
-					{
1041
-						$pdf->SetXY($this->marge_gauche, $posy);
1042
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1043
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1044
-						$posy=$pdf->GetY()+1;
1045
-
1046
-			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1047
-			            {
1048
-							$pdf->SetXY($this->marge_gauche, $posy);
1049
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1050
-							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1051
-							$posy=$pdf->GetY()+2;
1052
-			            }
1053
-					}
1054
-				}
1055
-			}
1056
-
1057
-			// If payment mode not forced or forced to VIR, show payment with BAN
1058
-			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1059
-			{
1060
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1061
-				{
1062
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1063
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1064
-					$account = new Account($this->db);
1065
-					$account->fetch($bankid);
1066
-
1067
-					$curx=$this->marge_gauche;
1068
-					$cury=$posy;
1069
-
1070
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1071
-
1072
-					$posy+=2;
1073
-				}
1074
-			}
1075
-		}
1076
-
1077
-		return $posy;
1078
-	}
935
+        global $conf;
936
+
937
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
938
+
939
+        $pdf->SetFont('','', $default_font_size - 1);
940
+
941
+        // If France, show VAT mention if not applicable
942
+        if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
943
+        {
944
+            $pdf->SetFont('','B', $default_font_size - 2);
945
+            $pdf->SetXY($this->marge_gauche, $posy);
946
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
947
+
948
+            $posy=$pdf->GetY()+4;
949
+        }
950
+
951
+        $posxval=52;
952
+
953
+        // Show payments conditions
954
+        if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
955
+        {
956
+            $pdf->SetFont('','B', $default_font_size - 2);
957
+            $pdf->SetXY($this->marge_gauche, $posy);
958
+            $titre = $outputlangs->transnoentities("PaymentConditions").':';
959
+            $pdf->MultiCell(43, 4, $titre, 0, 'L');
960
+
961
+            $pdf->SetFont('','', $default_font_size - 2);
962
+            $pdf->SetXY($posxval, $posy);
963
+            $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
964
+            $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
965
+            $pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
966
+
967
+            $posy=$pdf->GetY()+3;
968
+        }
969
+
970
+        if ($object->type != 2)
971
+        {
972
+            // Check a payment mode is defined
973
+            if (empty($object->mode_reglement_code)
974
+            && empty($conf->global->FACTURE_CHQ_NUMBER)
975
+            && empty($conf->global->FACTURE_RIB_NUMBER))
976
+            {
977
+                $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
978
+            }
979
+            // Avoid having any valid PDF with setup that is not complete
980
+            elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
981
+                || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)))
982
+            {
983
+                $outputlangs->load("errors");
984
+
985
+                $pdf->SetXY($this->marge_gauche, $posy);
986
+                $pdf->SetTextColor(200,0,0);
987
+                $pdf->SetFont('','B', $default_font_size - 2);
988
+                $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
989
+                $pdf->MultiCell(80, 3, $this->error,0,'L',0);
990
+                $pdf->SetTextColor(0,0,0);
991
+
992
+                $posy=$pdf->GetY()+1;
993
+            }
994
+
995
+            // Show payment mode
996
+            if ($object->mode_reglement_code
997
+            && $object->mode_reglement_code != 'CHQ'
998
+            && $object->mode_reglement_code != 'VIR')
999
+            {
1000
+                $pdf->SetFont('','B', $default_font_size - 2);
1001
+                $pdf->SetXY($this->marge_gauche, $posy);
1002
+                $titre = $outputlangs->transnoentities("PaymentMode").':';
1003
+                $pdf->MultiCell(80, 5, $titre, 0, 'L');
1004
+
1005
+                $pdf->SetFont('','', $default_font_size - 2);
1006
+                $pdf->SetXY($posxval, $posy);
1007
+                $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1008
+                $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1009
+
1010
+                $posy=$pdf->GetY()+2;
1011
+            }
1012
+
1013
+            // Show payment mode CHQ
1014
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1015
+            {
1016
+                // Si mode reglement non force ou si force a CHQ
1017
+                if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1018
+                {
1019
+                    $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1020
+
1021
+                    if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1022
+                    {
1023
+                        $account = new Account($this->db);
1024
+                        $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1025
+
1026
+                        $pdf->SetXY($this->marge_gauche, $posy);
1027
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1028
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1029
+                        $posy=$pdf->GetY()+1;
1030
+
1031
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1032
+                        {
1033
+                            $pdf->SetXY($this->marge_gauche, $posy);
1034
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1035
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1036
+                            $posy=$pdf->GetY()+2;
1037
+                        }
1038
+                    }
1039
+                    if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1040
+                    {
1041
+                        $pdf->SetXY($this->marge_gauche, $posy);
1042
+                        $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1043
+                        $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1044
+                        $posy=$pdf->GetY()+1;
1045
+
1046
+                        if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1047
+                        {
1048
+                            $pdf->SetXY($this->marge_gauche, $posy);
1049
+                            $pdf->SetFont('','', $default_font_size - $diffsizetitle);
1050
+                            $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1051
+                            $posy=$pdf->GetY()+2;
1052
+                        }
1053
+                    }
1054
+                }
1055
+            }
1056
+
1057
+            // If payment mode not forced or forced to VIR, show payment with BAN
1058
+            if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1059
+            {
1060
+                if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1061
+                {
1062
+                    $bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1063
+                    if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1064
+                    $account = new Account($this->db);
1065
+                    $account->fetch($bankid);
1066
+
1067
+                    $curx=$this->marge_gauche;
1068
+                    $cury=$posy;
1069
+
1070
+                    $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1071
+
1072
+                    $posy+=2;
1073
+                }
1074
+            }
1075
+        }
1076
+
1077
+        return $posy;
1078
+    }
1079 1079
 
1080 1080
 
1081 1081
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1082
-	/**
1083
-	 *	Show total to pay
1084
-	 *
1085
-	 *	@param	PDF			$pdf           Object PDF
1086
-	 *	@param  Facture		$object         Object invoice
1087
-	 *	@param  int			$deja_regle     Montant deja regle
1088
-	 *	@param	int			$posy			Position depart
1089
-	 *	@param	Translate	$outputlangs	Objet langs
1090
-	 *	@return int							Position pour suite
1091
-	 */
1092
-	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1093
-	{
1082
+    /**
1083
+     *	Show total to pay
1084
+     *
1085
+     *	@param	PDF			$pdf           Object PDF
1086
+     *	@param  Facture		$object         Object invoice
1087
+     *	@param  int			$deja_regle     Montant deja regle
1088
+     *	@param	int			$posy			Position depart
1089
+     *	@param	Translate	$outputlangs	Objet langs
1090
+     *	@return int							Position pour suite
1091
+     */
1092
+    function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1093
+    {
1094 1094
         // phpcs:enable
1095
-		global $conf,$mysoc;
1095
+        global $conf,$mysoc;
1096 1096
 
1097 1097
         $sign=1;
1098 1098
         if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1099 1099
 
1100 1100
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1101 1101
 
1102
-		$tab2_top = $posy;
1103
-		$tab2_hl = 4;
1104
-		$pdf->SetFont('','', $default_font_size - 1);
1105
-
1106
-		// Tableau total
1107
-		$col1x = 120; $col2x = 170;
1108
-		if ($this->page_largeur < 210) // To work with US executive format
1109
-		{
1110
-			$col2x-=20;
1111
-		}
1112
-		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1113
-
1114
-		$useborder=0;
1115
-		$index = 0;
1116
-
1117
-		// Total HT
1118
-		$pdf->SetFillColor(255,255,255);
1119
-		$pdf->SetXY($col1x, $tab2_top + 0);
1120
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1121
-
1122
-		$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1123
-		$pdf->SetXY($col2x, $tab2_top + 0);
1124
-		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1125
-
1126
-		// Show VAT by rates and total
1127
-		$pdf->SetFillColor(248,248,248);
1128
-
1129
-		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1130
-
1131
-		$this->atleastoneratenotnull=0;
1132
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1133
-		{
1134
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1135
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1136
-			{
1137
-				// Nothing to do
1138
-			}
1139
-			else
1140
-			{
1141
-			    // FIXME amount of vat not supported with multicurrency
1142
-
1143
-				//Local tax 1 before VAT
1144
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1145
-				//{
1146
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1147
-					{
1148
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1149
-
1150
-						foreach( $localtax_rate as $tvakey => $tvaval )
1151
-						{
1152
-							if ($tvakey!=0)    // On affiche pas taux 0
1153
-							{
1154
-								//$this->atleastoneratenotnull++;
1155
-
1156
-								$index++;
1157
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1158
-
1159
-								$tvacompl='';
1160
-								if (preg_match('/\*/',$tvakey))
1161
-								{
1162
-									$tvakey=str_replace('*','',$tvakey);
1163
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1164
-								}
1165
-
1166
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1167
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1168
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1169
-
1170
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1171
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1172
-							}
1173
-						}
1174
-					}
1175
-	      		//}
1176
-				//Local tax 2 before VAT
1177
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1178
-				//{
1179
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1180
-					{
1181
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1182
-
1183
-						foreach( $localtax_rate as $tvakey => $tvaval )
1184
-						{
1185
-							if ($tvakey!=0)    // On affiche pas taux 0
1186
-							{
1187
-								//$this->atleastoneratenotnull++;
1188
-
1189
-
1190
-
1191
-								$index++;
1192
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1193
-
1194
-								$tvacompl='';
1195
-								if (preg_match('/\*/',$tvakey))
1196
-								{
1197
-									$tvakey=str_replace('*','',$tvakey);
1198
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1199
-								}
1200
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1201
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1202
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1203
-
1204
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1205
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1206
-							}
1207
-						}
1208
-					}
1102
+        $tab2_top = $posy;
1103
+        $tab2_hl = 4;
1104
+        $pdf->SetFont('','', $default_font_size - 1);
1105
+
1106
+        // Tableau total
1107
+        $col1x = 120; $col2x = 170;
1108
+        if ($this->page_largeur < 210) // To work with US executive format
1109
+        {
1110
+            $col2x-=20;
1111
+        }
1112
+        $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1113
+
1114
+        $useborder=0;
1115
+        $index = 0;
1116
+
1117
+        // Total HT
1118
+        $pdf->SetFillColor(255,255,255);
1119
+        $pdf->SetXY($col1x, $tab2_top + 0);
1120
+        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1121
+
1122
+        $total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1123
+        $pdf->SetXY($col2x, $tab2_top + 0);
1124
+        $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1125
+
1126
+        // Show VAT by rates and total
1127
+        $pdf->SetFillColor(248,248,248);
1128
+
1129
+        $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1130
+
1131
+        $this->atleastoneratenotnull=0;
1132
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1133
+        {
1134
+            $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1135
+            if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1136
+            {
1137
+                // Nothing to do
1138
+            }
1139
+            else
1140
+            {
1141
+                // FIXME amount of vat not supported with multicurrency
1142
+
1143
+                //Local tax 1 before VAT
1144
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1145
+                //{
1146
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1147
+                    {
1148
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1149
+
1150
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1151
+                        {
1152
+                            if ($tvakey!=0)    // On affiche pas taux 0
1153
+                            {
1154
+                                //$this->atleastoneratenotnull++;
1155
+
1156
+                                $index++;
1157
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1158
+
1159
+                                $tvacompl='';
1160
+                                if (preg_match('/\*/',$tvakey))
1161
+                                {
1162
+                                    $tvakey=str_replace('*','',$tvakey);
1163
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1164
+                                }
1165
+
1166
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1167
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1168
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1169
+
1170
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1171
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1172
+                            }
1173
+                        }
1174
+                    }
1175
+                    //}
1176
+                //Local tax 2 before VAT
1177
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1178
+                //{
1179
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1180
+                    {
1181
+                        if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1182
+
1183
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1184
+                        {
1185
+                            if ($tvakey!=0)    // On affiche pas taux 0
1186
+                            {
1187
+                                //$this->atleastoneratenotnull++;
1188
+
1189
+
1190
+
1191
+                                $index++;
1192
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1193
+
1194
+                                $tvacompl='';
1195
+                                if (preg_match('/\*/',$tvakey))
1196
+                                {
1197
+                                    $tvakey=str_replace('*','',$tvakey);
1198
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1199
+                                }
1200
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1201
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1202
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1203
+
1204
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1205
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1206
+                            }
1207
+                        }
1208
+                    }
1209 1209
 
1210 1210
                 //}
1211 1211
 
1212
-				// VAT
1213
-				// Situations totals migth be wrong on huge amounts
1214
-				if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1215
-
1216
-					$sum_pdf_tva = 0;
1217
-					foreach($this->tva as $tvakey => $tvaval){
1218
-						$sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1219
-					}
1220
-
1221
-					if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1222
-						$coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1223
-
1224
-						foreach($this->tva as $tvakey => $tvaval) {
1225
-							$this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1226
-						}
1227
-					}
1228
-				}
1229
-
1230
-				foreach($this->tva as $tvakey => $tvaval)
1231
-				{
1232
-					if ($tvakey != 0)    // On affiche pas taux 0
1233
-					{
1234
-						$this->atleastoneratenotnull++;
1235
-
1236
-						$index++;
1237
-						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1238
-
1239
-						$tvacompl='';
1240
-						if (preg_match('/\*/',$tvakey))
1241
-						{
1242
-							$tvakey=str_replace('*','',$tvakey);
1243
-							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1244
-						}
1245
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1246
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1247
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1248
-
1249
-						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1250
-						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1251
-					}
1252
-				}
1253
-
1254
-				//Local tax 1 after VAT
1255
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1256
-				//{
1257
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1258
-					{
1259
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1260
-
1261
-						foreach( $localtax_rate as $tvakey => $tvaval )
1262
-						{
1263
-							if ($tvakey != 0)    // On affiche pas taux 0
1264
-							{
1265
-								//$this->atleastoneratenotnull++;
1266
-
1267
-								$index++;
1268
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1269
-
1270
-								$tvacompl='';
1271
-								if (preg_match('/\*/',$tvakey))
1272
-								{
1273
-									$tvakey=str_replace('*','',$tvakey);
1274
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1275
-								}
1276
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1277
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1278
-
1279
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1280
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1281
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1282
-							}
1283
-						}
1284
-					}
1285
-	      		//}
1286
-				//Local tax 2 after VAT
1287
-				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1288
-				//{
1289
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1290
-					{
1291
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1292
-
1293
-						foreach( $localtax_rate as $tvakey => $tvaval )
1294
-						{
1295
-						    // retrieve global local tax
1296
-							if ($tvakey != 0)    // On affiche pas taux 0
1297
-							{
1298
-								//$this->atleastoneratenotnull++;
1299
-
1300
-								$index++;
1301
-								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1302
-
1303
-								$tvacompl='';
1304
-								if (preg_match('/\*/',$tvakey))
1305
-								{
1306
-									$tvakey=str_replace('*','',$tvakey);
1307
-									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1308
-								}
1309
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1310
-
1311
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1312
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1313
-
1314
-								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1315
-								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1316
-							}
1317
-						}
1318
-					//}
1319
-				}
1320
-
1321
-				// Revenue stamp
1322
-				if (price2num($object->revenuestamp) != 0)
1323
-				{
1324
-					$index++;
1325
-					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1326
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1327
-
1328
-					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1329
-					$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1330
-				}
1331
-
1332
-				// Total TTC
1333
-				$index++;
1334
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1335
-				$pdf->SetTextColor(0,0,60);
1336
-				$pdf->SetFillColor(224,224,224);
1337
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1338
-
1339
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1340
-				$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1341
-			}
1342
-		}
1343
-
1344
-		$pdf->SetTextColor(0,0,0);
1345
-		$creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);	// Warning, this also include excess received
1346
-		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1347
-		//print "x".$creditnoteamount."-".$depositsamount;exit;
1348
-		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1349
-		if ($object->paye) $resteapayer=0;
1350
-
1351
-		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1352
-		{
1353
-			// Already paid + Deposits
1354
-			$index++;
1355
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1356
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1357
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1358
-			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1359
-
1360
-			// Credit note
1361
-			if ($creditnoteamount)
1362
-			{
1363
-				$labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1364
-				$index++;
1365
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1366
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1367
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1368
-				$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1369
-			}
1370
-
1371
-			// Escompte
1372
-			if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1373
-			{
1374
-				$index++;
1375
-				$pdf->SetFillColor(255,255,255);
1376
-
1377
-				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1378
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1379
-				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1380
-				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1381
-
1382
-				$resteapayer=0;
1383
-			}
1384
-
1385
-			$index++;
1386
-			$pdf->SetTextColor(0,0,60);
1387
-			$pdf->SetFillColor(224,224,224);
1388
-			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1389
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1390
-			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391
-			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1392
-
1393
-			$pdf->SetFont('','', $default_font_size - 1);
1394
-			$pdf->SetTextColor(0,0,0);
1395
-		}
1396
-
1397
-		$index++;
1398
-		return ($tab2_top + ($tab2_hl * $index));
1399
-	}
1400
-
1401
-	/**
1402
-	 *   Show table for lines
1403
-	 *
1404
-	 *   @param		PDF			$pdf     		Object PDF
1405
-	 *   @param		string		$tab_top		Top position of table
1406
-	 *   @param		string		$tab_height		Height of table (rectangle)
1407
-	 *   @param		int			$nexY			Y (not used)
1408
-	 *   @param		Translate	$outputlangs	Langs object
1409
-	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1410
-	 *   @param		int			$hidebottom		Hide bottom bar of array
1411
-	 *   @param		string		$currency		Currency code
1412
-	 *   @return	void
1413
-	 */
1414
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1415
-	{
1416
-		global $conf;
1417
-
1418
-		// Force to disable hidetop and hidebottom
1419
-		$hidebottom=0;
1420
-		if ($hidetop) $hidetop=-1;
1421
-
1422
-		$currency = !empty($currency) ? $currency : $conf->currency;
1423
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1424
-
1425
-		// Amount in (at tab_top - 1)
1426
-		$pdf->SetTextColor(0,0,0);
1427
-		$pdf->SetFont('','', $default_font_size - 2);
1428
-
1429
-		if (empty($hidetop))
1430
-		{
1431
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1432
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1433
-			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1434
-
1435
-			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1436
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1437
-		}
1438
-
1439
-		$pdf->SetDrawColor(128,128,128);
1440
-		$pdf->SetFont('','', $default_font_size - 1);
1441
-
1442
-		// Output Rect
1443
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1444
-
1445
-		if (empty($hidetop))
1446
-		{
1447
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1448
-
1449
-			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1450
-			$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1451
-		}
1452
-
1453
-		if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
1454
-		{
1455
-			$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1456
-			if (empty($hidetop))
1457
-			{
1458
-				//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1459
-				//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1460
-			}
1461
-		}
1462
-
1463
-		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1464
-		{
1465
-			$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1466
-			if (empty($hidetop))
1467
-			{
1468
-				$pdf->SetXY($this->posxtva-3, $tab_top+1);
1469
-				$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1470
-			}
1471
-		}
1472
-
1473
-		$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1474
-		if (empty($hidetop))
1475
-		{
1476
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
1477
-			$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1478
-		}
1479
-
1480
-		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1481
-		if (empty($hidetop))
1482
-		{
1483
-			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1484
-
1485
-			if($this->situationinvoice)
1486
-			{
1487
-				$pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1488
-			}
1489
-			else if($conf->global->PRODUCT_USE_UNITS)
1490
-			{
1491
-				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1492
-			}
1493
-			else
1494
-			{
1495
-				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1496
-			}
1497
-		}
1498
-
1499
-		if ($this->situationinvoice) {
1500
-			$pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1501
-
1502
-			if (empty($hidetop)) {
1503
-
1504
-				$pdf->SetXY($this->posxprogress, $tab_top+1);
1505
-
1506
-				if($conf->global->PRODUCT_USE_UNITS)
1507
-				{
1508
-					$pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1509
-				}
1510
-				else if ($this->atleastonediscount)
1511
-				{
1512
-					$pdf->MultiCell($this->posxdiscount-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1513
-				}
1514
-				else
1515
-				{
1516
-					$pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1517
-				}
1518
-			}
1519
-		}
1520
-
1521
-		if($conf->global->PRODUCT_USE_UNITS) {
1522
-			$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1523
-			if (empty($hidetop)) {
1524
-				$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1525
-				$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1526
-					'C');
1527
-			}
1528
-		}
1529
-
1530
-		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1531
-		if (empty($hidetop))
1532
-		{
1533
-			if ($this->atleastonediscount)
1534
-			{
1535
-				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1536
-				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1537
-			}
1538
-		}
1539
-
1540
-		if ($this->situationinvoice)
1541
-		{
1542
-			$pdf->line($this->postotalht+4, $tab_top, $this->postotalht+4, $tab_top + $tab_height);
1543
-			if (empty($hidetop))
1544
-			{
1545
-				$pdf->SetXY($this->postotalht-19, $tab_top+1);
1546
-				$pdf->MultiCell(30,2, $outputlangs->transnoentities("Situation"),'','C');
1547
-			}
1548
-		}
1549
-
1550
-		if ($this->atleastonediscount)
1551
-		{
1552
-			$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1553
-		}
1554
-		if (empty($hidetop))
1555
-		{
1556
-			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1557
-			$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1558
-		}
1559
-	}
1560
-
1561
-	/**
1562
-	 *  Show top header of page.
1563
-	 *
1564
-	 *  @param	PDF			$pdf     		Object PDF
1565
-	 *  @param  Object		$object     	Object to show
1566
-	 *  @param  int	    	$showaddress    0=no, 1=yes
1567
-	 *  @param  Translate	$outputlangs	Object lang for output
1568
-	 *  @return	void
1569
-	 */
1570
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1571
-	{
1572
-		global $conf, $langs;
1573
-
1574
-		// Load traductions files requiredby by page
1575
-		$outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1576
-
1577
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
1578
-
1579
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1580
-
1581
-		// Show Draft Watermark
1582
-		if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1212
+                // VAT
1213
+                // Situations totals migth be wrong on huge amounts
1214
+                if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1215
+
1216
+                    $sum_pdf_tva = 0;
1217
+                    foreach($this->tva as $tvakey => $tvaval){
1218
+                        $sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1219
+                    }
1220
+
1221
+                    if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1222
+                        $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1223
+
1224
+                        foreach($this->tva as $tvakey => $tvaval) {
1225
+                            $this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1226
+                        }
1227
+                    }
1228
+                }
1229
+
1230
+                foreach($this->tva as $tvakey => $tvaval)
1231
+                {
1232
+                    if ($tvakey != 0)    // On affiche pas taux 0
1233
+                    {
1234
+                        $this->atleastoneratenotnull++;
1235
+
1236
+                        $index++;
1237
+                        $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1238
+
1239
+                        $tvacompl='';
1240
+                        if (preg_match('/\*/',$tvakey))
1241
+                        {
1242
+                            $tvakey=str_replace('*','',$tvakey);
1243
+                            $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1244
+                        }
1245
+                        $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1246
+                        $totalvat.=vatrate($tvakey,1).$tvacompl;
1247
+                        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1248
+
1249
+                        $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1250
+                        $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1251
+                    }
1252
+                }
1253
+
1254
+                //Local tax 1 after VAT
1255
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1256
+                //{
1257
+                    foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1258
+                    {
1259
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1260
+
1261
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1262
+                        {
1263
+                            if ($tvakey != 0)    // On affiche pas taux 0
1264
+                            {
1265
+                                //$this->atleastoneratenotnull++;
1266
+
1267
+                                $index++;
1268
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1269
+
1270
+                                $tvacompl='';
1271
+                                if (preg_match('/\*/',$tvakey))
1272
+                                {
1273
+                                    $tvakey=str_replace('*','',$tvakey);
1274
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1275
+                                }
1276
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1277
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1278
+
1279
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1280
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1281
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1282
+                            }
1283
+                        }
1284
+                    }
1285
+                    //}
1286
+                //Local tax 2 after VAT
1287
+                //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1288
+                //{
1289
+                    foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1290
+                    {
1291
+                        if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1292
+
1293
+                        foreach( $localtax_rate as $tvakey => $tvaval )
1294
+                        {
1295
+                            // retrieve global local tax
1296
+                            if ($tvakey != 0)    // On affiche pas taux 0
1297
+                            {
1298
+                                //$this->atleastoneratenotnull++;
1299
+
1300
+                                $index++;
1301
+                                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1302
+
1303
+                                $tvacompl='';
1304
+                                if (preg_match('/\*/',$tvakey))
1305
+                                {
1306
+                                    $tvakey=str_replace('*','',$tvakey);
1307
+                                    $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1308
+                                }
1309
+                                $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1310
+
1311
+                                $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1312
+                                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1313
+
1314
+                                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1315
+                                $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1316
+                            }
1317
+                        }
1318
+                    //}
1319
+                }
1320
+
1321
+                // Revenue stamp
1322
+                if (price2num($object->revenuestamp) != 0)
1323
+                {
1324
+                    $index++;
1325
+                    $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1326
+                    $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1327
+
1328
+                    $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1329
+                    $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1330
+                }
1331
+
1332
+                // Total TTC
1333
+                $index++;
1334
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1335
+                $pdf->SetTextColor(0,0,60);
1336
+                $pdf->SetFillColor(224,224,224);
1337
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1338
+
1339
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1340
+                $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1341
+            }
1342
+        }
1343
+
1344
+        $pdf->SetTextColor(0,0,0);
1345
+        $creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);	// Warning, this also include excess received
1346
+        $depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1347
+        //print "x".$creditnoteamount."-".$depositsamount;exit;
1348
+        $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1349
+        if ($object->paye) $resteapayer=0;
1350
+
1351
+        if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1352
+        {
1353
+            // Already paid + Deposits
1354
+            $index++;
1355
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1356
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1357
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1358
+            $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1359
+
1360
+            // Credit note
1361
+            if ($creditnoteamount)
1362
+            {
1363
+                $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1364
+                $index++;
1365
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1366
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1367
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1368
+                $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1369
+            }
1370
+
1371
+            // Escompte
1372
+            if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1373
+            {
1374
+                $index++;
1375
+                $pdf->SetFillColor(255,255,255);
1376
+
1377
+                $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1378
+                $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1379
+                $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1380
+                $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1381
+
1382
+                $resteapayer=0;
1383
+            }
1384
+
1385
+            $index++;
1386
+            $pdf->SetTextColor(0,0,60);
1387
+            $pdf->SetFillColor(224,224,224);
1388
+            $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1389
+            $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1390
+            $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391
+            $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1392
+
1393
+            $pdf->SetFont('','', $default_font_size - 1);
1394
+            $pdf->SetTextColor(0,0,0);
1395
+        }
1396
+
1397
+        $index++;
1398
+        return ($tab2_top + ($tab2_hl * $index));
1399
+    }
1400
+
1401
+    /**
1402
+     *   Show table for lines
1403
+     *
1404
+     *   @param		PDF			$pdf     		Object PDF
1405
+     *   @param		string		$tab_top		Top position of table
1406
+     *   @param		string		$tab_height		Height of table (rectangle)
1407
+     *   @param		int			$nexY			Y (not used)
1408
+     *   @param		Translate	$outputlangs	Langs object
1409
+     *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1410
+     *   @param		int			$hidebottom		Hide bottom bar of array
1411
+     *   @param		string		$currency		Currency code
1412
+     *   @return	void
1413
+     */
1414
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1415
+    {
1416
+        global $conf;
1417
+
1418
+        // Force to disable hidetop and hidebottom
1419
+        $hidebottom=0;
1420
+        if ($hidetop) $hidetop=-1;
1421
+
1422
+        $currency = !empty($currency) ? $currency : $conf->currency;
1423
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1424
+
1425
+        // Amount in (at tab_top - 1)
1426
+        $pdf->SetTextColor(0,0,0);
1427
+        $pdf->SetFont('','', $default_font_size - 2);
1428
+
1429
+        if (empty($hidetop))
1430
+        {
1431
+            $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1432
+            $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1433
+            $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1434
+
1435
+            //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1436
+            if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1437
+        }
1438
+
1439
+        $pdf->SetDrawColor(128,128,128);
1440
+        $pdf->SetFont('','', $default_font_size - 1);
1441
+
1442
+        // Output Rect
1443
+        $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1444
+
1445
+        if (empty($hidetop))
1446
+        {
1447
+            $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1448
+
1449
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1450
+            $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1451
+        }
1452
+
1453
+        if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
1454
+        {
1455
+            $pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1456
+            if (empty($hidetop))
1457
+            {
1458
+                //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1459
+                //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1460
+            }
1461
+        }
1462
+
1463
+        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1583 1464
         {
1584
-		      pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1465
+            $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1466
+            if (empty($hidetop))
1467
+            {
1468
+                $pdf->SetXY($this->posxtva-3, $tab_top+1);
1469
+                $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1470
+            }
1585 1471
         }
1586 1472
 
1587
-		$pdf->SetTextColor(0,0,60);
1588
-		$pdf->SetFont('','B', $default_font_size + 3);
1473
+        $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1474
+        if (empty($hidetop))
1475
+        {
1476
+            $pdf->SetXY($this->posxup-1, $tab_top+1);
1477
+            $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1478
+        }
1479
+
1480
+        $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1481
+        if (empty($hidetop))
1482
+        {
1483
+            $pdf->SetXY($this->posxqty-1, $tab_top+1);
1484
+
1485
+            if($this->situationinvoice)
1486
+            {
1487
+                $pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1488
+            }
1489
+            else if($conf->global->PRODUCT_USE_UNITS)
1490
+            {
1491
+                $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1492
+            }
1493
+            else
1494
+            {
1495
+                $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1496
+            }
1497
+        }
1589 1498
 
1590
-		$w = 110;
1499
+        if ($this->situationinvoice) {
1500
+            $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1591 1501
 
1592
-		$posy=$this->marge_haute;
1502
+            if (empty($hidetop)) {
1503
+
1504
+                $pdf->SetXY($this->posxprogress, $tab_top+1);
1505
+
1506
+                if($conf->global->PRODUCT_USE_UNITS)
1507
+                {
1508
+                    $pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1509
+                }
1510
+                else if ($this->atleastonediscount)
1511
+                {
1512
+                    $pdf->MultiCell($this->posxdiscount-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1513
+                }
1514
+                else
1515
+                {
1516
+                    $pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1517
+                }
1518
+            }
1519
+        }
1520
+
1521
+        if($conf->global->PRODUCT_USE_UNITS) {
1522
+            $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1523
+            if (empty($hidetop)) {
1524
+                $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1525
+                $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1526
+                    'C');
1527
+            }
1528
+        }
1529
+
1530
+        $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1531
+        if (empty($hidetop))
1532
+        {
1533
+            if ($this->atleastonediscount)
1534
+            {
1535
+                $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1536
+                $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1537
+            }
1538
+        }
1539
+
1540
+        if ($this->situationinvoice)
1541
+        {
1542
+            $pdf->line($this->postotalht+4, $tab_top, $this->postotalht+4, $tab_top + $tab_height);
1543
+            if (empty($hidetop))
1544
+            {
1545
+                $pdf->SetXY($this->postotalht-19, $tab_top+1);
1546
+                $pdf->MultiCell(30,2, $outputlangs->transnoentities("Situation"),'','C');
1547
+            }
1548
+        }
1549
+
1550
+        if ($this->atleastonediscount)
1551
+        {
1552
+            $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1553
+        }
1554
+        if (empty($hidetop))
1555
+        {
1556
+            $pdf->SetXY($this->postotalht-1, $tab_top+1);
1557
+            $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1558
+        }
1559
+    }
1560
+
1561
+    /**
1562
+     *  Show top header of page.
1563
+     *
1564
+     *  @param	PDF			$pdf     		Object PDF
1565
+     *  @param  Object		$object     	Object to show
1566
+     *  @param  int	    	$showaddress    0=no, 1=yes
1567
+     *  @param  Translate	$outputlangs	Object lang for output
1568
+     *  @return	void
1569
+     */
1570
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1571
+    {
1572
+        global $conf, $langs;
1573
+
1574
+        // Load traductions files requiredby by page
1575
+        $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1576
+
1577
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
1578
+
1579
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1580
+
1581
+        // Show Draft Watermark
1582
+        if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1583
+        {
1584
+                pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1585
+        }
1586
+
1587
+        $pdf->SetTextColor(0,0,60);
1588
+        $pdf->SetFont('','B', $default_font_size + 3);
1589
+
1590
+        $w = 110;
1591
+
1592
+        $posy=$this->marge_haute;
1593 1593
         $posx=$this->page_largeur-$this->marge_droite-$w;
1594 1594
 
1595
-		$pdf->SetXY($this->marge_gauche,$posy);
1596
-
1597
-		// Logo
1598
-		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1599
-		{
1600
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1601
-			if ($this->emetteur->logo)
1602
-			{
1603
-				if (is_readable($logo))
1604
-				{
1605
-				    $height=pdf_getHeightForLogo($logo);
1606
-					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1607
-				}
1608
-				else
1609
-				{
1610
-					$pdf->SetTextColor(200,0,0);
1611
-					$pdf->SetFont('','B',$default_font_size - 2);
1612
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1613
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1614
-				}
1615
-			}
1616
-			else
1617
-			{
1618
-				$text=$this->emetteur->name;
1619
-				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1620
-			}
1621
-		}
1622
-
1623
-		$pdf->SetFont('','B', $default_font_size + 3);
1624
-		$pdf->SetXY($posx,$posy);
1625
-		$pdf->SetTextColor(0,0,60);
1626
-		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1627
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1628
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1629
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1630
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1631
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1632
-		$pdf->MultiCell($w, 3, $title, '', 'R');
1633
-
1634
-		$pdf->SetFont('','B',$default_font_size);
1635
-
1636
-		$posy+=5;
1637
-		$pdf->SetXY($posx,$posy);
1638
-		$pdf->SetTextColor(0,0,60);
1639
-		$textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1640
-		if ($object->statut == Facture::STATUS_DRAFT)
1641
-		{
1642
-			$pdf->SetTextColor(128,0,0);
1643
-			$textref.=' - '.$outputlangs->transnoentities("NotValidated");
1644
-		}
1645
-		$pdf->MultiCell($w, 4, $textref, '', 'R');
1646
-
1647
-		$posy+=1;
1648
-		$pdf->SetFont('','', $default_font_size - 2);
1649
-
1650
-		if ($object->ref_client)
1651
-		{
1652
-			$posy+=4;
1653
-			$pdf->SetXY($posx,$posy);
1654
-			$pdf->SetTextColor(0,0,60);
1655
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1656
-		}
1657
-
1658
-		$objectidnext=$object->getIdReplacingInvoice('validated');
1659
-		if ($object->type == 0 && $objectidnext)
1660
-		{
1661
-			$objectreplacing=new Facture($this->db);
1662
-			$objectreplacing->fetch($objectidnext);
1663
-
1664
-			$posy+=3;
1665
-			$pdf->SetXY($posx,$posy);
1666
-			$pdf->SetTextColor(0,0,60);
1667
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1668
-		}
1669
-		if ($object->type == 1)
1670
-		{
1671
-			$objectreplaced=new Facture($this->db);
1672
-			$objectreplaced->fetch($object->fk_facture_source);
1673
-
1674
-			$posy+=4;
1675
-			$pdf->SetXY($posx,$posy);
1676
-			$pdf->SetTextColor(0,0,60);
1677
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1678
-		}
1679
-		if ($object->type == 2 && !empty($object->fk_facture_source))
1680
-		{
1681
-			$objectreplaced=new Facture($this->db);
1682
-			$objectreplaced->fetch($object->fk_facture_source);
1683
-
1684
-			$posy+=3;
1685
-			$pdf->SetXY($posx,$posy);
1686
-			$pdf->SetTextColor(0,0,60);
1687
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1688
-		}
1689
-
1690
-		$posy+=4;
1691
-		$pdf->SetXY($posx,$posy);
1692
-		$pdf->SetTextColor(0,0,60);
1693
-		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1694
-
1695
-		if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1696
-		{
1697
-			$posy+=4;
1698
-			$pdf->SetXY($posx,$posy);
1699
-			$pdf->SetTextColor(0,0,60);
1700
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1701
-		}
1702
-
1703
-		if ($object->type != 2)
1704
-		{
1705
-			$posy+=3;
1706
-			$pdf->SetXY($posx,$posy);
1707
-			$pdf->SetTextColor(0,0,60);
1708
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1709
-		}
1710
-
1711
-		if ($object->thirdparty->code_client)
1712
-		{
1713
-			$posy+=3;
1714
-			$pdf->SetXY($posx,$posy);
1715
-			$pdf->SetTextColor(0,0,60);
1716
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1717
-		}
1718
-
1719
-		// Get contact
1720
-		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1721
-		{
1722
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1723
-		    if (count($arrayidcontact) > 0)
1724
-		    {
1725
-		        $usertmp=new User($this->db);
1726
-		        $usertmp->fetch($arrayidcontact[0]);
1595
+        $pdf->SetXY($this->marge_gauche,$posy);
1596
+
1597
+        // Logo
1598
+        if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1599
+        {
1600
+            $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1601
+            if ($this->emetteur->logo)
1602
+            {
1603
+                if (is_readable($logo))
1604
+                {
1605
+                    $height=pdf_getHeightForLogo($logo);
1606
+                    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1607
+                }
1608
+                else
1609
+                {
1610
+                    $pdf->SetTextColor(200,0,0);
1611
+                    $pdf->SetFont('','B',$default_font_size - 2);
1612
+                    $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1613
+                    $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1614
+                }
1615
+            }
1616
+            else
1617
+            {
1618
+                $text=$this->emetteur->name;
1619
+                $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1620
+            }
1621
+        }
1622
+
1623
+        $pdf->SetFont('','B', $default_font_size + 3);
1624
+        $pdf->SetXY($posx,$posy);
1625
+        $pdf->SetTextColor(0,0,60);
1626
+        $title=$outputlangs->transnoentities("PdfInvoiceTitle");
1627
+        if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1628
+        if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1629
+        if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1630
+        if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1631
+        if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1632
+        $pdf->MultiCell($w, 3, $title, '', 'R');
1633
+
1634
+        $pdf->SetFont('','B',$default_font_size);
1635
+
1636
+        $posy+=5;
1637
+        $pdf->SetXY($posx,$posy);
1638
+        $pdf->SetTextColor(0,0,60);
1639
+        $textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1640
+        if ($object->statut == Facture::STATUS_DRAFT)
1641
+        {
1642
+            $pdf->SetTextColor(128,0,0);
1643
+            $textref.=' - '.$outputlangs->transnoentities("NotValidated");
1644
+        }
1645
+        $pdf->MultiCell($w, 4, $textref, '', 'R');
1646
+
1647
+        $posy+=1;
1648
+        $pdf->SetFont('','', $default_font_size - 2);
1649
+
1650
+        if ($object->ref_client)
1651
+        {
1652
+            $posy+=4;
1653
+            $pdf->SetXY($posx,$posy);
1654
+            $pdf->SetTextColor(0,0,60);
1655
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1656
+        }
1657
+
1658
+        $objectidnext=$object->getIdReplacingInvoice('validated');
1659
+        if ($object->type == 0 && $objectidnext)
1660
+        {
1661
+            $objectreplacing=new Facture($this->db);
1662
+            $objectreplacing->fetch($objectidnext);
1663
+
1664
+            $posy+=3;
1665
+            $pdf->SetXY($posx,$posy);
1666
+            $pdf->SetTextColor(0,0,60);
1667
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1668
+        }
1669
+        if ($object->type == 1)
1670
+        {
1671
+            $objectreplaced=new Facture($this->db);
1672
+            $objectreplaced->fetch($object->fk_facture_source);
1673
+
1674
+            $posy+=4;
1675
+            $pdf->SetXY($posx,$posy);
1676
+            $pdf->SetTextColor(0,0,60);
1677
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1678
+        }
1679
+        if ($object->type == 2 && !empty($object->fk_facture_source))
1680
+        {
1681
+            $objectreplaced=new Facture($this->db);
1682
+            $objectreplaced->fetch($object->fk_facture_source);
1683
+
1684
+            $posy+=3;
1685
+            $pdf->SetXY($posx,$posy);
1686
+            $pdf->SetTextColor(0,0,60);
1687
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1688
+        }
1689
+
1690
+        $posy+=4;
1691
+        $pdf->SetXY($posx,$posy);
1692
+        $pdf->SetTextColor(0,0,60);
1693
+        $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1694
+
1695
+        if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1696
+        {
1697
+            $posy+=4;
1698
+            $pdf->SetXY($posx,$posy);
1699
+            $pdf->SetTextColor(0,0,60);
1700
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1701
+        }
1702
+
1703
+        if ($object->type != 2)
1704
+        {
1705
+            $posy+=3;
1706
+            $pdf->SetXY($posx,$posy);
1707
+            $pdf->SetTextColor(0,0,60);
1708
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1709
+        }
1710
+
1711
+        if ($object->thirdparty->code_client)
1712
+        {
1713
+            $posy+=3;
1714
+            $pdf->SetXY($posx,$posy);
1715
+            $pdf->SetTextColor(0,0,60);
1716
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1717
+        }
1718
+
1719
+        // Get contact
1720
+        if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1721
+        {
1722
+            $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1723
+            if (count($arrayidcontact) > 0)
1724
+            {
1725
+                $usertmp=new User($this->db);
1726
+                $usertmp->fetch($arrayidcontact[0]);
1727 1727
                 $posy+=4;
1728 1728
                 $pdf->SetXY($posx,$posy);
1729
-		        $pdf->SetTextColor(0,0,60);
1730
-		        $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1731
-		    }
1732
-		}
1733
-
1734
-		$posy+=1;
1735
-
1736
-		$top_shift = 0;
1737
-		// Show list of linked objects
1738
-		$current_y = $pdf->getY();
1739
-		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1740
-		if ($current_y < $pdf->getY())
1741
-		{
1742
-			$top_shift = $pdf->getY() - $current_y;
1743
-		}
1744
-
1745
-		if ($showaddress)
1746
-		{
1747
-			// Sender properties
1748
-			$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1749
-
1750
-			// Show sender
1751
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1752
-			$posy+=$top_shift;
1753
-			$posx=$this->marge_gauche;
1754
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1755
-
1756
-			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1757
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1758
-
1759
-
1760
-			// Show sender frame
1761
-			$pdf->SetTextColor(0,0,0);
1762
-			$pdf->SetFont('','', $default_font_size - 2);
1763
-			$pdf->SetXY($posx,$posy-5);
1764
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1765
-			$pdf->SetXY($posx,$posy);
1766
-			$pdf->SetFillColor(230,230,230);
1767
-			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1768
-			$pdf->SetTextColor(0,0,60);
1769
-
1770
-			// Show sender name
1771
-			$pdf->SetXY($posx+2,$posy+3);
1772
-			$pdf->SetFont('','B', $default_font_size);
1773
-			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1774
-			$posy=$pdf->getY();
1775
-
1776
-			// Show sender information
1777
-			$pdf->SetXY($posx+2,$posy);
1778
-			$pdf->SetFont('','', $default_font_size - 1);
1779
-			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1780
-
1781
-
1782
-
1783
-			// If BILLING contact defined on invoice, we use it
1784
-			$usecontact=false;
1785
-			$arrayidcontact=$object->getIdContact('external','BILLING');
1786
-			if (count($arrayidcontact) > 0)
1787
-			{
1788
-				$usecontact=true;
1789
-				$result=$object->fetch_contact($arrayidcontact[0]);
1790
-			}
1791
-
1792
-			//Recipient name
1793
-			// On peut utiliser le nom de la societe du contact
1794
-			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1795
-				$thirdparty = $object->contact;
1796
-			} else {
1797
-				$thirdparty = $object->thirdparty;
1798
-			}
1799
-
1800
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1801
-
1802
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1803
-
1804
-			// Show recipient
1805
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1806
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1807
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1808
-			$posy+=$top_shift;
1809
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1810
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1811
-
1812
-			// Show recipient frame
1813
-			$pdf->SetTextColor(0,0,0);
1814
-			$pdf->SetFont('','', $default_font_size - 2);
1815
-			$pdf->SetXY($posx+2,$posy-5);
1816
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1817
-			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1818
-
1819
-			// Show recipient name
1820
-			$pdf->SetXY($posx+2,$posy+3);
1821
-			$pdf->SetFont('','B', $default_font_size);
1822
-			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1823
-
1824
-			$posy = $pdf->getY();
1825
-
1826
-			// Show recipient information
1827
-			$pdf->SetFont('','', $default_font_size - 1);
1828
-			$pdf->SetXY($posx+2,$posy);
1829
-			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1830
-		}
1831
-
1832
-		$pdf->SetTextColor(0,0,0);
1833
-		return $top_shift;
1834
-	}
1835
-
1836
-	/**
1837
-	 *   	Show footer of page. Need this->emetteur object
1729
+                $pdf->SetTextColor(0,0,60);
1730
+                $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1731
+            }
1732
+        }
1733
+
1734
+        $posy+=1;
1735
+
1736
+        $top_shift = 0;
1737
+        // Show list of linked objects
1738
+        $current_y = $pdf->getY();
1739
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1740
+        if ($current_y < $pdf->getY())
1741
+        {
1742
+            $top_shift = $pdf->getY() - $current_y;
1743
+        }
1744
+
1745
+        if ($showaddress)
1746
+        {
1747
+            // Sender properties
1748
+            $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1749
+
1750
+            // Show sender
1751
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1752
+            $posy+=$top_shift;
1753
+            $posx=$this->marge_gauche;
1754
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1755
+
1756
+            $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1757
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1758
+
1759
+
1760
+            // Show sender frame
1761
+            $pdf->SetTextColor(0,0,0);
1762
+            $pdf->SetFont('','', $default_font_size - 2);
1763
+            $pdf->SetXY($posx,$posy-5);
1764
+            $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1765
+            $pdf->SetXY($posx,$posy);
1766
+            $pdf->SetFillColor(230,230,230);
1767
+            $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1768
+            $pdf->SetTextColor(0,0,60);
1769
+
1770
+            // Show sender name
1771
+            $pdf->SetXY($posx+2,$posy+3);
1772
+            $pdf->SetFont('','B', $default_font_size);
1773
+            $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1774
+            $posy=$pdf->getY();
1775
+
1776
+            // Show sender information
1777
+            $pdf->SetXY($posx+2,$posy);
1778
+            $pdf->SetFont('','', $default_font_size - 1);
1779
+            $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1780
+
1781
+
1782
+
1783
+            // If BILLING contact defined on invoice, we use it
1784
+            $usecontact=false;
1785
+            $arrayidcontact=$object->getIdContact('external','BILLING');
1786
+            if (count($arrayidcontact) > 0)
1787
+            {
1788
+                $usecontact=true;
1789
+                $result=$object->fetch_contact($arrayidcontact[0]);
1790
+            }
1791
+
1792
+            //Recipient name
1793
+            // On peut utiliser le nom de la societe du contact
1794
+            if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1795
+                $thirdparty = $object->contact;
1796
+            } else {
1797
+                $thirdparty = $object->thirdparty;
1798
+            }
1799
+
1800
+            $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1801
+
1802
+            $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1803
+
1804
+            // Show recipient
1805
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1806
+            if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1807
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1808
+            $posy+=$top_shift;
1809
+            $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1810
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1811
+
1812
+            // Show recipient frame
1813
+            $pdf->SetTextColor(0,0,0);
1814
+            $pdf->SetFont('','', $default_font_size - 2);
1815
+            $pdf->SetXY($posx+2,$posy-5);
1816
+            $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1817
+            $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1818
+
1819
+            // Show recipient name
1820
+            $pdf->SetXY($posx+2,$posy+3);
1821
+            $pdf->SetFont('','B', $default_font_size);
1822
+            $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1823
+
1824
+            $posy = $pdf->getY();
1825
+
1826
+            // Show recipient information
1827
+            $pdf->SetFont('','', $default_font_size - 1);
1828
+            $pdf->SetXY($posx+2,$posy);
1829
+            $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1830
+        }
1831
+
1832
+        $pdf->SetTextColor(0,0,0);
1833
+        return $top_shift;
1834
+    }
1835
+
1836
+    /**
1837
+     *   	Show footer of page. Need this->emetteur object
1838 1838
      *
1839
-	 *   	@param	PDF			$pdf     			PDF
1840
-	 * 		@param	Object		$object				Object to show
1841
-	 *      @param	Translate	$outputlangs		Object lang for output
1842
-	 *      @param	int			$hidefreetext		1=Hide free text
1843
-	 *      @return	int								Return height of bottom margin including footer text
1844
-	 */
1845
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1846
-	{
1847
-		global $conf;
1848
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1849
-		return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1850
-	}
1839
+     *   	@param	PDF			$pdf     			PDF
1840
+     * 		@param	Object		$object				Object to show
1841
+     *      @param	Translate	$outputlangs		Object lang for output
1842
+     *      @param	int			$hidefreetext		1=Hide free text
1843
+     *      @return	int								Return height of bottom margin including footer text
1844
+     */
1845
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1846
+    {
1847
+        global $conf;
1848
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1849
+        return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1850
+    }
1851 1851
 }
Please login to merge, or discard this patch.
Spacing   +540 added lines, -540 removed lines patch added patch discarded remove patch
@@ -147,74 +147,74 @@  discard block
 block discarded – undo
147 147
 		$this->db = $db;
148 148
 		$this->name = "crabe";
149 149
 		$this->description = $langs->trans('PDFCrabeDescription');
150
-		$this->update_main_doc_field = 1;		// Save the name of generated file as the main doc when generating a doc with this template
150
+		$this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
151 151
 
152 152
 		// Dimensiont page
153 153
 		$this->type = 'pdf';
154
-		$formatarray=pdf_getFormat();
154
+		$formatarray = pdf_getFormat();
155 155
 		$this->page_largeur = $formatarray['width'];
156 156
 		$this->page_hauteur = $formatarray['height'];
157
-		$this->format = array($this->page_largeur,$this->page_hauteur);
158
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
159
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
160
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
161
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
162
-
163
-		$this->option_logo = 1;                    // Affiche logo
164
-		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
165
-		$this->option_modereg = 1;                 // Affiche mode reglement
166
-		$this->option_condreg = 1;                 // Affiche conditions reglement
167
-		$this->option_codeproduitservice = 1;      // Affiche code produit-service
168
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
169
-		$this->option_escompte = 1;                // Affiche si il y a eu escompte
170
-		$this->option_credit_note = 1;             // Support credit notes
171
-		$this->option_freetext = 1;				   // Support add of a personalised text
172
-		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
173
-
174
-		$this->franchise=!$mysoc->tva_assuj;
157
+		$this->format = array($this->page_largeur, $this->page_hauteur);
158
+		$this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
159
+		$this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
160
+		$this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
161
+		$this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
162
+
163
+		$this->option_logo = 1; // Affiche logo
164
+		$this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
165
+		$this->option_modereg = 1; // Affiche mode reglement
166
+		$this->option_condreg = 1; // Affiche conditions reglement
167
+		$this->option_codeproduitservice = 1; // Affiche code produit-service
168
+		$this->option_multilang = 1; // Dispo en plusieurs langues
169
+		$this->option_escompte = 1; // Affiche si il y a eu escompte
170
+		$this->option_credit_note = 1; // Support credit notes
171
+		$this->option_freetext = 1; // Support add of a personalised text
172
+		$this->option_draft_watermark = 1; // Support add of a watermark on drafts
173
+
174
+		$this->franchise = !$mysoc->tva_assuj;
175 175
 
176 176
 		// Get source company
177
-		$this->emetteur=$mysoc;
178
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
177
+		$this->emetteur = $mysoc;
178
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
179 179
 
180 180
 		// Define position of columns
181
-		$this->posxdesc=$this->marge_gauche+1;
182
-		if($conf->global->PRODUCT_USE_UNITS)
181
+		$this->posxdesc = $this->marge_gauche + 1;
182
+		if ($conf->global->PRODUCT_USE_UNITS)
183 183
 		{
184
-			$this->posxtva=101;
185
-			$this->posxup=118;
186
-			$this->posxqty=135;
187
-			$this->posxunit=151;
184
+			$this->posxtva = 101;
185
+			$this->posxup = 118;
186
+			$this->posxqty = 135;
187
+			$this->posxunit = 151;
188 188
 		}
189 189
 		else
190 190
 		{
191
-			$this->posxtva=110;
192
-			$this->posxup=126;
193
-			$this->posxqty=145;
191
+			$this->posxtva = 110;
192
+			$this->posxup = 126;
193
+			$this->posxqty = 145;
194 194
 		}
195
-		$this->posxdiscount=162;
196
-		$this->posxprogress=126; // Only displayed for situation invoices
197
-		$this->postotalht=174;
198
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
199
-		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
195
+		$this->posxdiscount = 162;
196
+		$this->posxprogress = 126; // Only displayed for situation invoices
197
+		$this->postotalht = 174;
198
+		if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva = $this->posxup;
199
+		$this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
200 200
 		if ($this->page_largeur < 210) // To work with US executive format
201 201
 		{
202
-		    $this->posxpicture-=20;
203
-		    $this->posxtva-=20;
204
-		    $this->posxup-=20;
205
-		    $this->posxqty-=20;
206
-		    $this->posxunit-=20;
207
-		    $this->posxdiscount-=20;
208
-		    $this->posxprogress-=20;
209
-		    $this->postotalht-=20;
202
+		    $this->posxpicture -= 20;
203
+		    $this->posxtva -= 20;
204
+		    $this->posxup -= 20;
205
+		    $this->posxqty -= 20;
206
+		    $this->posxunit -= 20;
207
+		    $this->posxdiscount -= 20;
208
+		    $this->posxprogress -= 20;
209
+		    $this->postotalht -= 20;
210 210
 		}
211 211
 
212
-		$this->tva=array();
213
-		$this->localtax1=array();
214
-		$this->localtax2=array();
215
-		$this->atleastoneratenotnull=0;
216
-		$this->atleastonediscount=0;
217
-		$this->situationinvoice=false;
212
+		$this->tva = array();
213
+		$this->localtax1 = array();
214
+		$this->localtax2 = array();
215
+		$this->atleastoneratenotnull = 0;
216
+		$this->atleastonediscount = 0;
217
+		$this->situationinvoice = false;
218 218
 	}
219 219
 
220 220
 
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
      *  @param		int			$hideref			Do not show ref
231 231
      *  @return     int         	    			1=OK, 0=KO
232 232
 	 */
233
-	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
233
+	function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
234 234
 	{
235 235
         // phpcs:enable
236
-		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
236
+		global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblignes;
237 237
 
238
-		if (! is_object($outputlangs)) $outputlangs=$langs;
238
+		if (!is_object($outputlangs)) $outputlangs = $langs;
239 239
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
240
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
240
+		if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
241 241
 
242 242
 		// Load traductions files requiredby by page
243 243
 		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
@@ -245,32 +245,32 @@  discard block
 block discarded – undo
245 245
 		$nblignes = count($object->lines);
246 246
 
247 247
 		// Loop on each lines to detect if there is at least one image to show
248
-		$realpatharray=array();
249
-		if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
248
+		$realpatharray = array();
249
+		if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
250 250
 		{
251
-			for ($i = 0 ; $i < $nblignes ; $i++)
251
+			for ($i = 0; $i < $nblignes; $i++)
252 252
 			{
253 253
 				if (empty($object->lines[$i]->fk_product)) continue;
254 254
 
255 255
 				$objphoto = new Product($this->db);
256 256
 				$objphoto->fetch($object->lines[$i]->fk_product);
257 257
 
258
-				$pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
258
+				$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
259 259
 				$dir = $conf->product->dir_output.'/'.$pdir;
260 260
 
261
-				$realpath='';
262
-				foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
261
+				$realpath = '';
262
+				foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
263 263
 				{
264
-					$filename=$obj['photo'];
264
+					$filename = $obj['photo'];
265 265
 					//if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
266 266
 					$realpath = $dir.$filename;
267 267
 					break;
268 268
 				}
269 269
 
270
-				if ($realpath) $realpatharray[$i]=$realpath;
270
+				if ($realpath) $realpatharray[$i] = $realpath;
271 271
 			}
272 272
 		}
273
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
273
+		if (count($realpatharray) == 0) $this->posxpicture = $this->posxtva;
274 274
 
275 275
 		if ($conf->facture->dir_output)
276 276
 		{
@@ -284,19 +284,19 @@  discard block
 block discarded – undo
284 284
 			if ($object->specimen)
285 285
 			{
286 286
 				$dir = $conf->facture->dir_output;
287
-				$file = $dir . "/SPECIMEN.pdf";
287
+				$file = $dir."/SPECIMEN.pdf";
288 288
 			}
289 289
 			else
290 290
 			{
291 291
 				$objectref = dol_sanitizeFileName($object->ref);
292
-				$dir = $conf->facture->dir_output . "/" . $objectref;
293
-				$file = $dir . "/" . $objectref . ".pdf";
292
+				$dir = $conf->facture->dir_output."/".$objectref;
293
+				$file = $dir."/".$objectref.".pdf";
294 294
 			}
295
-			if (! file_exists($dir))
295
+			if (!file_exists($dir))
296 296
 			{
297 297
 				if (dol_mkdir($dir) < 0)
298 298
 				{
299
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
299
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
300 300
 					return 0;
301 301
 				}
302 302
 			}
@@ -304,29 +304,29 @@  discard block
 block discarded – undo
304 304
 			if (file_exists($dir))
305 305
 			{
306 306
 				// Add pdfgeneration hook
307
-				if (! is_object($hookmanager))
307
+				if (!is_object($hookmanager))
308 308
 				{
309 309
 					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
310
-					$hookmanager=new HookManager($this->db);
310
+					$hookmanager = new HookManager($this->db);
311 311
 				}
312 312
 				$hookmanager->initHooks(array('pdfgeneration'));
313
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
313
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
314 314
 				global $action;
315
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
315
+				$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
316 316
 
317 317
 				// Set nblignes with the new facture lines content after hook
318 318
 				$nblignes = count($object->lines);
319 319
 				$nbpayments = count($object->getListOfPayments());
320 320
 
321 321
 				// Create pdf instance
322
-				$pdf=pdf_getInstance($this->format);
323
-                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
324
-                $pdf->SetAutoPageBreak(1,0);
322
+				$pdf = pdf_getInstance($this->format);
323
+                $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
324
+                $pdf->SetAutoPageBreak(1, 0);
325 325
 
326
-                $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
327
-		        $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
328
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
329
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
326
+                $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
327
+		        $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
328
+	            $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
329
+	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
330 330
 
331 331
                 if (class_exists('TCPDF'))
332 332
                 {
@@ -336,27 +336,27 @@  discard block
 block discarded – undo
336 336
                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
337 337
 
338 338
                 // Set path to the background PDF File
339
-                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
339
+                if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
340 340
                 {
341 341
 				    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
342 342
 				    $tplidx = $pdf->importPage(1);
343 343
                 }
344 344
 
345 345
 				$pdf->Open();
346
-				$pagenb=0;
347
-				$pdf->SetDrawColor(128,128,128);
346
+				$pagenb = 0;
347
+				$pdf->SetDrawColor(128, 128, 128);
348 348
 
349 349
 				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
350 350
 				$pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
351 351
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
352 352
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
353 353
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
354
+				if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
355 355
 
356
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
356
+				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
357 357
 
358 358
 				// Positionne $this->atleastonediscount si on a au moins une remise
359
-				for ($i = 0 ; $i < $nblignes ; $i++)
359
+				for ($i = 0; $i < $nblignes; $i++)
360 360
 				{
361 361
 					if ($object->lines[$i]->remise_percent)
362 362
 					{
@@ -365,11 +365,11 @@  discard block
 block discarded – undo
365 365
 				}
366 366
 				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))    // retreive space not used by discount
367 367
 				{
368
-					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
369
-					$this->posxtva+=($this->postotalht - $this->posxdiscount);
370
-					$this->posxup+=($this->postotalht - $this->posxdiscount);
371
-					$this->posxqty+=($this->postotalht - $this->posxdiscount);
372
-					$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
368
+					$this->posxpicture += ($this->postotalht - $this->posxdiscount);
369
+					$this->posxtva += ($this->postotalht - $this->posxdiscount);
370
+					$this->posxup += ($this->postotalht - $this->posxdiscount);
371
+					$this->posxqty += ($this->postotalht - $this->posxdiscount);
372
+					$this->posxdiscount += ($this->postotalht - $this->posxdiscount);
373 373
 					//$this->postotalht;
374 374
 				}
375 375
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 					$this->posxtva -= $progress_width;
383 383
 					$this->posxup -= $progress_width;
384 384
 					$this->posxqty -= $progress_width;
385
-					if(empty($conf->global->PRODUCT_USE_UNITS)) {
385
+					if (empty($conf->global->PRODUCT_USE_UNITS)) {
386 386
 						$this->posxprogress += $progress_width;
387 387
 					}
388 388
 					/*$this->posxdiscount -= $progress_width;
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
 
392 392
 				// New page
393 393
 				$pdf->AddPage();
394
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
394
+				if (!empty($tplidx)) $pdf->useTemplate($tplidx);
395 395
 				$pagenb++;
396 396
 
397 397
 				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
398
-				$pdf->SetFont('','', $default_font_size - 1);
399
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
400
-				$pdf->SetTextColor(0,0,0);
398
+				$pdf->SetFont('', '', $default_font_size - 1);
399
+				$pdf->MultiCell(0, 3, ''); // Set interline to 3
400
+				$pdf->SetTextColor(0, 0, 0);
401 401
 
402
-				$tab_top = 90+$top_shift;
403
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
402
+				$tab_top = 90 + $top_shift;
403
+				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
404 404
 
405 405
 				// Incoterm
406 406
 				if ($conf->incoterm->enabled)
@@ -410,50 +410,50 @@  discard block
 block discarded – undo
410 410
 					{
411 411
 						$tab_top -= 2;
412 412
 
413
-						$pdf->SetFont('','', $default_font_size - 1);
414
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
413
+						$pdf->SetFont('', '', $default_font_size - 1);
414
+						$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
415 415
 						$nexY = $pdf->GetY();
416
-						$height_incoterms=$nexY-$tab_top;
416
+						$height_incoterms = $nexY - $tab_top;
417 417
 
418 418
 						// Rect prend une longueur en 3eme param
419
-						$pdf->SetDrawColor(192,192,192);
420
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
419
+						$pdf->SetDrawColor(192, 192, 192);
420
+						$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
421 421
 
422
-						$tab_top = $nexY+6;
422
+						$tab_top = $nexY + 6;
423 423
 					}
424 424
 				}
425 425
 
426 426
 				// Affiche notes
427
-				$notetoshow=empty($object->note_public)?'':$object->note_public;
428
-				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
427
+				$notetoshow = empty($object->note_public) ? '' : $object->note_public;
428
+				if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
429 429
 				{
430 430
 					// Get first sale rep
431 431
 					if (is_object($object->thirdparty))
432 432
 					{
433
-						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
434
-						$salerepobj=new User($this->db);
433
+						$salereparray = $object->thirdparty->getSalesRepresentatives($user);
434
+						$salerepobj = new User($this->db);
435 435
 						$salerepobj->fetch($salereparray[0]['id']);
436
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
436
+						if (!empty($salerepobj->signature)) $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
437 437
 					}
438 438
 				}
439 439
 				if ($notetoshow)
440 440
 				{
441 441
 					$tab_top -= 2;
442 442
 
443
-					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
443
+					$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
444 444
 					complete_substitutions_array($substitutionarray, $outputlangs, $object);
445 445
 					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
446 446
 
447
-					$pdf->SetFont('','', $default_font_size - 1);
448
-					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
447
+					$pdf->SetFont('', '', $default_font_size - 1);
448
+					$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
449 449
 					$nexY = $pdf->GetY();
450
-					$height_note=$nexY-$tab_top;
450
+					$height_note = $nexY - $tab_top;
451 451
 
452 452
 					// Rect prend une longueur en 3eme param
453
-					$pdf->SetDrawColor(192,192,192);
454
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
453
+					$pdf->SetDrawColor(192, 192, 192);
454
+					$pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
455 455
 
456
-					$tab_top = $nexY+6;
456
+					$tab_top = $nexY + 6;
457 457
 				}
458 458
 
459 459
 				$iniY = $tab_top + 7;
@@ -464,104 +464,104 @@  discard block
 block discarded – undo
464 464
 				for ($i = 0; $i < $nblignes; $i++)
465 465
 				{
466 466
 					$curY = $nexY;
467
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
468
-					$pdf->SetTextColor(0,0,0);
467
+					$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
468
+					$pdf->SetTextColor(0, 0, 0);
469 469
 
470 470
 					// Define size of image if we need it
471
-					$imglinesize=array();
472
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
471
+					$imglinesize = array();
472
+					if (!empty($realpatharray[$i])) $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
473 473
 
474 474
 					$pdf->setTopMargin($tab_top_newpage);
475
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
476
-					$pageposbefore=$pdf->getPage();
475
+					$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
476
+					$pageposbefore = $pdf->getPage();
477 477
 
478
-					$showpricebeforepagebreak=1;
479
-					$posYAfterImage=0;
480
-					$posYAfterDescription=0;
478
+					$showpricebeforepagebreak = 1;
479
+					$posYAfterImage = 0;
480
+					$posYAfterDescription = 0;
481 481
 
482 482
 					// We start with Photo of product line
483
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
483
+					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))	// If photo too high, we moved completely on new page
484 484
 					{
485
-						$pdf->AddPage('','',true);
486
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
485
+						$pdf->AddPage('', '', true);
486
+						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
487 487
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488
-						$pdf->setPage($pageposbefore+1);
488
+						$pdf->setPage($pageposbefore + 1);
489 489
 
490 490
 						$curY = $tab_top_newpage;
491
-						$showpricebeforepagebreak=0;
491
+						$showpricebeforepagebreak = 0;
492 492
 					}
493 493
 
494 494
 					if (isset($imglinesize['width']) && isset($imglinesize['height']))
495 495
 					{
496
-						$curX = $this->posxpicture-1;
497
-						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
496
+						$curX = $this->posxpicture - 1;
497
+						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
498 498
 						// $pdf->Image does not increase value return by getY, so we save it manually
499
-						$posYAfterImage=$curY+$imglinesize['height'];
499
+						$posYAfterImage = $curY + $imglinesize['height'];
500 500
 					}
501 501
 
502 502
 					// Description of product line
503
-					$curX = $this->posxdesc-1;
503
+					$curX = $this->posxdesc - 1;
504 504
 
505 505
 					$pdf->startTransaction();
506
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
507
-					$pageposafter=$pdf->getPage();
506
+					pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
507
+					$pageposafter = $pdf->getPage();
508 508
 					if ($pageposafter > $pageposbefore)	// There is a pagebreak
509 509
 					{
510 510
 						$pdf->rollbackTransaction(true);
511
-						$pageposafter=$pageposbefore;
511
+						$pageposafter = $pageposbefore;
512 512
 						//print $pageposafter.'-'.$pageposbefore;exit;
513
-						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
514
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
515
-						$pageposafter=$pdf->getPage();
516
-						$posyafter=$pdf->GetY();
513
+						$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
514
+						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
515
+						$pageposafter = $pdf->getPage();
516
+						$posyafter = $pdf->GetY();
517 517
 						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
518
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
518
+						if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))	// There is no space left for total+free text
519 519
 						{
520
-							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
520
+							if ($i == ($nblignes - 1))	// No more lines, and no space left to show total, so we create a new page
521 521
 							{
522
-								$pdf->AddPage('','',true);
523
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
522
+								$pdf->AddPage('', '', true);
523
+								if (!empty($tplidx)) $pdf->useTemplate($tplidx);
524 524
 								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
525
-								$pdf->setPage($pageposafter+1);
525
+								$pdf->setPage($pageposafter + 1);
526 526
 							}
527 527
 						}
528 528
 						else
529 529
 						{
530 530
 							// We found a page break
531
-							$showpricebeforepagebreak=0;
531
+							$showpricebeforepagebreak = 0;
532 532
 						}
533 533
 					}
534 534
 					else	// No pagebreak
535 535
 					{
536 536
 						$pdf->commitTransaction();
537 537
 					}
538
-					$posYAfterDescription=$pdf->GetY();
538
+					$posYAfterDescription = $pdf->GetY();
539 539
 
540 540
 					$nexY = $pdf->GetY();
541
-					$pageposafter=$pdf->getPage();
541
+					$pageposafter = $pdf->getPage();
542 542
 					$pdf->setPage($pageposbefore);
543 543
 					$pdf->setTopMargin($this->marge_haute);
544
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
544
+					$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
545 545
 
546 546
 					// We suppose that a too long description or photo were moved completely on next page
547 547
 					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
548 548
 						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
549 549
 					}
550 550
 
551
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
551
+					$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
552 552
 
553 553
 					// VAT Rate
554 554
 					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
555 555
 					{
556 556
 						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
557
-						$pdf->SetXY($this->posxtva-5, $curY);
558
-						$pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
557
+						$pdf->SetXY($this->posxtva - 5, $curY);
558
+						$pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
559 559
 					}
560 560
 
561 561
 					// Unit price before discount
562 562
 					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
563 563
 					$pdf->SetXY($this->posxup, $curY);
564
-					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
564
+					$pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
565 565
 
566 566
 					// Quantity
567 567
 					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
@@ -570,15 +570,15 @@  discard block
 block discarded – undo
570 570
 
571 571
 					if ($this->situationinvoice)
572 572
 					{
573
-						$pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R');
573
+						$pdf->MultiCell($this->posxprogress - $this->posxqty - 0.8, 4, $qty, 0, 'R');
574 574
 					}
575
-					else if($conf->global->PRODUCT_USE_UNITS)
575
+					else if ($conf->global->PRODUCT_USE_UNITS)
576 576
 					{
577
-						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
577
+						$pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R');
578 578
 					}
579 579
 					else
580 580
 					{
581
-						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
581
+						$pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 4, $qty, 0, 'R');
582 582
 					}
583 583
 
584 584
 					// Situation progress
@@ -586,44 +586,44 @@  discard block
 block discarded – undo
586 586
 					{
587 587
 						$progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
588 588
 						$pdf->SetXY($this->posxprogress, $curY);
589
-						if($conf->global->PRODUCT_USE_UNITS)
589
+						if ($conf->global->PRODUCT_USE_UNITS)
590 590
 						{
591
-							$pdf->MultiCell($this->posxunit-$this->posxprogress-1, 3, $progress, 0, 'R');
591
+							$pdf->MultiCell($this->posxunit - $this->posxprogress - 1, 3, $progress, 0, 'R');
592 592
 						}
593 593
 						else if ($this->atleastonediscount)
594 594
 						{
595
-							$pdf->MultiCell($this->posxdiscount-$this->posxprogress-1, 3, $progress, 0, 'R');
595
+							$pdf->MultiCell($this->posxdiscount - $this->posxprogress - 1, 3, $progress, 0, 'R');
596 596
 						}
597 597
 						else
598 598
 						{
599
-							$pdf->MultiCell($this->postotalht-$this->posxprogress-1, 3, $progress, 0, 'R');
599
+							$pdf->MultiCell($this->postotalht - $this->posxprogress - 1, 3, $progress, 0, 'R');
600 600
 						}
601 601
 					}
602 602
 
603 603
 					// Unit
604
-					if($conf->global->PRODUCT_USE_UNITS)
604
+					if ($conf->global->PRODUCT_USE_UNITS)
605 605
 					{
606 606
 						$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
607 607
 						$pdf->SetXY($this->posxunit, $curY);
608
-						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
608
+						$pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
609 609
 					}
610 610
 
611 611
 					// Discount on line
612 612
 					if ($object->lines[$i]->remise_percent)
613 613
 					{
614
-                        $pdf->SetXY($this->posxdiscount-2, $curY);
614
+                        $pdf->SetXY($this->posxdiscount - 2, $curY);
615 615
 					    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
616
-						$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
616
+						$pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
617 617
 					}
618 618
 
619 619
 					// Total HT line
620 620
 					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
621 621
 					$pdf->SetXY($this->postotalht, $curY);
622
-					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
622
+					$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
623 623
 
624 624
 
625
-					$sign=1;
626
-					if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
625
+					$sign = 1;
626
+					if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
627 627
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
628 628
 					$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
629 629
 					if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
@@ -631,55 +631,55 @@  discard block
 block discarded – undo
631 631
 						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
632 632
 						else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
633 633
 					} else {
634
-						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
635
-						else $tvaligne= $sign * $object->lines[$i]->total_tva;
634
+						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
635
+						else $tvaligne = $sign * $object->lines[$i]->total_tva;
636 636
 					}
637 637
 
638
-					$localtax1ligne=$object->lines[$i]->total_localtax1;
639
-					$localtax2ligne=$object->lines[$i]->total_localtax2;
640
-					$localtax1_rate=$object->lines[$i]->localtax1_tx;
641
-					$localtax2_rate=$object->lines[$i]->localtax2_tx;
642
-					$localtax1_type=$object->lines[$i]->localtax1_type;
643
-					$localtax2_type=$object->lines[$i]->localtax2_type;
638
+					$localtax1ligne = $object->lines[$i]->total_localtax1;
639
+					$localtax2ligne = $object->lines[$i]->total_localtax2;
640
+					$localtax1_rate = $object->lines[$i]->localtax1_tx;
641
+					$localtax2_rate = $object->lines[$i]->localtax2_tx;
642
+					$localtax1_type = $object->lines[$i]->localtax1_type;
643
+					$localtax2_type = $object->lines[$i]->localtax2_type;
644 644
 
645
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
646
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
647
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
645
+					if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
646
+					if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
647
+					if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
648 648
 
649
-					$vatrate=(string) $object->lines[$i]->tva_tx;
649
+					$vatrate = (string) $object->lines[$i]->tva_tx;
650 650
 
651 651
 					// Retrieve type from database for backward compatibility with old records
652
-					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
653
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
652
+					if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
653
+					&& (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
654 654
 					{
655
-						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
655
+						$localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
656 656
 						$localtax1_type = $localtaxtmp_array[0];
657 657
 						$localtax2_type = $localtaxtmp_array[2];
658 658
 					}
659 659
 
660 660
 				    // retrieve global local tax
661 661
 					if ($localtax1_type && $localtax1ligne != 0)
662
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
662
+						$this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
663 663
 					if ($localtax2_type && $localtax2ligne != 0)
664
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
664
+						$this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
665 665
 
666
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
667
-					if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
666
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .= '*';
667
+					if (!isset($this->tva[$vatrate])) 				$this->tva[$vatrate] = 0;
668 668
 					$this->tva[$vatrate] += $tvaligne;
669 669
 
670
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
670
+					if ($posYAfterImage > $posYAfterDescription) $nexY = $posYAfterImage;
671 671
 
672 672
 					// Add line
673
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
673
+					if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
674 674
 					{
675 675
 						$pdf->setPage($pageposafter);
676
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
676
+						$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
677 677
 						//$pdf->SetDrawColor(190,190,200);
678
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
678
+						$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
679 679
 						$pdf->SetLineStyle(array('dash'=>0));
680 680
 					}
681 681
 
682
-					$nexY+=2;    // Passe espace entre les lignes
682
+					$nexY += 2; // Passe espace entre les lignes
683 683
 
684 684
 					// Detect if some page were added automatically and output _tableau for past pages
685 685
 					while ($pagenb < $pageposafter)
@@ -693,13 +693,13 @@  discard block
 block discarded – undo
693 693
 						{
694 694
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
695 695
 						}
696
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
696
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
697 697
 						$pagenb++;
698 698
 						$pdf->setPage($pagenb);
699
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
699
+						$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
700 700
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
701 701
 					}
702
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
702
+					if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
703 703
 					{
704 704
 						if ($pagenb == 1)
705 705
 						{
@@ -709,10 +709,10 @@  discard block
 block discarded – undo
709 709
 						{
710 710
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
711 711
 						}
712
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
712
+						$this->_pagefoot($pdf, $object, $outputlangs, 1);
713 713
 						// New page
714 714
 						$pdf->AddPage();
715
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
715
+						if (!empty($tplidx)) $pdf->useTemplate($tplidx);
716 716
 						$pagenb++;
717 717
 						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
718 718
 					}
@@ -722,56 +722,56 @@  discard block
 block discarded – undo
722 722
 				if ($pagenb == 1)
723 723
 				{
724 724
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
725
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
725
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
726 726
 				}
727 727
 				else
728 728
 				{
729 729
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
730
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
730
+					$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
731 731
 				}
732 732
 
733 733
 				// Affiche zone infos
734
-				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
734
+				$posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
735 735
 
736 736
 				// Affiche zone totaux
737
-				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
737
+				$posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
738 738
 
739 739
 				// Affiche zone versements
740 740
 				if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
741 741
 				{
742
-					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
742
+					$posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
743 743
 				}
744 744
 
745 745
 				// Pied de page
746
-				$this->_pagefoot($pdf,$object,$outputlangs);
747
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
746
+				$this->_pagefoot($pdf, $object, $outputlangs);
747
+				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
748 748
 
749 749
 				$pdf->Close();
750 750
 
751
-				$pdf->Output($file,'F');
751
+				$pdf->Output($file, 'F');
752 752
 
753 753
 				// Add pdfgeneration hook
754 754
 				$hookmanager->initHooks(array('pdfgeneration'));
755
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
755
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
756 756
 				global $action;
757
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
757
+				$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
758 758
 
759
-				if (! empty($conf->global->MAIN_UMASK))
759
+				if (!empty($conf->global->MAIN_UMASK))
760 760
 				@chmod($file, octdec($conf->global->MAIN_UMASK));
761 761
 
762 762
 				$this->result = array('fullpath'=>$file);
763 763
 
764
-				return 1;   // No error
764
+				return 1; // No error
765 765
 			}
766 766
 			else
767 767
 			{
768
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
768
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
769 769
 				return 0;
770 770
 			}
771 771
 		}
772 772
 		else
773 773
 		{
774
-			$this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
774
+			$this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
775 775
 			return 0;
776 776
 		}
777 777
 	}
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
         // phpcs:enable
793 793
 		global $conf;
794 794
 
795
-        $sign=1;
796
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
795
+        $sign = 1;
796
+        if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
797 797
 
798 798
         $tab3_posx = 120;
799 799
 		$tab3_top = $posy + 8;
@@ -806,114 +806,114 @@  discard block
 block discarded – undo
806 806
 
807 807
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
808 808
 
809
-		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
810
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
809
+		$title = $outputlangs->transnoentities("PaymentsAlreadyDone");
810
+		if ($object->type == 2) $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
811 811
 
812
-		$pdf->SetFont('','', $default_font_size - 3);
812
+		$pdf->SetFont('', '', $default_font_size - 3);
813 813
 		$pdf->SetXY($tab3_posx, $tab3_top - 4);
814 814
 		$pdf->MultiCell(60, 3, $title, 0, 'L', 0);
815 815
 
816
-		$pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
816
+		$pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
817 817
 
818
-		$pdf->SetFont('','', $default_font_size - 4);
818
+		$pdf->SetFont('', '', $default_font_size - 4);
819 819
 		$pdf->SetXY($tab3_posx, $tab3_top);
820 820
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
821
-		$pdf->SetXY($tab3_posx+21, $tab3_top);
821
+		$pdf->SetXY($tab3_posx + 21, $tab3_top);
822 822
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
823
-		$pdf->SetXY($tab3_posx+40, $tab3_top);
823
+		$pdf->SetXY($tab3_posx + 40, $tab3_top);
824 824
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
825
-		$pdf->SetXY($tab3_posx+58, $tab3_top);
825
+		$pdf->SetXY($tab3_posx + 58, $tab3_top);
826 826
 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
827 827
 
828
-		$pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
828
+		$pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
829 829
 
830
-		$y=0;
830
+		$y = 0;
831 831
 
832
-		$pdf->SetFont('','', $default_font_size - 4);
832
+		$pdf->SetFont('', '', $default_font_size - 4);
833 833
 
834 834
 
835 835
 		// Loop on each discount available (deposits and credit notes and excess of payment included)
836 836
 		$sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva,  re.amount_ttc, re.multicurrency_amount_ttc,";
837
-		$sql.= " re.description, re.fk_facture_source,";
838
-		$sql.= " f.type, f.datef";
839
-		$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
840
-		$sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
841
-		$resql=$this->db->query($sql);
837
+		$sql .= " re.description, re.fk_facture_source,";
838
+		$sql .= " f.type, f.datef";
839
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
840
+		$sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
841
+		$resql = $this->db->query($sql);
842 842
 		if ($resql)
843 843
 		{
844 844
 			$num = $this->db->num_rows($resql);
845
-			$i=0;
846
-			$invoice=new Facture($this->db);
845
+			$i = 0;
846
+			$invoice = new Facture($this->db);
847 847
 			while ($i < $num)
848 848
 			{
849
-				$y+=3;
849
+				$y += 3;
850 850
 				$obj = $this->db->fetch_object($resql);
851 851
 
852
-				if ($obj->type == 2) $text=$outputlangs->transnoentities("CreditNote");
853
-				elseif ($obj->type == 3) $text=$outputlangs->transnoentities("Deposit");
854
-				elseif ($obj->type == 0) $text=$outputlangs->transnoentities("ExcessReceived");
855
-				else $text=$outputlangs->transnoentities("UnknownType");
852
+				if ($obj->type == 2) $text = $outputlangs->transnoentities("CreditNote");
853
+				elseif ($obj->type == 3) $text = $outputlangs->transnoentities("Deposit");
854
+				elseif ($obj->type == 0) $text = $outputlangs->transnoentities("ExcessReceived");
855
+				else $text = $outputlangs->transnoentities("UnknownType");
856 856
 
857 857
 				$invoice->fetch($obj->fk_facture_source);
858 858
 
859
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
860
-				$pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
861
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
859
+				$pdf->SetXY($tab3_posx, $tab3_top + $y);
860
+				$pdf->MultiCell(20, 3, dol_print_date($obj->datef, 'day', false, $outputlangs, true), 0, 'L', 0);
861
+				$pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
862 862
 				$pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
863
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
863
+				$pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
864 864
 				$pdf->MultiCell(20, 3, $text, 0, 'L', 0);
865
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
865
+				$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
866 866
 				$pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
867 867
 
868
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
868
+				$pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
869 869
 
870 870
 				$i++;
871 871
 			}
872 872
 		}
873 873
 		else
874 874
 		{
875
-			$this->error=$this->db->lasterror();
875
+			$this->error = $this->db->lasterror();
876 876
 			return -1;
877 877
 		}
878 878
 
879 879
 		// Loop on each payment
880 880
 		// TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
881 881
 		$sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
882
-		$sql.= " cp.code";
883
-		$sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
884
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
885
-		$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
882
+		$sql .= " cp.code";
883
+		$sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
884
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
885
+		$sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
886 886
 		//$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
887
-		$sql.= " ORDER BY p.datep";
887
+		$sql .= " ORDER BY p.datep";
888 888
 
889
-		$resql=$this->db->query($sql);
889
+		$resql = $this->db->query($sql);
890 890
 		if ($resql)
891 891
 		{
892 892
 			$num = $this->db->num_rows($resql);
893
-			$i=0;
893
+			$i = 0;
894 894
 			while ($i < $num) {
895
-				$y+=3;
895
+				$y += 3;
896 896
 				$row = $this->db->fetch_object($resql);
897 897
 
898
-				$pdf->SetXY($tab3_posx, $tab3_top+$y);
899
-				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
900
-				$pdf->SetXY($tab3_posx+21, $tab3_top+$y);
898
+				$pdf->SetXY($tab3_posx, $tab3_top + $y);
899
+				$pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
900
+				$pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
901 901
 				$pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
902
-				$pdf->SetXY($tab3_posx+40, $tab3_top+$y);
903
-				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
902
+				$pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
903
+				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
904 904
 
905 905
 				$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
906
-				$pdf->SetXY($tab3_posx+58, $tab3_top+$y);
906
+				$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
907 907
 				$pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
908 908
 
909
-				$pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
909
+				$pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
910 910
 
911 911
 				$i++;
912 912
 			}
913 913
 		}
914 914
 		else
915 915
 		{
916
-			$this->error=$this->db->lasterror();
916
+			$this->error = $this->db->lasterror();
917 917
 			return -1;
918 918
 		}
919 919
 	}
@@ -936,35 +936,35 @@  discard block
 block discarded – undo
936 936
 
937 937
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
938 938
 
939
-		$pdf->SetFont('','', $default_font_size - 1);
939
+		$pdf->SetFont('', '', $default_font_size - 1);
940 940
 
941 941
 		// If France, show VAT mention if not applicable
942 942
 		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
943 943
 		{
944
-			$pdf->SetFont('','B', $default_font_size - 2);
944
+			$pdf->SetFont('', 'B', $default_font_size - 2);
945 945
 			$pdf->SetXY($this->marge_gauche, $posy);
946 946
 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
947 947
 
948
-			$posy=$pdf->GetY()+4;
948
+			$posy = $pdf->GetY() + 4;
949 949
 		}
950 950
 
951
-		$posxval=52;
951
+		$posxval = 52;
952 952
 
953 953
 		// Show payments conditions
954 954
 		if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
955 955
 		{
956
-			$pdf->SetFont('','B', $default_font_size - 2);
956
+			$pdf->SetFont('', 'B', $default_font_size - 2);
957 957
 			$pdf->SetXY($this->marge_gauche, $posy);
958 958
 			$titre = $outputlangs->transnoentities("PaymentConditions").':';
959 959
 			$pdf->MultiCell(43, 4, $titre, 0, 'L');
960 960
 
961
-			$pdf->SetFont('','', $default_font_size - 2);
961
+			$pdf->SetFont('', '', $default_font_size - 2);
962 962
 			$pdf->SetXY($posxval, $posy);
963
-			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
964
-			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
965
-			$pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
963
+			$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc);
964
+			$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
965
+			$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
966 966
 
967
-			$posy=$pdf->GetY()+3;
967
+			$posy = $pdf->GetY() + 3;
968 968
 		}
969 969
 
970 970
 		if ($object->type != 2)
@@ -983,13 +983,13 @@  discard block
 block discarded – undo
983 983
 				$outputlangs->load("errors");
984 984
 
985 985
 				$pdf->SetXY($this->marge_gauche, $posy);
986
-				$pdf->SetTextColor(200,0,0);
987
-				$pdf->SetFont('','B', $default_font_size - 2);
988
-				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
989
-				$pdf->MultiCell(80, 3, $this->error,0,'L',0);
990
-				$pdf->SetTextColor(0,0,0);
986
+				$pdf->SetTextColor(200, 0, 0);
987
+				$pdf->SetFont('', 'B', $default_font_size - 2);
988
+				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
989
+				$pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
990
+				$pdf->SetTextColor(0, 0, 0);
991 991
 
992
-				$posy=$pdf->GetY()+1;
992
+				$posy = $pdf->GetY() + 1;
993 993
 			}
994 994
 
995 995
 			// Show payment mode
@@ -997,26 +997,26 @@  discard block
 block discarded – undo
997 997
 			&& $object->mode_reglement_code != 'CHQ'
998 998
 			&& $object->mode_reglement_code != 'VIR')
999 999
 			{
1000
-				$pdf->SetFont('','B', $default_font_size - 2);
1000
+				$pdf->SetFont('', 'B', $default_font_size - 2);
1001 1001
 				$pdf->SetXY($this->marge_gauche, $posy);
1002 1002
 				$titre = $outputlangs->transnoentities("PaymentMode").':';
1003 1003
 				$pdf->MultiCell(80, 5, $titre, 0, 'L');
1004 1004
 
1005
-				$pdf->SetFont('','', $default_font_size - 2);
1005
+				$pdf->SetFont('', '', $default_font_size - 2);
1006 1006
 				$pdf->SetXY($posxval, $posy);
1007
-				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
1008
-				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
1007
+				$lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1008
+				$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1009 1009
 
1010
-				$posy=$pdf->GetY()+2;
1010
+				$posy = $pdf->GetY() + 2;
1011 1011
 			}
1012 1012
 
1013 1013
 			// Show payment mode CHQ
1014 1014
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
1015 1015
 			{
1016 1016
 				// Si mode reglement non force ou si force a CHQ
1017
-				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
1017
+				if (!empty($conf->global->FACTURE_CHQ_NUMBER))
1018 1018
 				{
1019
-					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
1019
+					$diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1020 1020
 
1021 1021
 					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
1022 1022
 					{
@@ -1024,31 +1024,31 @@  discard block
 block discarded – undo
1024 1024
 						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1025 1025
 
1026 1026
 						$pdf->SetXY($this->marge_gauche, $posy);
1027
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1028
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
1029
-						$posy=$pdf->GetY()+1;
1027
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1028
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1029
+						$posy = $pdf->GetY() + 1;
1030 1030
 
1031 1031
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1032 1032
 			            {
1033 1033
 							$pdf->SetXY($this->marge_gauche, $posy);
1034
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1034
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1035 1035
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1036
-							$posy=$pdf->GetY()+2;
1036
+							$posy = $pdf->GetY() + 2;
1037 1037
 			            }
1038 1038
 					}
1039 1039
 					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
1040 1040
 					{
1041 1041
 						$pdf->SetXY($this->marge_gauche, $posy);
1042
-						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
1043
-						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
1044
-						$posy=$pdf->GetY()+1;
1042
+						$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1043
+						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1044
+						$posy = $pdf->GetY() + 1;
1045 1045
 
1046 1046
 			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
1047 1047
 			            {
1048 1048
 							$pdf->SetXY($this->marge_gauche, $posy);
1049
-							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
1049
+							$pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1050 1050
 							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1051
-							$posy=$pdf->GetY()+2;
1051
+							$posy = $pdf->GetY() + 2;
1052 1052
 			            }
1053 1053
 					}
1054 1054
 				}
@@ -1057,19 +1057,19 @@  discard block
 block discarded – undo
1057 1057
 			// If payment mode not forced or forced to VIR, show payment with BAN
1058 1058
 			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1059 1059
 			{
1060
-				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1060
+				if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER))
1061 1061
 				{
1062
-					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1063
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1062
+					$bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1063
+					if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1064 1064
 					$account = new Account($this->db);
1065 1065
 					$account->fetch($bankid);
1066 1066
 
1067
-					$curx=$this->marge_gauche;
1068
-					$cury=$posy;
1067
+					$curx = $this->marge_gauche;
1068
+					$cury = $posy;
1069 1069
 
1070
-					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1070
+					$posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1071 1071
 
1072
-					$posy+=2;
1072
+					$posy += 2;
1073 1073
 				}
1074 1074
 			}
1075 1075
 		}
@@ -1092,47 +1092,47 @@  discard block
 block discarded – undo
1092 1092
 	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1093 1093
 	{
1094 1094
         // phpcs:enable
1095
-		global $conf,$mysoc;
1095
+		global $conf, $mysoc;
1096 1096
 
1097
-        $sign=1;
1098
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1097
+        $sign = 1;
1098
+        if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1099 1099
 
1100 1100
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1101 1101
 
1102 1102
 		$tab2_top = $posy;
1103 1103
 		$tab2_hl = 4;
1104
-		$pdf->SetFont('','', $default_font_size - 1);
1104
+		$pdf->SetFont('', '', $default_font_size - 1);
1105 1105
 
1106 1106
 		// Tableau total
1107 1107
 		$col1x = 120; $col2x = 170;
1108 1108
 		if ($this->page_largeur < 210) // To work with US executive format
1109 1109
 		{
1110
-			$col2x-=20;
1110
+			$col2x -= 20;
1111 1111
 		}
1112 1112
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1113 1113
 
1114
-		$useborder=0;
1114
+		$useborder = 0;
1115 1115
 		$index = 0;
1116 1116
 
1117 1117
 		// Total HT
1118
-		$pdf->SetFillColor(255,255,255);
1118
+		$pdf->SetFillColor(255, 255, 255);
1119 1119
 		$pdf->SetXY($col1x, $tab2_top + 0);
1120
-		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1120
+		$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1121 1121
 
1122 1122
 		$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1123 1123
 		$pdf->SetXY($col2x, $tab2_top + 0);
1124
-		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1124
+		$pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1125 1125
 
1126 1126
 		// Show VAT by rates and total
1127
-		$pdf->SetFillColor(248,248,248);
1127
+		$pdf->SetFillColor(248, 248, 248);
1128 1128
 
1129 1129
 		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1130 1130
 
1131
-		$this->atleastoneratenotnull=0;
1131
+		$this->atleastoneratenotnull = 0;
1132 1132
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1133 1133
 		{
1134
-			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1135
-			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1134
+			$tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1135
+			if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1136 1136
 			{
1137 1137
 				// Nothing to do
1138 1138
 			}
@@ -1143,29 +1143,29 @@  discard block
 block discarded – undo
1143 1143
 				//Local tax 1 before VAT
1144 1144
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1145 1145
 				//{
1146
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1146
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1147 1147
 					{
1148
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1148
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1149 1149
 
1150
-						foreach( $localtax_rate as $tvakey => $tvaval )
1150
+						foreach ($localtax_rate as $tvakey => $tvaval)
1151 1151
 						{
1152
-							if ($tvakey!=0)    // On affiche pas taux 0
1152
+							if ($tvakey != 0)    // On affiche pas taux 0
1153 1153
 							{
1154 1154
 								//$this->atleastoneratenotnull++;
1155 1155
 
1156 1156
 								$index++;
1157 1157
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1158 1158
 
1159
-								$tvacompl='';
1160
-								if (preg_match('/\*/',$tvakey))
1159
+								$tvacompl = '';
1160
+								if (preg_match('/\*/', $tvakey))
1161 1161
 								{
1162
-									$tvakey=str_replace('*','',$tvakey);
1162
+									$tvakey = str_replace('*', '', $tvakey);
1163 1163
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1164 1164
 								}
1165 1165
 
1166
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1167
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1168
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1166
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1167
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1168
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1169 1169
 
1170 1170
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1171 1171
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1176,13 +1176,13 @@  discard block
 block discarded – undo
1176 1176
 				//Local tax 2 before VAT
1177 1177
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1178 1178
 				//{
1179
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1179
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1180 1180
 					{
1181
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1181
+						if (in_array((string) $localtax_type, array('1', '3', '5'))) continue;
1182 1182
 
1183
-						foreach( $localtax_rate as $tvakey => $tvaval )
1183
+						foreach ($localtax_rate as $tvakey => $tvaval)
1184 1184
 						{
1185
-							if ($tvakey!=0)    // On affiche pas taux 0
1185
+							if ($tvakey != 0)    // On affiche pas taux 0
1186 1186
 							{
1187 1187
 								//$this->atleastoneratenotnull++;
1188 1188
 
@@ -1191,15 +1191,15 @@  discard block
 block discarded – undo
1191 1191
 								$index++;
1192 1192
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1193 1193
 
1194
-								$tvacompl='';
1195
-								if (preg_match('/\*/',$tvakey))
1194
+								$tvacompl = '';
1195
+								if (preg_match('/\*/', $tvakey))
1196 1196
 								{
1197
-									$tvakey=str_replace('*','',$tvakey);
1197
+									$tvakey = str_replace('*', '', $tvakey);
1198 1198
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1199 1199
 								}
1200
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1201
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1202
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1200
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1201
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1202
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1203 1203
 
1204 1204
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1205 1205
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1214,20 +1214,20 @@  discard block
 block discarded – undo
1214 1214
 				if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1215 1215
 
1216 1216
 					$sum_pdf_tva = 0;
1217
-					foreach($this->tva as $tvakey => $tvaval){
1218
-						$sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1217
+					foreach ($this->tva as $tvakey => $tvaval) {
1218
+						$sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1219 1219
 					}
1220 1220
 
1221
-					if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1221
+					if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1222 1222
 						$coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1223 1223
 
1224
-						foreach($this->tva as $tvakey => $tvaval) {
1225
-							$this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1224
+						foreach ($this->tva as $tvakey => $tvaval) {
1225
+							$this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1226 1226
 						}
1227 1227
 					}
1228 1228
 				}
1229 1229
 
1230
-				foreach($this->tva as $tvakey => $tvaval)
1230
+				foreach ($this->tva as $tvakey => $tvaval)
1231 1231
 				{
1232 1232
 					if ($tvakey != 0)    // On affiche pas taux 0
1233 1233
 					{
@@ -1236,15 +1236,15 @@  discard block
 block discarded – undo
1236 1236
 						$index++;
1237 1237
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1238 1238
 
1239
-						$tvacompl='';
1240
-						if (preg_match('/\*/',$tvakey))
1239
+						$tvacompl = '';
1240
+						if (preg_match('/\*/', $tvakey))
1241 1241
 						{
1242
-							$tvakey=str_replace('*','',$tvakey);
1242
+							$tvakey = str_replace('*', '', $tvakey);
1243 1243
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1244 1244
 						}
1245
-						$totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1246
-						$totalvat.=vatrate($tvakey,1).$tvacompl;
1247
-						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1245
+						$totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
1246
+						$totalvat .= vatrate($tvakey, 1).$tvacompl;
1247
+						$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1248 1248
 
1249 1249
 						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1250 1250
 						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1254,11 +1254,11 @@  discard block
 block discarded – undo
1254 1254
 				//Local tax 1 after VAT
1255 1255
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1256 1256
 				//{
1257
-					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1257
+					foreach ($this->localtax1 as $localtax_type => $localtax_rate)
1258 1258
 					{
1259
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1259
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1260 1260
 
1261
-						foreach( $localtax_rate as $tvakey => $tvaval )
1261
+						foreach ($localtax_rate as $tvakey => $tvaval)
1262 1262
 						{
1263 1263
 							if ($tvakey != 0)    // On affiche pas taux 0
1264 1264
 							{
@@ -1267,16 +1267,16 @@  discard block
 block discarded – undo
1267 1267
 								$index++;
1268 1268
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1269 1269
 
1270
-								$tvacompl='';
1271
-								if (preg_match('/\*/',$tvakey))
1270
+								$tvacompl = '';
1271
+								if (preg_match('/\*/', $tvakey))
1272 1272
 								{
1273
-									$tvakey=str_replace('*','',$tvakey);
1273
+									$tvakey = str_replace('*', '', $tvakey);
1274 1274
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1275 1275
 								}
1276
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1277
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1276
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1277
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1278 1278
 
1279
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1279
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1280 1280
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1281 1281
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1282 1282
 							}
@@ -1286,11 +1286,11 @@  discard block
 block discarded – undo
1286 1286
 				//Local tax 2 after VAT
1287 1287
 				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1288 1288
 				//{
1289
-					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1289
+					foreach ($this->localtax2 as $localtax_type => $localtax_rate)
1290 1290
 					{
1291
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1291
+						if (in_array((string) $localtax_type, array('2', '4', '6'))) continue;
1292 1292
 
1293
-						foreach( $localtax_rate as $tvakey => $tvaval )
1293
+						foreach ($localtax_rate as $tvakey => $tvaval)
1294 1294
 						{
1295 1295
 						    // retrieve global local tax
1296 1296
 							if ($tvakey != 0)    // On affiche pas taux 0
@@ -1300,16 +1300,16 @@  discard block
 block discarded – undo
1300 1300
 								$index++;
1301 1301
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1302 1302
 
1303
-								$tvacompl='';
1304
-								if (preg_match('/\*/',$tvakey))
1303
+								$tvacompl = '';
1304
+								if (preg_match('/\*/', $tvakey))
1305 1305
 								{
1306
-									$tvakey=str_replace('*','',$tvakey);
1306
+									$tvakey = str_replace('*', '', $tvakey);
1307 1307
 									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1308 1308
 								}
1309
-								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1309
+								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1310 1310
 
1311
-								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1312
-								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1311
+								$totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1312
+								$pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1313 1313
 
1314 1314
 								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1315 1315
 								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
 				{
1324 1324
 					$index++;
1325 1325
 					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1326
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1326
+					$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1327 1327
 
1328 1328
 					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1329 1329
 					$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
@@ -1332,28 +1332,28 @@  discard block
 block discarded – undo
1332 1332
 				// Total TTC
1333 1333
 				$index++;
1334 1334
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1335
-				$pdf->SetTextColor(0,0,60);
1336
-				$pdf->SetFillColor(224,224,224);
1337
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1335
+				$pdf->SetTextColor(0, 0, 60);
1336
+				$pdf->SetFillColor(224, 224, 224);
1337
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1338 1338
 
1339 1339
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1340 1340
 				$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1341 1341
 			}
1342 1342
 		}
1343 1343
 
1344
-		$pdf->SetTextColor(0,0,0);
1345
-		$creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);	// Warning, this also include excess received
1346
-		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1344
+		$pdf->SetTextColor(0, 0, 0);
1345
+		$creditnoteamount = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1346
+		$depositsamount = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1347 1347
 		//print "x".$creditnoteamount."-".$depositsamount;exit;
1348 1348
 		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1349
-		if ($object->paye) $resteapayer=0;
1349
+		if ($object->paye) $resteapayer = 0;
1350 1350
 
1351 1351
 		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1352 1352
 		{
1353 1353
 			// Already paid + Deposits
1354 1354
 			$index++;
1355 1355
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1356
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1356
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1357 1357
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1358 1358
 			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1359 1359
 
@@ -1363,7 +1363,7 @@  discard block
 block discarded – undo
1363 1363
 				$labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1364 1364
 				$index++;
1365 1365
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1366
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1366
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1367 1367
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1368 1368
 				$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1369 1369
 			}
@@ -1372,26 +1372,26 @@  discard block
 block discarded – undo
1372 1372
 			if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1373 1373
 			{
1374 1374
 				$index++;
1375
-				$pdf->SetFillColor(255,255,255);
1375
+				$pdf->SetFillColor(255, 255, 255);
1376 1376
 
1377 1377
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1378
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1378
+				$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1379 1379
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1380 1380
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1381 1381
 
1382
-				$resteapayer=0;
1382
+				$resteapayer = 0;
1383 1383
 			}
1384 1384
 
1385 1385
 			$index++;
1386
-			$pdf->SetTextColor(0,0,60);
1387
-			$pdf->SetFillColor(224,224,224);
1386
+			$pdf->SetTextColor(0, 0, 60);
1387
+			$pdf->SetFillColor(224, 224, 224);
1388 1388
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1389
-			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1389
+			$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1390 1390
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1391 1391
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1392 1392
 
1393
-			$pdf->SetFont('','', $default_font_size - 1);
1394
-			$pdf->SetTextColor(0,0,0);
1393
+			$pdf->SetFont('', '', $default_font_size - 1);
1394
+			$pdf->SetTextColor(0, 0, 0);
1395 1395
 		}
1396 1396
 
1397 1397
 		$index++;
@@ -1411,48 +1411,48 @@  discard block
 block discarded – undo
1411 1411
 	 *   @param		string		$currency		Currency code
1412 1412
 	 *   @return	void
1413 1413
 	 */
1414
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1414
+	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1415 1415
 	{
1416 1416
 		global $conf;
1417 1417
 
1418 1418
 		// Force to disable hidetop and hidebottom
1419
-		$hidebottom=0;
1420
-		if ($hidetop) $hidetop=-1;
1419
+		$hidebottom = 0;
1420
+		if ($hidetop) $hidetop = -1;
1421 1421
 
1422 1422
 		$currency = !empty($currency) ? $currency : $conf->currency;
1423 1423
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1424 1424
 
1425 1425
 		// Amount in (at tab_top - 1)
1426
-		$pdf->SetTextColor(0,0,0);
1427
-		$pdf->SetFont('','', $default_font_size - 2);
1426
+		$pdf->SetTextColor(0, 0, 0);
1427
+		$pdf->SetFont('', '', $default_font_size - 2);
1428 1428
 
1429 1429
 		if (empty($hidetop))
1430 1430
 		{
1431
-			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1432
-			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1431
+			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1432
+			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1433 1433
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1434 1434
 
1435 1435
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1436
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1436
+			if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1437 1437
 		}
1438 1438
 
1439
-		$pdf->SetDrawColor(128,128,128);
1440
-		$pdf->SetFont('','', $default_font_size - 1);
1439
+		$pdf->SetDrawColor(128, 128, 128);
1440
+		$pdf->SetFont('', '', $default_font_size - 1);
1441 1441
 
1442 1442
 		// Output Rect
1443
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
1443
+		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
1444 1444
 
1445 1445
 		if (empty($hidetop))
1446 1446
 		{
1447
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1447
+			$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line prend une position y en 2eme param et 4eme param
1448 1448
 
1449
-			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1450
-			$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1449
+			$pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1450
+			$pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1451 1451
 		}
1452 1452
 
1453
-		if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
1453
+		if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
1454 1454
 		{
1455
-			$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1455
+			$pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1456 1456
 			if (empty($hidetop))
1457 1457
 			{
1458 1458
 				//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
@@ -1462,37 +1462,37 @@  discard block
 block discarded – undo
1462 1462
 
1463 1463
 		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1464 1464
 		{
1465
-			$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1465
+			$pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1466 1466
 			if (empty($hidetop))
1467 1467
 			{
1468
-				$pdf->SetXY($this->posxtva-3, $tab_top+1);
1469
-				$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1468
+				$pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1469
+				$pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1470 1470
 			}
1471 1471
 		}
1472 1472
 
1473
-		$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1473
+		$pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1474 1474
 		if (empty($hidetop))
1475 1475
 		{
1476
-			$pdf->SetXY($this->posxup-1, $tab_top+1);
1477
-			$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1476
+			$pdf->SetXY($this->posxup - 1, $tab_top + 1);
1477
+			$pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1478 1478
 		}
1479 1479
 
1480
-		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1480
+		$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1481 1481
 		if (empty($hidetop))
1482 1482
 		{
1483
-			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1483
+			$pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1484 1484
 
1485
-			if($this->situationinvoice)
1485
+			if ($this->situationinvoice)
1486 1486
 			{
1487
-				$pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1487
+				$pdf->MultiCell($this->posxprogress - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1488 1488
 			}
1489
-			else if($conf->global->PRODUCT_USE_UNITS)
1489
+			else if ($conf->global->PRODUCT_USE_UNITS)
1490 1490
 			{
1491
-				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1491
+				$pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1492 1492
 			}
1493 1493
 			else
1494 1494
 			{
1495
-				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1495
+				$pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1496 1496
 			}
1497 1497
 		}
1498 1498
 
@@ -1501,24 +1501,24 @@  discard block
 block discarded – undo
1501 1501
 
1502 1502
 			if (empty($hidetop)) {
1503 1503
 
1504
-				$pdf->SetXY($this->posxprogress, $tab_top+1);
1504
+				$pdf->SetXY($this->posxprogress, $tab_top + 1);
1505 1505
 
1506
-				if($conf->global->PRODUCT_USE_UNITS)
1506
+				if ($conf->global->PRODUCT_USE_UNITS)
1507 1507
 				{
1508
-					$pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1508
+					$pdf->MultiCell($this->posxunit - $this->posxprogress, 2, $outputlangs->transnoentities("Progress"), '', 'C');
1509 1509
 				}
1510 1510
 				else if ($this->atleastonediscount)
1511 1511
 				{
1512
-					$pdf->MultiCell($this->posxdiscount-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1512
+					$pdf->MultiCell($this->posxdiscount - $this->posxprogress, 2, $outputlangs->transnoentities("Progress"), '', 'C');
1513 1513
 				}
1514 1514
 				else
1515 1515
 				{
1516
-					$pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1516
+					$pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("Progress"), '', 'C');
1517 1517
 				}
1518 1518
 			}
1519 1519
 		}
1520 1520
 
1521
-		if($conf->global->PRODUCT_USE_UNITS) {
1521
+		if ($conf->global->PRODUCT_USE_UNITS) {
1522 1522
 			$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1523 1523
 			if (empty($hidetop)) {
1524 1524
 				$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
@@ -1527,23 +1527,23 @@  discard block
 block discarded – undo
1527 1527
 			}
1528 1528
 		}
1529 1529
 
1530
-		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1530
+		$pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1531 1531
 		if (empty($hidetop))
1532 1532
 		{
1533 1533
 			if ($this->atleastonediscount)
1534 1534
 			{
1535
-				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1536
-				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1535
+				$pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1536
+				$pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1537 1537
 			}
1538 1538
 		}
1539 1539
 
1540 1540
 		if ($this->situationinvoice)
1541 1541
 		{
1542
-			$pdf->line($this->postotalht+4, $tab_top, $this->postotalht+4, $tab_top + $tab_height);
1542
+			$pdf->line($this->postotalht + 4, $tab_top, $this->postotalht + 4, $tab_top + $tab_height);
1543 1543
 			if (empty($hidetop))
1544 1544
 			{
1545
-				$pdf->SetXY($this->postotalht-19, $tab_top+1);
1546
-				$pdf->MultiCell(30,2, $outputlangs->transnoentities("Situation"),'','C');
1545
+				$pdf->SetXY($this->postotalht - 19, $tab_top + 1);
1546
+				$pdf->MultiCell(30, 2, $outputlangs->transnoentities("Situation"), '', 'C');
1547 1547
 			}
1548 1548
 		}
1549 1549
 
@@ -1553,8 +1553,8 @@  discard block
 block discarded – undo
1553 1553
 		}
1554 1554
 		if (empty($hidetop))
1555 1555
 		{
1556
-			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1557
-			$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1556
+			$pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1557
+			$pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
1558 1558
 		}
1559 1559
 	}
1560 1560
 
@@ -1576,162 +1576,162 @@  discard block
 block discarded – undo
1576 1576
 
1577 1577
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
1578 1578
 
1579
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1579
+		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1580 1580
 
1581 1581
 		// Show Draft Watermark
1582
-		if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1582
+		if ($object->statut == Facture::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK)))
1583 1583
         {
1584
-		      pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1584
+		      pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
1585 1585
         }
1586 1586
 
1587
-		$pdf->SetTextColor(0,0,60);
1588
-		$pdf->SetFont('','B', $default_font_size + 3);
1587
+		$pdf->SetTextColor(0, 0, 60);
1588
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1589 1589
 
1590 1590
 		$w = 110;
1591 1591
 
1592
-		$posy=$this->marge_haute;
1593
-        $posx=$this->page_largeur-$this->marge_droite-$w;
1592
+		$posy = $this->marge_haute;
1593
+        $posx = $this->page_largeur - $this->marge_droite - $w;
1594 1594
 
1595
-		$pdf->SetXY($this->marge_gauche,$posy);
1595
+		$pdf->SetXY($this->marge_gauche, $posy);
1596 1596
 
1597 1597
 		// Logo
1598 1598
 		if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
1599 1599
 		{
1600
-			$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1600
+			$logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1601 1601
 			if ($this->emetteur->logo)
1602 1602
 			{
1603 1603
 				if (is_readable($logo))
1604 1604
 				{
1605
-				    $height=pdf_getHeightForLogo($logo);
1606
-					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1605
+				    $height = pdf_getHeightForLogo($logo);
1606
+					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1607 1607
 				}
1608 1608
 				else
1609 1609
 				{
1610
-					$pdf->SetTextColor(200,0,0);
1611
-					$pdf->SetFont('','B',$default_font_size - 2);
1612
-					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1610
+					$pdf->SetTextColor(200, 0, 0);
1611
+					$pdf->SetFont('', 'B', $default_font_size - 2);
1612
+					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1613 1613
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1614 1614
 				}
1615 1615
 			}
1616 1616
 			else
1617 1617
 			{
1618
-				$text=$this->emetteur->name;
1618
+				$text = $this->emetteur->name;
1619 1619
 				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1620 1620
 			}
1621 1621
 		}
1622 1622
 
1623
-		$pdf->SetFont('','B', $default_font_size + 3);
1624
-		$pdf->SetXY($posx,$posy);
1625
-		$pdf->SetTextColor(0,0,60);
1626
-		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1627
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1628
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1629
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1630
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1631
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1623
+		$pdf->SetFont('', 'B', $default_font_size + 3);
1624
+		$pdf->SetXY($posx, $posy);
1625
+		$pdf->SetTextColor(0, 0, 60);
1626
+		$title = $outputlangs->transnoentities("PdfInvoiceTitle");
1627
+		if ($object->type == 1) $title = $outputlangs->transnoentities("InvoiceReplacement");
1628
+		if ($object->type == 2) $title = $outputlangs->transnoentities("InvoiceAvoir");
1629
+		if ($object->type == 3) $title = $outputlangs->transnoentities("InvoiceDeposit");
1630
+		if ($object->type == 4) $title = $outputlangs->transnoentities("InvoiceProForma");
1631
+		if ($this->situationinvoice) $title = $outputlangs->transnoentities("InvoiceSituation");
1632 1632
 		$pdf->MultiCell($w, 3, $title, '', 'R');
1633 1633
 
1634
-		$pdf->SetFont('','B',$default_font_size);
1634
+		$pdf->SetFont('', 'B', $default_font_size);
1635 1635
 
1636
-		$posy+=5;
1637
-		$pdf->SetXY($posx,$posy);
1638
-		$pdf->SetTextColor(0,0,60);
1639
-		$textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1636
+		$posy += 5;
1637
+		$pdf->SetXY($posx, $posy);
1638
+		$pdf->SetTextColor(0, 0, 60);
1639
+		$textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1640 1640
 		if ($object->statut == Facture::STATUS_DRAFT)
1641 1641
 		{
1642
-			$pdf->SetTextColor(128,0,0);
1643
-			$textref.=' - '.$outputlangs->transnoentities("NotValidated");
1642
+			$pdf->SetTextColor(128, 0, 0);
1643
+			$textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1644 1644
 		}
1645 1645
 		$pdf->MultiCell($w, 4, $textref, '', 'R');
1646 1646
 
1647
-		$posy+=1;
1648
-		$pdf->SetFont('','', $default_font_size - 2);
1647
+		$posy += 1;
1648
+		$pdf->SetFont('', '', $default_font_size - 2);
1649 1649
 
1650 1650
 		if ($object->ref_client)
1651 1651
 		{
1652
-			$posy+=4;
1653
-			$pdf->SetXY($posx,$posy);
1654
-			$pdf->SetTextColor(0,0,60);
1655
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1652
+			$posy += 4;
1653
+			$pdf->SetXY($posx, $posy);
1654
+			$pdf->SetTextColor(0, 0, 60);
1655
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1656 1656
 		}
1657 1657
 
1658
-		$objectidnext=$object->getIdReplacingInvoice('validated');
1658
+		$objectidnext = $object->getIdReplacingInvoice('validated');
1659 1659
 		if ($object->type == 0 && $objectidnext)
1660 1660
 		{
1661
-			$objectreplacing=new Facture($this->db);
1661
+			$objectreplacing = new Facture($this->db);
1662 1662
 			$objectreplacing->fetch($objectidnext);
1663 1663
 
1664
-			$posy+=3;
1665
-			$pdf->SetXY($posx,$posy);
1666
-			$pdf->SetTextColor(0,0,60);
1664
+			$posy += 3;
1665
+			$pdf->SetXY($posx, $posy);
1666
+			$pdf->SetTextColor(0, 0, 60);
1667 1667
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1668 1668
 		}
1669 1669
 		if ($object->type == 1)
1670 1670
 		{
1671
-			$objectreplaced=new Facture($this->db);
1671
+			$objectreplaced = new Facture($this->db);
1672 1672
 			$objectreplaced->fetch($object->fk_facture_source);
1673 1673
 
1674
-			$posy+=4;
1675
-			$pdf->SetXY($posx,$posy);
1676
-			$pdf->SetTextColor(0,0,60);
1674
+			$posy += 4;
1675
+			$pdf->SetXY($posx, $posy);
1676
+			$pdf->SetTextColor(0, 0, 60);
1677 1677
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1678 1678
 		}
1679 1679
 		if ($object->type == 2 && !empty($object->fk_facture_source))
1680 1680
 		{
1681
-			$objectreplaced=new Facture($this->db);
1681
+			$objectreplaced = new Facture($this->db);
1682 1682
 			$objectreplaced->fetch($object->fk_facture_source);
1683 1683
 
1684
-			$posy+=3;
1685
-			$pdf->SetXY($posx,$posy);
1686
-			$pdf->SetTextColor(0,0,60);
1684
+			$posy += 3;
1685
+			$pdf->SetXY($posx, $posy);
1686
+			$pdf->SetTextColor(0, 0, 60);
1687 1687
 			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1688 1688
 		}
1689 1689
 
1690
-		$posy+=4;
1691
-		$pdf->SetXY($posx,$posy);
1692
-		$pdf->SetTextColor(0,0,60);
1693
-		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1690
+		$posy += 4;
1691
+		$pdf->SetXY($posx, $posy);
1692
+		$pdf->SetTextColor(0, 0, 60);
1693
+		$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : ".dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
1694 1694
 
1695
-		if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1695
+		if (!empty($conf->global->INVOICE_POINTOFTAX_DATE))
1696 1696
 		{
1697
-			$posy+=4;
1698
-			$pdf->SetXY($posx,$posy);
1699
-			$pdf->SetTextColor(0,0,60);
1700
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1697
+			$posy += 4;
1698
+			$pdf->SetXY($posx, $posy);
1699
+			$pdf->SetTextColor(0, 0, 60);
1700
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
1701 1701
 		}
1702 1702
 
1703 1703
 		if ($object->type != 2)
1704 1704
 		{
1705
-			$posy+=3;
1706
-			$pdf->SetXY($posx,$posy);
1707
-			$pdf->SetTextColor(0,0,60);
1708
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1705
+			$posy += 3;
1706
+			$pdf->SetXY($posx, $posy);
1707
+			$pdf->SetTextColor(0, 0, 60);
1708
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
1709 1709
 		}
1710 1710
 
1711 1711
 		if ($object->thirdparty->code_client)
1712 1712
 		{
1713
-			$posy+=3;
1714
-			$pdf->SetXY($posx,$posy);
1715
-			$pdf->SetTextColor(0,0,60);
1716
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1713
+			$posy += 3;
1714
+			$pdf->SetXY($posx, $posy);
1715
+			$pdf->SetTextColor(0, 0, 60);
1716
+			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1717 1717
 		}
1718 1718
 
1719 1719
 		// Get contact
1720 1720
 		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1721 1721
 		{
1722
-		    $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1722
+		    $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1723 1723
 		    if (count($arrayidcontact) > 0)
1724 1724
 		    {
1725
-		        $usertmp=new User($this->db);
1725
+		        $usertmp = new User($this->db);
1726 1726
 		        $usertmp->fetch($arrayidcontact[0]);
1727
-                $posy+=4;
1728
-                $pdf->SetXY($posx,$posy);
1729
-		        $pdf->SetTextColor(0,0,60);
1727
+                $posy += 4;
1728
+                $pdf->SetXY($posx, $posy);
1729
+		        $pdf->SetTextColor(0, 0, 60);
1730 1730
 		        $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1731 1731
 		    }
1732 1732
 		}
1733 1733
 
1734
-		$posy+=1;
1734
+		$posy += 1;
1735 1735
 
1736 1736
 		$top_shift = 0;
1737 1737
 		// Show list of linked objects
@@ -1748,45 +1748,45 @@  discard block
 block discarded – undo
1748 1748
 			$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1749 1749
 
1750 1750
 			// Show sender
1751
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1752
-			$posy+=$top_shift;
1753
-			$posx=$this->marge_gauche;
1754
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1751
+			$posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1752
+			$posy += $top_shift;
1753
+			$posx = $this->marge_gauche;
1754
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1755 1755
 
1756
-			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1757
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1756
+			$hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1757
+			$widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1758 1758
 
1759 1759
 
1760 1760
 			// Show sender frame
1761
-			$pdf->SetTextColor(0,0,0);
1762
-			$pdf->SetFont('','', $default_font_size - 2);
1763
-			$pdf->SetXY($posx,$posy-5);
1764
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1765
-			$pdf->SetXY($posx,$posy);
1766
-			$pdf->SetFillColor(230,230,230);
1761
+			$pdf->SetTextColor(0, 0, 0);
1762
+			$pdf->SetFont('', '', $default_font_size - 2);
1763
+			$pdf->SetXY($posx, $posy - 5);
1764
+			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1765
+			$pdf->SetXY($posx, $posy);
1766
+			$pdf->SetFillColor(230, 230, 230);
1767 1767
 			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1768
-			$pdf->SetTextColor(0,0,60);
1768
+			$pdf->SetTextColor(0, 0, 60);
1769 1769
 
1770 1770
 			// Show sender name
1771
-			$pdf->SetXY($posx+2,$posy+3);
1772
-			$pdf->SetFont('','B', $default_font_size);
1773
-			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1774
-			$posy=$pdf->getY();
1771
+			$pdf->SetXY($posx + 2, $posy + 3);
1772
+			$pdf->SetFont('', 'B', $default_font_size);
1773
+			$pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1774
+			$posy = $pdf->getY();
1775 1775
 
1776 1776
 			// Show sender information
1777
-			$pdf->SetXY($posx+2,$posy);
1778
-			$pdf->SetFont('','', $default_font_size - 1);
1779
-			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1777
+			$pdf->SetXY($posx + 2, $posy);
1778
+			$pdf->SetFont('', '', $default_font_size - 1);
1779
+			$pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1780 1780
 
1781 1781
 
1782 1782
 
1783 1783
 			// If BILLING contact defined on invoice, we use it
1784
-			$usecontact=false;
1785
-			$arrayidcontact=$object->getIdContact('external','BILLING');
1784
+			$usecontact = false;
1785
+			$arrayidcontact = $object->getIdContact('external', 'BILLING');
1786 1786
 			if (count($arrayidcontact) > 0)
1787 1787
 			{
1788
-				$usecontact=true;
1789
-				$result=$object->fetch_contact($arrayidcontact[0]);
1788
+				$usecontact = true;
1789
+				$result = $object->fetch_contact($arrayidcontact[0]);
1790 1790
 			}
1791 1791
 
1792 1792
 			//Recipient name
@@ -1797,39 +1797,39 @@  discard block
 block discarded – undo
1797 1797
 				$thirdparty = $object->thirdparty;
1798 1798
 			}
1799 1799
 
1800
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1800
+			$carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1801 1801
 
1802
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1802
+			$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1803 1803
 
1804 1804
 			// Show recipient
1805
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1806
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1807
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1808
-			$posy+=$top_shift;
1809
-			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1810
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1805
+			$widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1806
+			if ($this->page_largeur < 210) $widthrecbox = 84; // To work with US executive format
1807
+			$posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1808
+			$posy += $top_shift;
1809
+			$posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1810
+			if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1811 1811
 
1812 1812
 			// Show recipient frame
1813
-			$pdf->SetTextColor(0,0,0);
1814
-			$pdf->SetFont('','', $default_font_size - 2);
1815
-			$pdf->SetXY($posx+2,$posy-5);
1816
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1813
+			$pdf->SetTextColor(0, 0, 0);
1814
+			$pdf->SetFont('', '', $default_font_size - 2);
1815
+			$pdf->SetXY($posx + 2, $posy - 5);
1816
+			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1817 1817
 			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1818 1818
 
1819 1819
 			// Show recipient name
1820
-			$pdf->SetXY($posx+2,$posy+3);
1821
-			$pdf->SetFont('','B', $default_font_size);
1820
+			$pdf->SetXY($posx + 2, $posy + 3);
1821
+			$pdf->SetFont('', 'B', $default_font_size);
1822 1822
 			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1823 1823
 
1824 1824
 			$posy = $pdf->getY();
1825 1825
 
1826 1826
 			// Show recipient information
1827
-			$pdf->SetFont('','', $default_font_size - 1);
1828
-			$pdf->SetXY($posx+2,$posy);
1827
+			$pdf->SetFont('', '', $default_font_size - 1);
1828
+			$pdf->SetXY($posx + 2, $posy);
1829 1829
 			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1830 1830
 		}
1831 1831
 
1832
-		$pdf->SetTextColor(0,0,0);
1832
+		$pdf->SetTextColor(0, 0, 0);
1833 1833
 		return $top_shift;
1834 1834
 	}
1835 1835
 
@@ -1842,10 +1842,10 @@  discard block
 block discarded – undo
1842 1842
 	 *      @param	int			$hidefreetext		1=Hide free text
1843 1843
 	 *      @return	int								Return height of bottom margin including footer text
1844 1844
 	 */
1845
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1845
+	function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1846 1846
 	{
1847 1847
 		global $conf;
1848
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1849
-		return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1848
+		$showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1849
+		return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1850 1850
 	}
1851 1851
 }
Please login to merge, or discard this patch.
Braces   +230 added lines, -117 removed lines patch added patch discarded remove patch
@@ -175,7 +175,10 @@  discard block
 block discarded – undo
175 175
 
176 176
 		// Get source company
177 177
 		$this->emetteur=$mysoc;
178
-		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
178
+		if (empty($this->emetteur->country_code)) {
179
+		    $this->emetteur->country_code=substr($langs->defaultlang,-2);
180
+		}
181
+		// By default, if was not defined
179 182
 
180 183
 		// Define position of columns
181 184
 		$this->posxdesc=$this->marge_gauche+1;
@@ -185,8 +188,7 @@  discard block
 block discarded – undo
185 188
 			$this->posxup=118;
186 189
 			$this->posxqty=135;
187 190
 			$this->posxunit=151;
188
-		}
189
-		else
191
+		} else
190 192
 		{
191 193
 			$this->posxtva=110;
192 194
 			$this->posxup=126;
@@ -195,11 +197,15 @@  discard block
 block discarded – undo
195 197
 		$this->posxdiscount=162;
196 198
 		$this->posxprogress=126; // Only displayed for situation invoices
197 199
 		$this->postotalht=174;
198
-		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
200
+		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
201
+		    $this->posxtva=$this->posxup;
202
+		}
199 203
 		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
200
-		if ($this->page_largeur < 210) // To work with US executive format
204
+		if ($this->page_largeur < 210) {
205
+		    // To work with US executive format
201 206
 		{
202 207
 		    $this->posxpicture-=20;
208
+		}
203 209
 		    $this->posxtva-=20;
204 210
 		    $this->posxup-=20;
205 211
 		    $this->posxqty-=20;
@@ -235,9 +241,13 @@  discard block
 block discarded – undo
235 241
         // phpcs:enable
236 242
 		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
237 243
 
238
-		if (! is_object($outputlangs)) $outputlangs=$langs;
244
+		if (! is_object($outputlangs)) {
245
+		    $outputlangs=$langs;
246
+		}
239 247
 		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
240
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
248
+		if (! empty($conf->global->MAIN_USE_FPDF)) {
249
+		    $outputlangs->charset_output='ISO-8859-1';
250
+		}
241 251
 
242 252
 		// Load traductions files requiredby by page
243 253
 		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
@@ -250,7 +260,9 @@  discard block
 block discarded – undo
250 260
 		{
251 261
 			for ($i = 0 ; $i < $nblignes ; $i++)
252 262
 			{
253
-				if (empty($object->lines[$i]->fk_product)) continue;
263
+				if (empty($object->lines[$i]->fk_product)) {
264
+				    continue;
265
+				}
254 266
 
255 267
 				$objphoto = new Product($this->db);
256 268
 				$objphoto->fetch($object->lines[$i]->fk_product);
@@ -267,10 +279,14 @@  discard block
 block discarded – undo
267 279
 					break;
268 280
 				}
269 281
 
270
-				if ($realpath) $realpatharray[$i]=$realpath;
282
+				if ($realpath) {
283
+				    $realpatharray[$i]=$realpath;
284
+				}
271 285
 			}
272 286
 		}
273
-		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
287
+		if (count($realpatharray) == 0) {
288
+		    $this->posxpicture=$this->posxtva;
289
+		}
274 290
 
275 291
 		if ($conf->facture->dir_output)
276 292
 		{
@@ -285,8 +301,7 @@  discard block
 block discarded – undo
285 301
 			{
286 302
 				$dir = $conf->facture->dir_output;
287 303
 				$file = $dir . "/SPECIMEN.pdf";
288
-			}
289
-			else
304
+			} else
290 305
 			{
291 306
 				$objectref = dol_sanitizeFileName($object->ref);
292 307
 				$dir = $conf->facture->dir_output . "/" . $objectref;
@@ -326,7 +341,9 @@  discard block
 block discarded – undo
326 341
                 $heightforinfotot = 50+(4*$nbpayments);	// Height reserved to output the info and total part and payment part
327 342
 		        $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
328 343
 	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
329
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
344
+	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) {
345
+	                $heightforfooter+= 6;
346
+	            }
330 347
 
331 348
                 if (class_exists('TCPDF'))
332 349
                 {
@@ -351,7 +368,9 @@  discard block
 block discarded – undo
351 368
 				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
352 369
 				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
353 370
 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
371
+				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
372
+				    $pdf->SetCompression(false);
373
+				}
355 374
 
356 375
 				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
357 376
 
@@ -363,9 +382,11 @@  discard block
 block discarded – undo
363 382
 						$this->atleastonediscount++;
364 383
 					}
365 384
 				}
366
-				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))    // retreive space not used by discount
385
+				if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) {
386
+				    // retreive space not used by discount
367 387
 				{
368 388
 					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
389
+				}
369 390
 					$this->posxtva+=($this->postotalht - $this->posxdiscount);
370 391
 					$this->posxup+=($this->postotalht - $this->posxdiscount);
371 392
 					$this->posxqty+=($this->postotalht - $this->posxdiscount);
@@ -391,7 +412,9 @@  discard block
 block discarded – undo
391 412
 
392 413
 				// New page
393 414
 				$pdf->AddPage();
394
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
415
+				if (! empty($tplidx)) {
416
+				    $pdf->useTemplate($tplidx);
417
+				}
395 418
 				$pagenb++;
396 419
 
397 420
 				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
@@ -433,7 +456,9 @@  discard block
 block discarded – undo
433 456
 						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
434 457
 						$salerepobj=new User($this->db);
435 458
 						$salerepobj->fetch($salereparray[0]['id']);
436
-						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
459
+						if (! empty($salerepobj->signature)) {
460
+						    $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
461
+						}
437 462
 					}
438 463
 				}
439 464
 				if ($notetoshow)
@@ -469,7 +494,9 @@  discard block
 block discarded – undo
469 494
 
470 495
 					// Define size of image if we need it
471 496
 					$imglinesize=array();
472
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
497
+					if (! empty($realpatharray[$i])) {
498
+					    $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
499
+					}
473 500
 
474 501
 					$pdf->setTopMargin($tab_top_newpage);
475 502
 					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
@@ -480,11 +507,17 @@  discard block
 block discarded – undo
480 507
 					$posYAfterDescription=0;
481 508
 
482 509
 					// We start with Photo of product line
483
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
510
+					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) {
511
+					    // If photo too high, we moved completely on new page
484 512
 					{
485 513
 						$pdf->AddPage('','',true);
486
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
487
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
514
+					}
515
+						if (! empty($tplidx)) {
516
+						    $pdf->useTemplate($tplidx);
517
+						}
518
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
519
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
520
+						}
488 521
 						$pdf->setPage($pageposbefore+1);
489 522
 
490 523
 						$curY = $tab_top_newpage;
@@ -505,9 +538,11 @@  discard block
 block discarded – undo
505 538
 					$pdf->startTransaction();
506 539
 					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
507 540
 					$pageposafter=$pdf->getPage();
508
-					if ($pageposafter > $pageposbefore)	// There is a pagebreak
541
+					if ($pageposafter > $pageposbefore) {
542
+					    // There is a pagebreak
509 543
 					{
510 544
 						$pdf->rollbackTransaction(true);
545
+					}
511 546
 						$pageposafter=$pageposbefore;
512 547
 						//print $pageposafter.'-'.$pageposbefore;exit;
513 548
 						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
@@ -515,23 +550,27 @@  discard block
 block discarded – undo
515 550
 						$pageposafter=$pdf->getPage();
516 551
 						$posyafter=$pdf->GetY();
517 552
 						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
518
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
553
+						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) {
554
+						    // There is no space left for total+free text
519 555
 						{
520 556
 							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
521 557
 							{
522 558
 								$pdf->AddPage('','',true);
523
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
524
-								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
559
+						}
560
+								if (! empty($tplidx)) {
561
+								    $pdf->useTemplate($tplidx);
562
+								}
563
+								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
564
+								    $this->_pagehead($pdf, $object, 0, $outputlangs);
565
+								}
525 566
 								$pdf->setPage($pageposafter+1);
526 567
 							}
527
-						}
528
-						else
568
+						} else
529 569
 						{
530 570
 							// We found a page break
531 571
 							$showpricebeforepagebreak=0;
532 572
 						}
533
-					}
534
-					else	// No pagebreak
573
+					} else	// No pagebreak
535 574
 					{
536 575
 						$pdf->commitTransaction();
537 576
 					}
@@ -571,12 +610,10 @@  discard block
 block discarded – undo
571 610
 					if ($this->situationinvoice)
572 611
 					{
573 612
 						$pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R');
574
-					}
575
-					else if($conf->global->PRODUCT_USE_UNITS)
613
+					} else if($conf->global->PRODUCT_USE_UNITS)
576 614
 					{
577 615
 						$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
578
-					}
579
-					else
616
+					} else
580 617
 					{
581 618
 						$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
582 619
 					}
@@ -589,12 +626,10 @@  discard block
 block discarded – undo
589 626
 						if($conf->global->PRODUCT_USE_UNITS)
590 627
 						{
591 628
 							$pdf->MultiCell($this->posxunit-$this->posxprogress-1, 3, $progress, 0, 'R');
592
-						}
593
-						else if ($this->atleastonediscount)
629
+						} else if ($this->atleastonediscount)
594 630
 						{
595 631
 							$pdf->MultiCell($this->posxdiscount-$this->posxprogress-1, 3, $progress, 0, 'R');
596
-						}
597
-						else
632
+						} else
598 633
 						{
599 634
 							$pdf->MultiCell($this->postotalht-$this->posxprogress-1, 3, $progress, 0, 'R');
600 635
 						}
@@ -623,16 +658,24 @@  discard block
 block discarded – undo
623 658
 
624 659
 
625 660
 					$sign=1;
626
-					if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
661
+					if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
662
+					    $sign=-1;
663
+					}
627 664
 					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
628 665
 					$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
629
-					if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
666
+					if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
667
+					    // Compute progress from previous situation
630 668
 					{
631 669
 						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
632
-						else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
633 670
 					} else {
634
-						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
635
-						else $tvaligne= $sign * $object->lines[$i]->total_tva;
671
+						    $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
672
+						}
673
+					} else {
674
+						if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
675
+						    $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
676
+						} else {
677
+						    $tvaligne= $sign * $object->lines[$i]->total_tva;
678
+						}
636 679
 					}
637 680
 
638 681
 					$localtax1ligne=$object->lines[$i]->total_localtax1;
@@ -642,32 +685,48 @@  discard block
 block discarded – undo
642 685
 					$localtax1_type=$object->lines[$i]->localtax1_type;
643 686
 					$localtax2_type=$object->lines[$i]->localtax2_type;
644 687
 
645
-					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
646
-					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
647
-					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
688
+					if ($object->remise_percent) {
689
+					    $tvaligne-=($tvaligne*$object->remise_percent)/100;
690
+					}
691
+					if ($object->remise_percent) {
692
+					    $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
693
+					}
694
+					if ($object->remise_percent) {
695
+					    $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
696
+					}
648 697
 
649 698
 					$vatrate=(string) $object->lines[$i]->tva_tx;
650 699
 
651 700
 					// Retrieve type from database for backward compatibility with old records
652 701
 					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
653
-					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
702
+					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) {
703
+					    // and there is local tax
654 704
 					{
655 705
 						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
706
+					}
656 707
 						$localtax1_type = $localtaxtmp_array[0];
657 708
 						$localtax2_type = $localtaxtmp_array[2];
658 709
 					}
659 710
 
660 711
 				    // retrieve global local tax
661
-					if ($localtax1_type && $localtax1ligne != 0)
662
-						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
663
-					if ($localtax2_type && $localtax2ligne != 0)
664
-						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
712
+					if ($localtax1_type && $localtax1ligne != 0) {
713
+											$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
714
+					}
715
+					if ($localtax2_type && $localtax2ligne != 0) {
716
+											$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
717
+					}
665 718
 
666
-					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
667
-					if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
719
+					if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
720
+					    $vatrate.='*';
721
+					}
722
+					if (! isset($this->tva[$vatrate])) {
723
+					    $this->tva[$vatrate]=0;
724
+					}
668 725
 					$this->tva[$vatrate] += $tvaligne;
669 726
 
670
-					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
727
+					if ($posYAfterImage > $posYAfterDescription) {
728
+					    $nexY=$posYAfterImage;
729
+					}
671 730
 
672 731
 					// Add line
673 732
 					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
@@ -688,8 +747,7 @@  discard block
 block discarded – undo
688 747
 						if ($pagenb == 1)
689 748
 						{
690 749
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
691
-						}
692
-						else
750
+						} else
693 751
 						{
694 752
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
695 753
 						}
@@ -697,24 +755,29 @@  discard block
 block discarded – undo
697 755
 						$pagenb++;
698 756
 						$pdf->setPage($pagenb);
699 757
 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
700
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
758
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
759
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
760
+						}
701 761
 					}
702 762
 					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
703 763
 					{
704 764
 						if ($pagenb == 1)
705 765
 						{
706 766
 							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
707
-						}
708
-						else
767
+						} else
709 768
 						{
710 769
 							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
711 770
 						}
712 771
 						$this->_pagefoot($pdf,$object,$outputlangs,1);
713 772
 						// New page
714 773
 						$pdf->AddPage();
715
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
774
+						if (! empty($tplidx)) {
775
+						    $pdf->useTemplate($tplidx);
776
+						}
716 777
 						$pagenb++;
717
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
778
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
779
+						    $this->_pagehead($pdf, $object, 0, $outputlangs);
780
+						}
718 781
 					}
719 782
 				}
720 783
 
@@ -723,8 +786,7 @@  discard block
 block discarded – undo
723 786
 				{
724 787
 					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
725 788
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
726
-				}
727
-				else
789
+				} else
728 790
 				{
729 791
 					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
730 792
 					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
@@ -744,7 +806,9 @@  discard block
 block discarded – undo
744 806
 
745 807
 				// Pied de page
746 808
 				$this->_pagefoot($pdf,$object,$outputlangs);
747
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
809
+				if (method_exists($pdf,'AliasNbPages')) {
810
+				    $pdf->AliasNbPages();
811
+				}
748 812
 
749 813
 				$pdf->Close();
750 814
 
@@ -756,20 +820,19 @@  discard block
 block discarded – undo
756 820
 				global $action;
757 821
 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
758 822
 
759
-				if (! empty($conf->global->MAIN_UMASK))
760
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
823
+				if (! empty($conf->global->MAIN_UMASK)) {
824
+								@chmod($file, octdec($conf->global->MAIN_UMASK));
825
+				}
761 826
 
762 827
 				$this->result = array('fullpath'=>$file);
763 828
 
764 829
 				return 1;   // No error
765
-			}
766
-			else
830
+			} else
767 831
 			{
768 832
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
769 833
 				return 0;
770 834
 			}
771
-		}
772
-		else
835
+		} else
773 836
 		{
774 837
 			$this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
775 838
 			return 0;
@@ -793,21 +856,27 @@  discard block
 block discarded – undo
793 856
 		global $conf;
794 857
 
795 858
         $sign=1;
796
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
859
+        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
860
+            $sign=-1;
861
+        }
797 862
 
798 863
         $tab3_posx = 120;
799 864
 		$tab3_top = $posy + 8;
800 865
 		$tab3_width = 80;
801 866
 		$tab3_height = 4;
802
-		if ($this->page_largeur < 210) // To work with US executive format
867
+		if ($this->page_largeur < 210) {
868
+		    // To work with US executive format
803 869
 		{
804 870
 			$tab3_posx -= 20;
805 871
 		}
872
+		}
806 873
 
807 874
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
808 875
 
809 876
 		$title=$outputlangs->transnoentities("PaymentsAlreadyDone");
810
-		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
877
+		if ($object->type == 2) {
878
+		    $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
879
+		}
811 880
 
812 881
 		$pdf->SetFont('','', $default_font_size - 3);
813 882
 		$pdf->SetXY($tab3_posx, $tab3_top - 4);
@@ -849,10 +918,15 @@  discard block
 block discarded – undo
849 918
 				$y+=3;
850 919
 				$obj = $this->db->fetch_object($resql);
851 920
 
852
-				if ($obj->type == 2) $text=$outputlangs->transnoentities("CreditNote");
853
-				elseif ($obj->type == 3) $text=$outputlangs->transnoentities("Deposit");
854
-				elseif ($obj->type == 0) $text=$outputlangs->transnoentities("ExcessReceived");
855
-				else $text=$outputlangs->transnoentities("UnknownType");
921
+				if ($obj->type == 2) {
922
+				    $text=$outputlangs->transnoentities("CreditNote");
923
+				} elseif ($obj->type == 3) {
924
+				    $text=$outputlangs->transnoentities("Deposit");
925
+				} elseif ($obj->type == 0) {
926
+				    $text=$outputlangs->transnoentities("ExcessReceived");
927
+				} else {
928
+				    $text=$outputlangs->transnoentities("UnknownType");
929
+				}
856 930
 
857 931
 				$invoice->fetch($obj->fk_facture_source);
858 932
 
@@ -869,8 +943,7 @@  discard block
 block discarded – undo
869 943
 
870 944
 				$i++;
871 945
 			}
872
-		}
873
-		else
946
+		} else
874 947
 		{
875 948
 			$this->error=$this->db->lasterror();
876 949
 			return -1;
@@ -910,8 +983,7 @@  discard block
 block discarded – undo
910 983
 
911 984
 				$i++;
912 985
 			}
913
-		}
914
-		else
986
+		} else
915 987
 		{
916 988
 			$this->error=$this->db->lasterror();
917 989
 			return -1;
@@ -1060,7 +1132,10 @@  discard block
 block discarded – undo
1060 1132
 				if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1061 1133
 				{
1062 1134
 					$bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1063
-					if (! empty($object->fk_bank)) $bankid=$object->fk_bank;   // For backward compatibility when object->fk_account is forced with object->fk_bank
1135
+					if (! empty($object->fk_bank)) {
1136
+					    $bankid=$object->fk_bank;
1137
+					}
1138
+					// For backward compatibility when object->fk_account is forced with object->fk_bank
1064 1139
 					$account = new Account($this->db);
1065 1140
 					$account->fetch($bankid);
1066 1141
 
@@ -1095,7 +1170,9 @@  discard block
 block discarded – undo
1095 1170
 		global $conf,$mysoc;
1096 1171
 
1097 1172
         $sign=1;
1098
-        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1173
+        if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1174
+            $sign=-1;
1175
+        }
1099 1176
 
1100 1177
         $default_font_size = pdf_getPDFFontSize($outputlangs);
1101 1178
 
@@ -1105,10 +1182,12 @@  discard block
 block discarded – undo
1105 1182
 
1106 1183
 		// Tableau total
1107 1184
 		$col1x = 120; $col2x = 170;
1108
-		if ($this->page_largeur < 210) // To work with US executive format
1185
+		if ($this->page_largeur < 210) {
1186
+		    // To work with US executive format
1109 1187
 		{
1110 1188
 			$col2x-=20;
1111 1189
 		}
1190
+		}
1112 1191
 		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1113 1192
 
1114 1193
 		$useborder=0;
@@ -1135,8 +1214,7 @@  discard block
 block discarded – undo
1135 1214
 			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1136 1215
 			{
1137 1216
 				// Nothing to do
1138
-			}
1139
-			else
1217
+			} else
1140 1218
 			{
1141 1219
 			    // FIXME amount of vat not supported with multicurrency
1142 1220
 
@@ -1145,15 +1223,19 @@  discard block
 block discarded – undo
1145 1223
 				//{
1146 1224
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1147 1225
 					{
1148
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1226
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1227
+						    continue;
1228
+						}
1149 1229
 
1150 1230
 						foreach( $localtax_rate as $tvakey => $tvaval )
1151 1231
 						{
1152
-							if ($tvakey!=0)    // On affiche pas taux 0
1232
+							if ($tvakey!=0) {
1233
+							    // On affiche pas taux 0
1153 1234
 							{
1154 1235
 								//$this->atleastoneratenotnull++;
1155 1236
 
1156 1237
 								$index++;
1238
+							}
1157 1239
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1158 1240
 
1159 1241
 								$tvacompl='';
@@ -1178,17 +1260,21 @@  discard block
 block discarded – undo
1178 1260
 				//{
1179 1261
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1180 1262
 					{
1181
-						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1263
+						if (in_array((string) $localtax_type, array('1','3','5'))) {
1264
+						    continue;
1265
+						}
1182 1266
 
1183 1267
 						foreach( $localtax_rate as $tvakey => $tvaval )
1184 1268
 						{
1185
-							if ($tvakey!=0)    // On affiche pas taux 0
1269
+							if ($tvakey!=0) {
1270
+							    // On affiche pas taux 0
1186 1271
 							{
1187 1272
 								//$this->atleastoneratenotnull++;
1188 1273
 
1189 1274
 
1190 1275
 
1191 1276
 								$index++;
1277
+							}
1192 1278
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1193 1279
 
1194 1280
 								$tvacompl='';
@@ -1229,9 +1315,11 @@  discard block
 block discarded – undo
1229 1315
 
1230 1316
 				foreach($this->tva as $tvakey => $tvaval)
1231 1317
 				{
1232
-					if ($tvakey != 0)    // On affiche pas taux 0
1318
+					if ($tvakey != 0) {
1319
+					    // On affiche pas taux 0
1233 1320
 					{
1234 1321
 						$this->atleastoneratenotnull++;
1322
+					}
1235 1323
 
1236 1324
 						$index++;
1237 1325
 						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@@ -1256,15 +1344,19 @@  discard block
 block discarded – undo
1256 1344
 				//{
1257 1345
 					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1258 1346
 					{
1259
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1347
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1348
+						    continue;
1349
+						}
1260 1350
 
1261 1351
 						foreach( $localtax_rate as $tvakey => $tvaval )
1262 1352
 						{
1263
-							if ($tvakey != 0)    // On affiche pas taux 0
1353
+							if ($tvakey != 0) {
1354
+							    // On affiche pas taux 0
1264 1355
 							{
1265 1356
 								//$this->atleastoneratenotnull++;
1266 1357
 
1267 1358
 								$index++;
1359
+							}
1268 1360
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1269 1361
 
1270 1362
 								$tvacompl='';
@@ -1288,16 +1380,20 @@  discard block
 block discarded – undo
1288 1380
 				//{
1289 1381
 					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1290 1382
 					{
1291
-						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1383
+						if (in_array((string) $localtax_type, array('2','4','6'))) {
1384
+						    continue;
1385
+						}
1292 1386
 
1293 1387
 						foreach( $localtax_rate as $tvakey => $tvaval )
1294 1388
 						{
1295 1389
 						    // retrieve global local tax
1296
-							if ($tvakey != 0)    // On affiche pas taux 0
1390
+							if ($tvakey != 0) {
1391
+							    // On affiche pas taux 0
1297 1392
 							{
1298 1393
 								//$this->atleastoneratenotnull++;
1299 1394
 
1300 1395
 								$index++;
1396
+							}
1301 1397
 								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1302 1398
 
1303 1399
 								$tvacompl='';
@@ -1346,7 +1442,9 @@  discard block
 block discarded – undo
1346 1442
 		$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1347 1443
 		//print "x".$creditnoteamount."-".$depositsamount;exit;
1348 1444
 		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1349
-		if ($object->paye) $resteapayer=0;
1445
+		if ($object->paye) {
1446
+		    $resteapayer=0;
1447
+		}
1350 1448
 
1351 1449
 		if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
1352 1450
 		{
@@ -1417,7 +1515,9 @@  discard block
 block discarded – undo
1417 1515
 
1418 1516
 		// Force to disable hidetop and hidebottom
1419 1517
 		$hidebottom=0;
1420
-		if ($hidetop) $hidetop=-1;
1518
+		if ($hidetop) {
1519
+		    $hidetop=-1;
1520
+		}
1421 1521
 
1422 1522
 		$currency = !empty($currency) ? $currency : $conf->currency;
1423 1523
 		$default_font_size = pdf_getPDFFontSize($outputlangs);
@@ -1433,7 +1533,9 @@  discard block
 block discarded – undo
1433 1533
 			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1434 1534
 
1435 1535
 			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1436
-			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1536
+			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1537
+			    $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1538
+			}
1437 1539
 		}
1438 1540
 
1439 1541
 		$pdf->SetDrawColor(128,128,128);
@@ -1485,12 +1587,10 @@  discard block
 block discarded – undo
1485 1587
 			if($this->situationinvoice)
1486 1588
 			{
1487 1589
 				$pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1488
-			}
1489
-			else if($conf->global->PRODUCT_USE_UNITS)
1590
+			} else if($conf->global->PRODUCT_USE_UNITS)
1490 1591
 			{
1491 1592
 				$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1492
-			}
1493
-			else
1593
+			} else
1494 1594
 			{
1495 1595
 				$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1496 1596
 			}
@@ -1506,12 +1606,10 @@  discard block
 block discarded – undo
1506 1606
 				if($conf->global->PRODUCT_USE_UNITS)
1507 1607
 				{
1508 1608
 					$pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1509
-				}
1510
-				else if ($this->atleastonediscount)
1609
+				} else if ($this->atleastonediscount)
1511 1610
 				{
1512 1611
 					$pdf->MultiCell($this->posxdiscount-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1513
-				}
1514
-				else
1612
+				} else
1515 1613
 				{
1516 1614
 					$pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1517 1615
 				}
@@ -1604,16 +1702,14 @@  discard block
 block discarded – undo
1604 1702
 				{
1605 1703
 				    $height=pdf_getHeightForLogo($logo);
1606 1704
 					$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1607
-				}
1608
-				else
1705
+				} else
1609 1706
 				{
1610 1707
 					$pdf->SetTextColor(200,0,0);
1611 1708
 					$pdf->SetFont('','B',$default_font_size - 2);
1612 1709
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1613 1710
 					$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1614 1711
 				}
1615
-			}
1616
-			else
1712
+			} else
1617 1713
 			{
1618 1714
 				$text=$this->emetteur->name;
1619 1715
 				$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
@@ -1624,11 +1720,21 @@  discard block
 block discarded – undo
1624 1720
 		$pdf->SetXY($posx,$posy);
1625 1721
 		$pdf->SetTextColor(0,0,60);
1626 1722
 		$title=$outputlangs->transnoentities("PdfInvoiceTitle");
1627
-		if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1628
-		if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1629
-		if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1630
-		if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1631
-		if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1723
+		if ($object->type == 1) {
1724
+		    $title=$outputlangs->transnoentities("InvoiceReplacement");
1725
+		}
1726
+		if ($object->type == 2) {
1727
+		    $title=$outputlangs->transnoentities("InvoiceAvoir");
1728
+		}
1729
+		if ($object->type == 3) {
1730
+		    $title=$outputlangs->transnoentities("InvoiceDeposit");
1731
+		}
1732
+		if ($object->type == 4) {
1733
+		    $title=$outputlangs->transnoentities("InvoiceProForma");
1734
+		}
1735
+		if ($this->situationinvoice) {
1736
+		    $title=$outputlangs->transnoentities("InvoiceSituation");
1737
+		}
1632 1738
 		$pdf->MultiCell($w, 3, $title, '', 'R');
1633 1739
 
1634 1740
 		$pdf->SetFont('','B',$default_font_size);
@@ -1751,7 +1857,9 @@  discard block
 block discarded – undo
1751 1857
 			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1752 1858
 			$posy+=$top_shift;
1753 1859
 			$posx=$this->marge_gauche;
1754
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1860
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1861
+			    $posx=$this->page_largeur-$this->marge_droite-80;
1862
+			}
1755 1863
 
1756 1864
 			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1757 1865
 			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
@@ -1803,11 +1911,16 @@  discard block
 block discarded – undo
1803 1911
 
1804 1912
 			// Show recipient
1805 1913
 			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1806
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1914
+			if ($this->page_largeur < 210) {
1915
+			    $widthrecbox=84;
1916
+			}
1917
+			// To work with US executive format
1807 1918
 			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1808 1919
 			$posy+=$top_shift;
1809 1920
 			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1810
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1921
+			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1922
+			    $posx=$this->marge_gauche;
1923
+			}
1811 1924
 
1812 1925
 			// Show recipient frame
1813 1926
 			$pdf->SetTextColor(0,0,0);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/facture/mod_facture_mars.php 3 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -30,160 +30,160 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class mod_facture_mars extends ModeleNumRefFactures
32 32
 {
33
-	/**
33
+    /**
34 34
      * Dolibarr version of the loaded document
35 35
      * @public string
36 36
      */
37
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
38
-
39
-	public $prefixinvoice='FA';
40
-
41
-	public $prefixreplacement='FR';
42
-
43
-	public $prefixdeposit='AC';
44
-
45
-	public $prefixcreditnote='AV';
46
-
47
-	/**
48
-	 * @var string Error code (or message)
49
-	 */
50
-	public $error='';
51
-
52
-
53
-	/**
54
-	 * Constructor
55
-	 */
56
-	function __construct()
57
-	{
58
-		if (! empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX))
59
-		{
60
-			$this->prefixinvoice = $conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX;
61
-		}
62
-	}
63
-
64
-	/**
65
-	 *  Renvoi la description du modele de numerotation
66
-	 *
67
-	 *  @return     string      Texte descripif
68
-	 */
69
-	function info()
70
-	{
71
-		global $langs;
72
-		$langs->load("bills");
73
-		return $langs->trans('MarsNumRefModelDesc1',$this->prefixinvoice,$this->prefixreplacement,$this->prefixdeposit,$this->prefixcreditnote);
74
-	}
75
-
76
-	/**
77
-	 *  Renvoi un exemple de numerotation
78
-	 *
79
-	 *  @return     string      Example
80
-	 */
81
-	function getExample()
82
-	{
83
-		return $this->prefixinvoice."0501-0001";
84
-	}
85
-
86
-	/**
87
-	 *  Test si les numeros deja en vigueur dans la base ne provoquent pas de
88
-	 *  de conflits qui empechera cette numerotation de fonctionner.
89
-	 *
90
-	 *  @return     boolean     false si conflit, true si ok
91
-	 */
92
-	function canBeActivated()
93
-	{
94
-		global $langs,$conf,$db;
95
-
96
-		$langs->load("bills");
97
-
98
-		// Check invoice num
99
-		$fayymm=''; $max='';
100
-
101
-		$posindice=8;
102
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED) as max";	// This is standard SQL
103
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
104
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
105
-		$sql.= " AND entity = ".$conf->entity;
106
-
107
-		$resql=$db->query($sql);
108
-		if ($resql)
109
-		{
110
-			$row = $db->fetch_row($resql);
111
-			if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
112
-		}
113
-		if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm))
114
-		{
115
-			$langs->load("errors");
116
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
117
-			return false;
118
-		}
119
-
120
-		// Check credit note num
121
-		$fayymm='';
122
-
123
-		$posindice=8;
124
-		$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";	// This is standard SQL
125
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
126
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
127
-		$sql.= " AND entity = ".$conf->entity;
128
-
129
-		$resql=$db->query($sql);
130
-		if ($resql)
131
-		{
132
-			$row = $db->fetch_row($resql);
133
-			if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
134
-		}
135
-		if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm))
136
-		{
137
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
138
-			return false;
139
-		}
140
-
141
-		return true;
142
-	}
143
-
144
-	/**
145
-	 * Return next value not used or last value used
146
-	 *
147
-	 * @param	Societe		$objsoc		Object third party
148
-	 * @param   Facture		$invoice	Object invoice
37
+    public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
38
+
39
+    public $prefixinvoice='FA';
40
+
41
+    public $prefixreplacement='FR';
42
+
43
+    public $prefixdeposit='AC';
44
+
45
+    public $prefixcreditnote='AV';
46
+
47
+    /**
48
+     * @var string Error code (or message)
49
+     */
50
+    public $error='';
51
+
52
+
53
+    /**
54
+     * Constructor
55
+     */
56
+    function __construct()
57
+    {
58
+        if (! empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX))
59
+        {
60
+            $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX;
61
+        }
62
+    }
63
+
64
+    /**
65
+     *  Renvoi la description du modele de numerotation
66
+     *
67
+     *  @return     string      Texte descripif
68
+     */
69
+    function info()
70
+    {
71
+        global $langs;
72
+        $langs->load("bills");
73
+        return $langs->trans('MarsNumRefModelDesc1',$this->prefixinvoice,$this->prefixreplacement,$this->prefixdeposit,$this->prefixcreditnote);
74
+    }
75
+
76
+    /**
77
+     *  Renvoi un exemple de numerotation
78
+     *
79
+     *  @return     string      Example
80
+     */
81
+    function getExample()
82
+    {
83
+        return $this->prefixinvoice."0501-0001";
84
+    }
85
+
86
+    /**
87
+     *  Test si les numeros deja en vigueur dans la base ne provoquent pas de
88
+     *  de conflits qui empechera cette numerotation de fonctionner.
89
+     *
90
+     *  @return     boolean     false si conflit, true si ok
91
+     */
92
+    function canBeActivated()
93
+    {
94
+        global $langs,$conf,$db;
95
+
96
+        $langs->load("bills");
97
+
98
+        // Check invoice num
99
+        $fayymm=''; $max='';
100
+
101
+        $posindice=8;
102
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED) as max";	// This is standard SQL
103
+        $sql.= " FROM ".MAIN_DB_PREFIX."facture";
104
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
105
+        $sql.= " AND entity = ".$conf->entity;
106
+
107
+        $resql=$db->query($sql);
108
+        if ($resql)
109
+        {
110
+            $row = $db->fetch_row($resql);
111
+            if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
112
+        }
113
+        if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm))
114
+        {
115
+            $langs->load("errors");
116
+            $this->error=$langs->trans('ErrorNumRefModel',$max);
117
+            return false;
118
+        }
119
+
120
+        // Check credit note num
121
+        $fayymm='';
122
+
123
+        $posindice=8;
124
+        $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";	// This is standard SQL
125
+        $sql.= " FROM ".MAIN_DB_PREFIX."facture";
126
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
127
+        $sql.= " AND entity = ".$conf->entity;
128
+
129
+        $resql=$db->query($sql);
130
+        if ($resql)
131
+        {
132
+            $row = $db->fetch_row($resql);
133
+            if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
134
+        }
135
+        if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm))
136
+        {
137
+            $this->error=$langs->trans('ErrorNumRefModel',$max);
138
+            return false;
139
+        }
140
+
141
+        return true;
142
+    }
143
+
144
+    /**
145
+     * Return next value not used or last value used
146
+     *
147
+     * @param	Societe		$objsoc		Object third party
148
+     * @param   Facture		$invoice	Object invoice
149 149
      * @param   string		$mode       'next' for next value or 'last' for last value
150
-	 * @return  string       			Value
151
-	 */
152
-	function getNextValue($objsoc, $invoice, $mode='next')
153
-	{
154
-		global $db;
155
-
156
-		$prefix=$this->prefixinvoice;
157
-
158
-		if ($invoice->type == 1) $prefix=$this->prefixreplacement;
159
-		else if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
160
-		else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
161
-		else $prefix=$this->prefixinvoice;
162
-
163
-		// D'abord on recupere la valeur max
164
-		$posindice=8;
165
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
166
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
167
-		$sql.= " WHERE ref LIKE '".$prefix."____-%'";
168
-		$sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
169
-
170
-		$resql=$db->query($sql);
171
-		dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
172
-		if ($resql)
173
-		{
174
-			$obj = $db->fetch_object($resql);
175
-			if ($obj) $max = intval($obj->max);
176
-			else $max=0;
177
-		}
178
-		else
179
-		{
180
-			return -1;
181
-		}
182
-
183
-		if ($mode == 'last')
184
-		{
185
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
186
-    		else $num = sprintf("%04s",$max);
150
+     * @return  string       			Value
151
+     */
152
+    function getNextValue($objsoc, $invoice, $mode='next')
153
+    {
154
+        global $db;
155
+
156
+        $prefix=$this->prefixinvoice;
157
+
158
+        if ($invoice->type == 1) $prefix=$this->prefixreplacement;
159
+        else if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
160
+        else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
161
+        else $prefix=$this->prefixinvoice;
162
+
163
+        // D'abord on recupere la valeur max
164
+        $posindice=8;
165
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
166
+        $sql.= " FROM ".MAIN_DB_PREFIX."facture";
167
+        $sql.= " WHERE ref LIKE '".$prefix."____-%'";
168
+        $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
169
+
170
+        $resql=$db->query($sql);
171
+        dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
172
+        if ($resql)
173
+        {
174
+            $obj = $db->fetch_object($resql);
175
+            if ($obj) $max = intval($obj->max);
176
+            else $max=0;
177
+        }
178
+        else
179
+        {
180
+            return -1;
181
+        }
182
+
183
+        if ($mode == 'last')
184
+        {
185
+            if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
186
+            else $num = sprintf("%04s",$max);
187 187
 
188 188
             $ref='';
189 189
             $sql = "SELECT ref as ref";
@@ -201,32 +201,32 @@  discard block
 block discarded – undo
201 201
             else dol_print_error($db);
202 202
 
203 203
             return $ref;
204
-		}
205
-		else if ($mode == 'next')
206
-		{
207
-			$date=$invoice->date;	// This is invoice date (not creation date)
208
-    		$yymm = strftime("%y%m",$date);
209
-
210
-    		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
211
-    		else $num = sprintf("%04s",$max+1);
212
-
213
-    		dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
214
-    		return $prefix.$yymm."-".$num;
215
-		}
216
-		else dol_print_error('','Bad parameter for getNextValue');
217
-	}
218
-
219
-	/**
220
-	 * Return next free value
221
-	 *
204
+        }
205
+        else if ($mode == 'next')
206
+        {
207
+            $date=$invoice->date;	// This is invoice date (not creation date)
208
+            $yymm = strftime("%y%m",$date);
209
+
210
+            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
211
+            else $num = sprintf("%04s",$max+1);
212
+
213
+            dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
214
+            return $prefix.$yymm."-".$num;
215
+        }
216
+        else dol_print_error('','Bad parameter for getNextValue');
217
+    }
218
+
219
+    /**
220
+     * Return next free value
221
+     *
222 222
      * @param	Societe		$objsoc     	Object third party
223 223
      * @param	string		$objforref		Object for number to search
224 224
      * @param   string		$mode       	'next' for next value or 'last' for last value
225 225
      * @return  string      				Next free value
226
-	 */
227
-	function getNumRef($objsoc,$objforref,$mode='next')
228
-	{
229
-		return $this->getNextValue($objsoc,$objforref,$mode);
230
-	}
226
+     */
227
+    function getNumRef($objsoc,$objforref,$mode='next')
228
+    {
229
+        return $this->getNextValue($objsoc,$objforref,$mode);
230
+    }
231 231
 }
232 232
 
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *	\ingroup    facture
24 24
  *	\brief      File containing class for numbering module Mars
25 25
  */
26
-require_once DOL_DOCUMENT_ROOT .'/core/modules/facture/modules_facture.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
27 27
 
28 28
 /**
29 29
  * 	Classe du modele de numerotation de reference de facture Mars
@@ -34,20 +34,20 @@  discard block
 block discarded – undo
34 34
      * Dolibarr version of the loaded document
35 35
      * @public string
36 36
      */
37
-	public $version = 'dolibarr';		// 'development', 'experimental', 'dolibarr'
37
+	public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38 38
 
39
-	public $prefixinvoice='FA';
39
+	public $prefixinvoice = 'FA';
40 40
 
41
-	public $prefixreplacement='FR';
41
+	public $prefixreplacement = 'FR';
42 42
 
43
-	public $prefixdeposit='AC';
43
+	public $prefixdeposit = 'AC';
44 44
 
45
-	public $prefixcreditnote='AV';
45
+	public $prefixcreditnote = 'AV';
46 46
 
47 47
 	/**
48 48
 	 * @var string Error code (or message)
49 49
 	 */
50
-	public $error='';
50
+	public $error = '';
51 51
 
52 52
 
53 53
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	function __construct()
57 57
 	{
58
-		if (! empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX))
58
+		if (!empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX))
59 59
 		{
60 60
 			$this->prefixinvoice = $conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX;
61 61
 		}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	{
71 71
 		global $langs;
72 72
 		$langs->load("bills");
73
-		return $langs->trans('MarsNumRefModelDesc1',$this->prefixinvoice,$this->prefixreplacement,$this->prefixdeposit,$this->prefixcreditnote);
73
+		return $langs->trans('MarsNumRefModelDesc1', $this->prefixinvoice, $this->prefixreplacement, $this->prefixdeposit, $this->prefixcreditnote);
74 74
 	}
75 75
 
76 76
 	/**
@@ -91,50 +91,50 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	function canBeActivated()
93 93
 	{
94
-		global $langs,$conf,$db;
94
+		global $langs, $conf, $db;
95 95
 
96 96
 		$langs->load("bills");
97 97
 
98 98
 		// Check invoice num
99
-		$fayymm=''; $max='';
99
+		$fayymm = ''; $max = '';
100 100
 
101
-		$posindice=8;
102
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED) as max";	// This is standard SQL
103
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
104
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
105
-		$sql.= " AND entity = ".$conf->entity;
101
+		$posindice = 8;
102
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED) as max"; // This is standard SQL
103
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture";
104
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'";
105
+		$sql .= " AND entity = ".$conf->entity;
106 106
 
107
-		$resql=$db->query($sql);
107
+		$resql = $db->query($sql);
108 108
 		if ($resql)
109 109
 		{
110 110
 			$row = $db->fetch_row($resql);
111
-			if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
111
+			if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
112 112
 		}
113
-		if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm))
113
+		if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm))
114 114
 		{
115 115
 			$langs->load("errors");
116
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
116
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
117 117
 			return false;
118 118
 		}
119 119
 
120 120
 		// Check credit note num
121
-		$fayymm='';
121
+		$fayymm = '';
122 122
 
123
-		$posindice=8;
124
-		$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";	// This is standard SQL
125
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
126
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
127
-		$sql.= " AND entity = ".$conf->entity;
123
+		$posindice = 8;
124
+		$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
125
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture";
126
+		$sql .= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'";
127
+		$sql .= " AND entity = ".$conf->entity;
128 128
 
129
-		$resql=$db->query($sql);
129
+		$resql = $db->query($sql);
130 130
 		if ($resql)
131 131
 		{
132 132
 			$row = $db->fetch_row($resql);
133
-			if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
133
+			if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; }
134 134
 		}
135
-		if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm))
135
+		if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm))
136 136
 		{
137
-			$this->error=$langs->trans('ErrorNumRefModel',$max);
137
+			$this->error = $langs->trans('ErrorNumRefModel', $max);
138 138
 			return false;
139 139
 		}
140 140
 
@@ -149,31 +149,31 @@  discard block
 block discarded – undo
149 149
      * @param   string		$mode       'next' for next value or 'last' for last value
150 150
 	 * @return  string       			Value
151 151
 	 */
152
-	function getNextValue($objsoc, $invoice, $mode='next')
152
+	function getNextValue($objsoc, $invoice, $mode = 'next')
153 153
 	{
154 154
 		global $db;
155 155
 
156
-		$prefix=$this->prefixinvoice;
156
+		$prefix = $this->prefixinvoice;
157 157
 
158
-		if ($invoice->type == 1) $prefix=$this->prefixreplacement;
159
-		else if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
160
-		else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
161
-		else $prefix=$this->prefixinvoice;
158
+		if ($invoice->type == 1) $prefix = $this->prefixreplacement;
159
+		else if ($invoice->type == 2) $prefix = $this->prefixcreditnote;
160
+		else if ($invoice->type == 3) $prefix = $this->prefixdeposit;
161
+		else $prefix = $this->prefixinvoice;
162 162
 
163 163
 		// D'abord on recupere la valeur max
164
-		$posindice=8;
165
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";	// This is standard SQL
166
-		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
167
-		$sql.= " WHERE ref LIKE '".$prefix."____-%'";
168
-		$sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
164
+		$posindice = 8;
165
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
166
+		$sql .= " FROM ".MAIN_DB_PREFIX."facture";
167
+		$sql .= " WHERE ref LIKE '".$prefix."____-%'";
168
+		$sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
169 169
 
170
-		$resql=$db->query($sql);
170
+		$resql = $db->query($sql);
171 171
 		dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
172 172
 		if ($resql)
173 173
 		{
174 174
 			$obj = $db->fetch_object($resql);
175 175
 			if ($obj) $max = intval($obj->max);
176
-			else $max=0;
176
+			else $max = 0;
177 177
 		}
178 178
 		else
179 179
 		{
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 
183 183
 		if ($mode == 'last')
184 184
 		{
185
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
186
-    		else $num = sprintf("%04s",$max);
185
+    		if ($max >= (pow(10, 4) - 1)) $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is
186
+    		else $num = sprintf("%04s", $max);
187 187
 
188
-            $ref='';
188
+            $ref = '';
189 189
             $sql = "SELECT ref as ref";
190
-            $sql.= " FROM ".MAIN_DB_PREFIX."facture";
191
-            $sql.= " WHERE ref LIKE '".$prefix."____-".$num."'";
192
-            $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
190
+            $sql .= " FROM ".MAIN_DB_PREFIX."facture";
191
+            $sql .= " WHERE ref LIKE '".$prefix."____-".$num."'";
192
+            $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
193 193
 
194 194
             dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
195
-            $resql=$db->query($sql);
195
+            $resql = $db->query($sql);
196 196
             if ($resql)
197 197
             {
198 198
                 $obj = $db->fetch_object($resql);
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
 		}
205 205
 		else if ($mode == 'next')
206 206
 		{
207
-			$date=$invoice->date;	// This is invoice date (not creation date)
208
-    		$yymm = strftime("%y%m",$date);
207
+			$date = $invoice->date; // This is invoice date (not creation date)
208
+    		$yymm = strftime("%y%m", $date);
209 209
 
210
-    		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
211
-    		else $num = sprintf("%04s",$max+1);
210
+    		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
211
+    		else $num = sprintf("%04s", $max + 1);
212 212
 
213 213
     		dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
214 214
     		return $prefix.$yymm."-".$num;
215 215
 		}
216
-		else dol_print_error('','Bad parameter for getNextValue');
216
+		else dol_print_error('', 'Bad parameter for getNextValue');
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
      * @param   string		$mode       	'next' for next value or 'last' for last value
225 225
      * @return  string      				Next free value
226 226
 	 */
227
-	function getNumRef($objsoc,$objforref,$mode='next')
227
+	function getNumRef($objsoc, $objforref, $mode = 'next')
228 228
 	{
229
-		return $this->getNextValue($objsoc,$objforref,$mode);
229
+		return $this->getNextValue($objsoc, $objforref, $mode);
230 230
 	}
231 231
 }
232 232
 
Please login to merge, or discard this patch.
Braces   +37 added lines, -17 removed lines patch added patch discarded remove patch
@@ -155,10 +155,15 @@  discard block
 block discarded – undo
155 155
 
156 156
 		$prefix=$this->prefixinvoice;
157 157
 
158
-		if ($invoice->type == 1) $prefix=$this->prefixreplacement;
159
-		else if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
160
-		else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
161
-		else $prefix=$this->prefixinvoice;
158
+		if ($invoice->type == 1) {
159
+		    $prefix=$this->prefixreplacement;
160
+		} else if ($invoice->type == 2) {
161
+		    $prefix=$this->prefixcreditnote;
162
+		} else if ($invoice->type == 3) {
163
+		    $prefix=$this->prefixdeposit;
164
+		} else {
165
+		    $prefix=$this->prefixinvoice;
166
+		}
162 167
 
163 168
 		// D'abord on recupere la valeur max
164 169
 		$posindice=8;
@@ -172,18 +177,25 @@  discard block
 block discarded – undo
172 177
 		if ($resql)
173 178
 		{
174 179
 			$obj = $db->fetch_object($resql);
175
-			if ($obj) $max = intval($obj->max);
176
-			else $max=0;
177
-		}
178
-		else
180
+			if ($obj) {
181
+			    $max = intval($obj->max);
182
+			} else {
183
+			    $max=0;
184
+			}
185
+		} else
179 186
 		{
180 187
 			return -1;
181 188
 		}
182 189
 
183 190
 		if ($mode == 'last')
184 191
 		{
185
-    		if ($max >= (pow(10, 4) - 1)) $num=$max;	// If counter > 9999, we do not format on 4 chars, we take number as it is
186
-    		else $num = sprintf("%04s",$max);
192
+    		if ($max >= (pow(10, 4) - 1)) {
193
+    		    $num=$max;
194
+    		}
195
+    		// If counter > 9999, we do not format on 4 chars, we take number as it is
196
+    		else {
197
+    		    $num = sprintf("%04s",$max);
198
+    		}
187 199
 
188 200
             $ref='';
189 201
             $sql = "SELECT ref as ref";
@@ -196,24 +208,32 @@  discard block
 block discarded – undo
196 208
             if ($resql)
197 209
             {
198 210
                 $obj = $db->fetch_object($resql);
199
-                if ($obj) $ref = $obj->ref;
211
+                if ($obj) {
212
+                    $ref = $obj->ref;
213
+                }
214
+            } else {
215
+                dol_print_error($db);
200 216
             }
201
-            else dol_print_error($db);
202 217
 
203 218
             return $ref;
204
-		}
205
-		else if ($mode == 'next')
219
+		} else if ($mode == 'next')
206 220
 		{
207 221
 			$date=$invoice->date;	// This is invoice date (not creation date)
208 222
     		$yymm = strftime("%y%m",$date);
209 223
 
210
-    		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
211
-    		else $num = sprintf("%04s",$max+1);
224
+    		if ($max >= (pow(10, 4) - 1)) {
225
+    		    $num=$max+1;
226
+    		}
227
+    		// If counter > 9999, we do not format on 4 chars, we take number as it is
228
+    		else {
229
+    		    $num = sprintf("%04s",$max+1);
230
+    		}
212 231
 
213 232
     		dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
214 233
     		return $prefix.$yymm."-".$num;
234
+		} else {
235
+		    dol_print_error('','Bad parameter for getNextValue');
215 236
 		}
216
-		else dol_print_error('','Bad parameter for getNextValue');
217 237
 	}
218 238
 
219 239
 	/**
Please login to merge, or discard this patch.