@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | |
26 | 26 | if (! function_exists('json_encode')) |
27 | 27 | { |
28 | - /** |
|
29 | - * Implement json_encode for PHP that does not have module enabled. |
|
30 | - * |
|
31 | - * @param mixed $elements PHP Object to json encode |
|
32 | - * @return string Json encoded string |
|
33 | - */ |
|
34 | - function json_encode($elements) |
|
35 | - { |
|
36 | - return dol_json_encode($elements); |
|
37 | - } |
|
28 | + /** |
|
29 | + * Implement json_encode for PHP that does not have module enabled. |
|
30 | + * |
|
31 | + * @param mixed $elements PHP Object to json encode |
|
32 | + * @return string Json encoded string |
|
33 | + */ |
|
34 | + function json_encode($elements) |
|
35 | + { |
|
36 | + return dol_json_encode($elements); |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,56 +47,56 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function dol_json_encode($elements) |
49 | 49 | { |
50 | - dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); |
|
51 | - |
|
52 | - $num=0; |
|
53 | - if (is_object($elements)) // Count number of properties for an object |
|
54 | - { |
|
55 | - foreach($elements as $key => $value) $num++; |
|
56 | - } |
|
57 | - else |
|
58 | - { |
|
59 | - $num=count($elements); |
|
60 | - } |
|
61 | - //var_dump($num); |
|
62 | - |
|
63 | - // determine type |
|
64 | - if (is_numeric(key($elements)) && key($elements) == 0) |
|
65 | - { |
|
66 | - // indexed (list) |
|
67 | - $keysofelements=array_keys($elements); // Elements array mus have key that does not start with 0 and end with num-1, so we will use this later. |
|
68 | - $output = '['; |
|
69 | - for ($i = 0, $last = ($num - 1); $i < $num; $i++) |
|
70 | - { |
|
71 | - if (! isset($elements[$keysofelements[$i]])) continue; |
|
72 | - if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]); |
|
73 | - else $output .= _val($elements[$keysofelements[$i]]); |
|
74 | - if ($i !== $last) $output.= ','; |
|
75 | - } |
|
76 | - $output.= ']'; |
|
77 | - } |
|
78 | - else |
|
79 | - { |
|
80 | - // associative (object) |
|
81 | - $output = '{'; |
|
82 | - $last = $num - 1; |
|
83 | - $i = 0; |
|
84 | - $tmpelements=array(); |
|
85 | - if (is_array($elements)) $tmpelements=$elements; |
|
86 | - if (is_object($elements)) $tmpelements=get_object_vars($elements); |
|
87 | - foreach($tmpelements as $key => $value) |
|
88 | - { |
|
89 | - $output .= '"'.$key.'":'; |
|
90 | - if (is_array($value)) $output.= json_encode($value); |
|
91 | - else $output .= _val($value); |
|
92 | - if ($i !== $last) $output.= ','; |
|
93 | - ++$i; |
|
94 | - } |
|
95 | - $output.= '}'; |
|
96 | - } |
|
97 | - |
|
98 | - // return |
|
99 | - return $output; |
|
50 | + dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); |
|
51 | + |
|
52 | + $num=0; |
|
53 | + if (is_object($elements)) // Count number of properties for an object |
|
54 | + { |
|
55 | + foreach($elements as $key => $value) $num++; |
|
56 | + } |
|
57 | + else |
|
58 | + { |
|
59 | + $num=count($elements); |
|
60 | + } |
|
61 | + //var_dump($num); |
|
62 | + |
|
63 | + // determine type |
|
64 | + if (is_numeric(key($elements)) && key($elements) == 0) |
|
65 | + { |
|
66 | + // indexed (list) |
|
67 | + $keysofelements=array_keys($elements); // Elements array mus have key that does not start with 0 and end with num-1, so we will use this later. |
|
68 | + $output = '['; |
|
69 | + for ($i = 0, $last = ($num - 1); $i < $num; $i++) |
|
70 | + { |
|
71 | + if (! isset($elements[$keysofelements[$i]])) continue; |
|
72 | + if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]); |
|
73 | + else $output .= _val($elements[$keysofelements[$i]]); |
|
74 | + if ($i !== $last) $output.= ','; |
|
75 | + } |
|
76 | + $output.= ']'; |
|
77 | + } |
|
78 | + else |
|
79 | + { |
|
80 | + // associative (object) |
|
81 | + $output = '{'; |
|
82 | + $last = $num - 1; |
|
83 | + $i = 0; |
|
84 | + $tmpelements=array(); |
|
85 | + if (is_array($elements)) $tmpelements=$elements; |
|
86 | + if (is_object($elements)) $tmpelements=get_object_vars($elements); |
|
87 | + foreach($tmpelements as $key => $value) |
|
88 | + { |
|
89 | + $output .= '"'.$key.'":'; |
|
90 | + if (is_array($value)) $output.= json_encode($value); |
|
91 | + else $output .= _val($value); |
|
92 | + if ($i !== $last) $output.= ','; |
|
93 | + ++$i; |
|
94 | + } |
|
95 | + $output.= '}'; |
|
96 | + } |
|
97 | + |
|
98 | + // return |
|
99 | + return $output; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | */ |
108 | 108 | function _val($val) |
109 | 109 | { |
110 | - if (is_string($val)) |
|
111 | - { |
|
110 | + if (is_string($val)) |
|
111 | + { |
|
112 | 112 | // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
113 | 113 | $ascii = ''; |
114 | 114 | $strlen_var = strlen($val); |
@@ -117,107 +117,107 @@ discard block |
||
117 | 117 | * Iterate over every character in the string, |
118 | 118 | * escaping with a slash or encoding to UTF-8 where necessary |
119 | 119 | */ |
120 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
121 | - |
|
122 | - $ord_var_c = ord($val{$c}); |
|
123 | - |
|
124 | - switch (true) { |
|
125 | - case $ord_var_c == 0x08: |
|
126 | - $ascii .= '\b'; |
|
127 | - break; |
|
128 | - case $ord_var_c == 0x09: |
|
129 | - $ascii .= '\t'; |
|
130 | - break; |
|
131 | - case $ord_var_c == 0x0A: |
|
132 | - $ascii .= '\n'; |
|
133 | - break; |
|
134 | - case $ord_var_c == 0x0C: |
|
135 | - $ascii .= '\f'; |
|
136 | - break; |
|
137 | - case $ord_var_c == 0x0D: |
|
138 | - $ascii .= '\r'; |
|
139 | - break; |
|
140 | - |
|
141 | - case $ord_var_c == 0x22: |
|
142 | - case $ord_var_c == 0x2F: |
|
143 | - case $ord_var_c == 0x5C: |
|
144 | - // double quote, slash, slosh |
|
145 | - $ascii .= '\\'.$val{$c}; |
|
146 | - break; |
|
147 | - |
|
148 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
149 | - // characters U-00000000 - U-0000007F (same as ASCII) |
|
150 | - $ascii .= $val{$c}; |
|
151 | - break; |
|
152 | - |
|
153 | - case (($ord_var_c & 0xE0) == 0xC0): |
|
154 | - // characters U-00000080 - U-000007FF, mask 110XXXXX |
|
155 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
156 | - $char = pack('C*', $ord_var_c, ord($val{$c + 1})); |
|
157 | - $c += 1; |
|
158 | - $utf16 = utf82utf16($char); |
|
159 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
160 | - break; |
|
161 | - |
|
162 | - case (($ord_var_c & 0xF0) == 0xE0): |
|
163 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
164 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
165 | - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2})); |
|
166 | - $c += 2; |
|
167 | - $utf16 = utf82utf16($char); |
|
168 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
169 | - break; |
|
170 | - |
|
171 | - case (($ord_var_c & 0xF8) == 0xF0): |
|
172 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
173 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
174 | - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3})); |
|
175 | - $c += 3; |
|
176 | - $utf16 = utf82utf16($char); |
|
177 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
178 | - break; |
|
179 | - |
|
180 | - case (($ord_var_c & 0xFC) == 0xF8): |
|
181 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
182 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
183 | - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4})); |
|
184 | - $c += 4; |
|
185 | - $utf16 = utf82utf16($char); |
|
186 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
187 | - break; |
|
188 | - |
|
189 | - case (($ord_var_c & 0xFE) == 0xFC): |
|
190 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
191 | - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
192 | - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}), ord($val{$c + 5})); |
|
193 | - $c += 5; |
|
194 | - $utf16 = utf82utf16($char); |
|
195 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
196 | - break; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - return '"'.$ascii.'"'; |
|
201 | - } |
|
202 | - elseif (is_int($val)) return sprintf('%d', $val); |
|
203 | - elseif (is_float($val)) return sprintf('%F', $val); |
|
204 | - elseif (is_bool($val)) return ($val ? 'true' : 'false'); |
|
205 | - else return 'null'; |
|
120 | + for ($c = 0; $c < $strlen_var; ++$c) { |
|
121 | + |
|
122 | + $ord_var_c = ord($val{$c}); |
|
123 | + |
|
124 | + switch (true) { |
|
125 | + case $ord_var_c == 0x08: |
|
126 | + $ascii .= '\b'; |
|
127 | + break; |
|
128 | + case $ord_var_c == 0x09: |
|
129 | + $ascii .= '\t'; |
|
130 | + break; |
|
131 | + case $ord_var_c == 0x0A: |
|
132 | + $ascii .= '\n'; |
|
133 | + break; |
|
134 | + case $ord_var_c == 0x0C: |
|
135 | + $ascii .= '\f'; |
|
136 | + break; |
|
137 | + case $ord_var_c == 0x0D: |
|
138 | + $ascii .= '\r'; |
|
139 | + break; |
|
140 | + |
|
141 | + case $ord_var_c == 0x22: |
|
142 | + case $ord_var_c == 0x2F: |
|
143 | + case $ord_var_c == 0x5C: |
|
144 | + // double quote, slash, slosh |
|
145 | + $ascii .= '\\'.$val{$c}; |
|
146 | + break; |
|
147 | + |
|
148 | + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
149 | + // characters U-00000000 - U-0000007F (same as ASCII) |
|
150 | + $ascii .= $val{$c}; |
|
151 | + break; |
|
152 | + |
|
153 | + case (($ord_var_c & 0xE0) == 0xC0): |
|
154 | + // characters U-00000080 - U-000007FF, mask 110XXXXX |
|
155 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
156 | + $char = pack('C*', $ord_var_c, ord($val{$c + 1})); |
|
157 | + $c += 1; |
|
158 | + $utf16 = utf82utf16($char); |
|
159 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
160 | + break; |
|
161 | + |
|
162 | + case (($ord_var_c & 0xF0) == 0xE0): |
|
163 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
164 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
165 | + $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2})); |
|
166 | + $c += 2; |
|
167 | + $utf16 = utf82utf16($char); |
|
168 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
169 | + break; |
|
170 | + |
|
171 | + case (($ord_var_c & 0xF8) == 0xF0): |
|
172 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
173 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
174 | + $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3})); |
|
175 | + $c += 3; |
|
176 | + $utf16 = utf82utf16($char); |
|
177 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
178 | + break; |
|
179 | + |
|
180 | + case (($ord_var_c & 0xFC) == 0xF8): |
|
181 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
182 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
183 | + $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4})); |
|
184 | + $c += 4; |
|
185 | + $utf16 = utf82utf16($char); |
|
186 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
187 | + break; |
|
188 | + |
|
189 | + case (($ord_var_c & 0xFE) == 0xFC): |
|
190 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
191 | + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
192 | + $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}), ord($val{$c + 5})); |
|
193 | + $c += 5; |
|
194 | + $utf16 = utf82utf16($char); |
|
195 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
196 | + break; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + return '"'.$ascii.'"'; |
|
201 | + } |
|
202 | + elseif (is_int($val)) return sprintf('%d', $val); |
|
203 | + elseif (is_float($val)) return sprintf('%F', $val); |
|
204 | + elseif (is_bool($val)) return ($val ? 'true' : 'false'); |
|
205 | + else return 'null'; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | if (! function_exists('json_decode')) |
209 | 209 | { |
210 | - /** |
|
211 | - * Implement json_decode for PHP that does not support it |
|
212 | - * |
|
213 | - * @param string $json Json encoded to PHP Object or Array |
|
214 | - * @param bool $assoc False return an object, true return an array |
|
215 | - * @return mixed Object or Array |
|
216 | - */ |
|
217 | - function json_decode($json, $assoc=false) |
|
218 | - { |
|
219 | - return dol_json_decode($json, $assoc); |
|
220 | - } |
|
210 | + /** |
|
211 | + * Implement json_decode for PHP that does not support it |
|
212 | + * |
|
213 | + * @param string $json Json encoded to PHP Object or Array |
|
214 | + * @param bool $assoc False return an object, true return an array |
|
215 | + * @return mixed Object or Array |
|
216 | + */ |
|
217 | + function json_decode($json, $assoc=false) |
|
218 | + { |
|
219 | + return dol_json_decode($json, $assoc); |
|
220 | + } |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -231,52 +231,52 @@ discard block |
||
231 | 231 | */ |
232 | 232 | function dol_json_decode($json, $assoc=false) |
233 | 233 | { |
234 | - dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); |
|
234 | + dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); |
|
235 | 235 | |
236 | - $comment = false; |
|
236 | + $comment = false; |
|
237 | 237 | |
238 | 238 | $out=''; |
239 | - $strLength = strlen($json); // Must stay strlen and not dol_strlen because we want technical length, not visible length |
|
240 | - for ($i=0; $i<$strLength; $i++) |
|
241 | - { |
|
242 | - if (! $comment) |
|
243 | - { |
|
244 | - if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array('; |
|
245 | - else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')'; |
|
246 | - else if ($json[$i] == ':') $out.= ' => '; |
|
247 | - else $out.=$json[$i]; |
|
248 | - } |
|
249 | - else $out.= $json[$i]; |
|
250 | - if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment; |
|
251 | - } |
|
252 | - |
|
253 | - $out=_unval($out); |
|
254 | - |
|
255 | - // Return an array |
|
256 | - if ($out != '') eval('$array = '.$out.';'); |
|
257 | - else $array=array(); |
|
258 | - |
|
259 | - // Return an object |
|
260 | - if (! $assoc) |
|
261 | - { |
|
262 | - if (! empty($array)) |
|
263 | - { |
|
264 | - $object = false; |
|
265 | - if (count($array)>0) { |
|
266 | - $object = (object) array(); |
|
267 | - } |
|
268 | - foreach ($array as $key => $value) |
|
269 | - { |
|
270 | - if ($key) $object->{$key} = $value; |
|
271 | - } |
|
272 | - |
|
273 | - return $object; |
|
274 | - } |
|
275 | - |
|
276 | - return false; |
|
277 | - } |
|
278 | - |
|
279 | - return $array; |
|
239 | + $strLength = strlen($json); // Must stay strlen and not dol_strlen because we want technical length, not visible length |
|
240 | + for ($i=0; $i<$strLength; $i++) |
|
241 | + { |
|
242 | + if (! $comment) |
|
243 | + { |
|
244 | + if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array('; |
|
245 | + else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')'; |
|
246 | + else if ($json[$i] == ':') $out.= ' => '; |
|
247 | + else $out.=$json[$i]; |
|
248 | + } |
|
249 | + else $out.= $json[$i]; |
|
250 | + if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment; |
|
251 | + } |
|
252 | + |
|
253 | + $out=_unval($out); |
|
254 | + |
|
255 | + // Return an array |
|
256 | + if ($out != '') eval('$array = '.$out.';'); |
|
257 | + else $array=array(); |
|
258 | + |
|
259 | + // Return an object |
|
260 | + if (! $assoc) |
|
261 | + { |
|
262 | + if (! empty($array)) |
|
263 | + { |
|
264 | + $object = false; |
|
265 | + if (count($array)>0) { |
|
266 | + $object = (object) array(); |
|
267 | + } |
|
268 | + foreach ($array as $key => $value) |
|
269 | + { |
|
270 | + if ($key) $object->{$key} = $value; |
|
271 | + } |
|
272 | + |
|
273 | + return $object; |
|
274 | + } |
|
275 | + |
|
276 | + return false; |
|
277 | + } |
|
278 | + |
|
279 | + return $array; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | */ |
288 | 288 | function _unval($val) |
289 | 289 | { |
290 | - while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg)) |
|
291 | - { |
|
292 | - // single, escaped unicode character |
|
293 | - $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2])); |
|
294 | - $utf8 = utf162utf8($utf16); |
|
295 | - $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val); |
|
296 | - } |
|
297 | - return $val; |
|
290 | + while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg)) |
|
291 | + { |
|
292 | + // single, escaped unicode character |
|
293 | + $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2])); |
|
294 | + $utf8 = utf162utf8($utf16); |
|
295 | + $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val); |
|
296 | + } |
|
297 | + return $val; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -309,35 +309,35 @@ discard block |
||
309 | 309 | */ |
310 | 310 | function utf162utf8($utf16) |
311 | 311 | { |
312 | - // oh please oh please oh please oh please oh please |
|
313 | - if(function_exists('mb_convert_encoding')) { |
|
314 | - return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
315 | - } |
|
316 | - |
|
317 | - $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
|
318 | - |
|
319 | - switch(true) { |
|
320 | - case ((0x7F & $bytes) == $bytes): |
|
321 | - // this case should never be reached, because we are in ASCII range |
|
322 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
323 | - return chr($bytes); |
|
324 | - |
|
325 | - case (0x07FF & $bytes) == $bytes: |
|
326 | - // return a 2-byte UTF-8 character |
|
327 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
328 | - return chr(0xC0 | (($bytes >> 6) & 0x1F)) |
|
329 | - . chr(0x80 | ($bytes & 0x3F)); |
|
330 | - |
|
331 | - case (0xFFFF & $bytes) == $bytes: |
|
332 | - // return a 3-byte UTF-8 character |
|
333 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
334 | - return chr(0xE0 | (($bytes >> 12) & 0x0F)) |
|
335 | - . chr(0x80 | (($bytes >> 6) & 0x3F)) |
|
336 | - . chr(0x80 | ($bytes & 0x3F)); |
|
337 | - } |
|
338 | - |
|
339 | - // ignoring UTF-32 for now, sorry |
|
340 | - return ''; |
|
312 | + // oh please oh please oh please oh please oh please |
|
313 | + if(function_exists('mb_convert_encoding')) { |
|
314 | + return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
315 | + } |
|
316 | + |
|
317 | + $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
|
318 | + |
|
319 | + switch(true) { |
|
320 | + case ((0x7F & $bytes) == $bytes): |
|
321 | + // this case should never be reached, because we are in ASCII range |
|
322 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
323 | + return chr($bytes); |
|
324 | + |
|
325 | + case (0x07FF & $bytes) == $bytes: |
|
326 | + // return a 2-byte UTF-8 character |
|
327 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
328 | + return chr(0xC0 | (($bytes >> 6) & 0x1F)) |
|
329 | + . chr(0x80 | ($bytes & 0x3F)); |
|
330 | + |
|
331 | + case (0xFFFF & $bytes) == $bytes: |
|
332 | + // return a 3-byte UTF-8 character |
|
333 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
334 | + return chr(0xE0 | (($bytes >> 12) & 0x0F)) |
|
335 | + . chr(0x80 | (($bytes >> 6) & 0x3F)) |
|
336 | + . chr(0x80 | ($bytes & 0x3F)); |
|
337 | + } |
|
338 | + |
|
339 | + // ignoring UTF-32 for now, sorry |
|
340 | + return ''; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -352,28 +352,28 @@ discard block |
||
352 | 352 | */ |
353 | 353 | function utf82utf16($utf8) |
354 | 354 | { |
355 | - // oh please oh please oh please oh please oh please |
|
356 | - if(function_exists('mb_convert_encoding')) { |
|
357 | - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
358 | - } |
|
359 | - |
|
360 | - switch(strlen($utf8)) { |
|
361 | - case 1: |
|
362 | - // this case should never be reached, because we are in ASCII range |
|
363 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
364 | - return $utf8; |
|
365 | - |
|
366 | - case 2: |
|
367 | - // return a UTF-16 character from a 2-byte UTF-8 char |
|
368 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
369 | - return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1}))); |
|
370 | - |
|
371 | - case 3: |
|
372 | - // return a UTF-16 character from a 3-byte UTF-8 char |
|
373 | - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
374 | - return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2}))); |
|
375 | - } |
|
376 | - |
|
377 | - // ignoring UTF-32 for now, sorry |
|
378 | - return ''; |
|
355 | + // oh please oh please oh please oh please oh please |
|
356 | + if(function_exists('mb_convert_encoding')) { |
|
357 | + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
358 | + } |
|
359 | + |
|
360 | + switch(strlen($utf8)) { |
|
361 | + case 1: |
|
362 | + // this case should never be reached, because we are in ASCII range |
|
363 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
364 | + return $utf8; |
|
365 | + |
|
366 | + case 2: |
|
367 | + // return a UTF-16 character from a 2-byte UTF-8 char |
|
368 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
369 | + return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1}))); |
|
370 | + |
|
371 | + case 3: |
|
372 | + // return a UTF-16 character from a 3-byte UTF-8 char |
|
373 | + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
374 | + return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2}))); |
|
375 | + } |
|
376 | + |
|
377 | + // ignoring UTF-32 for now, sorry |
|
378 | + return ''; |
|
379 | 379 | } |
@@ -40,129 +40,129 @@ |
||
40 | 40 | */ |
41 | 41 | function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0) |
42 | 42 | { |
43 | - global $db, $conf, $langs; |
|
43 | + global $db, $conf, $langs; |
|
44 | 44 | |
45 | - $idprod=$line->fk_product; |
|
46 | - $label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:'')); |
|
47 | - $desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:'')); |
|
48 | - $ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:'')); // TODO Not yet saved for supplier invoices, only supplier orders |
|
49 | - $note=(! empty($line->note)?$line->note:''); |
|
45 | + $idprod=$line->fk_product; |
|
46 | + $label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:'')); |
|
47 | + $desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:'')); |
|
48 | + $ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:'')); // TODO Not yet saved for supplier invoices, only supplier orders |
|
49 | + $note=(! empty($line->note)?$line->note:''); |
|
50 | 50 | |
51 | - if ($issupplierline) $prodser = new ProductFournisseur($db); |
|
52 | - else $prodser = new Product($db); |
|
51 | + if ($issupplierline) $prodser = new ProductFournisseur($db); |
|
52 | + else $prodser = new Product($db); |
|
53 | 53 | |
54 | - if ($idprod) |
|
55 | - { |
|
56 | - $prodser->fetch($idprod); |
|
57 | - // If a predefined product and multilang and on other lang, we renamed label with label translated |
|
58 | - if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) |
|
59 | - { |
|
60 | - if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"]; |
|
61 | - if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"]; |
|
62 | - if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"]; |
|
63 | - } |
|
64 | - } |
|
54 | + if ($idprod) |
|
55 | + { |
|
56 | + $prodser->fetch($idprod); |
|
57 | + // If a predefined product and multilang and on other lang, we renamed label with label translated |
|
58 | + if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) |
|
59 | + { |
|
60 | + if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"]; |
|
61 | + if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"]; |
|
62 | + if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"]; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - // Description short of product line |
|
67 | - $libelleproduitservice=$label; |
|
66 | + // Description short of product line |
|
67 | + $libelleproduitservice=$label; |
|
68 | 68 | |
69 | - // Description long of product line |
|
70 | - if ($desc && ($desc != $label)) |
|
71 | - { |
|
72 | - if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) |
|
73 | - { |
|
74 | - $discount=new DiscountAbsolute($db); |
|
75 | - $discount->fetch($line->fk_remise_except); |
|
76 | - $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source; |
|
77 | - $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref); |
|
78 | - } |
|
79 | - elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) |
|
80 | - { |
|
81 | - $discount=new DiscountAbsolute($db); |
|
82 | - $discount->fetch($line->fk_remise_except); |
|
83 | - $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source; |
|
84 | - $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref); |
|
85 | - // Add date of deposit |
|
86 | - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; |
|
87 | - } |
|
88 | - elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) |
|
89 | - { |
|
90 | - $discount=new DiscountAbsolute($db); |
|
91 | - $discount->fetch($line->fk_remise_except); |
|
92 | - $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source); |
|
93 | - } |
|
94 | - elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except) |
|
95 | - { |
|
96 | - $discount=new DiscountAbsolute($db); |
|
97 | - $discount->fetch($line->fk_remise_except); |
|
98 | - $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source); |
|
99 | - } |
|
100 | - else |
|
101 | - { |
|
102 | - if ($idprod) |
|
103 | - { |
|
104 | - if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); |
|
105 | - } |
|
106 | - else |
|
107 | - { |
|
108 | - $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
69 | + // Description long of product line |
|
70 | + if ($desc && ($desc != $label)) |
|
71 | + { |
|
72 | + if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) |
|
73 | + { |
|
74 | + $discount=new DiscountAbsolute($db); |
|
75 | + $discount->fetch($line->fk_remise_except); |
|
76 | + $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source; |
|
77 | + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref); |
|
78 | + } |
|
79 | + elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) |
|
80 | + { |
|
81 | + $discount=new DiscountAbsolute($db); |
|
82 | + $discount->fetch($line->fk_remise_except); |
|
83 | + $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source; |
|
84 | + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref); |
|
85 | + // Add date of deposit |
|
86 | + if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; |
|
87 | + } |
|
88 | + elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) |
|
89 | + { |
|
90 | + $discount=new DiscountAbsolute($db); |
|
91 | + $discount->fetch($line->fk_remise_except); |
|
92 | + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source); |
|
93 | + } |
|
94 | + elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except) |
|
95 | + { |
|
96 | + $discount=new DiscountAbsolute($db); |
|
97 | + $discount->fetch($line->fk_remise_except); |
|
98 | + $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source); |
|
99 | + } |
|
100 | + else |
|
101 | + { |
|
102 | + if ($idprod) |
|
103 | + { |
|
104 | + if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); |
|
105 | + } |
|
106 | + else |
|
107 | + { |
|
108 | + $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - // If line linked to a product |
|
114 | - if ($idprod) |
|
115 | - { |
|
116 | - // On ajoute la ref |
|
117 | - if ($prodser->ref) |
|
118 | - { |
|
119 | - $prefix_prodserv = ""; |
|
120 | - $ref_prodserv = ""; |
|
121 | - if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this |
|
122 | - { |
|
123 | - if ($prodser->isService()) |
|
124 | - { |
|
125 | - $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." "; |
|
126 | - } |
|
127 | - else |
|
128 | - { |
|
129 | - $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." "; |
|
130 | - } |
|
131 | - } |
|
113 | + // If line linked to a product |
|
114 | + if ($idprod) |
|
115 | + { |
|
116 | + // On ajoute la ref |
|
117 | + if ($prodser->ref) |
|
118 | + { |
|
119 | + $prefix_prodserv = ""; |
|
120 | + $ref_prodserv = ""; |
|
121 | + if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this |
|
122 | + { |
|
123 | + if ($prodser->isService()) |
|
124 | + { |
|
125 | + $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." "; |
|
126 | + } |
|
127 | + else |
|
128 | + { |
|
129 | + $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." "; |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - if (empty($hideref)) |
|
134 | - { |
|
135 | - if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref |
|
136 | - else $ref_prodserv = $prodser->ref; // Show local ref only |
|
133 | + if (empty($hideref)) |
|
134 | + { |
|
135 | + if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref |
|
136 | + else $ref_prodserv = $prodser->ref; // Show local ref only |
|
137 | 137 | |
138 | - $ref_prodserv .= " - "; |
|
139 | - } |
|
138 | + $ref_prodserv .= " - "; |
|
139 | + } |
|
140 | 140 | |
141 | - $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice; |
|
142 | - } |
|
143 | - } |
|
141 | + $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice; |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - if (! empty($line->date_start) || ! empty($line->date_end)) |
|
146 | - { |
|
147 | - $format='day'; |
|
148 | - // Show duration if exists |
|
149 | - if ($line->date_start && $line->date_end) |
|
150 | - { |
|
151 | - $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')'; |
|
152 | - } |
|
153 | - if ($line->date_start && ! $line->date_end) |
|
154 | - { |
|
155 | - $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')'; |
|
156 | - } |
|
157 | - if (! $line->date_start && $line->date_end) |
|
158 | - { |
|
159 | - $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')'; |
|
160 | - } |
|
161 | - //print '>'.$outputlangs->charset_output.','.$period; |
|
162 | - $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period); |
|
163 | - //print $libelleproduitservice; |
|
164 | - } |
|
145 | + if (! empty($line->date_start) || ! empty($line->date_end)) |
|
146 | + { |
|
147 | + $format='day'; |
|
148 | + // Show duration if exists |
|
149 | + if ($line->date_start && $line->date_end) |
|
150 | + { |
|
151 | + $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')'; |
|
152 | + } |
|
153 | + if ($line->date_start && ! $line->date_end) |
|
154 | + { |
|
155 | + $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')'; |
|
156 | + } |
|
157 | + if (! $line->date_start && $line->date_end) |
|
158 | + { |
|
159 | + $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')'; |
|
160 | + } |
|
161 | + //print '>'.$outputlangs->charset_output.','.$period; |
|
162 | + $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period); |
|
163 | + //print $libelleproduitservice; |
|
164 | + } |
|
165 | 165 | |
166 | - return $libelleproduitservice; |
|
166 | + return $libelleproduitservice; |
|
167 | 167 | } |
168 | 168 |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | $h = 0; |
42 | 42 | $head = array(); |
43 | 43 | |
44 | - $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id; |
|
45 | - $head[$h][1] = $langs->trans('Card'); |
|
46 | - $head[$h][2] = 'card'; |
|
47 | - $h++; |
|
44 | + $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id; |
|
45 | + $head[$h][1] = $langs->trans('Card'); |
|
46 | + $head[$h][2] = 'card'; |
|
47 | + $h++; |
|
48 | 48 | |
49 | 49 | // Show more tabs from modules |
50 | 50 | // Entries must be declared in modules descriptor with line |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | // $this->tabs = array('entity:-tabname); to remove a tab |
53 | 53 | complete_head_from_modules($conf,$langs,$object,$head,$h,'tax'); |
54 | 54 | |
55 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
55 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
56 | 56 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
57 | - $upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
58 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
57 | + $upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
58 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
59 | 59 | $nbLinks=Link::count($db, $object->element, $object->id); |
60 | - $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id; |
|
61 | - $head[$h][1] = $langs->trans("Documents"); |
|
62 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
63 | - $head[$h][2] = 'documents'; |
|
64 | - $h++; |
|
60 | + $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id; |
|
61 | + $head[$h][1] = $langs->trans("Documents"); |
|
62 | + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
63 | + $head[$h][2] = 'documents'; |
|
64 | + $h++; |
|
65 | 65 | |
66 | 66 | $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/info.php?id='.$object->id; |
67 | 67 | $head[$h][1] = $langs->trans("Info"); |
@@ -95,39 +95,39 @@ discard block |
||
95 | 95 | // If we use date_start and date_end, we must not use $y, $m, $q |
96 | 96 | if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q))) |
97 | 97 | { |
98 | - dol_print_error('', 'Bad value of input parameter for tax_by_rate'); |
|
98 | + dol_print_error('', 'Bad value of input parameter for tax_by_rate'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $list=array(); |
102 | 102 | if ($direction == 'sell') |
103 | 103 | { |
104 | - $invoicetable='facture'; |
|
105 | - $invoicedettable='facturedet'; |
|
106 | - $fk_facture='fk_facture'; |
|
107 | - $fk_facture2='fk_facture'; |
|
108 | - $fk_payment='fk_paiement'; |
|
109 | - $total_tva='total_tva'; |
|
110 | - $paymenttable='paiement'; |
|
111 | - $paymentfacturetable='paiement_facture'; |
|
112 | - $invoicefieldref='ref'; |
|
104 | + $invoicetable='facture'; |
|
105 | + $invoicedettable='facturedet'; |
|
106 | + $fk_facture='fk_facture'; |
|
107 | + $fk_facture2='fk_facture'; |
|
108 | + $fk_payment='fk_paiement'; |
|
109 | + $total_tva='total_tva'; |
|
110 | + $paymenttable='paiement'; |
|
111 | + $paymentfacturetable='paiement_facture'; |
|
112 | + $invoicefieldref='ref'; |
|
113 | 113 | } |
114 | 114 | if ($direction == 'buy') |
115 | 115 | { |
116 | - $invoicetable='facture_fourn'; |
|
117 | - $invoicedettable='facture_fourn_det'; |
|
118 | - $fk_facture='fk_facture_fourn'; |
|
119 | - $fk_facture2='fk_facturefourn'; |
|
120 | - $fk_payment='fk_paiementfourn'; |
|
121 | - $total_tva='tva'; |
|
122 | - $paymenttable='paiementfourn'; |
|
123 | - $paymentfacturetable='paiementfourn_facturefourn'; |
|
124 | - $invoicefieldref='ref'; |
|
116 | + $invoicetable='facture_fourn'; |
|
117 | + $invoicedettable='facture_fourn_det'; |
|
118 | + $fk_facture='fk_facture_fourn'; |
|
119 | + $fk_facture2='fk_facturefourn'; |
|
120 | + $fk_payment='fk_paiementfourn'; |
|
121 | + $total_tva='tva'; |
|
122 | + $paymenttable='paiementfourn'; |
|
123 | + $paymentfacturetable='paiementfourn_facturefourn'; |
|
124 | + $invoicefieldref='ref'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if ( strpos( $type, 'localtax' ) === 0 ) { |
128 | - $f_rate = $type . '_tx'; |
|
128 | + $f_rate = $type . '_tx'; |
|
129 | 129 | } else { |
130 | - $f_rate = 'tva_tx'; |
|
130 | + $f_rate = 'tva_tx'; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | $total_localtax1='total_localtax1'; |
@@ -139,146 +139,146 @@ discard block |
||
139 | 139 | // Define sql request |
140 | 140 | $sql=''; |
141 | 141 | if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') |
142 | - || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) |
|
142 | + || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) |
|
143 | 143 | { |
144 | - // Count on delivery date (use invoice date as delivery is unknown) |
|
145 | - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
146 | - $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
147 | - $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
148 | - $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
149 | - $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
150 | - $sql.= " 0 as payment_id, 0 as payment_amount"; |
|
151 | - $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
152 | - $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
153 | - $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; |
|
154 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
155 | - $sql.= " WHERE f.entity = " . $conf->entity; |
|
156 | - $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) |
|
157 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
158 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
159 | - $sql.= " AND f.rowid = d.".$fk_facture; |
|
160 | - $sql.= " AND s.rowid = f.fk_soc"; |
|
161 | - if ($y && $m) |
|
162 | - { |
|
163 | - $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
164 | - $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
165 | - } |
|
166 | - else if ($y) |
|
167 | - { |
|
168 | - $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
169 | - $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
170 | - } |
|
171 | - if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; |
|
172 | - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; |
|
173 | - $sql.= " AND (d.product_type = 0"; // Limit to products |
|
174 | - $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
175 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
176 | - $sql.= " ORDER BY d.rowid, d.".$fk_facture; |
|
144 | + // Count on delivery date (use invoice date as delivery is unknown) |
|
145 | + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
146 | + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
147 | + $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
148 | + $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
149 | + $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
150 | + $sql.= " 0 as payment_id, 0 as payment_amount"; |
|
151 | + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
152 | + $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
153 | + $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; |
|
154 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
155 | + $sql.= " WHERE f.entity = " . $conf->entity; |
|
156 | + $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) |
|
157 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
158 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
159 | + $sql.= " AND f.rowid = d.".$fk_facture; |
|
160 | + $sql.= " AND s.rowid = f.fk_soc"; |
|
161 | + if ($y && $m) |
|
162 | + { |
|
163 | + $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
164 | + $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
165 | + } |
|
166 | + else if ($y) |
|
167 | + { |
|
168 | + $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
169 | + $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
170 | + } |
|
171 | + if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; |
|
172 | + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; |
|
173 | + $sql.= " AND (d.product_type = 0"; // Limit to products |
|
174 | + $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
175 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
176 | + $sql.= " ORDER BY d.rowid, d.".$fk_facture; |
|
177 | 177 | } |
178 | 178 | else |
179 | 179 | { |
180 | - // Count on payments date |
|
181 | - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
182 | - $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
183 | - $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
184 | - $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
185 | - $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
186 | - $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
187 | - $sql.= " pa.datep as datep"; |
|
188 | - $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
189 | - $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
190 | - $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
191 | - $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
192 | - $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
193 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
194 | - $sql.= " WHERE f.entity = " . $conf->entity; |
|
195 | - $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
196 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
197 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
198 | - $sql.= " AND f.rowid = d.".$fk_facture; |
|
199 | - $sql.= " AND s.rowid = f.fk_soc"; |
|
200 | - $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
201 | - $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
202 | - if ($y && $m) |
|
203 | - { |
|
204 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
205 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
206 | - } |
|
207 | - else if ($y) |
|
208 | - { |
|
209 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
210 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
211 | - } |
|
212 | - if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
213 | - if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
214 | - $sql.= " AND (d.product_type = 0"; // Limit to products |
|
215 | - $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
216 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
217 | - $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
180 | + // Count on payments date |
|
181 | + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
182 | + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
183 | + $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
184 | + $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
185 | + $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
186 | + $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
187 | + $sql.= " pa.datep as datep"; |
|
188 | + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
189 | + $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
190 | + $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
191 | + $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
192 | + $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
193 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
194 | + $sql.= " WHERE f.entity = " . $conf->entity; |
|
195 | + $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
196 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
197 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
198 | + $sql.= " AND f.rowid = d.".$fk_facture; |
|
199 | + $sql.= " AND s.rowid = f.fk_soc"; |
|
200 | + $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
201 | + $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
202 | + if ($y && $m) |
|
203 | + { |
|
204 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
205 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
206 | + } |
|
207 | + else if ($y) |
|
208 | + { |
|
209 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
210 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
211 | + } |
|
212 | + if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
213 | + if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
214 | + $sql.= " AND (d.product_type = 0"; // Limit to products |
|
215 | + $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
216 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
217 | + $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | if (! $sql) return -1; |
221 | 221 | if ($sql == 'TODO') return -2; |
222 | 222 | if ($sql != 'TODO') |
223 | 223 | { |
224 | - dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG); |
|
225 | - |
|
226 | - $resql = $db->query($sql); |
|
227 | - if ($resql) |
|
228 | - { |
|
229 | - $company_id = -1; |
|
230 | - $oldrowid=''; |
|
231 | - while($assoc = $db->fetch_array($resql)) |
|
232 | - { |
|
233 | - if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
234 | - if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
235 | - if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
236 | - if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
237 | - |
|
238 | - if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
239 | - { |
|
240 | - $oldrowid=$assoc['rowid']; |
|
241 | - $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
242 | - $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
243 | - $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
244 | - $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
245 | - } |
|
246 | - $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
247 | - $list[$assoc['company_id']]['dtype'][] = $assoc['dtype']; |
|
248 | - $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']); |
|
249 | - $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']); |
|
250 | - $list[$assoc['company_id']]['company_name'][] = $assoc['company_name']; |
|
251 | - $list[$assoc['company_id']]['company_id'][] = $assoc['company_id']; |
|
252 | - $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
253 | - $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
254 | - $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
255 | - |
|
256 | - $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
257 | - $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
258 | - $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
259 | - $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
260 | - $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
261 | - |
|
262 | - $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
263 | - $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
264 | - $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
265 | - $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
266 | - |
|
267 | - $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
268 | - $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
269 | - $list[$assoc['company_id']]['ptype'][] = $assoc['ptype']; |
|
270 | - |
|
271 | - $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
272 | - $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
273 | - |
|
274 | - $company_id = $assoc['company_id']; |
|
275 | - } |
|
276 | - } |
|
277 | - else |
|
278 | - { |
|
279 | - dol_print_error($db); |
|
280 | - return -3; |
|
281 | - } |
|
224 | + dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG); |
|
225 | + |
|
226 | + $resql = $db->query($sql); |
|
227 | + if ($resql) |
|
228 | + { |
|
229 | + $company_id = -1; |
|
230 | + $oldrowid=''; |
|
231 | + while($assoc = $db->fetch_array($resql)) |
|
232 | + { |
|
233 | + if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
234 | + if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
235 | + if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
236 | + if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
237 | + |
|
238 | + if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
239 | + { |
|
240 | + $oldrowid=$assoc['rowid']; |
|
241 | + $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
242 | + $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
243 | + $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
244 | + $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
245 | + } |
|
246 | + $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
247 | + $list[$assoc['company_id']]['dtype'][] = $assoc['dtype']; |
|
248 | + $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']); |
|
249 | + $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']); |
|
250 | + $list[$assoc['company_id']]['company_name'][] = $assoc['company_name']; |
|
251 | + $list[$assoc['company_id']]['company_id'][] = $assoc['company_id']; |
|
252 | + $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
253 | + $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
254 | + $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
255 | + |
|
256 | + $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
257 | + $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
258 | + $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
259 | + $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
260 | + $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
261 | + |
|
262 | + $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
263 | + $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
264 | + $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
265 | + $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
266 | + |
|
267 | + $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
268 | + $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
269 | + $list[$assoc['company_id']]['ptype'][] = $assoc['ptype']; |
|
270 | + |
|
271 | + $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
272 | + $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
273 | + |
|
274 | + $company_id = $assoc['company_id']; |
|
275 | + } |
|
276 | + } |
|
277 | + else |
|
278 | + { |
|
279 | + dol_print_error($db); |
|
280 | + return -3; |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -287,149 +287,149 @@ discard block |
||
287 | 287 | // Define sql request |
288 | 288 | $sql=''; |
289 | 289 | if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice') |
290 | - || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) |
|
290 | + || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) |
|
291 | 291 | { |
292 | - // Count on invoice date |
|
293 | - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
294 | - $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
295 | - $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
296 | - $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
297 | - $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
298 | - $sql.= " 0 as payment_id, 0 as payment_amount"; |
|
299 | - $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
300 | - $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
301 | - $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; |
|
302 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
303 | - $sql.= " WHERE f.entity = " . $conf->entity; |
|
304 | - $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) |
|
305 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
306 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
307 | - $sql.= " AND f.rowid = d.".$fk_facture; |
|
308 | - $sql.= " AND s.rowid = f.fk_soc"; |
|
309 | - if ($y && $m) |
|
310 | - { |
|
311 | - $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
312 | - $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
313 | - } |
|
314 | - else if ($y) |
|
315 | - { |
|
316 | - $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
317 | - $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
318 | - } |
|
319 | - if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; |
|
320 | - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; |
|
321 | - $sql.= " AND (d.product_type = 1"; // Limit to services |
|
322 | - $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service |
|
323 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
324 | - $sql.= " ORDER BY d.rowid, d.".$fk_facture; |
|
292 | + // Count on invoice date |
|
293 | + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
294 | + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
295 | + $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
296 | + $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
297 | + $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
298 | + $sql.= " 0 as payment_id, 0 as payment_amount"; |
|
299 | + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
300 | + $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
301 | + $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; |
|
302 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
303 | + $sql.= " WHERE f.entity = " . $conf->entity; |
|
304 | + $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) |
|
305 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
306 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
307 | + $sql.= " AND f.rowid = d.".$fk_facture; |
|
308 | + $sql.= " AND s.rowid = f.fk_soc"; |
|
309 | + if ($y && $m) |
|
310 | + { |
|
311 | + $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
312 | + $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
313 | + } |
|
314 | + else if ($y) |
|
315 | + { |
|
316 | + $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
317 | + $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
318 | + } |
|
319 | + if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; |
|
320 | + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; |
|
321 | + $sql.= " AND (d.product_type = 1"; // Limit to services |
|
322 | + $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service |
|
323 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
324 | + $sql.= " ORDER BY d.rowid, d.".$fk_facture; |
|
325 | 325 | } |
326 | 326 | else |
327 | 327 | { |
328 | - // Count on payments date |
|
329 | - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
330 | - $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
331 | - $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
332 | - $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
333 | - $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
334 | - $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
335 | - $sql.= " pa.datep as datep"; |
|
336 | - $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
337 | - $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
338 | - $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
339 | - $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
340 | - $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
341 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
342 | - $sql.= " WHERE f.entity = " . $conf->entity; |
|
343 | - $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
344 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
345 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
346 | - $sql.= " AND f.rowid = d.".$fk_facture; |
|
347 | - $sql.= " AND s.rowid = f.fk_soc"; |
|
348 | - $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
349 | - $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
350 | - if ($y && $m) |
|
351 | - { |
|
352 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
353 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
354 | - } |
|
355 | - else if ($y) |
|
356 | - { |
|
357 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
358 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
359 | - } |
|
360 | - if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
361 | - if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
362 | - $sql.= " AND (d.product_type = 1"; // Limit to services |
|
363 | - $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service |
|
364 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
365 | - $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
328 | + // Count on payments date |
|
329 | + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
330 | + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
331 | + $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
332 | + $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
333 | + $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
334 | + $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
335 | + $sql.= " pa.datep as datep"; |
|
336 | + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
337 | + $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
338 | + $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
339 | + $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
340 | + $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
341 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
342 | + $sql.= " WHERE f.entity = " . $conf->entity; |
|
343 | + $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
344 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
345 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
346 | + $sql.= " AND f.rowid = d.".$fk_facture; |
|
347 | + $sql.= " AND s.rowid = f.fk_soc"; |
|
348 | + $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
349 | + $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
350 | + if ($y && $m) |
|
351 | + { |
|
352 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
353 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
354 | + } |
|
355 | + else if ($y) |
|
356 | + { |
|
357 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
358 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
359 | + } |
|
360 | + if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
361 | + if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
362 | + $sql.= " AND (d.product_type = 1"; // Limit to services |
|
363 | + $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service |
|
364 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
365 | + $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | if (! $sql) |
369 | 369 | { |
370 | - dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
371 | - return -1; // -1 = Not accountancy module enabled |
|
370 | + dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
371 | + return -1; // -1 = Not accountancy module enabled |
|
372 | 372 | } |
373 | 373 | if ($sql == 'TODO') return -2; // -2 = Feature not yet available |
374 | 374 | if ($sql != 'TODO') |
375 | 375 | { |
376 | - dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
377 | - $resql = $db->query($sql); |
|
378 | - if ($resql) |
|
379 | - { |
|
380 | - $company_id = -1; |
|
381 | - $oldrowid=''; |
|
382 | - while($assoc = $db->fetch_array($resql)) |
|
383 | - { |
|
384 | - if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
385 | - if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
386 | - if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
387 | - if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
388 | - |
|
389 | - if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
390 | - { |
|
391 | - $oldrowid=$assoc['rowid']; |
|
392 | - $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
393 | - $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
394 | - $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
395 | - $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
396 | - } |
|
397 | - $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
398 | - $list[$assoc['company_id']]['dtype'][] = $assoc['dtype']; |
|
399 | - $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']); |
|
400 | - $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']); |
|
401 | - $list[$assoc['company_id']]['company_name'][] = $assoc['company_name']; |
|
402 | - $list[$assoc['company_id']]['company_id'][] = $assoc['company_id']; |
|
403 | - $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
404 | - $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
405 | - $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
406 | - |
|
407 | - $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
408 | - $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
409 | - $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
410 | - $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
411 | - $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
412 | - |
|
413 | - $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
414 | - $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
415 | - $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
416 | - $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
417 | - |
|
418 | - $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
419 | - $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
420 | - $list[$assoc['company_id']]['ptype'][] = $assoc['ptype']; |
|
421 | - |
|
422 | - $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
423 | - $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
424 | - |
|
425 | - $company_id = $assoc['company_id']; |
|
426 | - } |
|
427 | - } |
|
428 | - else |
|
429 | - { |
|
430 | - dol_print_error($db); |
|
431 | - return -3; |
|
432 | - } |
|
376 | + dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
377 | + $resql = $db->query($sql); |
|
378 | + if ($resql) |
|
379 | + { |
|
380 | + $company_id = -1; |
|
381 | + $oldrowid=''; |
|
382 | + while($assoc = $db->fetch_array($resql)) |
|
383 | + { |
|
384 | + if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
385 | + if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
386 | + if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
387 | + if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
388 | + |
|
389 | + if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
390 | + { |
|
391 | + $oldrowid=$assoc['rowid']; |
|
392 | + $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
393 | + $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
394 | + $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
395 | + $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
396 | + } |
|
397 | + $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
398 | + $list[$assoc['company_id']]['dtype'][] = $assoc['dtype']; |
|
399 | + $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']); |
|
400 | + $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']); |
|
401 | + $list[$assoc['company_id']]['company_name'][] = $assoc['company_name']; |
|
402 | + $list[$assoc['company_id']]['company_id'][] = $assoc['company_id']; |
|
403 | + $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
404 | + $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
405 | + $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
406 | + |
|
407 | + $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
408 | + $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
409 | + $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
410 | + $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
411 | + $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
412 | + |
|
413 | + $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
414 | + $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
415 | + $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
416 | + $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
417 | + |
|
418 | + $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
419 | + $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
420 | + $list[$assoc['company_id']]['ptype'][] = $assoc['ptype']; |
|
421 | + |
|
422 | + $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
423 | + $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
424 | + |
|
425 | + $company_id = $assoc['company_id']; |
|
426 | + } |
|
427 | + } |
|
428 | + else |
|
429 | + { |
|
430 | + dol_print_error($db); |
|
431 | + return -3; |
|
432 | + } |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -437,104 +437,104 @@ discard block |
||
437 | 437 | |
438 | 438 | if ($direction == 'buy') // buy only for expense reports |
439 | 439 | { |
440 | - // Define sql request |
|
441 | - $sql=''; |
|
442 | - |
|
443 | - // Count on payments date |
|
444 | - $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; |
|
445 | - $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; |
|
446 | - $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; |
|
447 | - $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; |
|
448 | - $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; |
|
449 | - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e"; |
|
450 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid "; |
|
451 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid "; |
|
452 | - $sql.= " WHERE e.entity = " . $conf->entity; |
|
453 | - $sql.= " AND e.fk_statut in (6)"; |
|
454 | - if ($y && $m) |
|
455 | - { |
|
456 | - $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
457 | - $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
458 | - } |
|
459 | - else if ($y) |
|
460 | - { |
|
461 | - $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
462 | - $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
463 | - } |
|
464 | - if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")"; |
|
465 | - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; |
|
466 | - $sql.= " AND (d.product_type = -1"; |
|
467 | - $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service |
|
468 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)"; |
|
469 | - $sql.= " ORDER BY e.rowid"; |
|
470 | - |
|
471 | - if (! $sql) |
|
472 | - { |
|
473 | - dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
474 | - return -1; // -1 = Not accountancy module enabled |
|
475 | - } |
|
476 | - if ($sql == 'TODO') return -2; // -2 = Feature not yet available |
|
477 | - if ($sql != 'TODO') |
|
478 | - { |
|
479 | - dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
480 | - $resql = $db->query($sql); |
|
481 | - if ($resql) |
|
482 | - { |
|
483 | - $company_id = -1; |
|
484 | - $oldrowid=''; |
|
485 | - while($assoc = $db->fetch_array($resql)) |
|
486 | - { |
|
487 | - if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
488 | - if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
489 | - if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
490 | - if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
491 | - |
|
492 | - if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
493 | - { |
|
494 | - $oldrowid=$assoc['rowid']; |
|
495 | - $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
496 | - $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
497 | - $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
498 | - $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
499 | - } |
|
500 | - |
|
501 | - $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
502 | - $list[$assoc['company_id']]['dtype'][] = 'ExpenseReportPayment'; |
|
503 | - $list[$assoc['company_id']]['datef'][] = $assoc['datef']; |
|
504 | - $list[$assoc['company_id']]['company_name'][] = ''; |
|
505 | - $list[$assoc['company_id']]['company_id'][] = ''; |
|
506 | - $list[$assoc['company_id']]['user_id'][] = $assoc['fk_user_author']; |
|
507 | - $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
508 | - $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
509 | - $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
510 | - |
|
511 | - $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
512 | - $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
513 | - $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
514 | - $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
515 | - $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
516 | - |
|
517 | - $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
518 | - $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
519 | - $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
520 | - $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
521 | - |
|
522 | - $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
523 | - $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
524 | - $list[$assoc['company_id']]['ptype'][] = 'ExpenseReportPayment'; |
|
525 | - |
|
526 | - $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
527 | - $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
528 | - |
|
529 | - $company_id = $assoc['company_id']; |
|
530 | - } |
|
531 | - } |
|
532 | - else |
|
533 | - { |
|
534 | - dol_print_error($db); |
|
535 | - return -3; |
|
536 | - } |
|
537 | - } |
|
440 | + // Define sql request |
|
441 | + $sql=''; |
|
442 | + |
|
443 | + // Count on payments date |
|
444 | + $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; |
|
445 | + $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; |
|
446 | + $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; |
|
447 | + $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; |
|
448 | + $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; |
|
449 | + $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e"; |
|
450 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid "; |
|
451 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid "; |
|
452 | + $sql.= " WHERE e.entity = " . $conf->entity; |
|
453 | + $sql.= " AND e.fk_statut in (6)"; |
|
454 | + if ($y && $m) |
|
455 | + { |
|
456 | + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
457 | + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
458 | + } |
|
459 | + else if ($y) |
|
460 | + { |
|
461 | + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
462 | + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
463 | + } |
|
464 | + if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")"; |
|
465 | + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; |
|
466 | + $sql.= " AND (d.product_type = -1"; |
|
467 | + $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service |
|
468 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)"; |
|
469 | + $sql.= " ORDER BY e.rowid"; |
|
470 | + |
|
471 | + if (! $sql) |
|
472 | + { |
|
473 | + dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
474 | + return -1; // -1 = Not accountancy module enabled |
|
475 | + } |
|
476 | + if ($sql == 'TODO') return -2; // -2 = Feature not yet available |
|
477 | + if ($sql != 'TODO') |
|
478 | + { |
|
479 | + dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
480 | + $resql = $db->query($sql); |
|
481 | + if ($resql) |
|
482 | + { |
|
483 | + $company_id = -1; |
|
484 | + $oldrowid=''; |
|
485 | + while($assoc = $db->fetch_array($resql)) |
|
486 | + { |
|
487 | + if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0; |
|
488 | + if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0; |
|
489 | + if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0; |
|
490 | + if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0; |
|
491 | + |
|
492 | + if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
493 | + { |
|
494 | + $oldrowid=$assoc['rowid']; |
|
495 | + $list[$assoc['company_id']]['totalht'] += $assoc['total_ht']; |
|
496 | + $list[$assoc['company_id']]['vat'] += $assoc['total_vat']; |
|
497 | + $list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1']; |
|
498 | + $list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2']; |
|
499 | + } |
|
500 | + |
|
501 | + $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
502 | + $list[$assoc['company_id']]['dtype'][] = 'ExpenseReportPayment'; |
|
503 | + $list[$assoc['company_id']]['datef'][] = $assoc['datef']; |
|
504 | + $list[$assoc['company_id']]['company_name'][] = ''; |
|
505 | + $list[$assoc['company_id']]['company_id'][] = ''; |
|
506 | + $list[$assoc['company_id']]['user_id'][] = $assoc['fk_user_author']; |
|
507 | + $list[$assoc['company_id']]['drate'][] = $assoc['rate']; |
|
508 | + $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
509 | + $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
510 | + |
|
511 | + $list[$assoc['company_id']]['facid'][] = $assoc['facid']; |
|
512 | + $list[$assoc['company_id']]['facnum'][] = $assoc['facnum']; |
|
513 | + $list[$assoc['company_id']]['type'][] = $assoc['type']; |
|
514 | + $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
515 | + $list[$assoc['company_id']]['descr'][] = $assoc['descr']; |
|
516 | + |
|
517 | + $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht']; |
|
518 | + $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat']; |
|
519 | + $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
520 | + $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
521 | + |
|
522 | + $list[$assoc['company_id']]['pid'][] = $assoc['pid']; |
|
523 | + $list[$assoc['company_id']]['pref'][] = $assoc['pref']; |
|
524 | + $list[$assoc['company_id']]['ptype'][] = 'ExpenseReportPayment'; |
|
525 | + |
|
526 | + $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id']; |
|
527 | + $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount']; |
|
528 | + |
|
529 | + $company_id = $assoc['company_id']; |
|
530 | + } |
|
531 | + } |
|
532 | + else |
|
533 | + { |
|
534 | + dol_print_error($db); |
|
535 | + return -3; |
|
536 | + } |
|
537 | + } |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | return $list; |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | // If we use date_start and date_end, we must not use $y, $m, $q |
564 | 564 | if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q))) |
565 | 565 | { |
566 | - dol_print_error('', 'Bad value of input parameter for tax_by_rate'); |
|
566 | + dol_print_error('', 'Bad value of input parameter for tax_by_rate'); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | $list=array(); |
@@ -593,14 +593,14 @@ discard block |
||
593 | 593 | $invoicefieldref='ref'; |
594 | 594 | } |
595 | 595 | |
596 | - if ( strpos( $type, 'localtax' ) === 0 ) { |
|
597 | - $f_rate = $type . '_tx'; |
|
598 | - } else { |
|
599 | - $f_rate = 'tva_tx'; |
|
600 | - } |
|
596 | + if ( strpos( $type, 'localtax' ) === 0 ) { |
|
597 | + $f_rate = $type . '_tx'; |
|
598 | + } else { |
|
599 | + $f_rate = 'tva_tx'; |
|
600 | + } |
|
601 | 601 | |
602 | - $total_localtax1='total_localtax1'; |
|
603 | - $total_localtax2='total_localtax2'; |
|
602 | + $total_localtax1='total_localtax1'; |
|
603 | + $total_localtax2='total_localtax2'; |
|
604 | 604 | |
605 | 605 | |
606 | 606 | // CAS DES BIENS/PRODUITS |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | // Define sql request |
609 | 609 | $sql=''; |
610 | 610 | if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') |
611 | - || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) |
|
611 | + || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) |
|
612 | 612 | { |
613 | 613 | // Count on delivery date (use invoice date as delivery is unknown) |
614 | 614 | $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
@@ -646,44 +646,44 @@ discard block |
||
646 | 646 | } |
647 | 647 | else |
648 | 648 | { |
649 | - // Count on payments date |
|
650 | - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
651 | - $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
652 | - $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
653 | - $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
654 | - $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
655 | - $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
656 | - $sql.= " pa.datep as datep"; |
|
657 | - $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
658 | - $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
659 | - $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
660 | - $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
661 | - $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
662 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
663 | - $sql.= " WHERE f.entity = " . $conf->entity; |
|
664 | - $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
665 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
666 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
667 | - $sql.= " AND f.rowid = d.".$fk_facture; |
|
668 | - $sql.= " AND s.rowid = f.fk_soc"; |
|
669 | - $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
670 | - $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
671 | - if ($y && $m) |
|
672 | - { |
|
673 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
674 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
675 | - } |
|
676 | - else if ($y) |
|
677 | - { |
|
678 | - $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
679 | - $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
680 | - } |
|
681 | - if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
682 | - if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
683 | - $sql.= " AND (d.product_type = 0"; // Limit to products |
|
684 | - $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
685 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
686 | - $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
649 | + // Count on payments date |
|
650 | + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
|
651 | + $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; |
|
652 | + $sql.= " d.date_start as date_start, d.date_end as date_end,"; |
|
653 | + $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; |
|
654 | + $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; |
|
655 | + $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; |
|
656 | + $sql.= " pa.datep as datep"; |
|
657 | + $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; |
|
658 | + $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; |
|
659 | + $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; |
|
660 | + $sql.= " ".MAIN_DB_PREFIX."societe as s,"; |
|
661 | + $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; |
|
662 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; |
|
663 | + $sql.= " WHERE f.entity = " . $conf->entity; |
|
664 | + $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
|
665 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
|
666 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
667 | + $sql.= " AND f.rowid = d.".$fk_facture; |
|
668 | + $sql.= " AND s.rowid = f.fk_soc"; |
|
669 | + $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
|
670 | + $sql.= " AND pa.rowid = pf.".$fk_payment; |
|
671 | + if ($y && $m) |
|
672 | + { |
|
673 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
674 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
675 | + } |
|
676 | + else if ($y) |
|
677 | + { |
|
678 | + $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
679 | + $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
680 | + } |
|
681 | + if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")"; |
|
682 | + if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'"; |
|
683 | + $sql.= " AND (d.product_type = 0"; // Limit to products |
|
684 | + $sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products |
|
685 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)"; |
|
686 | + $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid"; |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | if (! $sql) return -1; |
@@ -699,8 +699,8 @@ discard block |
||
699 | 699 | $oldrowid=''; |
700 | 700 | while($assoc = $db->fetch_array($resql)) |
701 | 701 | { |
702 | - // Code to avoid warnings when array entry not defined |
|
703 | - if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
702 | + // Code to avoid warnings when array entry not defined |
|
703 | + if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
704 | 704 | if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; |
705 | 705 | if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; |
706 | 706 | if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | // Define sql request |
757 | 757 | $sql=''; |
758 | 758 | if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice') |
759 | - || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) |
|
759 | + || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) |
|
760 | 760 | { |
761 | 761 | // Count on invoice date |
762 | 762 | $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | $sql.= " WHERE f.entity = " . $conf->entity; |
773 | 773 | $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) |
774 | 774 | if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
775 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
775 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
776 | 776 | $sql.= " AND f.rowid = d.".$fk_facture; |
777 | 777 | $sql.= " AND s.rowid = f.fk_soc"; |
778 | 778 | if ($y && $m) |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | $sql.= " WHERE f.entity = " . $conf->entity; |
812 | 812 | $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) |
813 | 813 | if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; |
814 | - else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
814 | + else $sql.= " AND f.type IN (0,1,2,3,5)"; |
|
815 | 815 | $sql.= " AND f.rowid = d.".$fk_facture; |
816 | 816 | $sql.= " AND s.rowid = f.fk_soc"; |
817 | 817 | $sql.= " AND pf.".$fk_facture2." = f.rowid"; |
@@ -850,10 +850,10 @@ discard block |
||
850 | 850 | $oldrowid=''; |
851 | 851 | while($assoc = $db->fetch_array($resql)) |
852 | 852 | { |
853 | - // Code to avoid warnings when array entry not defined |
|
854 | - if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
853 | + // Code to avoid warnings when array entry not defined |
|
854 | + if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
855 | 855 | if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; |
856 | - if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; |
|
856 | + if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; |
|
857 | 857 | if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; |
858 | 858 | |
859 | 859 | if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
@@ -904,108 +904,108 @@ discard block |
||
904 | 904 | |
905 | 905 | // CASE OF EXPENSE REPORT |
906 | 906 | |
907 | - if ($direction == 'buy') // buy only for expense reports |
|
908 | - { |
|
909 | - // Define sql request |
|
910 | - $sql=''; |
|
911 | - |
|
912 | - // Count on payments date |
|
913 | - $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; |
|
914 | - $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; |
|
915 | - $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; |
|
916 | - $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; |
|
917 | - $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; |
|
918 | - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e "; |
|
919 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid "; |
|
920 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid "; |
|
921 | - $sql.= " WHERE e.entity = " . $conf->entity; |
|
922 | - $sql.= " AND e.fk_statut in (6)"; |
|
923 | - if ($y && $m) |
|
924 | - { |
|
925 | - $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
926 | - $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
927 | - } |
|
928 | - else if ($y) |
|
929 | - { |
|
930 | - $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
931 | - $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
932 | - } |
|
933 | - if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")"; |
|
934 | - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; |
|
935 | - $sql.= " AND (d.product_type = -1"; |
|
936 | - $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service |
|
937 | - if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)"; |
|
938 | - $sql.= " ORDER BY e.rowid"; |
|
939 | - |
|
940 | - if (! $sql) |
|
941 | - { |
|
942 | - dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
943 | - return -1; // -1 = Not accountancy module enabled |
|
944 | - } |
|
945 | - if ($sql == 'TODO') return -2; // -2 = Feature not yet available |
|
946 | - if ($sql != 'TODO') |
|
947 | - { |
|
948 | - dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
949 | - $resql = $db->query($sql); |
|
950 | - if ($resql) |
|
951 | - { |
|
952 | - $rate = -1; |
|
953 | - $oldrowid=''; |
|
954 | - while($assoc = $db->fetch_array($resql)) |
|
955 | - { |
|
956 | - // Code to avoid warnings when array entry not defined |
|
957 | - if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
958 | - if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; |
|
959 | - if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; |
|
960 | - if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; |
|
961 | - |
|
962 | - if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
963 | - { |
|
964 | - $oldrowid=$assoc['rowid']; |
|
965 | - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; |
|
907 | + if ($direction == 'buy') // buy only for expense reports |
|
908 | + { |
|
909 | + // Define sql request |
|
910 | + $sql=''; |
|
911 | + |
|
912 | + // Count on payments date |
|
913 | + $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; |
|
914 | + $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; |
|
915 | + $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; |
|
916 | + $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; |
|
917 | + $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; |
|
918 | + $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e "; |
|
919 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid "; |
|
920 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid "; |
|
921 | + $sql.= " WHERE e.entity = " . $conf->entity; |
|
922 | + $sql.= " AND e.fk_statut in (6)"; |
|
923 | + if ($y && $m) |
|
924 | + { |
|
925 | + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'"; |
|
926 | + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'"; |
|
927 | + } |
|
928 | + else if ($y) |
|
929 | + { |
|
930 | + $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'"; |
|
931 | + $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'"; |
|
932 | + } |
|
933 | + if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")"; |
|
934 | + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; |
|
935 | + $sql.= " AND (d.product_type = -1"; |
|
936 | + $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service |
|
937 | + if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)"; |
|
938 | + $sql.= " ORDER BY e.rowid"; |
|
939 | + |
|
940 | + if (! $sql) |
|
941 | + { |
|
942 | + dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR); |
|
943 | + return -1; // -1 = Not accountancy module enabled |
|
944 | + } |
|
945 | + if ($sql == 'TODO') return -2; // -2 = Feature not yet available |
|
946 | + if ($sql != 'TODO') |
|
947 | + { |
|
948 | + dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG); |
|
949 | + $resql = $db->query($sql); |
|
950 | + if ($resql) |
|
951 | + { |
|
952 | + $rate = -1; |
|
953 | + $oldrowid=''; |
|
954 | + while($assoc = $db->fetch_array($resql)) |
|
955 | + { |
|
956 | + // Code to avoid warnings when array entry not defined |
|
957 | + if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0; |
|
958 | + if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0; |
|
959 | + if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0; |
|
960 | + if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0; |
|
961 | + |
|
962 | + if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid |
|
963 | + { |
|
964 | + $oldrowid=$assoc['rowid']; |
|
965 | + $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; |
|
966 | 966 | $list[$assoc['rate']]['vat'] += $assoc['total_vat']; |
967 | - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; |
|
968 | - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; |
|
969 | - } |
|
970 | - |
|
971 | - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
972 | - $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment'; |
|
973 | - $list[$assoc['rate']]['datef'][] = $assoc['datef']; |
|
974 | - $list[$assoc['rate']]['company_name'][] = ''; |
|
975 | - $list[$assoc['rate']]['company_id'][] = ''; |
|
976 | - $list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author']; |
|
977 | - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
978 | - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
979 | - |
|
980 | - $list[$assoc['rate']]['facid'][] = $assoc['facid']; |
|
981 | - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; |
|
982 | - $list[$assoc['rate']]['type'][] = $assoc['type']; |
|
983 | - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
984 | - $list[$assoc['rate']]['descr'][] = $assoc['descr']; |
|
985 | - |
|
986 | - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; |
|
987 | - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; |
|
988 | - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
989 | - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
990 | - |
|
991 | - $list[$assoc['rate']]['pid'][] = $assoc['pid']; |
|
992 | - $list[$assoc['rate']]['pref'][] = $assoc['pref']; |
|
993 | - $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment'; |
|
994 | - |
|
995 | - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; |
|
996 | - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; |
|
997 | - |
|
998 | - $rate = $assoc['rate']; |
|
999 | - } |
|
1000 | - } |
|
1001 | - else |
|
1002 | - { |
|
1003 | - dol_print_error($db); |
|
1004 | - return -3; |
|
1005 | - } |
|
1006 | - } |
|
1007 | - } |
|
1008 | - |
|
1009 | - return $list; |
|
967 | + $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; |
|
968 | + $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; |
|
969 | + } |
|
970 | + |
|
971 | + $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; |
|
972 | + $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment'; |
|
973 | + $list[$assoc['rate']]['datef'][] = $assoc['datef']; |
|
974 | + $list[$assoc['rate']]['company_name'][] = ''; |
|
975 | + $list[$assoc['rate']]['company_id'][] = ''; |
|
976 | + $list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author']; |
|
977 | + $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); |
|
978 | + $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); |
|
979 | + |
|
980 | + $list[$assoc['rate']]['facid'][] = $assoc['facid']; |
|
981 | + $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; |
|
982 | + $list[$assoc['rate']]['type'][] = $assoc['type']; |
|
983 | + $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; |
|
984 | + $list[$assoc['rate']]['descr'][] = $assoc['descr']; |
|
985 | + |
|
986 | + $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; |
|
987 | + $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; |
|
988 | + $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; |
|
989 | + $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; |
|
990 | + |
|
991 | + $list[$assoc['rate']]['pid'][] = $assoc['pid']; |
|
992 | + $list[$assoc['rate']]['pref'][] = $assoc['pref']; |
|
993 | + $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment'; |
|
994 | + |
|
995 | + $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; |
|
996 | + $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; |
|
997 | + |
|
998 | + $rate = $assoc['rate']; |
|
999 | + } |
|
1000 | + } |
|
1001 | + else |
|
1002 | + { |
|
1003 | + dol_print_error($db); |
|
1004 | + return -3; |
|
1005 | + } |
|
1006 | + } |
|
1007 | + } |
|
1008 | + |
|
1009 | + return $list; |
|
1010 | 1010 | } |
1011 | 1011 |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | |
56 | 56 | // Input search_htmlname is original field |
57 | 57 | // Input htmlname is a second input field used when using ajax autocomplete. |
58 | - $script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />'; |
|
58 | + $script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />'; |
|
59 | 59 | |
60 | - $script.= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n"; |
|
61 | - $script.= '<script type="text/javascript">'."\n"; |
|
62 | - $script.= '$(document).ready(function() { |
|
60 | + $script.= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n"; |
|
61 | + $script.= '<script type="text/javascript">'."\n"; |
|
62 | + $script.= '$(document).ready(function() { |
|
63 | 63 | var autoselect = '.$autoselect.'; |
64 | 64 | var options = '.json_encode($ajaxoptions).'; |
65 | 65 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | }; |
203 | 203 | |
204 | 204 | });'; |
205 | - $script.= '</script>'; |
|
205 | + $script.= '</script>'; |
|
206 | 206 | |
207 | - return $script; |
|
207 | + return $script; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | */ |
224 | 224 | function ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0) |
225 | 225 | { |
226 | - $script = '<!-- Autocomplete -->'."\n"; |
|
227 | - $script.= '<script type="text/javascript">'; |
|
228 | - $script.= 'jQuery(document).ready(function() { |
|
226 | + $script = '<!-- Autocomplete -->'."\n"; |
|
227 | + $script.= '<script type="text/javascript">'; |
|
228 | + $script.= 'jQuery(document).ready(function() { |
|
229 | 229 | var fields = '.json_encode($fields).'; |
230 | 230 | var nboffields = fields.length; |
231 | 231 | var autoselect = '.$autoselect.'; |
@@ -314,9 +314,9 @@ discard block |
||
314 | 314 | } |
315 | 315 | }); |
316 | 316 | });'; |
317 | - $script.= '</script>'; |
|
317 | + $script.= '</script>'; |
|
318 | 318 | |
319 | - return $script; |
|
319 | + return $script; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | */ |
331 | 331 | function ajax_dialog($title,$message,$w=350,$h=150) |
332 | 332 | { |
333 | - global $langs; |
|
333 | + global $langs; |
|
334 | 334 | |
335 | - $newtitle=dol_textishtml($title)?dol_string_nohtmltag($title,1):$title; |
|
336 | - $msg= '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">'; |
|
337 | - $msg.= $message; |
|
338 | - $msg.= '</div>'."\n"; |
|
335 | + $newtitle=dol_textishtml($title)?dol_string_nohtmltag($title,1):$title; |
|
336 | + $msg= '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">'; |
|
337 | + $msg.= $message; |
|
338 | + $msg.= '</div>'."\n"; |
|
339 | 339 | $msg.= '<script type="text/javascript"> |
340 | 340 | jQuery(function() { |
341 | 341 | jQuery("#dialog-info").dialog({ |
@@ -373,17 +373,17 @@ discard block |
||
373 | 373 | */ |
374 | 374 | function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve') |
375 | 375 | { |
376 | - global $conf; |
|
376 | + global $conf; |
|
377 | 377 | |
378 | - // select2 disabled for smartphones with standard browser. |
|
379 | - // TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array) |
|
380 | - if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return ''; |
|
378 | + // select2 disabled for smartphones with standard browser. |
|
379 | + // TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array) |
|
380 | + if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return ''; |
|
381 | 381 | |
382 | - if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; |
|
383 | - if (empty($conf->use_javascript_ajax)) return ''; |
|
384 | - if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return ''; |
|
382 | + if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; |
|
383 | + if (empty($conf->use_javascript_ajax)) return ''; |
|
384 | + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return ''; |
|
385 | 385 | |
386 | - if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0; |
|
386 | + if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0; |
|
387 | 387 | |
388 | 388 | $tmpplugin='select2'; |
389 | 389 | $msg="\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' --> |
@@ -410,12 +410,12 @@ discard block |
||
410 | 410 | }, |
411 | 411 | dropdownCssClass: \'ui-dialog\' |
412 | 412 | })'; |
413 | - if ($forcefocus) $msg.= '.select2(\'focus\')'; |
|
414 | - $msg.= ';'."\n"; |
|
413 | + if ($forcefocus) $msg.= '.select2(\'focus\')'; |
|
414 | + $msg.= ';'."\n"; |
|
415 | 415 | |
416 | - if (is_array($events) && count($events)) // If an array of js events to do were provided. |
|
417 | - { |
|
418 | - $msg.= ' |
|
416 | + if (is_array($events) && count($events)) // If an array of js events to do were provided. |
|
417 | + { |
|
418 | + $msg.= ' |
|
419 | 419 | jQuery("#'.$htmlname.'").change(function () { |
420 | 420 | var obj = '.json_encode($events).'; |
421 | 421 | $.each(obj, function(key,values) { |
@@ -462,9 +462,9 @@ discard block |
||
462 | 462 | } |
463 | 463 | ); |
464 | 464 | }'; |
465 | - } |
|
465 | + } |
|
466 | 466 | |
467 | - $msg.= '});'."\n"; |
|
467 | + $msg.= '});'."\n"; |
|
468 | 468 | $msg.= "</script>\n"; |
469 | 469 | |
470 | 470 | return $msg; |
@@ -482,18 +482,18 @@ discard block |
||
482 | 482 | */ |
483 | 483 | function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0) |
484 | 484 | { |
485 | - global $conf, $langs; |
|
486 | - |
|
487 | - $entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity); |
|
488 | - |
|
489 | - if (empty($conf->use_javascript_ajax)) |
|
490 | - { |
|
491 | - if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
492 | - else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
493 | - } |
|
494 | - else |
|
495 | - { |
|
496 | - $out= "\n<!-- Ajax code to switch constant ".$code." -->".' |
|
485 | + global $conf, $langs; |
|
486 | + |
|
487 | + $entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity); |
|
488 | + |
|
489 | + if (empty($conf->use_javascript_ajax)) |
|
490 | + { |
|
491 | + if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
492 | + else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
493 | + } |
|
494 | + else |
|
495 | + { |
|
496 | + $out= "\n<!-- Ajax code to switch constant ".$code." -->".' |
|
497 | 497 | <script type="text/javascript"> |
498 | 498 | $(document).ready(function() { |
499 | 499 | var input = '.json_encode($input).'; |
@@ -528,13 +528,13 @@ discard block |
||
528 | 528 | }); |
529 | 529 | </script>'."\n"; |
530 | 530 | |
531 | - $out.= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>'; |
|
532 | - $out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).'</span>'; |
|
533 | - $out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).'</span>'; |
|
534 | - $out.="\n"; |
|
535 | - } |
|
531 | + $out.= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>'; |
|
532 | + $out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).'</span>'; |
|
533 | + $out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).'</span>'; |
|
534 | + $out.="\n"; |
|
535 | + } |
|
536 | 536 | |
537 | - return $out; |
|
537 | + return $out; |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -50,234 +50,234 @@ |
||
50 | 50 | */ |
51 | 51 | function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $filesuffix='', $paymentbankid='', $thirdpartiesid='', $fileprefix='mergedpdf') |
52 | 52 | { |
53 | - $sql = "SELECT DISTINCT f.rowid, f.ref"; |
|
54 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; |
|
55 | - $sqlwhere=''; |
|
56 | - $sqlorder=''; |
|
57 | - if (in_array('all',$filter)) |
|
58 | - { |
|
59 | - $sqlorder = " ORDER BY f.ref ASC"; |
|
60 | - } |
|
61 | - if (in_array('date',$filter)) |
|
62 | - { |
|
63 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
64 | - else $sqlwhere.=" AND"; |
|
65 | - $sqlwhere.= " f.fk_statut > 0"; |
|
66 | - $sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'"; |
|
67 | - $sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'"; |
|
68 | - $sqlorder = " ORDER BY f.datef ASC"; |
|
69 | - } |
|
70 | - if (in_array('nopayment',$filter)) |
|
71 | - { |
|
72 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; |
|
73 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
74 | - else $sqlwhere.=" AND"; |
|
75 | - $sqlwhere.= " f.fk_statut > 0"; |
|
76 | - $sqlwhere.= " AND pf.fk_paiement IS NULL"; |
|
77 | - } |
|
78 | - if (in_array('payments',$filter) || in_array('bank',$filter)) |
|
79 | - { |
|
80 | - $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; |
|
81 | - if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b"; |
|
82 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
83 | - else $sqlwhere.=" AND"; |
|
84 | - $sqlwhere.= " f.fk_statut > 0"; |
|
85 | - $sqlwhere.= " AND f.rowid = pf.fk_facture"; |
|
86 | - $sqlwhere.= " AND pf.fk_paiement = p.rowid"; |
|
87 | - if (in_array('payments',$filter)) |
|
88 | - { |
|
89 | - $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'"; |
|
90 | - $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'"; |
|
91 | - } |
|
92 | - if (in_array('bank',$filter)) |
|
93 | - { |
|
94 | - $sqlwhere.= " AND p.fk_bank = b.rowid"; |
|
95 | - $sqlwhere.= " AND b.fk_account = ".$paymentbankid; |
|
96 | - } |
|
97 | - $sqlorder = " ORDER BY p.datep ASC"; |
|
98 | - } |
|
99 | - if (in_array('nodeposit',$filter)) |
|
100 | - { |
|
101 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
102 | - else $sqlwhere.=" AND"; |
|
103 | - $sqlwhere.=' type <> 3'; |
|
104 | - } |
|
105 | - if (in_array('noreplacement',$filter)) |
|
106 | - { |
|
107 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
108 | - else $sqlwhere.=" AND"; |
|
109 | - $sqlwhere.=' type <> 1'; |
|
110 | - } |
|
111 | - if (in_array('nocreditnote',$filter)) |
|
112 | - { |
|
113 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
114 | - else $sqlwhere.=" AND"; |
|
115 | - $sqlwhere.=' type <> 2'; |
|
116 | - } |
|
117 | - if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid)) |
|
118 | - { |
|
119 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
120 | - else $sqlwhere.=" AND"; |
|
121 | - $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')'; |
|
122 | - } |
|
123 | - if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid)) |
|
124 | - { |
|
125 | - if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
126 | - else $sqlwhere.=" AND"; |
|
127 | - $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')'; |
|
128 | - } |
|
129 | - if ($sqlwhere) $sql.=$sqlwhere; |
|
130 | - if ($sqlorder) $sql.=$sqlorder; |
|
53 | + $sql = "SELECT DISTINCT f.rowid, f.ref"; |
|
54 | + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; |
|
55 | + $sqlwhere=''; |
|
56 | + $sqlorder=''; |
|
57 | + if (in_array('all',$filter)) |
|
58 | + { |
|
59 | + $sqlorder = " ORDER BY f.ref ASC"; |
|
60 | + } |
|
61 | + if (in_array('date',$filter)) |
|
62 | + { |
|
63 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
64 | + else $sqlwhere.=" AND"; |
|
65 | + $sqlwhere.= " f.fk_statut > 0"; |
|
66 | + $sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'"; |
|
67 | + $sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'"; |
|
68 | + $sqlorder = " ORDER BY f.datef ASC"; |
|
69 | + } |
|
70 | + if (in_array('nopayment',$filter)) |
|
71 | + { |
|
72 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; |
|
73 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
74 | + else $sqlwhere.=" AND"; |
|
75 | + $sqlwhere.= " f.fk_statut > 0"; |
|
76 | + $sqlwhere.= " AND pf.fk_paiement IS NULL"; |
|
77 | + } |
|
78 | + if (in_array('payments',$filter) || in_array('bank',$filter)) |
|
79 | + { |
|
80 | + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; |
|
81 | + if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b"; |
|
82 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
83 | + else $sqlwhere.=" AND"; |
|
84 | + $sqlwhere.= " f.fk_statut > 0"; |
|
85 | + $sqlwhere.= " AND f.rowid = pf.fk_facture"; |
|
86 | + $sqlwhere.= " AND pf.fk_paiement = p.rowid"; |
|
87 | + if (in_array('payments',$filter)) |
|
88 | + { |
|
89 | + $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'"; |
|
90 | + $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'"; |
|
91 | + } |
|
92 | + if (in_array('bank',$filter)) |
|
93 | + { |
|
94 | + $sqlwhere.= " AND p.fk_bank = b.rowid"; |
|
95 | + $sqlwhere.= " AND b.fk_account = ".$paymentbankid; |
|
96 | + } |
|
97 | + $sqlorder = " ORDER BY p.datep ASC"; |
|
98 | + } |
|
99 | + if (in_array('nodeposit',$filter)) |
|
100 | + { |
|
101 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
102 | + else $sqlwhere.=" AND"; |
|
103 | + $sqlwhere.=' type <> 3'; |
|
104 | + } |
|
105 | + if (in_array('noreplacement',$filter)) |
|
106 | + { |
|
107 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
108 | + else $sqlwhere.=" AND"; |
|
109 | + $sqlwhere.=' type <> 1'; |
|
110 | + } |
|
111 | + if (in_array('nocreditnote',$filter)) |
|
112 | + { |
|
113 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
114 | + else $sqlwhere.=" AND"; |
|
115 | + $sqlwhere.=' type <> 2'; |
|
116 | + } |
|
117 | + if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid)) |
|
118 | + { |
|
119 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
120 | + else $sqlwhere.=" AND"; |
|
121 | + $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')'; |
|
122 | + } |
|
123 | + if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid)) |
|
124 | + { |
|
125 | + if (empty($sqlwhere)) $sqlwhere=' WHERE '; |
|
126 | + else $sqlwhere.=" AND"; |
|
127 | + $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')'; |
|
128 | + } |
|
129 | + if ($sqlwhere) $sql.=$sqlwhere; |
|
130 | + if ($sqlorder) $sql.=$sqlorder; |
|
131 | 131 | |
132 | - //print $sql; exit; |
|
133 | - dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG); |
|
132 | + //print $sql; exit; |
|
133 | + dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG); |
|
134 | 134 | |
135 | - if ($usestdout) print '--- start'."\n"; |
|
135 | + if ($usestdout) print '--- start'."\n"; |
|
136 | 136 | |
137 | - // Start of transaction |
|
138 | - //$db->begin(); |
|
137 | + // Start of transaction |
|
138 | + //$db->begin(); |
|
139 | 139 | |
140 | - $error = 0; |
|
141 | - $result = 0; |
|
142 | - $files = array() ; // liste les fichiers |
|
140 | + $error = 0; |
|
141 | + $result = 0; |
|
142 | + $files = array() ; // liste les fichiers |
|
143 | 143 | |
144 | - dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG); |
|
145 | - if ( $resql=$db->query($sql) ) |
|
146 | - { |
|
147 | - $num = $db->num_rows($resql); |
|
148 | - $cpt = 0; |
|
149 | - $oldemail = ''; |
|
150 | - $message = ''; |
|
151 | - $total = ''; |
|
144 | + dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG); |
|
145 | + if ( $resql=$db->query($sql) ) |
|
146 | + { |
|
147 | + $num = $db->num_rows($resql); |
|
148 | + $cpt = 0; |
|
149 | + $oldemail = ''; |
|
150 | + $message = ''; |
|
151 | + $total = ''; |
|
152 | 152 | |
153 | - if ($num) |
|
154 | - { |
|
155 | - // First loop on each resultset to build PDF |
|
156 | - // ----------------------------------------- |
|
153 | + if ($num) |
|
154 | + { |
|
155 | + // First loop on each resultset to build PDF |
|
156 | + // ----------------------------------------- |
|
157 | 157 | |
158 | - while ($cpt < $num) |
|
159 | - { |
|
160 | - $obj = $db->fetch_object($resql); |
|
158 | + while ($cpt < $num) |
|
159 | + { |
|
160 | + $obj = $db->fetch_object($resql); |
|
161 | 161 | |
162 | - $fac = new Facture($db); |
|
163 | - $result=$fac->fetch($obj->rowid); |
|
164 | - if ($result > 0) |
|
165 | - { |
|
166 | - $outputlangs = $langs; |
|
167 | - if (! empty($newlangid)) |
|
168 | - { |
|
169 | - if ($outputlangs->defaultlang != $newlangid) |
|
170 | - { |
|
171 | - $outputlangs = new Translate("",$conf); |
|
172 | - $outputlangs->setDefaultLang($newlangid); |
|
173 | - } |
|
174 | - } |
|
175 | - $filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; |
|
176 | - if ($regenerate || ! dol_is_file($filename)) |
|
177 | - { |
|
178 | - if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n"; |
|
179 | - $result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs); |
|
180 | - } |
|
181 | - else { |
|
182 | - if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n"; |
|
183 | - } |
|
162 | + $fac = new Facture($db); |
|
163 | + $result=$fac->fetch($obj->rowid); |
|
164 | + if ($result > 0) |
|
165 | + { |
|
166 | + $outputlangs = $langs; |
|
167 | + if (! empty($newlangid)) |
|
168 | + { |
|
169 | + if ($outputlangs->defaultlang != $newlangid) |
|
170 | + { |
|
171 | + $outputlangs = new Translate("",$conf); |
|
172 | + $outputlangs->setDefaultLang($newlangid); |
|
173 | + } |
|
174 | + } |
|
175 | + $filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; |
|
176 | + if ($regenerate || ! dol_is_file($filename)) |
|
177 | + { |
|
178 | + if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n"; |
|
179 | + $result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs); |
|
180 | + } |
|
181 | + else { |
|
182 | + if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n"; |
|
183 | + } |
|
184 | 184 | |
185 | - // Add file into files array |
|
186 | - $files[] = $filename; |
|
187 | - } |
|
185 | + // Add file into files array |
|
186 | + $files[] = $filename; |
|
187 | + } |
|
188 | 188 | |
189 | - if ($result <= 0) |
|
190 | - { |
|
191 | - $error++; |
|
192 | - if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n"; |
|
193 | - else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR); |
|
194 | - } |
|
189 | + if ($result <= 0) |
|
190 | + { |
|
191 | + $error++; |
|
192 | + if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n"; |
|
193 | + else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR); |
|
194 | + } |
|
195 | 195 | |
196 | - $cpt++; |
|
197 | - } |
|
196 | + $cpt++; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - // Define format of output PDF |
|
201 | - $formatarray=pdf_getFormat($langs); |
|
202 | - $page_largeur = $formatarray['width']; |
|
203 | - $page_hauteur = $formatarray['height']; |
|
204 | - $format = array($page_largeur,$page_hauteur); |
|
200 | + // Define format of output PDF |
|
201 | + $formatarray=pdf_getFormat($langs); |
|
202 | + $page_largeur = $formatarray['width']; |
|
203 | + $page_hauteur = $formatarray['height']; |
|
204 | + $format = array($page_largeur,$page_hauteur); |
|
205 | 205 | |
206 | - if ($usestdout) print "Using output PDF format ".join('x',$format)."\n"; |
|
207 | - else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR); |
|
206 | + if ($usestdout) print "Using output PDF format ".join('x',$format)."\n"; |
|
207 | + else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR); |
|
208 | 208 | |
209 | 209 | |
210 | - // Now, build a merged files with all files in $files array |
|
211 | - //--------------------------------------------------------- |
|
210 | + // Now, build a merged files with all files in $files array |
|
211 | + //--------------------------------------------------------- |
|
212 | 212 | |
213 | - // Create empty PDF |
|
214 | - $pdf=pdf_getInstance($format); |
|
215 | - if (class_exists('TCPDF')) |
|
216 | - { |
|
217 | - $pdf->setPrintHeader(false); |
|
218 | - $pdf->setPrintFooter(false); |
|
219 | - } |
|
220 | - $pdf->SetFont(pdf_getPDFFont($langs)); |
|
213 | + // Create empty PDF |
|
214 | + $pdf=pdf_getInstance($format); |
|
215 | + if (class_exists('TCPDF')) |
|
216 | + { |
|
217 | + $pdf->setPrintHeader(false); |
|
218 | + $pdf->setPrintFooter(false); |
|
219 | + } |
|
220 | + $pdf->SetFont(pdf_getPDFFont($langs)); |
|
221 | 221 | |
222 | - if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); |
|
223 | - //$pdf->SetCompression(false); |
|
222 | + if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); |
|
223 | + //$pdf->SetCompression(false); |
|
224 | 224 | |
225 | - // Add all others |
|
226 | - foreach($files as $file) |
|
227 | - { |
|
228 | - if ($usestdout) print "Merge PDF file for invoice ".$file."\n"; |
|
229 | - else dol_syslog("Merge PDF file for invoice ".$file); |
|
225 | + // Add all others |
|
226 | + foreach($files as $file) |
|
227 | + { |
|
228 | + if ($usestdout) print "Merge PDF file for invoice ".$file."\n"; |
|
229 | + else dol_syslog("Merge PDF file for invoice ".$file); |
|
230 | 230 | |
231 | - // Charge un document PDF depuis un fichier. |
|
232 | - $pagecount = $pdf->setSourceFile($file); |
|
233 | - for ($i = 1; $i <= $pagecount; $i++) |
|
234 | - { |
|
235 | - $tplidx = $pdf->importPage($i); |
|
236 | - $s = $pdf->getTemplatesize($tplidx); |
|
237 | - $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); |
|
238 | - $pdf->useTemplate($tplidx); |
|
239 | - } |
|
240 | - } |
|
231 | + // Charge un document PDF depuis un fichier. |
|
232 | + $pagecount = $pdf->setSourceFile($file); |
|
233 | + for ($i = 1; $i <= $pagecount; $i++) |
|
234 | + { |
|
235 | + $tplidx = $pdf->importPage($i); |
|
236 | + $s = $pdf->getTemplatesize($tplidx); |
|
237 | + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); |
|
238 | + $pdf->useTemplate($tplidx); |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | - // Create output dir if not exists |
|
243 | - dol_mkdir($diroutputpdf); |
|
242 | + // Create output dir if not exists |
|
243 | + dol_mkdir($diroutputpdf); |
|
244 | 244 | |
245 | - // Save merged file |
|
246 | - $filename=$fileprefix; |
|
247 | - if (empty($filename)) $filename='mergedpdf'; |
|
248 | - if (! empty($filesuffix)) $filename.='_'.$filesuffix; |
|
249 | - $file=$diroutputpdf.'/'.$filename.'.pdf'; |
|
245 | + // Save merged file |
|
246 | + $filename=$fileprefix; |
|
247 | + if (empty($filename)) $filename='mergedpdf'; |
|
248 | + if (! empty($filesuffix)) $filename.='_'.$filesuffix; |
|
249 | + $file=$diroutputpdf.'/'.$filename.'.pdf'; |
|
250 | 250 | |
251 | - if (! $error && $pagecount) |
|
252 | - { |
|
253 | - $pdf->Output($file,'F'); |
|
254 | - if (! empty($conf->global->MAIN_UMASK)) |
|
255 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
256 | - } |
|
251 | + if (! $error && $pagecount) |
|
252 | + { |
|
253 | + $pdf->Output($file,'F'); |
|
254 | + if (! empty($conf->global->MAIN_UMASK)) |
|
255 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
256 | + } |
|
257 | 257 | |
258 | - if ($usestdout) |
|
259 | - { |
|
260 | - if (! $error) print "Merged PDF has been built in ".$file."\n"; |
|
261 | - else print "Can't build PDF ".$file."\n"; |
|
262 | - } |
|
258 | + if ($usestdout) |
|
259 | + { |
|
260 | + if (! $error) print "Merged PDF has been built in ".$file."\n"; |
|
261 | + else print "Can't build PDF ".$file."\n"; |
|
262 | + } |
|
263 | 263 | |
264 | - $result = 1; |
|
265 | - } |
|
266 | - else |
|
267 | - { |
|
268 | - if ($usestdout) print "No invoices found for criteria.\n"; |
|
269 | - else dol_syslog("No invoices found for criteria"); |
|
270 | - $result = 0; |
|
271 | - } |
|
272 | - } |
|
273 | - else |
|
274 | - { |
|
275 | - dol_print_error($db); |
|
276 | - dol_syslog("scripts/invoices/rebuild_merge.php: Error"); |
|
277 | - $error++; |
|
278 | - } |
|
264 | + $result = 1; |
|
265 | + } |
|
266 | + else |
|
267 | + { |
|
268 | + if ($usestdout) print "No invoices found for criteria.\n"; |
|
269 | + else dol_syslog("No invoices found for criteria"); |
|
270 | + $result = 0; |
|
271 | + } |
|
272 | + } |
|
273 | + else |
|
274 | + { |
|
275 | + dol_print_error($db); |
|
276 | + dol_syslog("scripts/invoices/rebuild_merge.php: Error"); |
|
277 | + $error++; |
|
278 | + } |
|
279 | 279 | |
280 | - if ($error) return -1; |
|
281 | - else return $result; |
|
280 | + if ($error) return -1; |
|
281 | + else return $result; |
|
282 | 282 | } |
283 | 283 |
@@ -33,31 +33,31 @@ discard block |
||
33 | 33 | */ |
34 | 34 | function prelevement_prepare_head(BonPrelevement $object) |
35 | 35 | { |
36 | - global $langs, $conf, $user; |
|
37 | - $langs->load("withdrawals"); |
|
36 | + global $langs, $conf, $user; |
|
37 | + $langs->load("withdrawals"); |
|
38 | 38 | |
39 | - $h = 0; |
|
40 | - $head = array(); |
|
39 | + $h = 0; |
|
40 | + $head = array(); |
|
41 | 41 | |
42 | - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$object->id; |
|
43 | - $head[$h][1] = $langs->trans("Card"); |
|
44 | - $head[$h][2] = 'prelevement'; |
|
45 | - $h++; |
|
42 | + $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$object->id; |
|
43 | + $head[$h][1] = $langs->trans("Card"); |
|
44 | + $head[$h][2] = 'prelevement'; |
|
45 | + $h++; |
|
46 | 46 | |
47 | - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id; |
|
48 | - $head[$h][1] = $langs->trans("Bills"); |
|
49 | - $head[$h][2] = 'invoices'; |
|
50 | - $h++; |
|
47 | + $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id; |
|
48 | + $head[$h][1] = $langs->trans("Bills"); |
|
49 | + $head[$h][2] = 'invoices'; |
|
50 | + $h++; |
|
51 | 51 | |
52 | - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$object->id; |
|
53 | - $head[$h][1] = $langs->trans("Rejects"); |
|
54 | - $head[$h][2] = 'rejects'; |
|
55 | - $h++; |
|
52 | + $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$object->id; |
|
53 | + $head[$h][1] = $langs->trans("Rejects"); |
|
54 | + $head[$h][2] = 'rejects'; |
|
55 | + $h++; |
|
56 | 56 | |
57 | - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$object->id; |
|
58 | - $head[$h][1] = $langs->trans("Statistics"); |
|
59 | - $head[$h][2] = 'statistics'; |
|
60 | - $h++; |
|
57 | + $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$object->id; |
|
58 | + $head[$h][1] = $langs->trans("Statistics"); |
|
59 | + $head[$h][2] = 'statistics'; |
|
60 | + $h++; |
|
61 | 61 | |
62 | 62 | // Show more tabs from modules |
63 | 63 | // Entries must be declared in modules descriptor with line |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function prelevement_check_config() |
79 | 79 | { |
80 | - global $conf; |
|
81 | - if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1; |
|
82 | - if(empty($conf->global->PRELEVEMENT_ICS)) return -1; |
|
80 | + global $conf; |
|
81 | + if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1; |
|
82 | + if(empty($conf->global->PRELEVEMENT_ICS)) return -1; |
|
83 | 83 | if(empty($conf->global->PRELEVEMENT_USER)) return -1; |
84 | - return 0; |
|
84 | + return 0; |
|
85 | 85 | } |
86 | 86 |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | return array( |
227 | 227 | "error" => '', |
228 | 228 | "encoding" => $encoding, |
229 | - "bars" => $line, |
|
230 | - "text" => $text |
|
229 | + "bars" => $line, |
|
230 | + "text" => $text |
|
231 | 231 | ); |
232 | 232 | } |
233 | 233 | |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | } |
272 | 272 | //var_dump($bars); |
273 | 273 | $ret=array( |
274 | - "bars" => trim($bars), |
|
275 | - "text" => trim($text), |
|
276 | - "encoding" => trim($encoding), |
|
277 | - "error" => "" |
|
274 | + "bars" => trim($bars), |
|
275 | + "text" => trim($text), |
|
276 | + "encoding" => trim($encoding), |
|
277 | + "error" => "" |
|
278 | 278 | ); |
279 | 279 | //var_dump($ret); |
280 | 280 | if (preg_match('/permission denied/i',$ret['bars'])) |
281 | 281 | { |
282 | - $ret['error']=$ret['bars']; $ret['bars']=''; |
|
283 | - return $ret; |
|
282 | + $ret['error']=$ret['bars']; $ret['bars']=''; |
|
283 | + return $ret; |
|
284 | 284 | } |
285 | 285 | if (!$ret['bars']) return false; |
286 | 286 | if (!$ret['text']) return false; |
@@ -31,25 +31,25 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function accounting_prepare_head(AccountingAccount $object) |
33 | 33 | { |
34 | - global $langs, $conf; |
|
34 | + global $langs, $conf; |
|
35 | 35 | |
36 | - $h = 0; |
|
37 | - $head = array (); |
|
36 | + $h = 0; |
|
37 | + $head = array (); |
|
38 | 38 | |
39 | - $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id; |
|
40 | - $head[$h][1] = $langs->trans("Card"); |
|
41 | - $head[$h][2] = 'card'; |
|
42 | - $h ++; |
|
39 | + $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id; |
|
40 | + $head[$h][1] = $langs->trans("Card"); |
|
41 | + $head[$h][2] = 'card'; |
|
42 | + $h ++; |
|
43 | 43 | |
44 | - // Show more tabs from modules |
|
45 | - // Entries must be declared in modules descriptor with line |
|
46 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
47 | - // $this->tabs = array('entity:-tabname); to remove a tab |
|
48 | - complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account'); |
|
44 | + // Show more tabs from modules |
|
45 | + // Entries must be declared in modules descriptor with line |
|
46 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
47 | + // $this->tabs = array('entity:-tabname); to remove a tab |
|
48 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account'); |
|
49 | 49 | |
50 | - complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove'); |
|
50 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove'); |
|
51 | 51 | |
52 | - return $head; |
|
52 | + return $head; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function clean_account($account) |
62 | 62 | { |
63 | - $account = rtrim($account,"0"); |
|
63 | + $account = rtrim($account,"0"); |
|
64 | 64 | |
65 | - return $account; |
|
65 | + return $account; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -73,31 +73,31 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function length_accountg($account) |
75 | 75 | { |
76 | - global $conf; |
|
76 | + global $conf; |
|
77 | 77 | |
78 | - if ($account < 0 || empty($account)) return ''; |
|
78 | + if ($account < 0 || empty($account)) return ''; |
|
79 | 79 | |
80 | - if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account; |
|
80 | + if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account; |
|
81 | 81 | |
82 | - $g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT; |
|
83 | - if (! empty($g)) { |
|
84 | - // Clean parameters |
|
85 | - $i = strlen($account); |
|
82 | + $g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT; |
|
83 | + if (! empty($g)) { |
|
84 | + // Clean parameters |
|
85 | + $i = strlen($account); |
|
86 | 86 | |
87 | - if ($i >= 1) { |
|
88 | - while ( $i < $g ) { |
|
89 | - $account .= '0'; |
|
87 | + if ($i >= 1) { |
|
88 | + while ( $i < $g ) { |
|
89 | + $account .= '0'; |
|
90 | 90 | |
91 | - $i ++; |
|
92 | - } |
|
91 | + $i ++; |
|
92 | + } |
|
93 | 93 | |
94 | - return $account; |
|
95 | - } else { |
|
96 | - return $account; |
|
97 | - } |
|
98 | - } else { |
|
99 | - return $account; |
|
100 | - } |
|
94 | + return $account; |
|
95 | + } else { |
|
96 | + return $account; |
|
97 | + } |
|
98 | + } else { |
|
99 | + return $account; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -108,31 +108,31 @@ discard block |
||
108 | 108 | */ |
109 | 109 | function length_accounta($accounta) |
110 | 110 | { |
111 | - global $conf, $langs; |
|
111 | + global $conf, $langs; |
|
112 | 112 | |
113 | - if ($accounta < 0 || empty($accounta)) return ''; |
|
113 | + if ($accounta < 0 || empty($accounta)) return ''; |
|
114 | 114 | |
115 | - if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta; |
|
115 | + if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta; |
|
116 | 116 | |
117 | - $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT; |
|
118 | - if (! empty($a)) { |
|
119 | - // Clean parameters |
|
120 | - $i = strlen($accounta); |
|
117 | + $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT; |
|
118 | + if (! empty($a)) { |
|
119 | + // Clean parameters |
|
120 | + $i = strlen($accounta); |
|
121 | 121 | |
122 | - if ($i >= 1) { |
|
123 | - while ( $i < $a ) { |
|
124 | - $accounta .= '0'; |
|
122 | + if ($i >= 1) { |
|
123 | + while ( $i < $a ) { |
|
124 | + $accounta .= '0'; |
|
125 | 125 | |
126 | - $i ++; |
|
127 | - } |
|
126 | + $i ++; |
|
127 | + } |
|
128 | 128 | |
129 | - return $accounta; |
|
130 | - } else { |
|
131 | - return $accounta; |
|
132 | - } |
|
133 | - } else { |
|
134 | - return $accounta; |
|
135 | - } |
|
129 | + return $accounta; |
|
130 | + } else { |
|
131 | + return $accounta; |
|
132 | + } |
|
133 | + } else { |
|
134 | + return $accounta; |
|
135 | + } |
|
136 | 136 | } |
137 | 137 | |
138 | 138 |
@@ -31,70 +31,70 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function resource_prepare_head($object) |
33 | 33 | { |
34 | - global $langs, $conf, $user; |
|
35 | - $h = 0; |
|
36 | - $head = array(); |
|
37 | - |
|
38 | - $head[$h][0] = dol_buildpath('/resource/card.php',1).'?id='.$object->id; |
|
39 | - $head[$h][1] = $langs->trans("ResourceCard"); |
|
40 | - $head[$h][2] = 'resource'; |
|
41 | - $h++; |
|
42 | - |
|
43 | - if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) |
|
44 | - { |
|
45 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
46 | - $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id; |
|
47 | - $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
48 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
49 | - $head[$h][2] = 'contact'; |
|
50 | - $h++; |
|
51 | - } |
|
52 | - |
|
53 | - // Show more tabs from modules |
|
54 | - // Entries must be declared in modules descriptor with line |
|
55 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
56 | - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
57 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'resource'); |
|
58 | - |
|
59 | - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
60 | - { |
|
61 | - $nbNote = 0; |
|
62 | - if(!empty($object->note_private)) $nbNote++; |
|
63 | - if(!empty($object->note_public)) $nbNote++; |
|
64 | - $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id; |
|
65 | - $head[$h][1] = $langs->trans('Notes'); |
|
66 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
67 | - $head[$h][2] = 'note'; |
|
68 | - $h++; |
|
69 | - } |
|
70 | - |
|
71 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
72 | - $upload_dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
73 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
74 | - $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id; |
|
75 | - $head[$h][1] = $langs->trans("Documents"); |
|
76 | - if($nbFiles > 0) $head[$h][1].= ' <span class="badge">'.$nbFiles.'</span>'; |
|
77 | - $head[$h][2] = 'documents'; |
|
78 | - $h++; |
|
79 | - |
|
80 | - $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id; |
|
81 | - $head[$h][1] = $langs->trans("Events"); |
|
82 | - if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
|
83 | - { |
|
84 | - $head[$h][1].= '/'; |
|
85 | - $head[$h][1].= $langs->trans("Agenda"); |
|
86 | - } |
|
87 | - $head[$h][2] = 'agenda'; |
|
88 | - $h++; |
|
89 | - |
|
90 | - /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id; |
|
34 | + global $langs, $conf, $user; |
|
35 | + $h = 0; |
|
36 | + $head = array(); |
|
37 | + |
|
38 | + $head[$h][0] = dol_buildpath('/resource/card.php',1).'?id='.$object->id; |
|
39 | + $head[$h][1] = $langs->trans("ResourceCard"); |
|
40 | + $head[$h][2] = 'resource'; |
|
41 | + $h++; |
|
42 | + |
|
43 | + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) |
|
44 | + { |
|
45 | + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
46 | + $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id; |
|
47 | + $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
48 | + if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
49 | + $head[$h][2] = 'contact'; |
|
50 | + $h++; |
|
51 | + } |
|
52 | + |
|
53 | + // Show more tabs from modules |
|
54 | + // Entries must be declared in modules descriptor with line |
|
55 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
56 | + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
57 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'resource'); |
|
58 | + |
|
59 | + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
60 | + { |
|
61 | + $nbNote = 0; |
|
62 | + if(!empty($object->note_private)) $nbNote++; |
|
63 | + if(!empty($object->note_public)) $nbNote++; |
|
64 | + $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id; |
|
65 | + $head[$h][1] = $langs->trans('Notes'); |
|
66 | + if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
67 | + $head[$h][2] = 'note'; |
|
68 | + $h++; |
|
69 | + } |
|
70 | + |
|
71 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
72 | + $upload_dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
73 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
74 | + $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id; |
|
75 | + $head[$h][1] = $langs->trans("Documents"); |
|
76 | + if($nbFiles > 0) $head[$h][1].= ' <span class="badge">'.$nbFiles.'</span>'; |
|
77 | + $head[$h][2] = 'documents'; |
|
78 | + $h++; |
|
79 | + |
|
80 | + $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id; |
|
81 | + $head[$h][1] = $langs->trans("Events"); |
|
82 | + if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
|
83 | + { |
|
84 | + $head[$h][1].= '/'; |
|
85 | + $head[$h][1].= $langs->trans("Agenda"); |
|
86 | + } |
|
87 | + $head[$h][2] = 'agenda'; |
|
88 | + $h++; |
|
89 | + |
|
90 | + /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id; |
|
91 | 91 | $head[$h][1] = $langs->trans('Info'); |
92 | 92 | $head[$h][2] = 'info'; |
93 | 93 | $h++;*/ |
94 | 94 | |
95 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'resource', 'remove'); |
|
95 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'resource', 'remove'); |
|
96 | 96 | |
97 | - return $head; |
|
97 | + return $head; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -105,28 +105,28 @@ discard block |
||
105 | 105 | function resource_admin_prepare_head() |
106 | 106 | { |
107 | 107 | |
108 | - global $langs, $conf, $user; |
|
108 | + global $langs, $conf, $user; |
|
109 | 109 | |
110 | - $h = 0; |
|
111 | - $head = array(); |
|
110 | + $h = 0; |
|
111 | + $head = array(); |
|
112 | 112 | |
113 | - $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php'; |
|
114 | - $head[$h][1] = $langs->trans("ResourceSetup"); |
|
115 | - $head[$h][2] = 'general'; |
|
116 | - $h++; |
|
113 | + $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php'; |
|
114 | + $head[$h][1] = $langs->trans("ResourceSetup"); |
|
115 | + $head[$h][2] = 'general'; |
|
116 | + $h++; |
|
117 | 117 | |
118 | - // Show more tabs from modules |
|
119 | - // Entries must be declared in modules descriptor with line |
|
120 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
121 | - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
122 | - complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin'); |
|
118 | + // Show more tabs from modules |
|
119 | + // Entries must be declared in modules descriptor with line |
|
120 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
121 | + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
122 | + complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin'); |
|
123 | 123 | |
124 | - $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php'; |
|
125 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
126 | - $head[$h][2] = 'attributes'; |
|
127 | - $h++; |
|
124 | + $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php'; |
|
125 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
126 | + $head[$h][2] = 'attributes'; |
|
127 | + $h++; |
|
128 | 128 | |
129 | - complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin','remove'); |
|
129 | + complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin','remove'); |
|
130 | 130 | |
131 | - return $head; |
|
131 | + return $head; |
|
132 | 132 | } |