@@ -31,108 +31,108 @@ |
||
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 |
@@ -33,198 +33,198 @@ |
||
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 | } |
@@ -31,82 +31,82 @@ |
||
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 |
@@ -33,223 +33,223 @@ |
||
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 |
@@ -43,17 +43,17 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -39,487 +39,487 @@ |
||
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 | } |
@@ -43,17 +43,17 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -30,160 +30,160 @@ discard block |
||
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 |
||
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 |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * Dolibarr version of the loaded document |
38 | 38 | * @public string |
39 | 39 | */ |
40 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
40 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
41 | 41 | |
42 | 42 | /** |
43 | - * @var string Error message |
|
44 | - */ |
|
45 | - public $error = ''; |
|
43 | + * @var string Error message |
|
44 | + */ |
|
45 | + public $error = ''; |
|
46 | 46 | |
47 | 47 | |
48 | 48 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">'; |
66 | 66 | $texte.= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">'; |
67 | 67 | $texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">'; |
68 | - $texte.= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">'; |
|
68 | + $texte.= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">'; |
|
69 | 69 | $texte.= '<table class="nobordernopadding" width="100%">'; |
70 | 70 | |
71 | 71 | $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice")); |
@@ -137,19 +137,19 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function getNextValue($objsoc, $invoice, $mode='next') |
139 | 139 | { |
140 | - global $db,$conf; |
|
140 | + global $db,$conf; |
|
141 | 141 | |
142 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
142 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
143 | 143 | |
144 | 144 | // Get Mask value |
145 | 145 | $mask = ''; |
146 | 146 | if (is_object($invoice) && $invoice->type == 1) |
147 | 147 | { |
148 | - $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; |
|
149 | - if (! $mask) |
|
150 | - { |
|
151 | - $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; |
|
152 | - } |
|
148 | + $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; |
|
149 | + if (! $mask) |
|
150 | + { |
|
151 | + $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; |
|
152 | + } |
|
153 | 153 | } |
154 | 154 | else if (is_object($invoice) && $invoice->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; |
155 | 155 | else if (is_object($invoice) && $invoice->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | return 0; |
161 | 161 | } |
162 | 162 | |
163 | - $where=''; |
|
164 | - //if ($facture->type == 2) $where.= " AND type = 2"; |
|
165 | - //else $where.=" AND type != 2"; |
|
163 | + $where=''; |
|
164 | + //if ($facture->type == 2) $where.= " AND type = 2"; |
|
165 | + //else $where.=" AND type != 2"; |
|
166 | 166 | |
167 | - // Get entities |
|
168 | - $entity = getEntity('invoicenumber', 1, $invoice); |
|
167 | + // Get entities |
|
168 | + $entity = getEntity('invoicenumber', 1, $invoice); |
|
169 | 169 | |
170 | - $numFinal=get_next_value($db,$mask,'facture','ref',$where,$objsoc,$invoice->date,$mode,false,null,$entity); |
|
171 | - if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; |
|
170 | + $numFinal=get_next_value($db,$mask,'facture','ref',$where,$objsoc,$invoice->date,$mode,false,null,$entity); |
|
171 | + if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; |
|
172 | 172 | |
173 | - return $numFinal; |
|
173 | + return $numFinal; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 |